[Git][ghc/ghc][master] 2 commits: haddock: Keep track of warnings/deprecations from dependent packages in `InstalledInterface`
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Mon Jul 15 16:13:08 UTC 2024
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
0b4ff9fa by Zubin Duggal at 2024-07-15T12:12:30-04:00
haddock: Keep track of warnings/deprecations from dependent packages in `InstalledInterface`
and use this to propagate these on items re-exported from dependent packages.
Fixes #25037
- - - - -
b8b4b212 by Zubin Duggal at 2024-07-15T12:12:30-04:00
haddock: Keep track of instance source locations in `InstalledInterface` and use this to add
source locations on out of package instances
Fixes #24929
- - - - -
7 changed files:
- utils/haddock/haddock-api/src/Haddock.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs
- utils/haddock/haddock-api/src/Haddock/Interface.hs
- utils/haddock/haddock-api/src/Haddock/Interface/AttachInstances.hs
- utils/haddock/haddock-api/src/Haddock/Interface/Create.hs
- utils/haddock/haddock-api/src/Haddock/InterfaceFile.hs
- utils/haddock/haddock-api/src/Haddock/Types.hs
Changes:
=====================================
utils/haddock/haddock-api/src/Haddock.hs
=====================================
@@ -438,16 +438,17 @@ render dflags languagesAndExtensions parserOpts logger unit_state flags sinceQua
= Map.insert k srcNameUrl pkgSrcMap
| otherwise = pkgSrcMap
+ pkgSrcLMap = Map.map (hypSrcModuleUrlToLineFormat . hypSrcPkgUrlToModuleFormat)
+ $ Map.mapKeys moduleUnit extSrcMap
-- These urls have a template for the module %M and the line %L
- -- TODO: Get these from the interface files as with srcMap
pkgSrcLMap'
| Flag_HyperlinkedSource `elem` flags
, Just k <- pkgKey
- = Map.singleton k hypSrcModuleLineUrlFormat
+ = Map.insert k hypSrcModuleLineUrlFormat pkgSrcLMap
| Just path <- srcLEntity
, Just k <- pkgKey
- = Map.singleton k path
- | otherwise = Map.empty
+ = Map.insert k path pkgSrcLMap
+ | otherwise = pkgSrcLMap
sourceUrls' = (srcBase, srcModule', pkgSrcMap', pkgSrcLMap')
=====================================
utils/haddock/haddock-api/src/Haddock/Backends/Hyperlinker/Utils.hs
=====================================
@@ -14,6 +14,7 @@ module Haddock.Backends.Hyperlinker.Utils
, hypSrcModuleNameUrlFormat
, hypSrcModuleLineUrlFormat
, hypSrcModuleUrlToNameFormat
+ , hypSrcModuleUrlToLineFormat
, hypSrcPkgUrlToModuleFormat
, spliceURL
, spliceURL'
@@ -86,6 +87,9 @@ hypSrcModuleLineUrlFormat = hypSrcModuleUrlFormat ++ "#" ++ lineFormat
hypSrcModuleUrlToNameFormat :: String -> String
hypSrcModuleUrlToNameFormat url = url ++ "#" ++ nameFormat
+hypSrcModuleUrlToLineFormat :: String -> String
+hypSrcModuleUrlToLineFormat url = url ++ "#" ++ lineFormat
+
hypSrcPkgUrlToModuleFormat :: String -> String
hypSrcPkgUrlToModuleFormat url = url </> moduleFormat
=====================================
utils/haddock/haddock-api/src/Haddock/Interface.hs
=====================================
@@ -240,25 +240,28 @@ createIfaces verbosity modules flags instIfaceMap = do
-- Visit modules in that order
sortedMods = concatMap go $ topSortModuleGraph False modGraph Nothing
out verbosity normal "Haddock coverage:"
- (ifaces, _) <- foldM f ([], Map.empty) sortedMods
+ let inst_warning_map = Map.unions $ map instWarningMap (Map.elems instIfaceMap)
+ (ifaces, _, _) <- foldM f ([], Map.empty, inst_warning_map) sortedMods
return (reverse ifaces)
where
- f (ifaces, ifaceMap) modSummary = do
+ f (ifaces, ifaceMap, warningMap) modSummary = do
x <- {-# SCC processModule #-}
withTimingM "processModule" (const ()) $ do
- processModule verbosity modSummary flags ifaceMap instIfaceMap
+ processModule verbosity modSummary flags ifaceMap instIfaceMap warningMap
return $ case x of
Just iface -> ( iface:ifaces
- , Map.insert (ifaceMod iface) iface ifaceMap )
+ , Map.insert (ifaceMod iface) iface ifaceMap
+ , Map.union (ifaceWarningMap iface) warningMap)
Nothing -> ( ifaces
- , ifaceMap ) -- Boot modules don't generate ifaces.
+ , ifaceMap
+ , warningMap ) -- Boot modules don't generate ifaces.
dropErr :: MaybeErr e a -> Maybe a
dropErr (Succeeded a) = Just a
dropErr (Failed _) = Nothing
-processModule :: Verbosity -> ModSummary -> [Flag] -> IfaceMap -> InstIfaceMap -> Ghc (Maybe Interface)
-processModule verbosity modSummary flags ifaceMap instIfaceMap = do
+processModule :: Verbosity -> ModSummary -> [Flag] -> IfaceMap -> InstIfaceMap -> WarningMap -> Ghc (Maybe Interface)
+processModule verbosity modSummary flags ifaceMap instIfaceMap warningMap = do
out verbosity verbose $ "Checking module " ++ moduleString (ms_mod modSummary) ++ "..."
hsc_env <- getSession
@@ -281,7 +284,7 @@ processModule verbosity modSummary flags ifaceMap instIfaceMap = do
{-# SCC createInterface #-}
withTiming logger "createInterface" (const ()) $
runIfM (liftIO . fmap dropErr . lookupGlobal_maybe hsc_env) $
- createInterface1 flags unit_state modSummary mod_iface ifaceMap instIfaceMap insts
+ createInterface1 flags unit_state modSummary mod_iface ifaceMap instIfaceMap insts warningMap
let
(haddockable, haddocked) =
@@ -387,13 +390,13 @@ createOneShotIface verbosity flags instIfaceMap moduleNameStr = do
let hieFilePath = case res of
Found ml _ -> ml_hie_file ml
_ -> throwE "createOneShotIface: module not found"
-
+ let inst_warning_map = Map.unions $ map instWarningMap (Map.elems instIfaceMap)
!interface <- do
logger <- getLogger
{-# SCC createInterface #-}
withTiming logger "createInterface" (const ()) $
runIfM (liftIO . fmap dropErr . lookupGlobal_maybe hsc_env) $
- createInterface1' flags (hsc_units hsc_env) dflags' hieFilePath iface mempty instIfaceMap insts
+ createInterface1' flags (hsc_units hsc_env) dflags' hieFilePath iface mempty instIfaceMap insts inst_warning_map
pure [interface]
=====================================
utils/haddock/haddock-api/src/Haddock/Interface/AttachInstances.hs
=====================================
@@ -143,10 +143,11 @@ attachInstances expInfo ifaces instIfaceMap isOneShot = do
attach (cls_insts, fam_insts, inst_map) iface = do
let getInstDoc = findInstDoc iface ifaceMap instIfaceMap
getFixity = findFixity iface ifaceMap instIfaceMap
+ getInstLocIface name = Map.lookup name . instInstanceLocMap =<< Map.lookup (nameModule name) instIfaceMap
newItems <-
mapM
- (attachToExportItem cls_insts fam_insts inst_map expInfo getInstDoc getFixity)
+ (attachToExportItem cls_insts fam_insts inst_map expInfo getInstDoc getFixity getInstLocIface)
(ifaceExportItems iface)
let orphanInstances = attachOrphanInstances expInfo getInstDoc (ifaceInstances iface) fam_insts
return $
@@ -184,9 +185,11 @@ attachToExportItem
-- ^ how to lookup the doc of an instance
-> (Name -> Maybe Fixity)
-- ^ how to lookup a fixity
+ -> (Name -> Maybe RealSrcSpan)
+ -- ^ how to lookup definition spans for instances
-> ExportItem GhcRn
-> Ghc (ExportItem GhcRn)
-attachToExportItem cls_index fam_index index expInfo getInstDoc getFixity export =
+attachToExportItem cls_index fam_index index expInfo getInstDoc getFixity getInstLocIface export =
case attachFixities export of
ExportDecl e@(ExportD{expDDecl = L eSpan (TyClD _ d)}) -> do
insts <-
@@ -267,12 +270,17 @@ attachToExportItem cls_index fam_index index expInfo getInstDoc getFixity export
-- spanName: attach the location to the name that is the same file as the instance location
spanName s (InstHead{ihdClsName = clsn}) (L instL instn) =
- let s1 = getSrcSpan s
+ let s1 = let orig_span = getSrcSpan s
+ in if isGoodSrcSpan orig_span
+ then orig_span
+ else case getInstLocIface s of
+ Nothing -> orig_span
+ Just rs -> RealSrcSpan rs mempty
sn =
if srcSpanFileName_maybe s1 == srcSpanFileName_maybe instL
then instn
else clsn
- in L (getSrcSpan s) sn
+ in L s1 sn
-- spanName on Either
spanNameE s (Left e) _ = L (getSrcSpan s) (Left e)
spanNameE s (Right ok) linst =
=====================================
utils/haddock/haddock-api/src/Haddock/Interface/Create.hs
=====================================
@@ -83,8 +83,9 @@ createInterface1
-> IfaceMap
-> InstIfaceMap
-> ([ClsInst], [FamInst])
+ -> WarningMap
-> IfM m Interface
-createInterface1 flags unit_state mod_sum mod_iface ifaces inst_ifaces (instances, fam_instances) =
+createInterface1 flags unit_state mod_sum mod_iface ifaces inst_ifaces (instances, fam_instances) depWarnings =
let
ModSummary
{ -- Cached flags from OPTIONS, INCLUDE and LANGUAGE
@@ -94,7 +95,7 @@ createInterface1 flags unit_state mod_sum mod_iface ifaces inst_ifaces (instance
, ms_location = modl
} = mod_sum
in
- createInterface1' flags unit_state ms_hspp_opts (ml_hie_file modl) mod_iface ifaces inst_ifaces (instances, fam_instances)
+ createInterface1' flags unit_state ms_hspp_opts (ml_hie_file modl) mod_iface ifaces inst_ifaces (instances, fam_instances) depWarnings
createInterface1'
:: MonadIO m
@@ -106,8 +107,9 @@ createInterface1'
-> IfaceMap
-> InstIfaceMap
-> ([ClsInst], [FamInst])
+ -> WarningMap
-> IfM m Interface
-createInterface1' flags unit_state dflags hie_file mod_iface ifaces inst_ifaces (instances, fam_instances) = do
+createInterface1' flags unit_state dflags hie_file mod_iface ifaces inst_ifaces (instances, fam_instances) depWarnings = do
let
sDocContext = DynFlags.initSDocContext dflags Outputable.defaultUserStyle
mLanguage = language dflags
@@ -205,7 +207,7 @@ createInterface1' flags unit_state dflags hie_file mod_iface ifaces inst_ifaces
let
-- Warnings in this module and transitive warnings from dependent modules
transitiveWarnings :: Map Name (Doc Name)
- transitiveWarnings = Map.unions (warningMap : map ifaceWarningMap (Map.elems ifaces))
+ transitiveWarnings = Map.union warningMap depWarnings
export_items <-
mkExportItems
=====================================
utils/haddock/haddock-api/src/Haddock/InterfaceFile.hs
=====================================
@@ -36,6 +36,7 @@ module Haddock.InterfaceFile
, binaryInterfaceVersionCompatibility
) where
+import Data.Coerce (coerce)
import Data.Function ((&))
import Data.IORef
import Data.Map (Map)
@@ -366,6 +367,8 @@ instance Binary InstalledInterface where
visExps
opts
fixMap
+ warnMap
+ locMap
) = do
put_ bh modu
put_ bh is_sig
@@ -376,6 +379,8 @@ instance Binary InstalledInterface where
put_ bh visExps
put_ bh opts
put_ bh fixMap
+ put_ bh warnMap
+ put_ bh (coerce @_ @(Map Name BinSpan) locMap)
get bh = do
modu <- get bh
@@ -387,6 +392,8 @@ instance Binary InstalledInterface where
visExps <- get bh
opts <- get bh
fixMap <- get bh
+ warnMap <- get bh
+ locMap <- get bh
return
( InstalledInterface
modu
@@ -399,6 +406,8 @@ instance Binary InstalledInterface where
visExps
opts
fixMap
+ warnMap
+ (coerce @(Map Name BinSpan) locMap)
)
instance Binary DocOption where
=====================================
utils/haddock/haddock-api/src/Haddock/Types.hs
=====================================
@@ -48,16 +48,18 @@ import Control.Monad.Catch
import Control.Monad.State.Strict
import Data.Data (Data)
import Data.Map (Map)
+import qualified Data.Map as Map
import qualified Data.Set as Set
import GHC
import qualified GHC.Data.Strict as Strict
import GHC.Driver.Session (Language)
import qualified GHC.LanguageExtensions as LangExt
+import GHC.Core.InstEnv (is_dfun_name)
import GHC.Types.Fixity (Fixity (..))
import GHC.Types.Name (stableNameCmp)
import GHC.Types.Name.Occurrence
import GHC.Types.Name.Reader (RdrName (..))
-import GHC.Types.SrcLoc (BufPos (..), BufSpan (..))
+import GHC.Types.SrcLoc (BufPos (..), BufSpan (..), srcSpanToRealSrcSpan)
import GHC.Types.Var (Specificity)
import GHC.Utils.Outputable
@@ -166,6 +168,8 @@ data InstalledInterface = InstalledInterface
, instOptions :: [DocOption]
-- ^ Haddock options for this module (prune, ignore-exports, etc).
, instFixMap :: Map Name Fixity
+ , instWarningMap :: WarningMap
+ , instInstanceLocMap :: Map Name RealSrcSpan
}
-- | Convert an 'Interface' to an 'InstalledInterface'
@@ -182,6 +186,8 @@ toInstalledIface interface =
, instOptions = interface.ifaceOptions
, instFixMap = interface.ifaceFixMap
, instDefMeths = interface.ifaceDefMeths
+ , instWarningMap = interface.ifaceWarningMap
+ , instInstanceLocMap = Map.fromList [(inst_name, loc) | i <- interface.ifaceInstances, let inst_name = is_dfun_name i, Just loc <- [srcSpanToRealSrcSpan (nameSrcSpan inst_name)]]
}
-- | A monad in which we create Haddock interfaces. Not to be confused with
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/84dadea9df46f11e2847a324d8c3ae0af936f5fd...b8b4b212ba2721fecba6ddce3b274e6f7c59630e
--
This project does not include diff previews in email notifications.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/84dadea9df46f11e2847a324d8c3ae0af936f5fd...b8b4b212ba2721fecba6ddce3b274e6f7c59630e
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240715/74f34660/attachment-0001.html>
More information about the ghc-commits
mailing list