Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit fb91c0f

Browse files
committed
Prune docstrings that are never rendered
When first creating a Haddock interface, trim `ifaceDocMap` and `ifaceArgMap` to not include docstrings that can never appear in the final output. Besides checking with GHC which names are exported, we also need to keep all the docs attached to instance declarations (it is much tougher to detect when an instance is fully private). This change means: * slightly smaller interface files (7% reduction on boot libs) * slightly less work to do processing docstrings that aren't used * no warnings in Haddock's output about private docstrings (see #1070) I've tested manually that this does not affect any of the boot library generated docs (the only change in output was some small re-ordering in a handful of instance lists). This should mean no docstrings have been incorrectly dropped.
1 parent d8aaaba commit fb91c0f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

haddock-api/src/Haddock/Interface/Create.hs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Haddock.Interface.LexParseRn
3131
import Data.Bifunctor
3232
import Data.Bitraversable
3333
import qualified Data.Map as M
34+
import qualified Data.Set as S
3435
import Data.Map (Map)
3536
import Data.List (find, foldl', sortBy)
3637
import Data.Maybe
@@ -165,6 +166,18 @@ createInterface tm flags modMap instIfaceMap = do
165166

166167
modWarn <- liftErrMsg (moduleWarning dflags gre warnings)
167168

169+
-- Prune the docstring 'Map's to keep only docstrings that are not private.
170+
--
171+
-- Besides all the names that GHC has told us this module exports, we also
172+
-- keep the docs for locally defined class instances. This is more names than
173+
-- we need, but figuring out which instances are fully private is tricky.
174+
--
175+
-- We do this pruning to avoid having to rename, emit warnings, and save
176+
-- docstrings which will anyways never be rendered.
177+
let !localVisibleNames = S.fromList (localInsts ++ exportedNames)
178+
!prunedDocMap = M.restrictKeys docMap localVisibleNames
179+
!prunedArgMap = M.restrictKeys argMap localVisibleNames
180+
168181
return $! Interface {
169182
ifaceMod = mdl
170183
, ifaceIsSig = is_sig
@@ -173,8 +186,8 @@ createInterface tm flags modMap instIfaceMap = do
173186
, ifaceDoc = Documentation mbDoc modWarn
174187
, ifaceRnDoc = Documentation Nothing Nothing
175188
, ifaceOptions = opts
176-
, ifaceDocMap = docMap
177-
, ifaceArgMap = argMap
189+
, ifaceDocMap = prunedDocMap
190+
, ifaceArgMap = prunedArgMap
178191
, ifaceRnDocMap = M.empty
179192
, ifaceRnArgMap = M.empty
180193
, ifaceExportItems = prunedExportItems

0 commit comments

Comments
 (0)