Hannes Siebenhandl pushed to branch wip/fendor/external-unit-db-cache at Glasgow Haskell Compiler / GHC
Commits:
-
7f764864
by fendor at 2026-06-16T17:03:36+02:00
9 changed files:
- compiler/GHC.hs
- compiler/GHC/Driver/Backpack.hs
- compiler/GHC/Driver/Env.hs
- compiler/GHC/Driver/Session/Units.hs
- compiler/GHC/Unit/Env.hs
- compiler/GHC/Unit/State.hs
- ghc/GHCi/UI.hs
- libraries/ghc-boot/GHC/Unit/Database.hs
- utils/haddock/haddock-api/src/Haddock.hs
Changes:
| ... | ... | @@ -671,7 +671,7 @@ setUnitDynFlagsNoCheck uid dflags1 = do |
| 671 | 671 | logger <- getLogger
|
| 672 | 672 | hsc_env <- getSession
|
| 673 | 673 | |
| 674 | - (unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags1 (hscEUDC hsc_env) (hsc_all_home_unit_ids hsc_env)
|
|
| 674 | + (unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags1 (hsc_unit_index hsc_env) (hscEUDC hsc_env) (hsc_all_home_unit_ids hsc_env)
|
|
| 675 | 675 | updated_dflags <- liftIO $ updatePlatformConstants dflags1 mconstants
|
| 676 | 676 | |
| 677 | 677 | let upd hue =
|
| ... | ... | @@ -760,7 +760,7 @@ setProgramDynFlags_ invalidate_needed dflags = do |
| 760 | 760 | old_hpt = homeUnitEnv_hpt homeUnitEnv
|
| 761 | 761 | home_units = HUG.allUnits (ue_home_unit_graph old_unit_env)
|
| 762 | 762 | |
| 763 | - (unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags (ue_eud old_unit_env) home_units
|
|
| 763 | + (unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags (ue_unit_index old_unit_env) (ue_eud old_unit_env) home_units
|
|
| 764 | 764 | |
| 765 | 765 | updated_dflags <- liftIO $ updatePlatformConstants dflags0 mconstants
|
| 766 | 766 | pure HomeUnitEnv
|
| ... | ... | @@ -779,6 +779,7 @@ setProgramDynFlags_ invalidate_needed dflags = do |
| 779 | 779 | , ue_module_graph = ue_module_graph old_unit_env
|
| 780 | 780 | , ue_eps = ue_eps old_unit_env
|
| 781 | 781 | , ue_eud = ue_eud old_unit_env
|
| 782 | + , ue_unit_index = ue_unit_index old_unit_env
|
|
| 782 | 783 | }
|
| 783 | 784 | modifySession $ \h -> hscSetFlags dflags1 h{ hsc_unit_env = unit_env }
|
| 784 | 785 | else modifySession (hscSetFlags dflags0)
|
| ... | ... | @@ -837,6 +838,7 @@ setProgramHUG_ invalidate_needed new_hug0 = do |
| 837 | 838 | , ue_eps = ue_eps unit_env0
|
| 838 | 839 | , ue_module_graph = ue_module_graph unit_env0
|
| 839 | 840 | , ue_eud = ue_eud unit_env0
|
| 841 | + , ue_unit_index = ue_unit_index unit_env0
|
|
| 840 | 842 | }
|
| 841 | 843 | modifySession $ \h ->
|
| 842 | 844 | -- hscSetFlags takes care of updating the logger as well.
|
| ... | ... | @@ -884,7 +886,7 @@ setProgramHUG_ invalidate_needed new_hug0 = do |
| 884 | 886 | old_hpt = homeUnitEnv_hpt homeUnitEnv
|
| 885 | 887 | home_units = HUG.allUnits (ue_home_unit_graph unit_env)
|
| 886 | 888 | |
| 887 | - (unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags (ue_eud unit_env) home_units
|
|
| 889 | + (unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags (ue_unit_index unit_env) (ue_eud unit_env) home_units
|
|
| 888 | 890 | |
| 889 | 891 | updated_dflags <- liftIO $ updatePlatformConstants dflags mconstants
|
| 890 | 892 | pure HomeUnitEnv
|
| ... | ... | @@ -175,6 +175,8 @@ withBkpSession :: UnitId |
| 175 | 175 | -> BkpM a
|
| 176 | 176 | withBkpSession cid insts deps session_type do_this = do
|
| 177 | 177 | dflags <- getDynFlags
|
| 178 | + env <- getSession
|
|
| 179 | + unitIndex <- liftIO $ hscUnitIndex env
|
|
| 178 | 180 | let cid_fs = unitFS cid
|
| 179 | 181 | is_primary = False
|
| 180 | 182 | uid_str = unpackFS (mkInstantiatedUnitHash cid insts)
|
| ... | ... | @@ -194,8 +196,8 @@ withBkpSession cid insts deps session_type do_this = do |
| 194 | 196 | | otherwise = sub_comp (key_base p)
|
| 195 | 197 | |
| 196 | 198 | mk_temp_env hsc_env =
|
| 197 | - hscUpdateFlags (\dflags -> mk_temp_dflags (hsc_units hsc_env) dflags) hsc_env
|
|
| 198 | - mk_temp_dflags unit_state dflags = dflags
|
|
| 199 | + hscUpdateFlags (\dflags -> mk_temp_dflags unitIndex (hsc_units hsc_env) dflags) hsc_env
|
|
| 200 | + mk_temp_dflags unit_index unit_state dflags = dflags
|
|
| 199 | 201 | { backend = case session_type of
|
| 200 | 202 | TcSession -> noBackend
|
| 201 | 203 | _ -> backend dflags
|
| ... | ... | @@ -242,7 +244,7 @@ withBkpSession cid insts deps session_type do_this = do |
| 242 | 244 | , importPaths = []
|
| 243 | 245 | -- Synthesize the flags
|
| 244 | 246 | , packageFlags = packageFlags dflags ++ map (\(uid0, rn) ->
|
| 245 | - let uid = unwireUnit unit_state
|
|
| 247 | + let uid = unwireUnit unit_index
|
|
| 246 | 248 | $ renameHoleUnit unit_state (listToUFM insts) uid0
|
| 247 | 249 | in ExposePackage
|
| 248 | 250 | (showSDoc dflags
|
| ... | ... | @@ -349,9 +351,9 @@ buildUnit session cid insts lunit = do |
| 349 | 351 | | otherwise
|
| 350 | 352 | = [Nothing]
|
| 351 | 353 | linkables <- liftIO $ catMaybes <$> concatHpt takeLinkables (hsc_HPT hsc_env)
|
| 354 | + unit_index <- liftIO $ hscUnitIndex hsc_env
|
|
| 352 | 355 | let
|
| 353 | 356 | obj_files = concatMap linkableFiles linkables
|
| 354 | - state = hsc_units hsc_env
|
|
| 355 | 357 | |
| 356 | 358 | compat_fs = unitIdFS cid
|
| 357 | 359 | compat_pn = PackageName compat_fs
|
| ... | ... | @@ -377,7 +379,7 @@ buildUnit session cid insts lunit = do |
| 377 | 379 | -- really used for anything, so we leave it
|
| 378 | 380 | -- blank for now.
|
| 379 | 381 | TcSession -> []
|
| 380 | - _ -> map (toUnitId . unwireUnit state)
|
|
| 382 | + _ -> map (toUnitId . unwireUnit unit_index)
|
|
| 381 | 383 | $ deps ++ [ moduleUnit mod
|
| 382 | 384 | | (_, mod) <- insts
|
| 383 | 385 | , not (isHoleModule mod) ],
|
| ... | ... | @@ -449,7 +451,7 @@ addUnit u = do |
| 449 | 451 | { packageDBFlags = packageDBFlags dflags0 ++ [PackageDB (PkgDbPath (unitDatabasePath newdb))]
|
| 450 | 452 | }
|
| 451 | 453 | |
| 452 | - (unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags1 eud (hsc_all_home_unit_ids hsc_env)
|
|
| 454 | + (unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags1 (ue_unit_index old_unit_env) eud (hsc_all_home_unit_ids hsc_env)
|
|
| 453 | 455 | |
| 454 | 456 | |
| 455 | 457 | -- update platform constants
|
| ... | ... | @@ -467,6 +469,7 @@ addUnit u = do |
| 467 | 469 | , ue_eps = ue_eps old_unit_env
|
| 468 | 470 | , ue_module_graph = ue_module_graph old_unit_env
|
| 469 | 471 | , ue_eud = ue_eud old_unit_env
|
| 472 | + , ue_unit_index = ue_unit_index old_unit_env
|
|
| 470 | 473 | }
|
| 471 | 474 | setSession $ hscSetFlags dflags $ hsc_env { hsc_unit_env = unit_env }
|
| 472 | 475 |
| ... | ... | @@ -13,6 +13,8 @@ module GHC.Driver.Env |
| 13 | 13 | , hsc_HUE
|
| 14 | 14 | , hsc_HUG
|
| 15 | 15 | , hsc_all_home_unit_ids
|
| 16 | + , hscUnitIndex
|
|
| 17 | + , hsc_unit_index
|
|
| 16 | 18 | , hscUpdateLoggerFlags
|
| 17 | 19 | , hscUpdateHUG
|
| 18 | 20 | , hscInsertHPT
|
| ... | ... | @@ -230,6 +232,12 @@ hscEUD = readExternalUnitDatabases . hscEUDC |
| 230 | 232 | hscEUDC :: HscEnv -> ExternalUnitDatabaseCache UnitId
|
| 231 | 233 | hscEUDC hsc_env = ue_eud (hsc_unit_env hsc_env)
|
| 232 | 234 | |
| 235 | +hscUnitIndex :: HscEnv -> IO UnitIndex
|
|
| 236 | +hscUnitIndex hsc_env = readIORef $ ue_unit_index (hsc_unit_env hsc_env)
|
|
| 237 | + |
|
| 238 | +hsc_unit_index :: HscEnv -> IORef UnitIndex
|
|
| 239 | +hsc_unit_index hsc_env = ue_unit_index (hsc_unit_env hsc_env)
|
|
| 240 | + |
|
| 233 | 241 | --------------------------------------------------------------------------------
|
| 234 | 242 | -- * Queries on Transitive Closure
|
| 235 | 243 | --------------------------------------------------------------------------------
|
| ... | ... | @@ -131,7 +131,7 @@ initMulti unitArgsFiles lintDynFlagsAndSrcs = do |
| 131 | 131 | home_unit_graph <- forM initial_home_graph $ \homeUnitEnv -> do
|
| 132 | 132 | let hue_flags = homeUnitEnv_dflags homeUnitEnv
|
| 133 | 133 | dflags = homeUnitEnv_dflags homeUnitEnv
|
| 134 | - (unit_state,home_unit,mconstants) <- liftIO $ State.initUnits logger hue_flags (hscEUDC hsc_env) home_units
|
|
| 134 | + (unit_state,home_unit,mconstants) <- liftIO $ State.initUnits logger hue_flags (hsc_unit_index hsc_env) (hscEUDC hsc_env) home_units
|
|
| 135 | 135 | |
| 136 | 136 | updated_dflags <- liftIO $ updatePlatformConstants dflags mconstants
|
| 137 | 137 | emptyHpt <- liftIO $ emptyHomePackageTable
|
| ... | ... | @@ -131,6 +131,7 @@ import GHC.Types.Annotations |
| 131 | 131 | import GHC.Types.CompleteMatch
|
| 132 | 132 | import GHC.Core.InstEnv
|
| 133 | 133 | import GHC.Core.FamInstEnv
|
| 134 | +import Data.IORef
|
|
| 134 | 135 | |
| 135 | 136 | --------------------------------------------------------------------------------
|
| 136 | 137 | -- The hard queries
|
| ... | ... | @@ -177,6 +178,8 @@ data UnitEnv = UnitEnv |
| 177 | 178 | |
| 178 | 179 | , ue_eud :: {-# UNPACK #-} !(ExternalUnitDatabaseCache UnitId)
|
| 179 | 180 | -- TODO: @fendor Docs
|
| 181 | + , ue_unit_index :: {-# UNPACK #-} !(IORef UnitIndex)
|
|
| 182 | + -- TODO: @fendor Docs
|
|
| 180 | 183 | }
|
| 181 | 184 | |
| 182 | 185 | ueEPS :: UnitEnv -> IO ExternalPackageState
|
| ... | ... | @@ -186,6 +189,7 @@ initUnitEnv :: UnitId -> HomeUnitGraph -> GhcNameVersion -> Platform -> IO UnitE |
| 186 | 189 | initUnitEnv cur_unit hug namever platform = do
|
| 187 | 190 | eps <- initExternalUnitCache
|
| 188 | 191 | eud <- initExternalUnitDatabaseCache
|
| 192 | + unit_index <- newIORef (initUnitIndex)
|
|
| 189 | 193 | return $ UnitEnv
|
| 190 | 194 | { ue_eps = eps
|
| 191 | 195 | , ue_home_unit_graph = hug
|
| ... | ... | @@ -194,6 +198,7 @@ initUnitEnv cur_unit hug namever platform = do |
| 194 | 198 | , ue_platform = platform
|
| 195 | 199 | , ue_namever = namever
|
| 196 | 200 | , ue_eud = eud
|
| 201 | + , ue_unit_index = unit_index
|
|
| 197 | 202 | }
|
| 198 | 203 | |
| 199 | 204 | updateHug :: (HomeUnitGraph -> HomeUnitGraph) -> UnitEnv -> UnitEnv
|
| ... | ... | @@ -435,16 +435,25 @@ type ModuleNameProvidersMap = |
| 435 | 435 | |
| 436 | 436 | data GlobalUnitKey =
|
| 437 | 437 | GlobalUnitKey
|
| 438 | - UnitId -- ^ Unit Id of the 'UnitInfo'
|
|
| 439 | - ST.ShortText
|
|
| 438 | + !UnitId -- ^ Unit Id of the 'UnitInfo'
|
|
| 439 | + !ST.ShortText
|
|
| 440 | + |
|
| 441 | +instance Uniquable GlobalUnitKey where
|
|
| 442 | + getUnique :: GlobalUnitKey -> Unique
|
|
| 443 | + getUnique (GlobalUnitKey unitId abiHash) = getUnique unitId -- TODO @fendor: how to incorporate abiHash
|
|
| 444 | + |
|
| 445 | +globalUnitKeyFromUnitInfo :: UnitInfo -> GlobalUnitKey
|
|
| 446 | +globalUnitKeyFromUnitInfo u = GlobalUnitKey (unitId u) (unitAbiHash u)
|
|
| 447 | + |
|
| 448 | +type GlobalUnitInfoMap = UniqMap GlobalUnitKey UnitInfo
|
|
| 440 | 449 | |
| 441 | 450 | data UnitIndex = UnitIndex
|
| 442 | - { ui_wireMap :: WiringMap
|
|
| 451 | + { ui_wireMap :: !WiringMap
|
|
| 443 | 452 | -- ^ TODO @fendor: document global property
|
| 444 | - , ui_unwireMap :: UnwiringMap
|
|
| 453 | + , ui_unwireMap :: !UnwiringMap
|
|
| 445 | 454 | -- ^ TODO @fendor: document global property
|
| 446 | - , ui_unitInfoMap :: UnitInfoMap
|
|
| 447 | - -- ^ TODO @fendor: This needs to be Map (UnitId, AbiHash) UnitInfo for absolut correctness
|
|
| 455 | + , ui_unitInfoMap :: !GlobalUnitInfoMap
|
|
| 456 | + -- ^ TODO @fendor: This needs to be UniqMap GlobalUnitKey UnitInfo for absolut correctness
|
|
| 448 | 457 | }
|
| 449 | 458 | |
| 450 | 459 | initUnitIndex :: UnitIndex
|
| ... | ... | @@ -468,8 +477,10 @@ isWireMapEmpty unit_index = |
| 468 | 477 | addUnitInfoMap :: UnitInfoMap -> UnitIndex -> UnitIndex
|
| 469 | 478 | addUnitInfoMap unit_info_map unit_index =
|
| 470 | 479 | unit_index
|
| 471 | - { ui_unitInfoMap = unit_info_map `plusUniqMap` ui_unitInfoMap unit_index
|
|
| 480 | + { ui_unitInfoMap = globalMap `plusUniqMap` ui_unitInfoMap unit_index
|
|
| 472 | 481 | }
|
| 482 | + where
|
|
| 483 | + globalMap = listToUniqMap . map (\(_, v) -> (globalUnitKeyFromUnitInfo v, v)) $ nonDetUniqMapToList unit_info_map
|
|
| 473 | 484 | |
| 474 | 485 | -- lookupUnitInfoMap :: UnitIndex -> UnitId -> Maybe UnitInfo
|
| 475 | 486 | -- lookupUnitInfoMap unit_index unit_id =
|
| ... | ... | @@ -945,28 +956,23 @@ mungeBytecodeLibFields pkg = |
| 945 | 956 | ds -> ds
|
| 946 | 957 | }
|
| 947 | 958 | |
| 959 | +seqUnitInfo :: UnitInfo -> b -> b
|
|
| 960 | +seqUnitInfo ui b =
|
|
| 961 | + unitImportDirs ui `seqList`
|
|
| 962 | + unitIncludeDirs ui `seqList`
|
|
| 963 | + unitLibraryDirs ui `seqList`
|
|
| 964 | + unitLibraryBytecodeDirs ui `seqList`
|
|
| 965 | + unitExtDepFrameworkDirs ui `seq`
|
|
| 966 | + unitHaddockInterfaces ui `seq`
|
|
| 967 | + unitHaddockHTMLs ui `seqList`
|
|
| 968 | + unitLibraryDynDirs ui `seqList`
|
|
| 969 | + unitLibraryDirsStatic ui `seqList`
|
|
| 970 | + unitDepends ui `seqList`
|
|
| 971 | + unitExposedModules ui `seqList`
|
|
| 972 | + b
|
|
| 973 | + |
|
| 948 | 974 | evaluateUnitInfo :: UnitInfo -> IO UnitInfo
|
| 949 | -evaluateUnitInfo ui = do
|
|
| 950 | - importDirs <- evaluate $ unitImportDirs ui
|
|
| 951 | - includeDirs <- evaluate $ unitIncludeDirs ui
|
|
| 952 | - libraryDirs <- evaluate $ unitLibraryDirs ui
|
|
| 953 | - libraryBytecodeDirs <- evaluate $ unitLibraryBytecodeDirs ui
|
|
| 954 | - extDepFrameworkDirs <- evaluate $ unitExtDepFrameworkDirs ui
|
|
| 955 | - haddockInterfaces <- evaluate $ unitHaddockInterfaces ui
|
|
| 956 | - haddockHTMLs <- evaluate $ unitHaddockHTMLs ui
|
|
| 957 | - libraryDynDirs <- evaluate $ unitLibraryDynDirs ui
|
|
| 958 | - libraryDirsStatic <- evaluate $ unitLibraryDirsStatic ui
|
|
| 959 | - evaluate ui
|
|
| 960 | - { unitImportDirs = importDirs
|
|
| 961 | - , unitIncludeDirs = includeDirs
|
|
| 962 | - , unitLibraryDirs = libraryDirs
|
|
| 963 | - , unitLibraryDynDirs = libraryDynDirs
|
|
| 964 | - , unitLibraryDirsStatic = libraryDirsStatic
|
|
| 965 | - , unitLibraryBytecodeDirs = libraryBytecodeDirs
|
|
| 966 | - , unitExtDepFrameworkDirs = extDepFrameworkDirs
|
|
| 967 | - , unitHaddockInterfaces = haddockInterfaces
|
|
| 968 | - , unitHaddockHTMLs = haddockHTMLs
|
|
| 969 | - }
|
|
| 975 | +evaluateUnitInfo ui = evaluate (seqUnitInfo ui ui)
|
|
| 970 | 976 | |
| 971 | 977 | -- -----------------------------------------------------------------------------
|
| 972 | 978 | -- Modify our copy of the unit database based on trust flags,
|
| ... | ... | @@ -1274,11 +1280,11 @@ findWiredInUnits logger prec_map pkgs vis_map = do |
| 1274 | 1280 | |
| 1275 | 1281 | return wiredInMap
|
| 1276 | 1282 | |
| 1277 | -updateWiredInUnits :: WiringMap -> UnitInfoMap -> [UnitInfo] -> [Either UnitInfo UnitInfo]
|
|
| 1283 | +updateWiredInUnits :: WiringMap -> GlobalUnitInfoMap -> [UnitInfo] -> [Either UnitInfo UnitInfo]
|
|
| 1278 | 1284 | updateWiredInUnits wiredInMap knownInfos pkgs =
|
| 1279 | 1285 | map (updateWiredInUnitsInUnitInfo wiredInMap knownInfos) pkgs
|
| 1280 | 1286 | |
| 1281 | -updateWiredInUnitsInUnitInfo :: WiringMap -> UnitInfoMap -> UnitInfo -> Either UnitInfo UnitInfo
|
|
| 1287 | +updateWiredInUnitsInUnitInfo :: WiringMap -> GlobalUnitInfoMap -> UnitInfo -> Either UnitInfo UnitInfo
|
|
| 1282 | 1288 | updateWiredInUnitsInUnitInfo wiredInMap knownInfos pkg =
|
| 1283 | 1289 | let
|
| 1284 | 1290 | upd_pkg pkg
|
| ... | ... | @@ -1299,14 +1305,14 @@ updateWiredInUnitsInUnitInfo wiredInMap knownInfos pkg = |
| 1299 | 1305 | (unitExposedModules pkg)
|
| 1300 | 1306 | }
|
| 1301 | 1307 | in
|
| 1302 | - case lookupUniqMap knownInfos (unitId pkg) of
|
|
| 1308 | + case lookupUniqMap knownInfos (globalUnitKeyFromUnitInfo pkg) of
|
|
| 1303 | 1309 | Just ui ->
|
| 1304 | 1310 | Right ui
|
| 1305 | 1311 | Nothing ->
|
| 1306 | 1312 | let
|
| 1307 | 1313 | updated_pkg = upd_deps $ upd_pkg pkg
|
| 1308 | 1314 | in
|
| 1309 | - Left updated_pkg
|
|
| 1315 | + Left $ seqUnitInfo updated_pkg updated_pkg
|
|
| 1310 | 1316 | |
| 1311 | 1317 | -- Helper functions for rewiring Module and Unit. These
|
| 1312 | 1318 | -- rewrite Units of modules in wired-in packages to the form known to the
|
| ... | ... | @@ -1725,12 +1731,12 @@ mkUnitState logger unit_index cfg = do |
| 1725 | 1731 | -- Note: we NEVER expose indefinite packages by
|
| 1726 | 1732 | -- default, because it's almost assuredly not
|
| 1727 | 1733 | -- what you want (no mix-in linking has occurred).
|
| 1728 | - if unitIsExposed p && unitIsDefinite (mkUnit p) && mostPreferable p
|
|
| 1734 | + let !x = fsPackageName p in if unitIsExposed p && unitIsDefinite (mkUnit p) && mostPreferable p
|
|
| 1729 | 1735 | then addToUniqMap vm (mkUnit p)
|
| 1730 | 1736 | UnitVisibility {
|
| 1731 | 1737 | uv_expose_all = True,
|
| 1732 | 1738 | uv_renamings = [],
|
| 1733 | - uv_package_name = First (Just (fsPackageName p)),
|
|
| 1739 | + uv_package_name = First (Just x),
|
|
| 1734 | 1740 | uv_requirements = emptyUniqMap,
|
| 1735 | 1741 | uv_explicit = Nothing
|
| 1736 | 1742 | }
|
| ... | ... | @@ -857,8 +857,9 @@ installInteractiveHomeUnits dflags = do |
| 857 | 857 | setupHomeUnitFor :: GHC.GhcMonad m => Logger -> DynFlags -> S.Set UnitId -> m HomeUnitEnv
|
| 858 | 858 | setupHomeUnitFor logger dflags all_home_units = do
|
| 859 | 859 | env <- GHC.getSession
|
| 860 | + let unit_index = hsc_unit_index env
|
|
| 860 | 861 | (unit_state,home_unit,_mconstants) <-
|
| 861 | - liftIO $ initUnits logger dflags (hscEUDC env) all_home_units
|
|
| 862 | + liftIO $ initUnits logger dflags unit_index (hscEUDC env) all_home_units
|
|
| 862 | 863 | hpt <- liftIO emptyHomePackageTable
|
| 863 | 864 | pure (HUG.mkHomeUnitEnv unit_state dflags hpt (Just home_unit))
|
| 864 | 865 |
| ... | ... | @@ -746,11 +746,20 @@ mungeUnitInfoPaths top_dir pkgroot pkg = |
| 746 | 746 | , unitHaddockHTMLs = munge_paths (munge_urls (unitHaddockHTMLs pkg))
|
| 747 | 747 | }
|
| 748 | 748 | where
|
| 749 | - munge_paths = map munge_path
|
|
| 750 | - munge_urls = map munge_url
|
|
| 749 | + munge_paths = strictMap munge_path
|
|
| 750 | + munge_urls = strictMap munge_url
|
|
| 751 | 751 | (munge_path,munge_url) = mkMungePathUrl top_dir pkgroot
|
| 752 | 752 | |
| 753 | 753 | -- | Decode an 'OsPath' to 'FilePath', throwing an 'error' if decoding failed.
|
| 754 | 754 | -- Prefer 'decodeUtf' and gracious error handling.
|
| 755 | 755 | unsafeDecodeUtf :: HasCallStack => OsPath -> FilePath
|
| 756 | 756 | unsafeDecodeUtf = OsPath.Internal.so
|
| 757 | + |
|
| 758 | +strictMap :: (a -> b) -> [a] -> [b]
|
|
| 759 | +strictMap _ [] = []
|
|
| 760 | +strictMap f (x:xs) =
|
|
| 761 | + let
|
|
| 762 | + !x' = f x
|
|
| 763 | + !xs' = strictMap f xs
|
|
| 764 | + in
|
|
| 765 | + x' : xs' |
| ... | ... | @@ -258,7 +258,9 @@ haddockWithGhc ghc args = handleTopExceptions $ do |
| 258 | 258 | logger' <- getLogger
|
| 259 | 259 | let logger = setLogFlags logger' (initLogFlags dflags)
|
| 260 | 260 | let parserOpts = Parser.initParserOpts dflags
|
| 261 | - !unit_state <- hsc_units <$> getSession
|
|
| 261 | + env <- getSession
|
|
| 262 | + let !unit_state = hsc_units env
|
|
| 263 | + !unit_index <- liftIO $ hscUnitIndex env
|
|
| 262 | 264 | |
| 263 | 265 | -- If any --show-interface was used, show the given interfaces
|
| 264 | 266 | forM_ (optShowInterfaceFile flags) $ \path -> liftIO $ do
|
| ... | ... | @@ -285,7 +287,7 @@ haddockWithGhc ghc args = handleTopExceptions $ do |
| 285 | 287 | }
|
| 286 | 288 | |
| 287 | 289 | -- Render the interfaces.
|
| 288 | - liftIO $ renderStep dflags parserOpts logger unit_state flags sinceQual qual concSem packages ifaces
|
|
| 290 | + liftIO $ renderStep dflags parserOpts logger unit_index unit_state flags sinceQual qual concSem packages ifaces
|
|
| 289 | 291 | |
| 290 | 292 | -- If we were not given any input files, error if documentation was
|
| 291 | 293 | -- requested
|
| ... | ... | @@ -298,7 +300,7 @@ haddockWithGhc ghc args = handleTopExceptions $ do |
| 298 | 300 | packages <- liftIO $ readInterfaceFiles name_cache (readIfaceArgs flags) noChecks
|
| 299 | 301 | |
| 300 | 302 | -- Render even though there are no input files (usually contents/index).
|
| 301 | - liftIO $ renderStep dflags parserOpts logger unit_state flags sinceQual qual concSem packages []
|
|
| 303 | + liftIO $ renderStep dflags parserOpts logger unit_index unit_state flags sinceQual qual concSem packages []
|
|
| 302 | 304 | |
| 303 | 305 | -- | Run the GHC action using a temporary output directory
|
| 304 | 306 | withTempOutputDir :: Ghc a -> Ghc a
|
| ... | ... | @@ -354,6 +356,7 @@ renderStep |
| 354 | 356 | :: DynFlags
|
| 355 | 357 | -> ParserOpts
|
| 356 | 358 | -> Logger
|
| 359 | + -> UnitIndex
|
|
| 357 | 360 | -> UnitState
|
| 358 | 361 | -> [Flag]
|
| 359 | 362 | -> SinceQual
|
| ... | ... | @@ -362,7 +365,7 @@ renderStep |
| 362 | 365 | -> [(DocPaths, Visibility, FilePath, InterfaceFile)]
|
| 363 | 366 | -> [Interface]
|
| 364 | 367 | -> IO ()
|
| 365 | -renderStep dflags parserOpts logger unit_state flags sinceQual nameQual concSem pkgs interfaces = do
|
|
| 368 | +renderStep dflags parserOpts logger unit_index unit_state flags sinceQual nameQual concSem pkgs interfaces = do
|
|
| 366 | 369 | updateHTMLXRefs (map (\(docPath, _ifaceFilePath, _showModules, ifaceFile) ->
|
| 367 | 370 | ( case baseUrl flags of
|
| 368 | 371 | Nothing -> docPathsHtml docPath
|
| ... | ... | @@ -378,7 +381,7 @@ renderStep dflags parserOpts logger unit_state flags sinceQual nameQual concSem |
| 378 | 381 | (DocPaths {docPathsSources=Just path}, _, _, ifile) <- pkgs
|
| 379 | 382 | iface <- ifInstalledIfaces ifile
|
| 380 | 383 | return (instMod iface, path)
|
| 381 | - render dflags parserOpts logger unit_state flags sinceQual nameQual concSem interfaces installedIfaces extSrcMap
|
|
| 384 | + render dflags parserOpts logger unit_index unit_state flags sinceQual nameQual concSem interfaces installedIfaces extSrcMap
|
|
| 382 | 385 | where
|
| 383 | 386 | -- get package name from unit-id
|
| 384 | 387 | packageName :: Unit -> String
|
| ... | ... | @@ -392,6 +395,7 @@ render |
| 392 | 395 | :: DynFlags
|
| 393 | 396 | -> ParserOpts
|
| 394 | 397 | -> Logger
|
| 398 | + -> UnitIndex
|
|
| 395 | 399 | -> UnitState
|
| 396 | 400 | -> [Flag]
|
| 397 | 401 | -> SinceQual
|
| ... | ... | @@ -401,7 +405,7 @@ render |
| 401 | 405 | -> [(FilePath, PackageInterfaces)]
|
| 402 | 406 | -> Map Module FilePath
|
| 403 | 407 | -> IO ()
|
| 404 | -render dflags parserOpts logger unit_state flags sinceQual qual concSem ifaces packages extSrcMap = do
|
|
| 408 | +render dflags parserOpts logger unit_index unit_state flags sinceQual qual concSem ifaces packages extSrcMap = do
|
|
| 405 | 409 | let
|
| 406 | 410 | packageInfo = PackageInfo { piPackageName = fromMaybe (PackageName mempty)
|
| 407 | 411 | $ optPackageName flags
|
| ... | ... | @@ -503,7 +507,7 @@ render dflags parserOpts logger unit_state flags sinceQual qual concSem ifaces p |
| 503 | 507 | -- records the *wired in* identity base. So untranslate it
|
| 504 | 508 | -- so that we can service the request.
|
| 505 | 509 | unwire :: Module -> Module
|
| 506 | - unwire m = m { moduleUnit = unwireUnit unit_state (moduleUnit m) }
|
|
| 510 | + unwire m = m { moduleUnit = unwireUnit unit_index (moduleUnit m) }
|
|
| 507 | 511 | |
| 508 | 512 | reexportedIfaces <- concat `fmap` (for (reexportFlags flags) $ \mod_str -> do
|
| 509 | 513 | let warn' = hPutStrLn stderr . ("Warning: " ++)
|