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

Remove some bad link warnings #1161

Merged
merged 2 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions haddock-api/src/Haddock/Interface/Create.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Haddock.Interface.LexParseRn
import Data.Bifunctor
import Data.Bitraversable
import qualified Data.Map as M
import qualified Data.Set as S
import Data.Map (Map)
import Data.List (find, foldl', sortBy)
import Data.Maybe
Expand Down Expand Up @@ -165,6 +166,18 @@ createInterface tm flags modMap instIfaceMap = do

modWarn <- liftErrMsg (moduleWarning dflags gre warnings)

-- Prune the docstring 'Map's to keep only docstrings that are not private.
--
-- Besides all the names that GHC has told us this module exports, we also
-- keep the docs for locally defined class instances. This is more names than
-- we need, but figuring out which instances are fully private is tricky.
--
-- We do this pruning to avoid having to rename, emit warnings, and save
-- docstrings which will anyways never be rendered.
let !localVisibleNames = S.fromList (localInsts ++ exportedNames)
!prunedDocMap = M.restrictKeys docMap localVisibleNames
!prunedArgMap = M.restrictKeys argMap localVisibleNames

return $! Interface {
ifaceMod = mdl
, ifaceIsSig = is_sig
Expand All @@ -173,12 +186,12 @@ createInterface tm flags modMap instIfaceMap = do
, ifaceDoc = Documentation mbDoc modWarn
, ifaceRnDoc = Documentation Nothing Nothing
, ifaceOptions = opts
, ifaceDocMap = docMap
, ifaceArgMap = argMap
, ifaceRnDocMap = M.empty
, ifaceRnArgMap = M.empty
, ifaceDocMap = prunedDocMap
, ifaceArgMap = prunedArgMap
, ifaceRnDocMap = M.empty -- Filled in `renameInterface`
, ifaceRnArgMap = M.empty -- Filled in `renameInterface`
, ifaceExportItems = prunedExportItems
, ifaceRnExportItems = []
, ifaceRnExportItems = [] -- Filled in `renameInterface`
, ifaceExports = exportedNames
, ifaceVisibleExports = visibleNames
, ifaceDeclMap = declMap
Expand Down
15 changes: 14 additions & 1 deletion haddock-api/src/Haddock/Interface/Rename.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ import Control.Monad hiding (mapM)
import qualified Data.Map as Map hiding ( Map )
import Prelude hiding (mapM)

-- | Traverse docstrings and ASTs in the Haddock interface, renaming 'Name' to
-- 'DocName'.
--
-- What this really boils down to is: for each 'Name', figure out which of the
-- modules that export the name is the preferred place to link to.
--
-- The renamed output gets written into fields in the Haddock interface record
-- that were previously left empty.
renameInterface :: DynFlags -> LinkEnv -> Bool -> Interface -> ErrMsgM Interface
renameInterface dflags renamingEnv warnings iface =

Expand Down Expand Up @@ -128,6 +136,11 @@ lookupRn name = RnM $ \lkp ->
(False,maps_to) -> (maps_to, (name :))
(True, maps_to) -> (maps_to, id)

-- | Look up a 'Name' in the renaming environment, but don't warn if you don't
-- find the name. Prefer to use 'lookupRn' whenever possible.
lookupRnNoWarn :: Name -> RnM DocName
lookupRnNoWarn name = RnM $ \lkp -> (snd (lkp name), id)

-- | Run the renamer action using lookup in a 'LinkEnv' as the lookup function.
-- Returns the renamed value along with a list of `Name`'s that could not be
-- renamed because they weren't in the environment.
Expand Down Expand Up @@ -532,7 +545,7 @@ renameSig sig = case sig of
lnames' <- mapM renameL lnames
return $ FixSig noExtField (FixitySig noExtField lnames' fixity)
MinimalSig _ src (L l s) -> do
s' <- traverse renameL s
s' <- traverse (traverse lookupRnNoWarn) s
return $ MinimalSig noExtField src (L l s')
-- we have filtered out all other kinds of signatures in Interface.Create
_ -> error "expected TypeSig"
Expand Down