Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC
Commits:
-
232bc7bf
by Hannes Siebenhandl at 2026-11-30T12:32:50+01:00
9 changed files:
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Driver/Env.hs
- compiler/GHC/Driver/Main/Hsc.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Iface/Recomp.hs
- compiler/GHC/IfaceToCore.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Unit/Home/PackageTable.hs
- ghc/GHCi/Leak.hs
Changes:
| ... | ... | @@ -102,7 +102,7 @@ core2core hsc_env guts@(ModGuts { mg_module = mod |
| 102 | 102 | logger = hsc_logger hsc_env
|
| 103 | 103 | unit_env = hsc_unit_env hsc_env
|
| 104 | 104 | extra_vars = interactiveInScope (hsc_IC hsc_env)
|
| 105 | - home_pkg_rules = hugRulesBelow hsc_env (moduleUnitId mod)
|
|
| 105 | + home_pkg_rules = hugRulesBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env) (moduleUnitId mod)
|
|
| 106 | 106 | (GWIB { gwib_mod = moduleName mod, gwib_isBoot = NotBoot })
|
| 107 | 107 | name_ppr_ctx = mkNamePprCtx ptc unit_env rdr_env
|
| 108 | 108 | ptc = initPromotionTickContext dflags
|
| ... | ... | @@ -99,6 +99,7 @@ import Data.IORef |
| 99 | 99 | import qualified Data.Set as Set
|
| 100 | 100 | import GHC.Types.Name.Reader (ExactRdrName(..))
|
| 101 | 101 | import qualified GHC.Unit.Home.PackageTable as HomePackageTable
|
| 102 | +import qualified GHC.Unit.Home.PackageTable as HPT
|
|
| 102 | 103 | |
| 103 | 104 | runHsc :: HscEnv -> Hsc a -> IO a
|
| 104 | 105 | runHsc hsc_env hsc = do
|
| ... | ... | @@ -259,26 +260,26 @@ hscUIC hsc_env = ue_uic (hsc_unit_env hsc_env) |
| 259 | 260 | |
| 260 | 261 | -- | Find all rules in modules that are in the transitive closure of the given
|
| 261 | 262 | -- module.
|
| 262 | -hugRulesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO RuleBase
|
|
| 263 | -hugRulesBelow hsc_env uid mn = foldr (flip extendRuleBaseList) emptyRuleBase <$>
|
|
| 264 | - hugSomeThingsBelowUs (md_rules . hm_details) False hsc_env uid mn
|
|
| 263 | +hugRulesBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO RuleBase
|
|
| 264 | +hugRulesBelow mg hug uid mn = foldr (flip extendRuleBaseList) emptyRuleBase <$>
|
|
| 265 | + hugSomeThingsBelowUs (md_rules . hm_details) False mg hug uid mn
|
|
| 265 | 266 | |
| 266 | 267 | -- | Get annotations from all modules "below" this one (in the dependency
|
| 267 | 268 | -- sense) within the home units. If the module is @Nothing@, returns /all/
|
| 268 | 269 | -- annotations in the home units.
|
| 269 | -hugAnnsBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO AnnEnv
|
|
| 270 | -hugAnnsBelow hsc_env uid mn = foldr (flip extendAnnEnvList) emptyAnnEnv <$>
|
|
| 271 | - hugSomeThingsBelowUs (md_anns . hm_details) False hsc_env uid mn
|
|
| 270 | +hugAnnsBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO AnnEnv
|
|
| 271 | +hugAnnsBelow mg hug uid mn = foldr (flip extendAnnEnvList) emptyAnnEnv <$>
|
|
| 272 | + hugSomeThingsBelowUs (md_anns . hm_details) False mg hug uid mn
|
|
| 272 | 273 | |
| 273 | 274 | -- | Find all COMPLETE pragmas in modules that are in the transitive closure of the
|
| 274 | 275 | -- given module.
|
| 275 | -hugCompleteSigsBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO CompleteMatches
|
|
| 276 | -hugCompleteSigsBelow hsc uid mn = foldr (++) [] <$>
|
|
| 277 | - hugSomeThingsBelowUs (md_complete_matches . hm_details) False hsc uid mn
|
|
| 276 | +hugCompleteSigsBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO CompleteMatches
|
|
| 277 | +hugCompleteSigsBelow mg hug uid mn = foldr (++) [] <$>
|
|
| 278 | + hugSomeThingsBelowUs (md_complete_matches . hm_details) False mg hug uid mn
|
|
| 278 | 279 | |
| 279 | 280 | -- | Find instances visible from the given set of imports
|
| 280 | -hugInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst])
|
|
| 281 | -hugInstancesBelow hsc_env uid mnwib = do
|
|
| 281 | +hugInstancesBelow :: ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst])
|
|
| 282 | +hugInstancesBelow mg hug uid mnwib = do
|
|
| 282 | 283 | let mn = mkModule uid (gwib_mod mnwib)
|
| 283 | 284 | (insts, famInsts) <-
|
| 284 | 285 | unzip . concat <$>
|
| ... | ... | @@ -289,7 +290,8 @@ hugInstancesBelow hsc_env uid mnwib = do |
| 289 | 290 | then []
|
| 290 | 291 | else [(md_insts details, md_fam_insts details)])
|
| 291 | 292 | True -- Include -hi-boot
|
| 292 | - hsc_env
|
|
| 293 | + mg
|
|
| 294 | + hug
|
|
| 293 | 295 | uid
|
| 294 | 296 | mnwib
|
| 295 | 297 | return (foldl' unionInstEnv emptyInstEnv insts, concat famInsts)
|
| ... | ... | @@ -297,17 +299,18 @@ hugInstancesBelow hsc_env uid mnwib = do |
| 297 | 299 | -- | Get things from modules in the transitive closure of the given module.
|
| 298 | 300 | --
|
| 299 | 301 | -- Note: Don't expose this function. This is a footgun if exposed!
|
| 300 | -hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO [[a]]
|
|
| 302 | +hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> ModuleGraph -> HomeUnitGraph -> UnitId -> ModuleNameWithIsBoot -> IO [[a]]
|
|
| 301 | 303 | -- An explicit check to see if we are in one-shot mode to avoid poking the ModuleGraph thunk
|
| 302 | 304 | -- These things are currently stored in the EPS for home packages. (See #25795 for
|
| 303 | 305 | -- progress in removing these kind of checks; and making these functions of
|
| 304 | 306 | -- `UnitEnv` rather than `HscEnv`)
|
| 305 | 307 | -- See Note [The ModuleGraph]
|
| 306 | -hugSomeThingsBelowUs _ _ hsc_env _ _ | isOneShot (ghcMode (hsc_dflags hsc_env)) = return []
|
|
| 307 | -hugSomeThingsBelowUs extract include_hi_boot hsc_env uid mn
|
|
| 308 | - = let hug = hsc_HUG hsc_env
|
|
| 309 | - mg = hsc_mod_graph hsc_env
|
|
| 310 | - in
|
|
| 308 | +hugSomeThingsBelowUs extract include_hi_boot mg hug uid mn =
|
|
| 309 | + -- If the first hpt is a one-shot table, we don't recurse into it.
|
|
| 310 | + -- TODO @fendor: I guess that's nonsense to a certain degree
|
|
| 311 | + if HPT.isOneShotMode $ homeUnitEnv_hpt $ unitEnv_lookup uid hug
|
|
| 312 | + then pure []
|
|
| 313 | + else
|
|
| 311 | 314 | sequence
|
| 312 | 315 | [ things
|
| 313 | 316 | -- "Finding each non-hi-boot module below me" maybe could be cached (well,
|
| ... | ... | @@ -347,7 +350,7 @@ prepareAnnotations hsc_env mb_guts = do |
| 347 | 350 | -- entries regardless of dependency ordering.
|
| 348 | 351 | get_mod mg = (moduleUnitId (mg_module mg), GWIB (moduleName (mg_module mg)) NotBoot)
|
| 349 | 352 | home_pkg_anns <- fromMaybe (hugAllAnns (hsc_unit_env hsc_env))
|
| 350 | - $ uncurry (hugAnnsBelow hsc_env)
|
|
| 353 | + $ uncurry (hugAnnsBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env))
|
|
| 351 | 354 | . get_mod <$> mb_guts
|
| 352 | 355 | more_home_pkg_anns <- HomePackageTable.hptLoadedAnnEnv $ hsc_HPT hsc_env
|
| 353 | 356 | let
|
| ... | ... | @@ -107,7 +107,10 @@ import System.IO |
| 107 | 107 | |
| 108 | 108 | newHscEnv :: FilePath -> DynFlags -> IO HscEnv
|
| 109 | 109 | newHscEnv top_dir dflags = do
|
| 110 | - hpt <- emptyHomePackageTable
|
|
| 110 | + hpt <- case ghcMode dflags of
|
|
| 111 | + OneShot -> emptyOnDemandHomePackageTable
|
|
| 112 | + CompManager -> emptyHomePackageTable
|
|
| 113 | + MkDepend -> emptyHomePackageTable
|
|
| 111 | 114 | newHscEnvWithHUG top_dir dflags (homeUnitId_ dflags) (home_unit_graph hpt)
|
| 112 | 115 | where
|
| 113 | 116 | home_unit_graph hpt = HUG.unitEnv_singleton
|
| ... | ... | @@ -100,66 +100,65 @@ import GHC.Builtin.PrimOps.Ids |
| 100 | 100 | import GHC.Builtin.WiredIn.Prim
|
| 101 | 101 | import GHC.Builtin.WiredIn.Ids( seqId )
|
| 102 | 102 | |
| 103 | +import GHC.Core (CoreRule)
|
|
| 104 | +import GHC.Core.FamInstEnv
|
|
| 105 | +import GHC.Core.InstEnv
|
|
| 103 | 106 | import GHC.Core.Rules
|
| 104 | 107 | import GHC.Core.TyCon
|
| 105 | -import GHC.Core.InstEnv
|
|
| 106 | -import GHC.Core.FamInstEnv
|
|
| 107 | 108 | |
| 108 | -import GHC.Parser.Annotation( noLocA, noAnn )
|
|
| 109 | +import GHC.Parser.Annotation (noAnn, noLocA)
|
|
| 109 | 110 | |
| 110 | 111 | import GHC.Types.Annotations
|
| 112 | +import GHC.Types.Avail
|
|
| 113 | +import GHC.Types.DefaultEnv (DefaultEnv)
|
|
| 114 | +import GHC.Types.Fixity
|
|
| 115 | +import GHC.Types.Fixity.Env
|
|
| 111 | 116 | import GHC.Types.Id
|
| 112 | 117 | import GHC.Types.Name
|
| 113 | 118 | import GHC.Types.Name.Cache
|
| 114 | 119 | import GHC.Types.Name.Env
|
| 115 | 120 | import GHC.Types.Name.Reader
|
| 116 | -import GHC.Types.Avail
|
|
| 117 | -import GHC.Types.Fixity
|
|
| 118 | -import GHC.Types.Fixity.Env
|
|
| 121 | +import GHC.Types.PkgQual
|
|
| 122 | +import GHC.Types.SafeHaskell
|
|
| 119 | 123 | import GHC.Types.SourceError
|
| 120 | 124 | import GHC.Types.SourceFile
|
| 121 | -import GHC.Types.SafeHaskell
|
|
| 122 | -import GHC.Types.TypeEnv
|
|
| 123 | -import GHC.Types.Unique.DSet
|
|
| 124 | -import GHC.Types.Unique.Map( listToUniqMap )
|
|
| 125 | -import GHC.Types.Unique.FM( UniqFM, listToUFM, lookupUFM, elemUFM )
|
|
| 125 | +import GHC.Types.SourceText
|
|
| 126 | 126 | import GHC.Types.SrcLoc
|
| 127 | 127 | import GHC.Types.TyThing
|
| 128 | -import GHC.Types.PkgQual
|
|
| 129 | -import GHC.Types.SourceText
|
|
| 128 | +import GHC.Types.TypeEnv
|
|
| 129 | +import GHC.Types.Unique.DSet
|
|
| 130 | +import GHC.Types.Unique.FM (UniqFM, elemUFM, listToUFM, lookupUFM)
|
|
| 131 | +import GHC.Types.Unique.Map (listToUniqMap)
|
|
| 130 | 132 | |
| 133 | +import GHC.Unit.Env
|
|
| 131 | 134 | import GHC.Unit.External
|
| 135 | +import GHC.Unit.Finder
|
|
| 136 | +import GHC.Unit.Home
|
|
| 137 | +import GHC.Unit.Home.Graph qualified as HUG
|
|
| 138 | +import GHC.Unit.Home.ModInfo (HomeModInfo (..), emptyHomeModInfoLinkable)
|
|
| 139 | +import GHC.Unit.Home.PackageTable
|
|
| 140 | +import GHC.Unit.Home.PackageTable qualified as HomePackageTable
|
|
| 132 | 141 | import GHC.Unit.Module
|
| 142 | +import GHC.Unit.Module.Deps
|
|
| 133 | 143 | import GHC.Unit.Module.Graph
|
| 134 | -import GHC.Unit.Module.Warnings
|
|
| 144 | +import GHC.Unit.Module.ModDetails (ModDetails (..))
|
|
| 135 | 145 | import GHC.Unit.Module.ModIface
|
| 136 | -import GHC.Unit.Module.Deps
|
|
| 146 | +import GHC.Unit.Module.Warnings
|
|
| 137 | 147 | import GHC.Unit.State
|
| 138 | -import GHC.Unit.Home
|
|
| 139 | -import qualified GHC.Unit.Home.Graph as HUG
|
|
| 140 | -import GHC.Unit.Home.PackageTable
|
|
| 141 | -import GHC.Unit.Finder
|
|
| 142 | -import GHC.Unit.Env
|
|
| 143 | 148 | |
| 144 | 149 | import GHC.Stack( callStack )
|
| 145 | 150 | import GHC.Data.Maybe
|
| 146 | 151 | |
| 147 | 152 | import Language.Haskell.Syntax.Lit (StringLiteral(..))
|
| 148 | 153 | |
| 154 | +import Control.Applicative ((<|>))
|
|
| 149 | 155 | import Control.Monad
|
| 150 | -import qualified Data.Foldable as Foldable
|
|
| 156 | +import Data.Foldable qualified as Foldable
|
|
| 151 | 157 | import Data.Function ((&))
|
| 152 | -import Data.Map ( toList )
|
|
| 153 | -import qualified Data.Set as Set
|
|
| 154 | -import System.FilePath
|
|
| 158 | +import Data.Map (toList)
|
|
| 159 | +import Data.Set qualified as Set
|
|
| 155 | 160 | import System.Directory
|
| 156 | -import GHC.Types.DefaultEnv (DefaultEnv)
|
|
| 157 | -import GHC.Core (CoreRule)
|
|
| 158 | -import GHC.Unit.Module.ModDetails (ModDetails(..))
|
|
| 159 | -import GHC.Unit.Home.ModInfo (HomeModInfo(..), emptyHomeModInfoLinkable)
|
|
| 160 | -import qualified Data.Set as Set
|
|
| 161 | -import qualified GHC.Unit.Home.PackageTable as HomePackageTable
|
|
| 162 | -import Control.Applicative ((<|>))
|
|
| 161 | +import System.FilePath
|
|
| 163 | 162 | |
| 164 | 163 | |
| 165 | 164 | {- *********************************************************************
|
| ... | ... | @@ -799,8 +798,8 @@ loadInterface doc_str mod from |
| 799 | 798 | |
| 800 | 799 | -- READ THE MODULE IN
|
| 801 | 800 | ; hpt <- getHpt
|
| 802 | - ; hls <- liftIO (hptLoaderState hpt)
|
|
| 803 | - ; read_result <- case wantHiBootFile mhome_unit hls mod from of
|
|
| 801 | + ; is_boot_map <- liftIO (hptLoadedIsBoot hpt)
|
|
| 802 | + ; read_result <- case wantHiBootFile mhome_unit is_boot_map mod from of
|
|
| 804 | 803 | Failed err -> return (Failed err)
|
| 805 | 804 | Succeeded hi_boot_file -> do
|
| 806 | 805 | hsc_env <- getTopEnv
|
| ... | ... | @@ -836,7 +835,7 @@ loadInterface doc_str mod from |
| 836 | 835 | massertPpr (moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env)
|
| 837 | 836 | (text "Attempting to non-home package interface into the Home Loader State" $$ ppr (HUG.allUnits $ hsc_HUG hsc_env) $$ doc_str $$ ppr mod $$ ppr (moduleUnitId mod))
|
| 838 | 837 | tcParts <- tcPartsOfTheIface mod iface
|
| 839 | - addModIfacePartsToHpt gbl_env mod loc iface tcParts
|
|
| 838 | + addModIfacePartsToHpt gbl_env mod iface tcParts
|
|
| 840 | 839 | else dontLeakTheHUG $ do
|
| 841 | 840 | -- Load the new ModIface into the External Package State
|
| 842 | 841 | --
|
| ... | ... | @@ -868,37 +867,36 @@ loadInterface doc_str mod from |
| 868 | 867 | |
| 869 | 868 | tcPartsOfTheIface :: Module -> ModIface -> IfL ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], CompleteMatches)
|
| 870 | 869 | tcPartsOfTheIface mod iface = do
|
| 871 | - ignore_prags <- goptM Opt_IgnoreInterfacePragmas
|
|
| 872 | - new_eps_decls <- tcIfaceDecls ignore_prags (mi_decls iface)
|
|
| 873 | - new_eps_insts <- mapM tcIfaceInst (mi_insts iface)
|
|
| 874 | - new_eps_defaults <- tcIfaceDefaults mod (mi_defaults iface)
|
|
| 875 | - new_eps_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts iface)
|
|
| 876 | - new_eps_rules <- tcIfaceRules ignore_prags (mi_rules iface)
|
|
| 877 | - new_eps_anns <- tcIfaceAnnotations (mi_anns iface)
|
|
| 878 | - new_eps_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface)
|
|
| 870 | + ignore_prags <- goptM Opt_IgnoreInterfacePragmas
|
|
| 871 | + new_decls <- tcIfaceDecls ignore_prags (mi_decls iface)
|
|
| 872 | + new_insts <- mapM tcIfaceInst (mi_insts iface)
|
|
| 873 | + new_defaults <- tcIfaceDefaults mod (mi_defaults iface)
|
|
| 874 | + new_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts iface)
|
|
| 875 | + new_rules <- tcIfaceRules ignore_prags (mi_rules iface)
|
|
| 876 | + new_anns <- tcIfaceAnnotations (mi_anns iface)
|
|
| 877 | + new_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface)
|
|
| 879 | 878 | pure
|
| 880 | - ( new_eps_decls
|
|
| 881 | - , new_eps_insts
|
|
| 882 | - , new_eps_defaults
|
|
| 883 | - , new_eps_fam_insts
|
|
| 884 | - , new_eps_rules
|
|
| 885 | - , new_eps_anns
|
|
| 886 | - , new_eps_complete_matches
|
|
| 879 | + ( new_decls
|
|
| 880 | + , new_insts
|
|
| 881 | + , new_defaults
|
|
| 882 | + , new_fam_insts
|
|
| 883 | + , new_rules
|
|
| 884 | + , new_anns
|
|
| 885 | + , new_complete_matches
|
|
| 887 | 886 | )
|
| 888 | 887 | |
| 889 | -addModIfacePartsToHpt :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL ()
|
|
| 890 | -addModIfacePartsToHpt gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_eps_defaults, new_eps_fam_insts, new_eps_rules, new_eps_anns, new_eps_complete_matches) = do
|
|
| 891 | - hsc_env <- getTopEnv
|
|
| 888 | +addModIfacePartsToHpt :: IfGblEnv -> Module -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL ()
|
|
| 889 | +addModIfacePartsToHpt gbl_env mod iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
|
|
| 892 | 890 | let
|
| 893 | 891 | details = ModDetails
|
| 894 | - { md_types = mkNameEnv new_eps_decls
|
|
| 892 | + { md_types = mkNameEnv new_decls
|
|
| 895 | 893 | , md_exports = mi_exports iface
|
| 896 | - , md_defaults = new_eps_defaults
|
|
| 897 | - , md_insts = mkInstEnv new_eps_insts
|
|
| 898 | - , md_fam_insts = new_eps_fam_insts
|
|
| 899 | - , md_rules = new_eps_rules
|
|
| 900 | - , md_anns = new_eps_anns
|
|
| 901 | - , md_complete_matches = new_eps_complete_matches
|
|
| 894 | + , md_defaults = new_defaults
|
|
| 895 | + , md_insts = mkInstEnv new_insts
|
|
| 896 | + , md_fam_insts = new_fam_insts
|
|
| 897 | + , md_rules = new_rules
|
|
| 898 | + , md_anns = new_anns
|
|
| 899 | + , md_complete_matches = new_complete_matches
|
|
| 902 | 900 | }
|
| 903 | 901 | |
| 904 | 902 | bad_boot = mi_boot iface == IsBoot
|
| ... | ... | @@ -909,16 +907,11 @@ addModIfacePartsToHpt gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_e |
| 909 | 907 | |
| 910 | 908 | warnPprTrace bad_boot "loadInterface" (ppr mod) $ do
|
| 911 | 909 | hpt <- getHpt
|
| 912 | - -- Create an IO action that loads and compiles bytecode from Core
|
|
| 913 | - -- bindings.
|
|
| 914 | - --
|
|
| 915 | - -- See Note [Interface Files with Core Definitions]
|
|
| 916 | - let lazy_bytecode = loadIfaceByteCode hsc_env iface loc (mkNameEnv new_eps_decls)
|
|
| 917 | 910 | liftIO $ addHomeModInfoToHpt (HomeModInfo iface details emptyHomeModInfoLinkable) hpt
|
| 918 | - liftIO $ addOnDemandHomeModule hpt mod bad_boot (new_eps_decls, new_eps_insts, new_eps_defaults, new_eps_fam_insts, new_eps_rules, new_eps_anns, new_eps_complete_matches) lazy_bytecode
|
|
| 911 | + liftIO $ addOnDemandHomeModule hpt mod bad_boot (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches)
|
|
| 919 | 912 | |
| 920 | 913 | addModIfacePartsToEps :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL ()
|
| 921 | -addModIfacePartsToEps gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_eps_defaults, new_eps_fam_insts, new_eps_rules, new_eps_anns, new_eps_complete_matches) = do
|
|
| 914 | +addModIfacePartsToEps gbl_env mod loc iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
|
|
| 922 | 915 | purged_hsc_env <- getTopEnv
|
| 923 | 916 | |
| 924 | 917 | let
|
| ... | ... | @@ -942,7 +935,7 @@ addModIfacePartsToEps gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_e |
| 942 | 935 | --
|
| 943 | 936 | -- See Note [Interface Files with Core Definitions]
|
| 944 | 937 | add_bytecode old
|
| 945 | - | Just action <- loadIfaceByteCode purged_hsc_env iface loc (mkNameEnv new_eps_decls)
|
|
| 938 | + | Just action <- loadIfaceByteCode purged_hsc_env iface loc (mkNameEnv new_decls)
|
|
| 946 | 939 | = extendModuleEnv old mod action
|
| 947 | 940 | -- Don't add an entry if the iface doesn't have 'extra_decls'
|
| 948 | 941 | -- so 'get_link_deps' knows that it should load object code.
|
| ... | ... | @@ -956,36 +949,36 @@ addModIfacePartsToEps gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_e |
| 956 | 949 | then eps
|
| 957 | 950 | else if bad_boot
|
| 958 | 951 | -- See Note [Loading your own hi-boot file]
|
| 959 | - then eps { eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls }
|
|
| 952 | + then eps { eps_PTE = addDeclsToPTE (eps_PTE eps) new_decls }
|
|
| 960 | 953 | else
|
| 961 | 954 | eps {
|
| 962 | 955 | eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
|
| 963 | - eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls,
|
|
| 956 | + eps_PTE = addDeclsToPTE (eps_PTE eps) new_decls,
|
|
| 964 | 957 | eps_iface_bytecode = add_bytecode (eps_iface_bytecode eps),
|
| 965 | 958 | eps_rule_base = extendRuleBaseList (eps_rule_base eps)
|
| 966 | - new_eps_rules,
|
|
| 959 | + new_rules,
|
|
| 967 | 960 | eps_complete_matches
|
| 968 | - = eps_complete_matches eps ++ new_eps_complete_matches,
|
|
| 961 | + = eps_complete_matches eps ++ new_complete_matches,
|
|
| 969 | 962 | eps_inst_env = extendInstEnvList (eps_inst_env eps)
|
| 970 | - new_eps_insts,
|
|
| 963 | + new_insts,
|
|
| 971 | 964 | eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
|
| 972 | - new_eps_fam_insts,
|
|
| 965 | + new_fam_insts,
|
|
| 973 | 966 | eps_ann_env = extendAnnEnvList (eps_ann_env eps)
|
| 974 | - new_eps_anns,
|
|
| 967 | + new_anns,
|
|
| 975 | 968 | eps_mod_fam_inst_env
|
| 976 | 969 | = let
|
| 977 | 970 | fam_inst_env =
|
| 978 | 971 | extendFamInstEnvList emptyFamInstEnv
|
| 979 | - new_eps_fam_insts
|
|
| 972 | + new_fam_insts
|
|
| 980 | 973 | in
|
| 981 | 974 | extendModuleEnv (eps_mod_fam_inst_env eps)
|
| 982 | 975 | mod
|
| 983 | 976 | fam_inst_env,
|
| 984 | 977 | eps_stats = addEpsInStats (eps_stats eps)
|
| 985 | - (length new_eps_decls)
|
|
| 986 | - (length new_eps_insts)
|
|
| 987 | - (length new_eps_rules),
|
|
| 988 | - eps_defaults = extendModuleEnv (eps_defaults eps) mod new_eps_defaults
|
|
| 978 | + (length new_decls)
|
|
| 979 | + (length new_insts)
|
|
| 980 | + (length new_rules),
|
|
| 981 | + eps_defaults = extendModuleEnv (eps_defaults eps) mod new_defaults
|
|
| 989 | 982 | }
|
| 990 | 983 | |
| 991 | 984 | |
| ... | ... | @@ -1204,10 +1197,10 @@ moduleFreeHolesPrecise doc_str mod |
| 1204 | 1197 | return (Succeeded (renameFreeHoles ifhs insts))
|
| 1205 | 1198 | Failed err -> return (Failed err)
|
| 1206 | 1199 | |
| 1207 | -wantHiBootFile :: Maybe HomeUnit -> HomeLoaderState -> Module -> WhereFrom
|
|
| 1200 | +wantHiBootFile :: Maybe HomeUnit -> InstalledModuleEnv ModuleNameWithIsBoot -> Module -> WhereFrom
|
|
| 1208 | 1201 | -> MaybeErr MissingInterfaceError IsBootInterface
|
| 1209 | 1202 | -- Figure out whether we want Foo.hi or Foo.hi-boot
|
| 1210 | -wantHiBootFile mhome_unit hls mod from
|
|
| 1203 | +wantHiBootFile mhome_unit is_boot_map mod from
|
|
| 1211 | 1204 | = case from of
|
| 1212 | 1205 | ImportByUser usr_boot
|
| 1213 | 1206 | | usr_boot == IsBoot && notHomeModuleMaybe mhome_unit mod
|
| ... | ... | @@ -1226,9 +1219,9 @@ wantHiBootFile mhome_unit hls mod from |
| 1226 | 1219 | -- We never import boot modules from other packages!
|
| 1227 | 1220 | |
| 1228 | 1221 | | otherwise
|
| 1229 | - -> case hlsIsBoot hls (toUnitId <$> mod) of
|
|
| 1230 | - Just is_boot ->
|
|
| 1231 | - Succeeded is_boot
|
|
| 1222 | + -> case lookupInstalledModuleEnv is_boot_map (toUnitId <$> mod) of
|
|
| 1223 | + Just mnib ->
|
|
| 1224 | + Succeeded $ gwib_isBoot mnib
|
|
| 1232 | 1225 | Nothing ->
|
| 1233 | 1226 | Succeeded NotBoot
|
| 1234 | 1227 | -- The boot-ness of the requested interface,
|
| ... | ... | @@ -427,10 +427,9 @@ checkVersions hsc_env mod_summary iface self_recomp |
| 427 | 427 | -- (in which case we are done with this module) or it'll fail (in which
|
| 428 | 428 | -- case we'll compile the module from scratch anyhow).
|
| 429 | 429 | |
| 430 | - when (isOneShot (ghcMode (hsc_dflags hsc_env))) $ do {
|
|
| 431 | - ; hpt <- getHpt
|
|
| 432 | - ; liftIO $ hlsSetBootInfo hpt (mkModDeps $ dep_boot_mods (mi_deps iface))
|
|
| 433 | - }
|
|
| 430 | + ; hpt <- getHpt
|
|
| 431 | + ; liftIO $ hptSetBootInfo hpt (mkModDeps $ dep_boot_mods (mi_deps iface))
|
|
| 432 | + |
|
| 434 | 433 | ; recomp <- checkList [checkModUsage (hsc_FC hsc_env) u
|
| 435 | 434 | | u <- mi_sr_usages self_recomp]
|
| 436 | 435 | ; case recomp of (NeedsRecompile reason) -> return $ OutOfDateItem reason (Just iface) ; _ -> do {
|
| ... | ... | @@ -633,12 +633,12 @@ tcHiBootIface hsc_src mod |
| 633 | 633 | -- a SOURCE import) or that our hi-boot file has mysteriously
|
| 634 | 634 | -- disappeared.
|
| 635 | 635 | do { hpt <- getHpt
|
| 636 | - ; hls <- liftIO $ hptLoaderState hpt
|
|
| 637 | - ; case hlsIsBoot hls (toUnitId <$> mod) of
|
|
| 636 | + ; is_boot_map <- liftIO $ hptLoadedIsBoot hpt
|
|
| 637 | + ; case lookupInstalledModuleEnv is_boot_map (toUnitId <$> mod) of
|
|
| 638 | 638 | -- The typical case
|
| 639 | 639 | Nothing -> return NoSelfBoot
|
| 640 | 640 | -- error cases
|
| 641 | - Just is_boot -> case is_boot of
|
|
| 641 | + Just mnib -> case gwib_isBoot mnib of
|
|
| 642 | 642 | IsBoot ->
|
| 643 | 643 | let diag = Can'tFindInterface err
|
| 644 | 644 | (LookingForHiBoot mod)
|
| ... | ... | @@ -191,7 +191,7 @@ import qualified Data.Map as M |
| 191 | 191 | import Data.Foldable ( for_ )
|
| 192 | 192 | import Data.Traversable ( for )
|
| 193 | 193 | import Data.IORef( newIORef )
|
| 194 | -import GHC.Unit.Home.PackageTable (hlsSetBootInfo)
|
|
| 194 | +import GHC.Unit.Home.PackageTable (hptSetBootInfo)
|
|
| 195 | 195 | |
| 196 | 196 | {-
|
| 197 | 197 | ************************************************************************
|
| ... | ... | @@ -501,21 +501,19 @@ tcRnImports hsc_env import_decls |
| 501 | 501 | -- modules batch (@--make@) compiled before this one, but
|
| 502 | 502 | -- which are not below this one.
|
| 503 | 503 | ; (home_insts, home_fam_insts) <- liftIO $
|
| 504 | - hugInstancesBelow hsc_env unitId mnwib
|
|
| 504 | + hugInstancesBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env) unitId mnwib
|
|
| 505 | 505 | |
| 506 | 506 | -- We use 'unsafeInterleaveIO' to avoid redundant memory allocations
|
| 507 | 507 | -- See Note [Lazily loading COMPLETE pragmas] from GHC.HsToCore.Monad
|
| 508 | 508 | -- and see https://gitlab.haskell.org/ghc/ghc/-/merge_requests/14274#note_620545
|
| 509 | 509 | ; completeSigsBelow <- liftIO $ unsafeInterleaveIO $
|
| 510 | - hugCompleteSigsBelow hsc_env unitId mnwib
|
|
| 510 | + hugCompleteSigsBelow (hsc_mod_graph hsc_env) (hsc_HUG hsc_env) unitId mnwib
|
|
| 511 | 511 | |
| 512 | - -- Record boot-file info in the EPS, so that it's
|
|
| 512 | + -- Record boot-file info in the HPT, so that it's
|
|
| 513 | 513 | -- visible to loadHiBootInterface in tcRnSrcDecls,
|
| 514 | 514 | -- and any other incrementally-performed imports
|
| 515 | - ; when (isOneShot (ghcMode (hsc_dflags hsc_env))) $ do {
|
|
| 516 | - ; hpt <- getHpt
|
|
| 517 | - ; liftIO $ hlsSetBootInfo hpt (imp_boot_mods imports)
|
|
| 518 | - }
|
|
| 515 | + ; hpt <- getHpt
|
|
| 516 | + ; liftIO $ hptSetBootInfo hpt (imp_boot_mods imports)
|
|
| 519 | 517 | |
| 520 | 518 | -- Update the gbl env
|
| 521 | 519 | ; updGblEnv ( \ gbl ->
|
| ... | ... | @@ -21,13 +21,17 @@ |
| 21 | 21 | -- Or, do you really need a function to traverse all modules in the HPT? It is
|
| 22 | 22 | -- often better to keep the computation internal to this module, such as in
|
| 23 | 23 | -- 'hptCollectObjects'...
|
| 24 | +{-# OPTIONS_GHC -Wall -Wincomplete-record-selectors #-}
|
|
| 24 | 25 | module GHC.Unit.Home.PackageTable
|
| 25 | 26 | (
|
| 26 | 27 | HomePackageTable(..)
|
| 27 | 28 | , emptyHomePackageTable
|
| 29 | + , emptyOnDemandHomePackageTable
|
|
| 28 | 30 | |
| 29 | - , HomeLoaderState -- TODO: should this be opaque? Probably
|
|
| 30 | - , emptyHomeLoaderState
|
|
| 31 | + , isOneShotMode
|
|
| 32 | + |
|
| 33 | + -- , HomeLoaderState -- TODO: should this be opaque? Probably
|
|
| 34 | + -- , emptyHomeLoaderState
|
|
| 31 | 35 | |
| 32 | 36 | -- * Lookups in the HPT
|
| 33 | 37 | , lookupHpt
|
| ... | ... | @@ -42,13 +46,14 @@ module GHC.Unit.Home.PackageTable |
| 42 | 46 | , restrictHpt
|
| 43 | 47 | |
| 44 | 48 | -- * Queries about home modules
|
| 49 | + , listHptIfaces
|
|
| 45 | 50 | , hptCompleteSigs
|
| 46 | 51 | , hptAllInstances
|
| 47 | 52 | , hptAllFamInstances
|
| 48 | 53 | , hptAllAnnotations
|
| 49 | 54 | , hlsIsModuleNameWithBoot
|
| 50 | 55 | , hlsIsBoot
|
| 51 | - , hlsSetBootInfo
|
|
| 56 | + , hptSetBootInfo
|
|
| 52 | 57 | , hptLoadedIsBoot
|
| 53 | 58 | , hptLoadedTypeEnv
|
| 54 | 59 | , hptLoadedInstEnv
|
| ... | ... | @@ -78,9 +83,8 @@ module GHC.Unit.Home.PackageTable |
| 78 | 83 | --
|
| 79 | 84 | -- In GHC itself these should be avoided, and other uses should justify why
|
| 80 | 85 | -- it is not sufficient to go through the intended insert-only API.
|
| 81 | - , hptInternalTableRef
|
|
| 86 | + -- , hptInternalTableRef
|
|
| 82 | 87 | , hptInternalTableFromRef
|
| 83 | - , hptLoaderState
|
|
| 84 | 88 | -- * Legacy API
|
| 85 | 89 | --
|
| 86 | 90 | -- | This API is deprecated and meant to be removed.
|
| ... | ... | @@ -98,7 +102,6 @@ import GHC.Core.FamInstEnv |
| 98 | 102 | import GHC.Core.InstEnv
|
| 99 | 103 | import GHC.Core.Rules (RuleBase, extendRuleBaseList, emptyRuleBase)
|
| 100 | 104 | import GHC.Data.Word64Set qualified as W64
|
| 101 | -import GHC.Linker.Types (Linkable)
|
|
| 102 | 105 | import GHC.Types.Annotations
|
| 103 | 106 | import GHC.Types.CompleteMatch
|
| 104 | 107 | import GHC.Types.TypeEnv
|
| ... | ... | @@ -117,24 +120,14 @@ import GHC.Types.DefaultEnv (DefaultEnv) |
| 117 | 120 | import GHC.Core
|
| 118 | 121 | |
| 119 | 122 | -- | Helps us find information about modules in the home package
|
| 120 | -data HomePackageTable = HPT {
|
|
| 123 | +data HomePackageTable
|
|
| 124 | + = HPT_Make { table :: {-# UNPACK #-} !(IORef (DModuleNameEnv HomeModInfo)) }
|
|
| 125 | + | HPT_OneShot { loader :: {-# UNPACK #-} !(IORef HomeLoaderState) }
|
|
| 121 | 126 | |
| 122 | - table :: IORef (DModuleNameEnv HomeModInfo),
|
|
| 123 | - -- ^ Domain = modules in this home unit
|
|
| 124 | - --
|
|
| 125 | - -- This is an IORef because we want to avoid leaking HPTs (see the particularly bad #25511).
|
|
| 126 | - -- Moreover, the HPT invariant allows mutability in this table without compromising thread safety or soundness.
|
|
| 127 | - -- To recall:
|
|
| 128 | - -- A query to the HPT should depend only on data relevant to that query, such that
|
|
| 129 | - -- there being more or less unrelated entries in the HPT does not influence the result in any way.
|
|
| 130 | - --
|
|
| 131 | - -- Note that the HPT increases monotonically, except at certain barrier
|
|
| 132 | - -- points like when 'restrictHpt' is called. At these barriers, it is safe
|
|
| 133 | - -- to temporarily violate the HPT monotonicity.
|
|
| 134 | - --
|
|
| 135 | - -- The elements of this table may be updated (e.g. on rehydration).
|
|
| 136 | - loader :: IORef HomeLoaderState
|
|
| 137 | - }
|
|
| 127 | +isOneShotMode :: HomePackageTable -> Bool
|
|
| 128 | +isOneShotMode = \ case
|
|
| 129 | + HPT_OneShot{} -> True
|
|
| 130 | + HPT_Make{} -> False
|
|
| 138 | 131 | |
| 139 | 132 | -- | Create a new 'HomePackageTable'.
|
| 140 | 133 | --
|
| ... | ... | @@ -145,14 +138,19 @@ emptyHomePackageTable :: IO HomePackageTable |
| 145 | 138 | -- romes:todo: use a MutableArray directly?
|
| 146 | 139 | emptyHomePackageTable = do
|
| 147 | 140 | table <- newIORef emptyUDFM
|
| 141 | + return HPT_Make{table}
|
|
| 142 | + |
|
| 143 | +emptyOnDemandHomePackageTable :: IO HomePackageTable
|
|
| 144 | +emptyOnDemandHomePackageTable = do
|
|
| 148 | 145 | loader <- newIORef emptyHomeLoaderState
|
| 149 | - return HPT{table, loader}
|
|
| 146 | + return HPT_OneShot{loader}
|
|
| 150 | 147 | |
| 151 | 148 | data HomeLoaderState = HomeLoaderState
|
| 152 | - { hls_modules :: ModuleEnv ()
|
|
| 149 | + { hls_table :: DModuleNameEnv HomeModInfo
|
|
| 150 | + , hls_modules :: ModuleEnv ()
|
|
| 153 | 151 | , hls_is_boot :: InstalledModuleEnv ModuleNameWithIsBoot
|
| 154 | 152 | , hls_type_env :: !TypeEnv
|
| 155 | - , hls_iface_bytecode :: !(ModuleEnv (IO Linkable))
|
|
| 153 | + -- , hls_iface_bytecode :: !(ModuleEnv (IO Linkable))
|
|
| 156 | 154 | , hls_inst_env :: !InstEnv
|
| 157 | 155 | , hls_fam_inst_env :: !FamInstEnv
|
| 158 | 156 | , hls_mod_fam_inst_env :: !(ModuleEnv FamInstEnv)
|
| ... | ... | @@ -165,10 +163,11 @@ data HomeLoaderState = HomeLoaderState |
| 165 | 163 | emptyHomeLoaderState :: HomeLoaderState
|
| 166 | 164 | emptyHomeLoaderState =
|
| 167 | 165 | HomeLoaderState
|
| 168 | - { hls_modules = emptyModuleEnv
|
|
| 166 | + { hls_table = emptyUDFM
|
|
| 167 | + , hls_modules = emptyModuleEnv
|
|
| 169 | 168 | , hls_is_boot = emptyInstalledModuleEnv
|
| 170 | 169 | , hls_type_env = emptyTypeEnv
|
| 171 | - , hls_iface_bytecode = emptyModuleEnv
|
|
| 170 | + -- , hls_iface_bytecode = emptyModuleEnv
|
|
| 172 | 171 | , hls_inst_env = emptyInstEnv
|
| 173 | 172 | , hls_fam_inst_env = emptyFamInstEnv
|
| 174 | 173 | , hls_mod_fam_inst_env = emptyModuleEnv
|
| ... | ... | @@ -184,7 +183,8 @@ emptyHomeLoaderState = |
| 184 | 183 | |
| 185 | 184 | -- | Lookup the 'HomeModInfo' of a module in the HPT, given its name.
|
| 186 | 185 | lookupHpt :: HomePackageTable -> ModuleName -> IO (Maybe HomeModInfo)
|
| 187 | -lookupHpt HPT{table=hpt} mn = (`lookupUDFM` mn) <$!> readIORef hpt
|
|
| 186 | +lookupHpt HPT_Make{table=hpt} mn = (`lookupUDFM` mn) <$!> readIORef hpt
|
|
| 187 | +lookupHpt HPT_OneShot{loader=hpt} mn = (`lookupUDFM` mn) . hls_table <$!> readIORef hpt
|
|
| 188 | 188 | |
| 189 | 189 | -- | Lookup the 'HomeModInfo' of a 'Module' in the HPT.
|
| 190 | 190 | lookupHptByModule :: HomePackageTable -> Module -> IO (Maybe HomeModInfo)
|
| ... | ... | @@ -195,35 +195,45 @@ lookupHptByModule hpt mod |
| 195 | 195 | Just hm | mi_module (hm_iface hm) == mod -> Just hm
|
| 196 | 196 | _otherwise -> Nothing
|
| 197 | 197 | |
| 198 | -hptLoaderState :: HomePackageTable -> IO HomeLoaderState
|
|
| 199 | -hptLoaderState = readIORef . loader
|
|
| 198 | +queryOnDemandHpt :: a -> (HomeLoaderState -> a) -> HomePackageTable -> IO a
|
|
| 199 | +queryOnDemandHpt a f hpt =
|
|
| 200 | + case hpt of
|
|
| 201 | + HPT_Make{} ->
|
|
| 202 | + pure a
|
|
| 203 | + HPT_OneShot{loader} ->
|
|
| 204 | + f <$> readIORef loader
|
|
| 200 | 205 | |
| 201 | 206 | hptLoadedIsBoot :: HomePackageTable -> IO (InstalledModuleEnv ModuleNameWithIsBoot)
|
| 202 | -hptLoadedIsBoot hpt = hls_is_boot <$> readIORef (loader hpt)
|
|
| 207 | +hptLoadedIsBoot = queryOnDemandHpt emptyInstalledModuleEnv hls_is_boot
|
|
| 203 | 208 | |
| 204 | 209 | hptLoadedTypeEnv :: HomePackageTable -> IO TypeEnv
|
| 205 | -hptLoadedTypeEnv hpt = hls_type_env <$> readIORef (loader hpt)
|
|
| 210 | +hptLoadedTypeEnv = queryOnDemandHpt emptyTypeEnv hls_type_env
|
|
| 206 | 211 | |
| 207 | 212 | hptLoadedInstEnv :: HomePackageTable -> IO InstEnv
|
| 208 | -hptLoadedInstEnv hpt = hls_inst_env <$> readIORef (loader hpt)
|
|
| 213 | +hptLoadedInstEnv = queryOnDemandHpt emptyInstEnv hls_inst_env
|
|
| 209 | 214 | |
| 210 | 215 | hptLoadedFamInstEnv :: HomePackageTable -> IO FamInstEnv
|
| 211 | -hptLoadedFamInstEnv hpt = hls_fam_inst_env <$> readIORef (loader hpt)
|
|
| 216 | +hptLoadedFamInstEnv = queryOnDemandHpt emptyFamInstEnv hls_fam_inst_env
|
|
| 212 | 217 | |
| 213 | 218 | hptLoadedModFamInstEnv :: HomePackageTable -> IO (ModuleEnv FamInstEnv)
|
| 214 | -hptLoadedModFamInstEnv hpt = hls_mod_fam_inst_env <$> readIORef (loader hpt)
|
|
| 219 | +hptLoadedModFamInstEnv = queryOnDemandHpt emptyModuleEnv hls_mod_fam_inst_env
|
|
| 215 | 220 | |
| 216 | 221 | hptLoadedRuleBase :: HomePackageTable -> IO RuleBase
|
| 217 | -hptLoadedRuleBase hpt = hls_rule_base <$> readIORef (loader hpt)
|
|
| 222 | +hptLoadedRuleBase = queryOnDemandHpt emptyRuleBase hls_rule_base
|
|
| 218 | 223 | |
| 219 | 224 | hptLoadedAnnEnv :: HomePackageTable -> IO AnnEnv
|
| 220 | -hptLoadedAnnEnv hpt = hls_ann_env <$> readIORef (loader hpt)
|
|
| 225 | +hptLoadedAnnEnv = queryOnDemandHpt emptyAnnEnv hls_ann_env
|
|
| 221 | 226 | |
| 222 | 227 | hptLoadedCompleteMatches :: HomePackageTable -> IO CompleteMatches
|
| 223 | -hptLoadedCompleteMatches hpt = hls_complete_matches <$> readIORef (loader hpt)
|
|
| 228 | +hptLoadedCompleteMatches = queryOnDemandHpt [] hls_complete_matches
|
|
| 224 | 229 | |
| 225 | 230 | hptLoadedDefaults :: HomePackageTable -> IO (ModuleEnv DefaultEnv)
|
| 226 | -hptLoadedDefaults hpt = hls_defaults <$> readIORef (loader hpt)
|
|
| 231 | +hptLoadedDefaults = queryOnDemandHpt emptyModuleEnv hls_defaults
|
|
| 232 | + |
|
| 233 | +listHptIfaces :: HomePackageTable -> IO (DModuleNameEnv HomeModInfo)
|
|
| 234 | +listHptIfaces = \ case
|
|
| 235 | + HPT_Make{table} -> readIORef table
|
|
| 236 | + HPT_OneShot{loader} -> hls_table <$> readIORef loader
|
|
| 227 | 237 | |
| 228 | 238 | --------------------------------------------------------------------------------
|
| 229 | 239 | -- * Extending the HPT
|
| ... | ... | @@ -244,10 +254,12 @@ addHomeModInfoToHpt hmi hpt = addToHpt hpt (moduleName (mi_module (hm_iface hmi) |
| 244 | 254 | {-# DEPRECATED addToHpt "Deprecated in favour of 'addHomeModInfoToHpt', as the module at which a 'HomeModInfo' is inserted should always be derived from the 'HomeModInfo' itself." #-}
|
| 245 | 255 | -- After deprecation cycle, move `addToHpt` to a `where` clause inside `addHomeModInfoToHpt`.
|
| 246 | 256 | addToHpt :: HomePackageTable -> ModuleName -> HomeModInfo -> IO ()
|
| 247 | -addToHpt HPT{table=hptr} mn hmi = do
|
|
| 257 | +addToHpt HPT_Make{table=hptr} mn hmi = do
|
|
| 248 | 258 | atomicModifyIORef' hptr (\hpt -> (addToUDFM hpt mn hmi, ()))
|
| 249 | 259 | -- If the key already existed in the map, this insertion is overwriting
|
| 250 | 260 | -- the HMI of a previously loaded module (likely in rehydration).
|
| 261 | +addToHpt HPT_OneShot{loader=hptr} mn hmi = do
|
|
| 262 | + atomicModifyIORef' hptr (\hpt -> (hpt { hls_table = addToUDFM (hls_table hpt) mn hmi }, ()))
|
|
| 251 | 263 | |
| 252 | 264 | -- | 'addHomeModInfoToHpt' for multiple module infos.
|
| 253 | 265 | addHomeModInfosToHpt :: HomePackageTable -> [HomeModInfo] -> IO ()
|
| ... | ... | @@ -262,19 +274,21 @@ addHomeModInfosToHpt hpt = mapM_ (flip addHomeModInfoToHpt hpt) |
| 262 | 274 | -- called at barrier points, such as the end of upsweep, when all threads are
|
| 263 | 275 | -- done and we want to clean up failed entries.
|
| 264 | 276 | restrictHpt :: HomePackageTable -> [HomeModInfo] -> IO ()
|
| 265 | -restrictHpt HPT{table=hptr} hmis =
|
|
| 277 | +restrictHpt HPT_Make{table=hptr} hmis =
|
|
| 266 | 278 | let key_set = map (getKey . getUnique . hmi_mod) hmis
|
| 267 | 279 | hmi_mod hmi = moduleName (mi_module (hm_iface hmi))
|
| 268 | 280 | in atomicModifyIORef' hptr (\hpt -> (udfmRestrictKeysSet hpt (W64.fromList key_set), ()))
|
| 281 | +restrictHpt HPT_OneShot{} _ = pure ()
|
|
| 269 | 282 | |
| 270 | 283 | {-# DEPRECATED addListToHpt "Deprecated in favour of 'addHomeModInfosToHpt', as the module at which a 'HomeModInfo' is inserted should always be derived from the 'HomeModInfo' itself." #-}
|
| 271 | 284 | -- After deprecation cycle, remove.
|
| 272 | 285 | addListToHpt :: HomePackageTable -> [(ModuleName, HomeModInfo)] -> IO ()
|
| 273 | 286 | addListToHpt hpt = mapM_ (uncurry (addToHpt hpt))
|
| 274 | 287 | |
| 275 | -addOnDemandHomeModule :: HomePackageTable -> Module -> Bool -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> Maybe (IO Linkable) -> IO ()
|
|
| 276 | -addOnDemandHomeModule hpt mn bad_boot (new_hls_decls, new_hls_insts, new_hls_defaults, new_hls_fam_insts, new_hls_rules, new_hls_anns, new_hls_complete_matches) bytecode = do
|
|
| 277 | - atomicModifyIORef (loader hpt) $ \hls ->
|
|
| 288 | +addOnDemandHomeModule :: HomePackageTable -> Module -> Bool -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IO ()
|
|
| 289 | +addOnDemandHomeModule HPT_Make{} _ _ _ = pure ()
|
|
| 290 | +addOnDemandHomeModule HPT_OneShot{loader} mn bad_boot (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
|
|
| 291 | + atomicModifyIORef loader $ \hls ->
|
|
| 278 | 292 | ( if mn `elemModuleEnv` hls_modules hls
|
| 279 | 293 | then hls -- If already loaded, don't add twice
|
| 280 | 294 | else
|
| ... | ... | @@ -285,41 +299,39 @@ addOnDemandHomeModule hpt mn bad_boot (new_hls_decls, new_hls_insts, new_hls_def |
| 285 | 299 | )
|
| 286 | 300 | where
|
| 287 | 301 | addHomeModTypeEnv hls = hls
|
| 288 | - { hls_type_env = extendNameEnvList (hls_type_env hls) new_hls_decls
|
|
| 302 | + { hls_type_env = extendNameEnvList (hls_type_env hls) new_decls
|
|
| 289 | 303 | }
|
| 290 | 304 | |
| 291 | 305 | addHomeModData hls = hls {
|
| 292 | - hls_modules = extendModuleEnv (hls_modules hls) mn (),
|
|
| 293 | - hls_type_env = extendNameEnvList (hls_type_env hls) new_hls_decls,
|
|
| 294 | - hls_iface_bytecode = case bytecode of
|
|
| 295 | - Nothing -> hls_iface_bytecode hls
|
|
| 296 | - Just bc -> extendModuleEnv (hls_iface_bytecode hls) mn bc,
|
|
| 306 | + hls_modules = extendModuleEnv (hls_modules hls) mn (),
|
|
| 307 | + hls_type_env = extendNameEnvList (hls_type_env hls) new_decls,
|
|
| 297 | 308 | hls_rule_base = extendRuleBaseList (hls_rule_base hls)
|
| 298 | - new_hls_rules,
|
|
| 309 | + new_rules,
|
|
| 299 | 310 | hls_complete_matches
|
| 300 | - = hls_complete_matches hls ++ new_hls_complete_matches,
|
|
| 311 | + = hls_complete_matches hls ++ new_complete_matches,
|
|
| 301 | 312 | hls_inst_env = extendInstEnvList (hls_inst_env hls)
|
| 302 | - new_hls_insts,
|
|
| 313 | + new_insts,
|
|
| 303 | 314 | hls_fam_inst_env = extendFamInstEnvList (hls_fam_inst_env hls)
|
| 304 | - new_hls_fam_insts,
|
|
| 315 | + new_fam_insts,
|
|
| 305 | 316 | hls_ann_env = extendAnnEnvList (hls_ann_env hls)
|
| 306 | - new_hls_anns,
|
|
| 317 | + new_anns,
|
|
| 307 | 318 | hls_mod_fam_inst_env
|
| 308 | 319 | =
|
| 309 | 320 | let
|
| 310 | 321 | fam_inst_env =
|
| 311 | 322 | extendFamInstEnvList emptyFamInstEnv
|
| 312 | - new_hls_fam_insts
|
|
| 323 | + new_fam_insts
|
|
| 313 | 324 | in
|
| 314 | 325 | extendModuleEnv (hls_mod_fam_inst_env hls)
|
| 315 | 326 | mn
|
| 316 | 327 | fam_inst_env,
|
| 317 | - hls_defaults = extendModuleEnv (hls_defaults hls) mn new_hls_defaults
|
|
| 328 | + hls_defaults = extendModuleEnv (hls_defaults hls) mn new_defaults
|
|
| 318 | 329 | }
|
| 319 | 330 | |
| 320 | -hlsSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO ()
|
|
| 321 | -hlsSetBootInfo hpt is_boot_env =
|
|
| 322 | - atomicModifyIORef' (loader hpt) $ \ hls ->
|
|
| 331 | +hptSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO ()
|
|
| 332 | +hptSetBootInfo HPT_Make{} _ = pure ()
|
|
| 333 | +hptSetBootInfo HPT_OneShot{loader} is_boot_env =
|
|
| 334 | + atomicModifyIORef' loader $ \ hls ->
|
|
| 323 | 335 | (hls { hls_is_boot = is_boot_env }, ())
|
| 324 | 336 | |
| 325 | 337 | ----------------------------------------------------------------------------------
|
| ... | ... | @@ -370,7 +382,11 @@ hlsIsModuleNameWithBoot hls mn = lookupInstalledModuleEnv (hls_is_boot hls) mn |
| 370 | 382 | -- currently takes all dependencies only to then filter them with an ad-hoc transitive closure check.
|
| 371 | 383 | -- See #25639
|
| 372 | 384 | hptCollectDependencies :: HomePackageTable -> IO (Set.Set (IfaceImportLevel, UnitId))
|
| 373 | -hptCollectDependencies HPT{table} = do
|
|
| 385 | +hptCollectDependencies HPT_OneShot{loader} = do
|
|
| 386 | + hpt <- readIORef loader
|
|
| 387 | + return $
|
|
| 388 | + foldr (Set.union . dep_direct_pkgs . mi_deps . hm_iface) Set.empty (hls_table hpt)
|
|
| 389 | +hptCollectDependencies HPT_Make{table} = do
|
|
| 374 | 390 | hpt <- readIORef table
|
| 375 | 391 | return $
|
| 376 | 392 | foldr (Set.union . dep_direct_pkgs . mi_deps . hm_iface) Set.empty hpt
|
| ... | ... | @@ -380,7 +396,11 @@ hptCollectDependencies HPT{table} = do |
| 380 | 396 | --
|
| 381 | 397 | -- $O(n)$ in the number of modules in the HPT.
|
| 382 | 398 | hptCollectHomeModInfo :: HomePackageTable -> IO [HomeModInfo]
|
| 383 | -hptCollectHomeModInfo HPT{table} = do
|
|
| 399 | +hptCollectHomeModInfo HPT_OneShot{loader} = do
|
|
| 400 | + hpt <- readIORef loader
|
|
| 401 | + return $
|
|
| 402 | + foldr (:) [] (hls_table hpt)
|
|
| 403 | +hptCollectHomeModInfo HPT_Make{table} = do
|
|
| 384 | 404 | hpt <- readIORef table
|
| 385 | 405 | return $
|
| 386 | 406 | foldr (:) [] hpt
|
| ... | ... | @@ -398,7 +418,13 @@ hptCollectHomeModInfo HPT{table} = do |
| 398 | 418 | -- unit map in failed lookups.
|
| 399 | 419 | pprHPT :: HomePackageTable -> IO SDoc
|
| 400 | 420 | -- A bit arbitrary for now
|
| 401 | -pprHPT HPT{table=hptr} = do
|
|
| 421 | +pprHPT HPT_OneShot{loader=hptr} = do
|
|
| 422 | + hpt <- readIORef hptr
|
|
| 423 | + return $!
|
|
| 424 | + pprUDFM (hls_table hpt) $ \hms ->
|
|
| 425 | + vcat [ ppr (mi_module (hm_iface hm))
|
|
| 426 | + | hm <- hms ]
|
|
| 427 | +pprHPT HPT_Make{table=hptr} = do
|
|
| 402 | 428 | hpt <- readIORef hptr
|
| 403 | 429 | return $!
|
| 404 | 430 | pprUDFM hpt $ \hms ->
|
| ... | ... | @@ -437,7 +463,12 @@ pprHPT HPT{table=hptr} = do |
| 437 | 463 | -- If this function is ever exposed from the HPT module, make sure the
|
| 438 | 464 | -- argument function doesn't introduce leaks.
|
| 439 | 465 | concatHpt :: (HomeModInfo -> [a]) -> HomePackageTable -> IO [a]
|
| 440 | -concatHpt f HPT{table} = do
|
|
| 466 | +concatHpt f HPT_OneShot{loader} = do
|
|
| 467 | + hpt <- readIORef loader
|
|
| 468 | + return $ concat . eltsUDFM . mapMaybeUDFM g $ hls_table hpt
|
|
| 469 | + where
|
|
| 470 | + g hmi = case f hmi of { [] -> Nothing; as -> Just as }
|
|
| 471 | +concatHpt f HPT_Make{table} = do
|
|
| 441 | 472 | hpt <- readIORef table
|
| 442 | 473 | return $ concat . eltsUDFM . mapMaybeUDFM g $ hpt
|
| 443 | 474 | where
|
| ... | ... | @@ -449,15 +480,15 @@ concatHpt f HPT{table} = do |
| 449 | 480 | |
| 450 | 481 | -- | Gets the internal 'IORef' which holds the 'HomeModInfo's of this HPT.
|
| 451 | 482 | -- Use with care.
|
| 452 | -hptInternalTableRef :: HomePackageTable -> IORef (DModuleNameEnv HomeModInfo)
|
|
| 453 | -hptInternalTableRef = table
|
|
| 483 | +-- hptInternalTableRef :: HomePackageTable -> IORef (DModuleNameEnv HomeModInfo)
|
|
| 484 | +-- hptInternalTableRef = \ case
|
|
| 485 | +-- HPT_Make{table} -> table
|
|
| 486 | +-- HPT_OneShot{} -> -- TODO: @fendor how does this make sense?
|
|
| 454 | 487 | |
| 455 | 488 | -- | Construct a HomePackageTable from the IORef.
|
| 456 | 489 | -- Use with care, only if you can really justify going around the intended insert-only API.
|
| 457 | 490 | hptInternalTableFromRef :: IORef (DModuleNameEnv HomeModInfo) -> IO HomePackageTable
|
| 458 | 491 | hptInternalTableFromRef ref = do
|
| 459 | - loader <- newIORef emptyHomeLoaderState
|
|
| 460 | - return HPT {
|
|
| 461 | - table = ref,
|
|
| 462 | - loader
|
|
| 492 | + return HPT_Make {
|
|
| 493 | + table = ref
|
|
| 463 | 494 | } |
| ... | ... | @@ -7,7 +7,6 @@ module GHCi.Leak |
| 7 | 7 | |
| 8 | 8 | import Control.Monad
|
| 9 | 9 | import Data.Bits
|
| 10 | -import Data.IORef
|
|
| 11 | 10 | import Foreign.Ptr (ptrToIntPtr, intPtrToPtr)
|
| 12 | 11 | import GHC
|
| 13 | 12 | import GHC.Ptr (Ptr (..))
|
| ... | ... | @@ -43,7 +42,7 @@ data LeakModIndicators = LeakModIndicators |
| 43 | 42 | getLeakIndicators :: HscEnv -> IO LeakIndicators
|
| 44 | 43 | getLeakIndicators hsc_env =
|
| 45 | 44 | fmap LeakIndicators $ do
|
| 46 | - hpt <- readIORef $ hptInternalTableRef $ hsc_HPT hsc_env
|
|
| 45 | + hpt <- listHptIfaces $ hsc_HPT hsc_env
|
|
| 47 | 46 | forM (eltsUDFM hpt) $ \hmi@HomeModInfo{..} -> do
|
| 48 | 47 | leakMod <- mkWeakPtr hmi Nothing
|
| 49 | 48 | leakIface <- mkWeakPtr hm_iface Nothing
|