Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC
Commits:
-
3f3a9049
by fendor at 2026-11-30T13:55:11+01:00
-
1f02fa8d
by Hannes Siebenhandl at 2026-11-30T13:55:12+01:00
26 changed files:
- compiler/GHC.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Rules.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/Tc/Utils/Instantiate.hs
- compiler/GHC/Unit/Env.hs
- compiler/GHC/Unit/Home/Graph.hs
- compiler/GHC/Unit/Home/PackageTable.hs
- compiler/GHC/Unit/Module/Env.hs
- ghc/GHCi/Leak.hs
- testsuite/tests/bytecode/T25090/Makefile
- testsuite/tests/bytecode/T25090/all.T
- + testsuite/tests/driver/one-shot-boot/A.hs
- + testsuite/tests/driver/one-shot-boot/B.hs
- + testsuite/tests/driver/one-shot-boot/Fam.hs
- + testsuite/tests/driver/one-shot-boot/M.hs
- + testsuite/tests/driver/one-shot-boot/M.hs-boot
- + testsuite/tests/driver/one-shot-boot/Main.hs
- + testsuite/tests/driver/one-shot-boot/Makefile
- + testsuite/tests/driver/one-shot-boot/all.T
- + testsuite/tests/driver/one-shot-boot/one-shot-boot.stdout
Changes:
| ... | ... | @@ -442,13 +442,14 @@ import GHC.Types.PkgQual |
| 442 | 442 | import GHC.Unit
|
| 443 | 443 | import GHC.Unit.Env as UnitEnv
|
| 444 | 444 | import GHC.Unit.Finder
|
| 445 | -import GHC.Unit.Module.ModIface
|
|
| 446 | -import GHC.Unit.Module.ModGuts
|
|
| 445 | +import GHC.Unit.Home.Graph qualified as HUG
|
|
| 446 | +import GHC.Unit.Home.ModInfo
|
|
| 447 | +import GHC.Unit.Home.PackageTable qualified as HPT
|
|
| 448 | +import GHC.Unit.Module.Graph
|
|
| 447 | 449 | import GHC.Unit.Module.ModDetails
|
| 450 | +import GHC.Unit.Module.ModGuts
|
|
| 451 | +import GHC.Unit.Module.ModIface
|
|
| 448 | 452 | import GHC.Unit.Module.ModSummary
|
| 449 | -import GHC.Unit.Module.Graph
|
|
| 450 | -import GHC.Unit.Home.ModInfo
|
|
| 451 | -import qualified GHC.Unit.Home.Graph as HUG
|
|
| 452 | 453 | |
| 453 | 454 | import Control.Applicative ((<|>))
|
| 454 | 455 | import Control.Monad
|
| ... | ... | @@ -693,14 +694,43 @@ setUnitDynFlagsNoCheck uid dflags1 = do |
| 693 | 694 | (unit_state,home_unit,mconstants) <- liftIO $ initUnits logger dflags1 (hscUIC hsc_env) (hsc_all_home_unit_ids hsc_env)
|
| 694 | 695 | updated_dflags <- liftIO $ updatePlatformConstants dflags1 mconstants
|
| 695 | 696 | |
| 696 | - let upd hue =
|
|
| 697 | - hue
|
|
| 698 | - { homeUnitEnv_units = unit_state
|
|
| 699 | - , homeUnitEnv_dflags = updated_dflags
|
|
| 700 | - , homeUnitEnv_home_unit = Just home_unit
|
|
| 701 | - }
|
|
| 697 | + let
|
|
| 698 | + upd hue = do
|
|
| 699 | + let
|
|
| 700 | + warnOnNonEmptyTable =
|
|
| 701 | + whenM (not <$> HPT.isHptEmpty (homeUnitEnv_hpt hue)) $ do
|
|
| 702 | + logInfo logger
|
|
| 703 | + ( text "Changed the ghc mode" <+> ppr (ghcMode $ homeUnitEnv_dflags hue) <+> text "to" <+> ppr (ghcMode updated_dflags) $$
|
|
| 704 | + text "The home package table was not empty!" $$
|
|
| 705 | + text "The table was cleared any way."
|
|
| 706 | + )
|
|
| 707 | + the_hpt <-
|
|
| 708 | + case (HPT.isOneShotMode (homeUnitEnv_hpt hue), ghcMode updated_dflags) of
|
|
| 709 | + (True, OneShot) ->
|
|
| 710 | + pure $ homeUnitEnv_hpt hue
|
|
| 711 | + (True, CompManager) -> do
|
|
| 712 | + warnOnNonEmptyTable
|
|
| 713 | + HPT.emptyHomePackageTable
|
|
| 714 | + (True, MkDepend) -> do
|
|
| 715 | + warnOnNonEmptyTable
|
|
| 716 | + HPT.emptyHomePackageTable
|
|
| 717 | + (False, OneShot) -> do
|
|
| 718 | + warnOnNonEmptyTable
|
|
| 719 | + HPT.emptyOnDemandHomePackageTable
|
|
| 720 | + (False, CompManager) ->
|
|
| 721 | + pure $ homeUnitEnv_hpt hue
|
|
| 722 | + (False, MkDepend) ->
|
|
| 723 | + pure $ homeUnitEnv_hpt hue
|
|
| 724 | + pure hue
|
|
| 725 | + { homeUnitEnv_units = unit_state
|
|
| 726 | + , homeUnitEnv_dflags = updated_dflags
|
|
| 727 | + , homeUnitEnv_home_unit = Just home_unit
|
|
| 728 | + , homeUnitEnv_hpt = the_hpt
|
|
| 729 | + }
|
|
| 730 | + |
|
| 731 | + |
|
| 702 | 732 | |
| 703 | - let unit_env = UnitEnv.ue_updateHomeUnitEnv upd uid (hsc_unit_env hsc_env)
|
|
| 733 | + unit_env <- liftIO $ UnitEnv.ue_adjustHomeUnitEnvA upd uid (hsc_unit_env hsc_env)
|
|
| 704 | 734 | |
| 705 | 735 | let dflags = updated_dflags
|
| 706 | 736 |
| ... | ... | @@ -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
|
| ... | ... | @@ -401,7 +401,7 @@ lookupRuleBase = lookupUFM |
| 401 | 401 | |
| 402 | 402 | unionRuleBase :: RuleBase -> RuleBase -> RuleBase
|
| 403 | 403 | unionRuleBase
|
| 404 | - = plusUFM
|
|
| 404 | + = plusUFM_C (++)
|
|
| 405 | 405 | |
| 406 | 406 | pprRuleBase :: RuleBase -> SDoc
|
| 407 | 407 | pprRuleBase rules = pprUFM rules $ \rss ->
|
| ... | ... | @@ -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
|
| ... | ... | @@ -834,9 +833,9 @@ loadInterface doc_str mod from |
| 834 | 833 | ; if fromMaybe False $ fmap (`isHomeModule` mod) mhome_unit -- TODO @fendor: horrible code
|
| 835 | 834 | then do -- TODO @fendor: document that we don't want/need 'dontLeakTheHUG' here
|
| 836 | 835 | massertPpr (moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env)
|
| 837 | - (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))
|
|
| 836 | + (text "Attempting to load 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 | --
|
| ... | ... | @@ -858,7 +857,7 @@ loadInterface doc_str mod from |
| 858 | 857 | (moduleUnitId mod `Set.notMember` hsc_all_home_unit_ids hsc_env)
|
| 859 | 858 | (text "Attempting to load home package interface into the EPS" $$ ppr (HUG.allUnits $ hsc_HUG hsc_env) $$ doc_str $$ ppr mod $$ ppr (moduleUnitId mod))
|
| 860 | 859 | tcParts <- tcPartsOfTheIface mod iface
|
| 861 | - addModIfacePartsToEps gbl_env mod loc iface tcParts
|
|
| 860 | + addModIfacePartsToEps mod loc iface tcParts
|
|
| 862 | 861 | |
| 863 | 862 | ; -- invoke plugins with *full* interface, not final_iface, to ensure
|
| 864 | 863 | -- that plugins have access to declarations, etc.
|
| ... | ... | @@ -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,12 @@ 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 | - 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
|
|
| 910 | + when (not bad_boot) $ do
|
|
| 911 | + liftIO $ addHomeModInfoToHpt (HomeModInfo iface details emptyHomeModInfoLinkable) hpt
|
|
| 912 | + liftIO $ addOnDemandHomeModule hpt mod bad_boot (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches)
|
|
| 919 | 913 | |
| 920 | -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 :: Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL ()
|
|
| 915 | +addModIfacePartsToEps mod loc iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
|
|
| 922 | 916 | purged_hsc_env <- getTopEnv
|
| 923 | 917 | |
| 924 | 918 | let
|
| ... | ... | @@ -930,19 +924,12 @@ addModIfacePartsToEps gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_e |
| 930 | 924 | & set_mi_rules (panic "No mi_rules in PIT")
|
| 931 | 925 | & set_mi_anns (panic "No mi_anns in PIT")
|
| 932 | 926 | & set_mi_simplified_core (panic "No mi_simplified_core in PIT")
|
| 933 | - |
|
| 934 | - bad_boot = mi_boot iface == IsBoot
|
|
| 935 | - && isJust (lookupKnotVars (if_rec_types gbl_env) mod)
|
|
| 936 | - -- Warn against an EPS-updating import
|
|
| 937 | - -- of one's own boot file! (one-shot only)
|
|
| 938 | - -- See Note [Loading your own hi-boot file]
|
|
| 939 | - |
|
| 940 | 927 | -- Create an IO action that loads and compiles bytecode from Core
|
| 941 | 928 | -- bindings.
|
| 942 | 929 | --
|
| 943 | 930 | -- See Note [Interface Files with Core Definitions]
|
| 944 | 931 | add_bytecode old
|
| 945 | - | Just action <- loadIfaceByteCode purged_hsc_env iface loc (mkNameEnv new_eps_decls)
|
|
| 932 | + | Just action <- loadIfaceByteCode purged_hsc_env iface loc (mkNameEnv new_decls)
|
|
| 946 | 933 | = extendModuleEnv old mod action
|
| 947 | 934 | -- Don't add an entry if the iface doesn't have 'extra_decls'
|
| 948 | 935 | -- so 'get_link_deps' knows that it should load object code.
|
| ... | ... | @@ -950,43 +937,39 @@ addModIfacePartsToEps gbl_env mod loc iface (new_eps_decls, new_eps_insts, new_e |
| 950 | 937 | = old
|
| 951 | 938 | |
| 952 | 939 | mhome_unit = ue_homeUnit (hsc_unit_env purged_hsc_env)
|
| 953 | - warnPprTrace bad_boot "loadInterface" (ppr mod) $
|
|
| 954 | - updateEps_ $ \ eps ->
|
|
| 955 | - if elemModuleEnv mod (eps_PIT eps) || is_external_sig mhome_unit iface
|
|
| 956 | - then eps
|
|
| 957 | - else if bad_boot
|
|
| 958 | - -- See Note [Loading your own hi-boot file]
|
|
| 959 | - then eps { eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls }
|
|
| 960 | - else
|
|
| 961 | - eps {
|
|
| 962 | - eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
|
|
| 963 | - eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls,
|
|
| 964 | - eps_iface_bytecode = add_bytecode (eps_iface_bytecode eps),
|
|
| 965 | - eps_rule_base = extendRuleBaseList (eps_rule_base eps)
|
|
| 966 | - new_eps_rules,
|
|
| 967 | - eps_complete_matches
|
|
| 968 | - = eps_complete_matches eps ++ new_eps_complete_matches,
|
|
| 969 | - eps_inst_env = extendInstEnvList (eps_inst_env eps)
|
|
| 970 | - new_eps_insts,
|
|
| 971 | - eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
|
|
| 972 | - new_eps_fam_insts,
|
|
| 973 | - eps_ann_env = extendAnnEnvList (eps_ann_env eps)
|
|
| 974 | - new_eps_anns,
|
|
| 975 | - eps_mod_fam_inst_env
|
|
| 976 | - = let
|
|
| 977 | - fam_inst_env =
|
|
| 978 | - extendFamInstEnvList emptyFamInstEnv
|
|
| 979 | - new_eps_fam_insts
|
|
| 980 | - in
|
|
| 981 | - extendModuleEnv (eps_mod_fam_inst_env eps)
|
|
| 982 | - mod
|
|
| 983 | - fam_inst_env,
|
|
| 984 | - 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
|
|
| 989 | - }
|
|
| 940 | + updateEps_ $ \ eps ->
|
|
| 941 | + if elemModuleEnv mod (eps_PIT eps) || is_external_sig mhome_unit iface
|
|
| 942 | + then eps
|
|
| 943 | + else
|
|
| 944 | + eps {
|
|
| 945 | + eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
|
|
| 946 | + eps_PTE = addDeclsToPTE (eps_PTE eps) new_decls,
|
|
| 947 | + eps_iface_bytecode = add_bytecode (eps_iface_bytecode eps),
|
|
| 948 | + eps_rule_base = extendRuleBaseList (eps_rule_base eps)
|
|
| 949 | + new_rules,
|
|
| 950 | + eps_complete_matches
|
|
| 951 | + = eps_complete_matches eps ++ new_complete_matches,
|
|
| 952 | + eps_inst_env = extendInstEnvList (eps_inst_env eps)
|
|
| 953 | + new_insts,
|
|
| 954 | + eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
|
|
| 955 | + new_fam_insts,
|
|
| 956 | + eps_ann_env = extendAnnEnvList (eps_ann_env eps)
|
|
| 957 | + new_anns,
|
|
| 958 | + eps_mod_fam_inst_env
|
|
| 959 | + = let
|
|
| 960 | + fam_inst_env =
|
|
| 961 | + extendFamInstEnvList emptyFamInstEnv
|
|
| 962 | + new_fam_insts
|
|
| 963 | + in
|
|
| 964 | + extendModuleEnv (eps_mod_fam_inst_env eps)
|
|
| 965 | + mod
|
|
| 966 | + fam_inst_env,
|
|
| 967 | + eps_stats = addEpsInStats (eps_stats eps)
|
|
| 968 | + (length new_decls)
|
|
| 969 | + (length new_insts)
|
|
| 970 | + (length new_rules),
|
|
| 971 | + eps_defaults = extendModuleEnv (eps_defaults eps) mod new_defaults
|
|
| 972 | + }
|
|
| 990 | 973 | |
| 991 | 974 | |
| 992 | 975 | {- Note [Loading your own hi-boot file]
|
| ... | ... | @@ -1204,10 +1187,10 @@ moduleFreeHolesPrecise doc_str mod |
| 1204 | 1187 | return (Succeeded (renameFreeHoles ifhs insts))
|
| 1205 | 1188 | Failed err -> return (Failed err)
|
| 1206 | 1189 | |
| 1207 | -wantHiBootFile :: Maybe HomeUnit -> HomeLoaderState -> Module -> WhereFrom
|
|
| 1190 | +wantHiBootFile :: Maybe HomeUnit -> InstalledModuleEnv ModuleNameWithIsBoot -> Module -> WhereFrom
|
|
| 1208 | 1191 | -> MaybeErr MissingInterfaceError IsBootInterface
|
| 1209 | 1192 | -- Figure out whether we want Foo.hi or Foo.hi-boot
|
| 1210 | -wantHiBootFile mhome_unit hls mod from
|
|
| 1193 | +wantHiBootFile mhome_unit is_boot_map mod from
|
|
| 1211 | 1194 | = case from of
|
| 1212 | 1195 | ImportByUser usr_boot
|
| 1213 | 1196 | | usr_boot == IsBoot && notHomeModuleMaybe mhome_unit mod
|
| ... | ... | @@ -1226,9 +1209,9 @@ wantHiBootFile mhome_unit hls mod from |
| 1226 | 1209 | -- We never import boot modules from other packages!
|
| 1227 | 1210 | |
| 1228 | 1211 | | otherwise
|
| 1229 | - -> case hlsIsBoot hls (toUnitId <$> mod) of
|
|
| 1230 | - Just is_boot ->
|
|
| 1231 | - Succeeded is_boot
|
|
| 1212 | + -> case lookupInstalledModuleEnv is_boot_map (toUnitId <$> mod) of
|
|
| 1213 | + Just mnib ->
|
|
| 1214 | + Succeeded $ gwib_isBoot mnib
|
|
| 1232 | 1215 | Nothing ->
|
| 1233 | 1216 | Succeeded NotBoot
|
| 1234 | 1217 | -- 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 ->
|
| ... | ... | @@ -947,13 +947,6 @@ addLocalInst (home_ie, my_insts) ispec |
| 947 | 947 | ; let (_tvs, cls, tys) = instanceHead ispec
|
| 948 | 948 | (matches, _, _) = lookupInstEnv False inst_envs cls tys
|
| 949 | 949 | dups = filter (identicalClsInstHead ispec) (map fst matches)
|
| 950 | - ; traceRn "addLocalInst 0" (ppr ispec)
|
|
| 951 | - ; traceRn "addLocalInst 1" (ppr home_ie)
|
|
| 952 | - ; traceRn "addLocalInst 2" (ppr my_insts)
|
|
| 953 | - ; traceRn "addLocalInst 3" (ppr matches)
|
|
| 954 | - ; traceRn "addLocalInst 4" (ppr dups)
|
|
| 955 | - ; traceRn "addLocalInst 5" (ppr global_ie)
|
|
| 956 | - ; traceRn "addLocalInst 6" (ppr extra_inst_env)
|
|
| 957 | 950 | ; unless (null dups) $
|
| 958 | 951 | dupInstErr ispec (head dups)
|
| 959 | 952 |
| ... | ... | @@ -52,6 +52,7 @@ module GHC.Unit.Env |
| 52 | 52 | , ue_unitHomeUnit
|
| 53 | 53 | , ue_unitHomeUnit_maybe
|
| 54 | 54 | , ue_updateHomeUnitEnv
|
| 55 | + , ue_adjustHomeUnitEnvA
|
|
| 55 | 56 | , ue_all_home_unit_ids
|
| 56 | 57 | , ue_unsafeHomeUnit
|
| 57 | 58 | |
| ... | ... | @@ -360,6 +361,13 @@ ue_updateHomeUnitEnv f uid e = e |
| 360 | 361 | { ue_home_unit_graph = HUG.unitEnv_adjust f uid $ ue_home_unit_graph e
|
| 361 | 362 | }
|
| 362 | 363 | |
| 364 | +ue_adjustHomeUnitEnvA :: Applicative f => (HomeUnitEnv -> f HomeUnitEnv) -> UnitId -> UnitEnv -> f UnitEnv
|
|
| 365 | +ue_adjustHomeUnitEnvA f uid e =
|
|
| 366 | + let
|
|
| 367 | + hugA = HUG.unitEnv_adjustA f uid $ ue_home_unit_graph e
|
|
| 368 | + in
|
|
| 369 | + (\ hug -> e { ue_home_unit_graph = hug }) <$> hugA
|
|
| 370 | + |
|
| 363 | 371 | ue_all_home_unit_ids :: UnitEnv -> Set.Set UnitId
|
| 364 | 372 | ue_all_home_unit_ids = HUG.allUnits . ue_home_unit_graph
|
| 365 | 373 |
| ... | ... | @@ -61,6 +61,8 @@ module GHC.Unit.Home.Graph |
| 61 | 61 | , unitEnv_foldWithKey
|
| 62 | 62 | , unitEnv_singleton
|
| 63 | 63 | , unitEnv_adjust
|
| 64 | + , unitEnv_adjustA
|
|
| 65 | + , unitEnv_alterF
|
|
| 64 | 66 | , unitEnv_keys
|
| 65 | 67 | , unitEnv_insert
|
| 66 | 68 | , unitEnv_new
|
| ... | ... | @@ -320,6 +322,17 @@ unitEnv_adjust f uid unitEnv = unitEnv |
| 320 | 322 | { unitEnv_graph = Map.adjust f uid (unitEnv_graph unitEnv)
|
| 321 | 323 | }
|
| 322 | 324 | |
| 325 | +unitEnv_adjustA :: Applicative f => (v -> f v) -> UnitEnvGraphKey -> UnitEnvGraph v -> f (UnitEnvGraph v)
|
|
| 326 | +unitEnv_adjustA f uid unitEnv =
|
|
| 327 | + unitEnv_alterF go uid unitEnv
|
|
| 328 | + where
|
|
| 329 | + go Nothing = pure Nothing
|
|
| 330 | + go (Just v) = Just <$> f v
|
|
| 331 | + |
|
| 332 | +unitEnv_alterF :: Functor f => (Maybe v -> f (Maybe v)) -> UnitEnvGraphKey -> UnitEnvGraph v -> f (UnitEnvGraph v)
|
|
| 333 | +unitEnv_alterF f uid unitEnv =
|
|
| 334 | + UnitEnvGraph <$> Map.alterF f uid (unitEnv_graph unitEnv)
|
|
| 335 | + |
|
| 323 | 336 | unitEnv_singleton :: UnitEnvGraphKey -> v -> UnitEnvGraph v
|
| 324 | 337 | unitEnv_singleton active m = UnitEnvGraph
|
| 325 | 338 | { unitEnv_graph = Map.singleton active m
|
| ... | ... | @@ -21,13 +21,18 @@ |
| 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 | - HomePackageTable(..)
|
|
| 27 | + HomePackageTable
|
|
| 27 | 28 | , emptyHomePackageTable
|
| 29 | + , emptyOnDemandHomePackageTable
|
|
| 28 | 30 | |
| 29 | - , HomeLoaderState -- TODO: should this be opaque? Probably
|
|
| 30 | - , emptyHomeLoaderState
|
|
| 31 | + , isOneShotMode
|
|
| 32 | + , isHptEmpty
|
|
| 33 | + |
|
| 34 | + -- , HomeLoaderState -- TODO: should this be opaque? Probably
|
|
| 35 | + -- , emptyHomeLoaderState
|
|
| 31 | 36 | |
| 32 | 37 | -- * Lookups in the HPT
|
| 33 | 38 | , lookupHpt
|
| ... | ... | @@ -42,13 +47,12 @@ module GHC.Unit.Home.PackageTable |
| 42 | 47 | , restrictHpt
|
| 43 | 48 | |
| 44 | 49 | -- * Queries about home modules
|
| 50 | + , listHptIfaces
|
|
| 45 | 51 | , hptCompleteSigs
|
| 46 | 52 | , hptAllInstances
|
| 47 | 53 | , hptAllFamInstances
|
| 48 | 54 | , hptAllAnnotations
|
| 49 | - , hlsIsModuleNameWithBoot
|
|
| 50 | - , hlsIsBoot
|
|
| 51 | - , hlsSetBootInfo
|
|
| 55 | + , hptSetBootInfo
|
|
| 52 | 56 | , hptLoadedIsBoot
|
| 53 | 57 | , hptLoadedTypeEnv
|
| 54 | 58 | , hptLoadedInstEnv
|
| ... | ... | @@ -78,9 +82,8 @@ module GHC.Unit.Home.PackageTable |
| 78 | 82 | --
|
| 79 | 83 | -- In GHC itself these should be avoided, and other uses should justify why
|
| 80 | 84 | -- it is not sufficient to go through the intended insert-only API.
|
| 81 | - , hptInternalTableRef
|
|
| 85 | + -- , hptInternalTableRef
|
|
| 82 | 86 | , hptInternalTableFromRef
|
| 83 | - , hptLoaderState
|
|
| 84 | 87 | -- * Legacy API
|
| 85 | 88 | --
|
| 86 | 89 | -- | This API is deprecated and meant to be removed.
|
| ... | ... | @@ -98,7 +101,6 @@ import GHC.Core.FamInstEnv |
| 98 | 101 | import GHC.Core.InstEnv
|
| 99 | 102 | import GHC.Core.Rules (RuleBase, extendRuleBaseList, emptyRuleBase)
|
| 100 | 103 | import GHC.Data.Word64Set qualified as W64
|
| 101 | -import GHC.Linker.Types (Linkable)
|
|
| 102 | 104 | import GHC.Types.Annotations
|
| 103 | 105 | import GHC.Types.CompleteMatch
|
| 104 | 106 | import GHC.Types.TypeEnv
|
| ... | ... | @@ -117,24 +119,19 @@ import GHC.Types.DefaultEnv (DefaultEnv) |
| 117 | 119 | import GHC.Core
|
| 118 | 120 | |
| 119 | 121 | -- | Helps us find information about modules in the home package
|
| 120 | -data HomePackageTable = HPT {
|
|
| 122 | +data HomePackageTable
|
|
| 123 | + = HPT_Make { table :: {-# UNPACK #-} !(IORef (DModuleNameEnv HomeModInfo)) }
|
|
| 124 | + | HPT_OneShot { loader :: {-# UNPACK #-} !(IORef HomeLoaderState) }
|
|
| 121 | 125 | |
| 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 | - }
|
|
| 126 | +isOneShotMode :: HomePackageTable -> Bool
|
|
| 127 | +isOneShotMode = \ case
|
|
| 128 | + HPT_OneShot{} -> True
|
|
| 129 | + HPT_Make{} -> False
|
|
| 130 | + |
|
| 131 | +isHptEmpty :: HomePackageTable -> IO Bool
|
|
| 132 | +isHptEmpty = \ case
|
|
| 133 | + HPT_OneShot{loader} -> null . hls_table <$> readIORef loader
|
|
| 134 | + HPT_Make{table} -> isNullUDFM <$> readIORef table
|
|
| 138 | 135 | |
| 139 | 136 | -- | Create a new 'HomePackageTable'.
|
| 140 | 137 | --
|
| ... | ... | @@ -145,14 +142,19 @@ emptyHomePackageTable :: IO HomePackageTable |
| 145 | 142 | -- romes:todo: use a MutableArray directly?
|
| 146 | 143 | emptyHomePackageTable = do
|
| 147 | 144 | table <- newIORef emptyUDFM
|
| 145 | + return HPT_Make{table}
|
|
| 146 | + |
|
| 147 | +emptyOnDemandHomePackageTable :: IO HomePackageTable
|
|
| 148 | +emptyOnDemandHomePackageTable = do
|
|
| 148 | 149 | loader <- newIORef emptyHomeLoaderState
|
| 149 | - return HPT{table, loader}
|
|
| 150 | + return HPT_OneShot{loader}
|
|
| 150 | 151 | |
| 151 | 152 | data HomeLoaderState = HomeLoaderState
|
| 152 | - { hls_modules :: ModuleEnv ()
|
|
| 153 | + { hls_table :: DModuleNameEnv HomeModInfo
|
|
| 154 | + , hls_modules :: ModuleEnv ()
|
|
| 153 | 155 | , hls_is_boot :: InstalledModuleEnv ModuleNameWithIsBoot
|
| 154 | 156 | , hls_type_env :: !TypeEnv
|
| 155 | - , hls_iface_bytecode :: !(ModuleEnv (IO Linkable))
|
|
| 157 | + -- , hls_iface_bytecode :: !(ModuleEnv (IO Linkable))
|
|
| 156 | 158 | , hls_inst_env :: !InstEnv
|
| 157 | 159 | , hls_fam_inst_env :: !FamInstEnv
|
| 158 | 160 | , hls_mod_fam_inst_env :: !(ModuleEnv FamInstEnv)
|
| ... | ... | @@ -165,10 +167,11 @@ data HomeLoaderState = HomeLoaderState |
| 165 | 167 | emptyHomeLoaderState :: HomeLoaderState
|
| 166 | 168 | emptyHomeLoaderState =
|
| 167 | 169 | HomeLoaderState
|
| 168 | - { hls_modules = emptyModuleEnv
|
|
| 170 | + { hls_table = emptyUDFM
|
|
| 171 | + , hls_modules = emptyModuleEnv
|
|
| 169 | 172 | , hls_is_boot = emptyInstalledModuleEnv
|
| 170 | 173 | , hls_type_env = emptyTypeEnv
|
| 171 | - , hls_iface_bytecode = emptyModuleEnv
|
|
| 174 | + -- , hls_iface_bytecode = emptyModuleEnv
|
|
| 172 | 175 | , hls_inst_env = emptyInstEnv
|
| 173 | 176 | , hls_fam_inst_env = emptyFamInstEnv
|
| 174 | 177 | , hls_mod_fam_inst_env = emptyModuleEnv
|
| ... | ... | @@ -184,46 +187,57 @@ emptyHomeLoaderState = |
| 184 | 187 | |
| 185 | 188 | -- | Lookup the 'HomeModInfo' of a module in the HPT, given its name.
|
| 186 | 189 | lookupHpt :: HomePackageTable -> ModuleName -> IO (Maybe HomeModInfo)
|
| 187 | -lookupHpt HPT{table=hpt} mn = (`lookupUDFM` mn) <$!> readIORef hpt
|
|
| 190 | +lookupHpt HPT_Make{table=hpt} mn = (`lookupUDFM` mn) <$!> readIORef hpt
|
|
| 191 | +lookupHpt HPT_OneShot{loader=hpt} mn = (`lookupUDFM` mn) . hls_table <$!> readIORef hpt
|
|
| 188 | 192 | |
| 189 | 193 | -- | Lookup the 'HomeModInfo' of a 'Module' in the HPT.
|
| 190 | 194 | lookupHptByModule :: HomePackageTable -> Module -> IO (Maybe HomeModInfo)
|
| 191 | -lookupHptByModule hpt mod
|
|
| 195 | +lookupHptByModule hpt modl
|
|
| 192 | 196 | = -- The HPT is indexed by ModuleName, not Module,
|
| 193 | 197 | -- we must check for a hit on the right Module
|
| 194 | - lookupHpt hpt (moduleName mod) >>= pure . \case
|
|
| 195 | - Just hm | mi_module (hm_iface hm) == mod -> Just hm
|
|
| 198 | + lookupHpt hpt (moduleName modl) >>= pure . \case
|
|
| 199 | + Just hm | mi_module (hm_iface hm) == modl -> Just hm
|
|
| 196 | 200 | _otherwise -> Nothing
|
| 197 | 201 | |
| 198 | -hptLoaderState :: HomePackageTable -> IO HomeLoaderState
|
|
| 199 | -hptLoaderState = readIORef . loader
|
|
| 202 | +queryOnDemandHpt :: a -> (HomeLoaderState -> a) -> HomePackageTable -> IO a
|
|
| 203 | +queryOnDemandHpt a f hpt =
|
|
| 204 | + case hpt of
|
|
| 205 | + HPT_Make{} ->
|
|
| 206 | + pure a
|
|
| 207 | + HPT_OneShot{loader} ->
|
|
| 208 | + f <$> readIORef loader
|
|
| 200 | 209 | |
| 201 | 210 | hptLoadedIsBoot :: HomePackageTable -> IO (InstalledModuleEnv ModuleNameWithIsBoot)
|
| 202 | -hptLoadedIsBoot hpt = hls_is_boot <$> readIORef (loader hpt)
|
|
| 211 | +hptLoadedIsBoot = queryOnDemandHpt emptyInstalledModuleEnv hls_is_boot
|
|
| 203 | 212 | |
| 204 | 213 | hptLoadedTypeEnv :: HomePackageTable -> IO TypeEnv
|
| 205 | -hptLoadedTypeEnv hpt = hls_type_env <$> readIORef (loader hpt)
|
|
| 214 | +hptLoadedTypeEnv = queryOnDemandHpt emptyTypeEnv hls_type_env
|
|
| 206 | 215 | |
| 207 | 216 | hptLoadedInstEnv :: HomePackageTable -> IO InstEnv
|
| 208 | -hptLoadedInstEnv hpt = hls_inst_env <$> readIORef (loader hpt)
|
|
| 217 | +hptLoadedInstEnv = queryOnDemandHpt emptyInstEnv hls_inst_env
|
|
| 209 | 218 | |
| 210 | 219 | hptLoadedFamInstEnv :: HomePackageTable -> IO FamInstEnv
|
| 211 | -hptLoadedFamInstEnv hpt = hls_fam_inst_env <$> readIORef (loader hpt)
|
|
| 220 | +hptLoadedFamInstEnv = queryOnDemandHpt emptyFamInstEnv hls_fam_inst_env
|
|
| 212 | 221 | |
| 213 | 222 | hptLoadedModFamInstEnv :: HomePackageTable -> IO (ModuleEnv FamInstEnv)
|
| 214 | -hptLoadedModFamInstEnv hpt = hls_mod_fam_inst_env <$> readIORef (loader hpt)
|
|
| 223 | +hptLoadedModFamInstEnv = queryOnDemandHpt emptyModuleEnv hls_mod_fam_inst_env
|
|
| 215 | 224 | |
| 216 | 225 | hptLoadedRuleBase :: HomePackageTable -> IO RuleBase
|
| 217 | -hptLoadedRuleBase hpt = hls_rule_base <$> readIORef (loader hpt)
|
|
| 226 | +hptLoadedRuleBase = queryOnDemandHpt emptyRuleBase hls_rule_base
|
|
| 218 | 227 | |
| 219 | 228 | hptLoadedAnnEnv :: HomePackageTable -> IO AnnEnv
|
| 220 | -hptLoadedAnnEnv hpt = hls_ann_env <$> readIORef (loader hpt)
|
|
| 229 | +hptLoadedAnnEnv = queryOnDemandHpt emptyAnnEnv hls_ann_env
|
|
| 221 | 230 | |
| 222 | 231 | hptLoadedCompleteMatches :: HomePackageTable -> IO CompleteMatches
|
| 223 | -hptLoadedCompleteMatches hpt = hls_complete_matches <$> readIORef (loader hpt)
|
|
| 232 | +hptLoadedCompleteMatches = queryOnDemandHpt [] hls_complete_matches
|
|
| 224 | 233 | |
| 225 | 234 | hptLoadedDefaults :: HomePackageTable -> IO (ModuleEnv DefaultEnv)
|
| 226 | -hptLoadedDefaults hpt = hls_defaults <$> readIORef (loader hpt)
|
|
| 235 | +hptLoadedDefaults = queryOnDemandHpt emptyModuleEnv hls_defaults
|
|
| 236 | + |
|
| 237 | +listHptIfaces :: HomePackageTable -> IO (DModuleNameEnv HomeModInfo)
|
|
| 238 | +listHptIfaces = \ case
|
|
| 239 | + HPT_Make{table} -> readIORef table
|
|
| 240 | + HPT_OneShot{loader} -> hls_table <$> readIORef loader
|
|
| 227 | 241 | |
| 228 | 242 | --------------------------------------------------------------------------------
|
| 229 | 243 | -- * Extending the HPT
|
| ... | ... | @@ -244,10 +258,12 @@ addHomeModInfoToHpt hmi hpt = addToHpt hpt (moduleName (mi_module (hm_iface hmi) |
| 244 | 258 | {-# 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 | 259 | -- After deprecation cycle, move `addToHpt` to a `where` clause inside `addHomeModInfoToHpt`.
|
| 246 | 260 | addToHpt :: HomePackageTable -> ModuleName -> HomeModInfo -> IO ()
|
| 247 | -addToHpt HPT{table=hptr} mn hmi = do
|
|
| 261 | +addToHpt HPT_Make{table=hptr} mn hmi = do
|
|
| 248 | 262 | atomicModifyIORef' hptr (\hpt -> (addToUDFM hpt mn hmi, ()))
|
| 249 | 263 | -- If the key already existed in the map, this insertion is overwriting
|
| 250 | 264 | -- the HMI of a previously loaded module (likely in rehydration).
|
| 265 | +addToHpt HPT_OneShot{loader=hptr} mn hmi = do
|
|
| 266 | + atomicModifyIORef' hptr (\hpt -> (hpt { hls_table = addToUDFM (hls_table hpt) mn hmi }, ()))
|
|
| 251 | 267 | |
| 252 | 268 | -- | 'addHomeModInfoToHpt' for multiple module infos.
|
| 253 | 269 | addHomeModInfosToHpt :: HomePackageTable -> [HomeModInfo] -> IO ()
|
| ... | ... | @@ -262,19 +278,21 @@ addHomeModInfosToHpt hpt = mapM_ (flip addHomeModInfoToHpt hpt) |
| 262 | 278 | -- called at barrier points, such as the end of upsweep, when all threads are
|
| 263 | 279 | -- done and we want to clean up failed entries.
|
| 264 | 280 | restrictHpt :: HomePackageTable -> [HomeModInfo] -> IO ()
|
| 265 | -restrictHpt HPT{table=hptr} hmis =
|
|
| 281 | +restrictHpt HPT_Make{table=hptr} hmis =
|
|
| 266 | 282 | let key_set = map (getKey . getUnique . hmi_mod) hmis
|
| 267 | 283 | hmi_mod hmi = moduleName (mi_module (hm_iface hmi))
|
| 268 | 284 | in atomicModifyIORef' hptr (\hpt -> (udfmRestrictKeysSet hpt (W64.fromList key_set), ()))
|
| 285 | +restrictHpt HPT_OneShot{} _ = pure ()
|
|
| 269 | 286 | |
| 270 | 287 | {-# 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 | 288 | -- After deprecation cycle, remove.
|
| 272 | 289 | addListToHpt :: HomePackageTable -> [(ModuleName, HomeModInfo)] -> IO ()
|
| 273 | 290 | addListToHpt hpt = mapM_ (uncurry (addToHpt hpt))
|
| 274 | 291 | |
| 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 ->
|
|
| 292 | +addOnDemandHomeModule :: HomePackageTable -> Module -> Bool -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IO ()
|
|
| 293 | +addOnDemandHomeModule HPT_Make{} _ _ _ = pure ()
|
|
| 294 | +addOnDemandHomeModule HPT_OneShot{loader} mn bad_boot (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
|
|
| 295 | + atomicModifyIORef loader $ \hls ->
|
|
| 278 | 296 | ( if mn `elemModuleEnv` hls_modules hls
|
| 279 | 297 | then hls -- If already loaded, don't add twice
|
| 280 | 298 | else
|
| ... | ... | @@ -285,41 +303,39 @@ addOnDemandHomeModule hpt mn bad_boot (new_hls_decls, new_hls_insts, new_hls_def |
| 285 | 303 | )
|
| 286 | 304 | where
|
| 287 | 305 | addHomeModTypeEnv hls = hls
|
| 288 | - { hls_type_env = extendNameEnvList (hls_type_env hls) new_hls_decls
|
|
| 306 | + { hls_type_env = extendNameEnvList (hls_type_env hls) new_decls
|
|
| 289 | 307 | }
|
| 290 | 308 | |
| 291 | 309 | 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,
|
|
| 310 | + hls_modules = extendModuleEnv (hls_modules hls) mn (),
|
|
| 311 | + hls_type_env = extendNameEnvList (hls_type_env hls) new_decls,
|
|
| 297 | 312 | hls_rule_base = extendRuleBaseList (hls_rule_base hls)
|
| 298 | - new_hls_rules,
|
|
| 313 | + new_rules,
|
|
| 299 | 314 | hls_complete_matches
|
| 300 | - = hls_complete_matches hls ++ new_hls_complete_matches,
|
|
| 315 | + = hls_complete_matches hls ++ new_complete_matches,
|
|
| 301 | 316 | hls_inst_env = extendInstEnvList (hls_inst_env hls)
|
| 302 | - new_hls_insts,
|
|
| 317 | + new_insts,
|
|
| 303 | 318 | hls_fam_inst_env = extendFamInstEnvList (hls_fam_inst_env hls)
|
| 304 | - new_hls_fam_insts,
|
|
| 319 | + new_fam_insts,
|
|
| 305 | 320 | hls_ann_env = extendAnnEnvList (hls_ann_env hls)
|
| 306 | - new_hls_anns,
|
|
| 321 | + new_anns,
|
|
| 307 | 322 | hls_mod_fam_inst_env
|
| 308 | 323 | =
|
| 309 | 324 | let
|
| 310 | 325 | fam_inst_env =
|
| 311 | 326 | extendFamInstEnvList emptyFamInstEnv
|
| 312 | - new_hls_fam_insts
|
|
| 327 | + new_fam_insts
|
|
| 313 | 328 | in
|
| 314 | 329 | extendModuleEnv (hls_mod_fam_inst_env hls)
|
| 315 | 330 | mn
|
| 316 | 331 | fam_inst_env,
|
| 317 | - hls_defaults = extendModuleEnv (hls_defaults hls) mn new_hls_defaults
|
|
| 332 | + hls_defaults = extendModuleEnv (hls_defaults hls) mn new_defaults
|
|
| 318 | 333 | }
|
| 319 | 334 | |
| 320 | -hlsSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO ()
|
|
| 321 | -hlsSetBootInfo hpt is_boot_env =
|
|
| 322 | - atomicModifyIORef' (loader hpt) $ \ hls ->
|
|
| 335 | +hptSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO ()
|
|
| 336 | +hptSetBootInfo HPT_Make{} _ = pure ()
|
|
| 337 | +hptSetBootInfo HPT_OneShot{loader} is_boot_env =
|
|
| 338 | + atomicModifyIORef' loader $ \ hls ->
|
|
| 323 | 339 | (hls { hls_is_boot = is_boot_env }, ())
|
| 324 | 340 | |
| 325 | 341 | ----------------------------------------------------------------------------------
|
| ... | ... | @@ -352,12 +368,6 @@ hptAllFamInstances = fmap mkModuleEnv . concatHpt (\hmi -> [(hmiModule hmi, hmiF |
| 352 | 368 | hptAllAnnotations :: HomePackageTable -> IO AnnEnv
|
| 353 | 369 | hptAllAnnotations = fmap mkAnnEnv . concatHpt (md_anns . hm_details)
|
| 354 | 370 | |
| 355 | -hlsIsBoot :: HomeLoaderState -> InstalledModule -> Maybe IsBootInterface
|
|
| 356 | -hlsIsBoot hls mn = gwib_isBoot <$> hlsIsModuleNameWithBoot hls mn
|
|
| 357 | - |
|
| 358 | -hlsIsModuleNameWithBoot :: HomeLoaderState -> InstalledModule -> Maybe ModuleNameWithIsBoot
|
|
| 359 | -hlsIsModuleNameWithBoot hls mn = lookupInstalledModuleEnv (hls_is_boot hls) mn
|
|
| 360 | - |
|
| 361 | 371 | --------------------------------------------------------------------------------
|
| 362 | 372 | -- * Traversal-based queries
|
| 363 | 373 | --------------------------------------------------------------------------------
|
| ... | ... | @@ -370,7 +380,11 @@ hlsIsModuleNameWithBoot hls mn = lookupInstalledModuleEnv (hls_is_boot hls) mn |
| 370 | 380 | -- currently takes all dependencies only to then filter them with an ad-hoc transitive closure check.
|
| 371 | 381 | -- See #25639
|
| 372 | 382 | hptCollectDependencies :: HomePackageTable -> IO (Set.Set (IfaceImportLevel, UnitId))
|
| 373 | -hptCollectDependencies HPT{table} = do
|
|
| 383 | +hptCollectDependencies HPT_OneShot{loader} = do
|
|
| 384 | + hpt <- readIORef loader
|
|
| 385 | + return $
|
|
| 386 | + foldr (Set.union . dep_direct_pkgs . mi_deps . hm_iface) Set.empty (hls_table hpt)
|
|
| 387 | +hptCollectDependencies HPT_Make{table} = do
|
|
| 374 | 388 | hpt <- readIORef table
|
| 375 | 389 | return $
|
| 376 | 390 | foldr (Set.union . dep_direct_pkgs . mi_deps . hm_iface) Set.empty hpt
|
| ... | ... | @@ -380,7 +394,11 @@ hptCollectDependencies HPT{table} = do |
| 380 | 394 | --
|
| 381 | 395 | -- $O(n)$ in the number of modules in the HPT.
|
| 382 | 396 | hptCollectHomeModInfo :: HomePackageTable -> IO [HomeModInfo]
|
| 383 | -hptCollectHomeModInfo HPT{table} = do
|
|
| 397 | +hptCollectHomeModInfo HPT_OneShot{loader} = do
|
|
| 398 | + hpt <- readIORef loader
|
|
| 399 | + return $
|
|
| 400 | + foldr (:) [] (hls_table hpt)
|
|
| 401 | +hptCollectHomeModInfo HPT_Make{table} = do
|
|
| 384 | 402 | hpt <- readIORef table
|
| 385 | 403 | return $
|
| 386 | 404 | foldr (:) [] hpt
|
| ... | ... | @@ -398,7 +416,13 @@ hptCollectHomeModInfo HPT{table} = do |
| 398 | 416 | -- unit map in failed lookups.
|
| 399 | 417 | pprHPT :: HomePackageTable -> IO SDoc
|
| 400 | 418 | -- A bit arbitrary for now
|
| 401 | -pprHPT HPT{table=hptr} = do
|
|
| 419 | +pprHPT HPT_OneShot{loader=hptr} = do
|
|
| 420 | + hpt <- readIORef hptr
|
|
| 421 | + return $!
|
|
| 422 | + pprUDFM (hls_table hpt) $ \hms ->
|
|
| 423 | + vcat [ ppr (mi_module (hm_iface hm))
|
|
| 424 | + | hm <- hms ]
|
|
| 425 | +pprHPT HPT_Make{table=hptr} = do
|
|
| 402 | 426 | hpt <- readIORef hptr
|
| 403 | 427 | return $!
|
| 404 | 428 | pprUDFM hpt $ \hms ->
|
| ... | ... | @@ -437,7 +461,12 @@ pprHPT HPT{table=hptr} = do |
| 437 | 461 | -- If this function is ever exposed from the HPT module, make sure the
|
| 438 | 462 | -- argument function doesn't introduce leaks.
|
| 439 | 463 | concatHpt :: (HomeModInfo -> [a]) -> HomePackageTable -> IO [a]
|
| 440 | -concatHpt f HPT{table} = do
|
|
| 464 | +concatHpt f HPT_OneShot{loader} = do
|
|
| 465 | + hpt <- readIORef loader
|
|
| 466 | + return $ concat . eltsUDFM . mapMaybeUDFM g $ hls_table hpt
|
|
| 467 | + where
|
|
| 468 | + g hmi = case f hmi of { [] -> Nothing; as -> Just as }
|
|
| 469 | +concatHpt f HPT_Make{table} = do
|
|
| 441 | 470 | hpt <- readIORef table
|
| 442 | 471 | return $ concat . eltsUDFM . mapMaybeUDFM g $ hpt
|
| 443 | 472 | where
|
| ... | ... | @@ -449,15 +478,15 @@ concatHpt f HPT{table} = do |
| 449 | 478 | |
| 450 | 479 | -- | Gets the internal 'IORef' which holds the 'HomeModInfo's of this HPT.
|
| 451 | 480 | -- Use with care.
|
| 452 | -hptInternalTableRef :: HomePackageTable -> IORef (DModuleNameEnv HomeModInfo)
|
|
| 453 | -hptInternalTableRef = table
|
|
| 481 | +-- hptInternalTableRef :: HomePackageTable -> IORef (DModuleNameEnv HomeModInfo)
|
|
| 482 | +-- hptInternalTableRef = \ case
|
|
| 483 | +-- HPT_Make{table} -> table
|
|
| 484 | +-- HPT_OneShot{} -> -- TODO: @fendor how does this make sense?
|
|
| 454 | 485 | |
| 455 | 486 | -- | Construct a HomePackageTable from the IORef.
|
| 456 | 487 | -- Use with care, only if you can really justify going around the intended insert-only API.
|
| 457 | 488 | hptInternalTableFromRef :: IORef (DModuleNameEnv HomeModInfo) -> IO HomePackageTable
|
| 458 | 489 | hptInternalTableFromRef ref = do
|
| 459 | - loader <- newIORef emptyHomeLoaderState
|
|
| 460 | - return HPT {
|
|
| 461 | - table = ref,
|
|
| 462 | - loader
|
|
| 490 | + return HPT_Make {
|
|
| 491 | + table = ref
|
|
| 463 | 492 | } |
| ... | ... | @@ -249,7 +249,7 @@ lookupModuleNameEnv :: ModuleNameEnv elt -> ModuleName -> Maybe elt |
| 249 | 249 | lookupModuleNameEnv = lookupUFM
|
| 250 | 250 | |
| 251 | 251 | unionModuleNameEnv :: ModuleNameEnv elt -> ModuleNameEnv elt -> ModuleNameEnv elt
|
| 252 | -unionModuleNameEnv = unionModuleNameEnv
|
|
| 252 | +unionModuleNameEnv = plusUFM
|
|
| 253 | 253 | |
| 254 | 254 | -- | A map keyed off of 'ModuleName's (actually, their 'Unique's)
|
| 255 | 255 | -- Has deterministic folds and can be deterministically converted to a list
|
| ... | ... | @@ -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
|
| ... | ... | @@ -16,6 +16,22 @@ T25090a: |
| 16 | 16 | '$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A.o -o exe
|
| 17 | 17 | ./exe
|
| 18 | 18 | |
| 19 | +# Like T25090a, but without .gbc files: the bytecode for the splice has to be
|
|
| 20 | +# compiled from the Core stored in the interface files
|
|
| 21 | +# (-fwrite-if-simplified-core). See Note [Interface Files with Core Definitions].
|
|
| 22 | +T25090c:
|
|
| 23 | + '$(TEST_HC)' -c -fwrite-if-simplified-core C.hs-boot
|
|
| 24 | + '$(TEST_HC)' -c -fwrite-if-simplified-core B.hs
|
|
| 25 | + '$(TEST_HC)' -c -fwrite-if-simplified-core C.hs
|
|
| 26 | + echo 'corrupt' > B.o
|
|
| 27 | + echo 'corrupt' > C.o
|
|
| 28 | + echo 'corrupt' > C.o-boot
|
|
| 29 | + '$(TEST_HC)' -c -fwrite-if-simplified-core D.hs
|
|
| 30 | + echo 'corrupt' > D.o
|
|
| 31 | + '$(TEST_HC)' -c -fwrite-if-simplified-core -fprefer-byte-code A.hs
|
|
| 32 | + '$(TEST_HC)' A.o -o exe
|
|
| 33 | + ./exe
|
|
| 34 | + |
|
| 19 | 35 | T25090b:
|
| 20 | 36 | '$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A -o exe -v0
|
| 21 | 37 | ./exe |
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | # the warning is added to the expected stderr for debugged builds.
|
| 5 | 5 | def test_T25090(name):
|
| 6 | 6 | assert_warn_spec = {'stderr': 'T25090-debug.stderr'}
|
| 7 | - extra_specs = assert_warn_spec if name == 'T25090a' and compiler_debugged() else {}
|
|
| 7 | + extra_specs = assert_warn_spec if name in ('T25090a', 'T25090c') and compiler_debugged() else {}
|
|
| 8 | 8 | return test(name,
|
| 9 | 9 | [extra_files(['A.hs', 'B.hs', 'C.hs-boot', 'C.hs', 'D.hs']),
|
| 10 | 10 | req_th,
|
| ... | ... | @@ -16,3 +16,4 @@ def test_T25090(name): |
| 16 | 16 | |
| 17 | 17 | test_T25090('T25090a')
|
| 18 | 18 | test_T25090('T25090b')
|
| 19 | +test_T25090('T25090c') |
| 1 | +{-# LANGUAGE TypeFamilies #-}
|
|
| 2 | +module A where
|
|
| 3 | + |
|
| 4 | +import Fam
|
|
| 5 | +import {-# SOURCE #-} M (T)
|
|
| 6 | + |
|
| 7 | +-- This instance mentions 'T' from M's boot file.
|
|
| 8 | +type instance F T = Int |
| 1 | +{-# LANGUAGE TypeFamilies #-}
|
|
| 2 | +module B where
|
|
| 3 | + |
|
| 4 | +import Fam
|
|
| 5 | + |
|
| 6 | +-- A second family-instance module for 'F', so that compiling M has to check
|
|
| 7 | +-- the consistency of A's and B's instances. That check forces 'T', which
|
|
| 8 | +-- makes GHC load M.hi-boot while compiling M itself.
|
|
| 9 | +-- See Note [Loading your own hi-boot file] in GHC.Iface.Load.
|
|
| 10 | +type instance F Bool = Char |
| 1 | +{-# LANGUAGE TypeFamilies #-}
|
|
| 2 | +module Fam where
|
|
| 3 | + |
|
| 4 | +type family F a |
| 1 | +{-# LANGUAGE TypeFamilies #-}
|
|
| 2 | +module M where
|
|
| 3 | + |
|
| 4 | +import Fam
|
|
| 5 | +import A ()
|
|
| 6 | +import B ()
|
|
| 7 | + |
|
| 8 | +data T = MkT Int
|
|
| 9 | + |
|
| 10 | +-- Also declared in M.hs-boot: loading M.hi-boot while compiling M must not
|
|
| 11 | +-- cause a duplicate instance error.
|
|
| 12 | +instance Show T where
|
|
| 13 | + show (MkT n) = "MkT " ++ show n
|
|
| 14 | + |
|
| 15 | +-- Not part of M.hs-boot. Needs A's instance of 'F' to typecheck.
|
|
| 16 | +onlyInM :: F T
|
|
| 17 | +onlyInM = 42 |
| 1 | +module M where
|
|
| 2 | + |
|
| 3 | +data T
|
|
| 4 | + |
|
| 5 | +instance Show T |
| 1 | +module Main where
|
|
| 2 | + |
|
| 3 | +import M
|
|
| 4 | + |
|
| 5 | +main :: IO ()
|
|
| 6 | +main = do
|
|
| 7 | + print (onlyInM :: Int)
|
|
| 8 | + print (MkT 1) |
| 1 | +TOP=../../..
|
|
| 2 | +include $(TOP)/mk/boilerplate.mk
|
|
| 3 | +include $(TOP)/mk/test.mk
|
|
| 4 | + |
|
| 5 | +# One-shot compilation of a SOURCE-import cycle where type family instances
|
|
| 6 | +# mention the type from the boot file. Every module is compiled by its own
|
|
| 7 | +# invocation of GHC.
|
|
| 8 | +OneShotBootFamInst:
|
|
| 9 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c Fam.hs
|
|
| 10 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs-boot
|
|
| 11 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c A.hs
|
|
| 12 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c B.hs
|
|
| 13 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs
|
|
| 14 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c Main.hs
|
|
| 15 | + '$(TEST_HC)' $(TEST_HC_OPTS) Fam.o A.o B.o M.o Main.o -o main
|
|
| 16 | + ./main
|
|
| 17 | + |
|
| 18 | +# Like OneShotBootFamInst, but M and Main are compiled by the same invocation.
|
|
| 19 | +# Compiling M loads M.hi-boot (see Note [Loading your own hi-boot file]); that
|
|
| 20 | +# must not make Main see the boot interface of M instead of the real one.
|
|
| 21 | +OneShotBootSameInvocation:
|
|
| 22 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c Fam.hs
|
|
| 23 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs-boot
|
|
| 24 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c A.hs
|
|
| 25 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c B.hs
|
|
| 26 | + '$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs Main.hs
|
|
| 27 | + '$(TEST_HC)' $(TEST_HC_OPTS) Fam.o A.o B.o M.o Main.o -o main
|
|
| 28 | + ./main |
| 1 | +# Compiling M loads M.hi-boot, which triggers a warnPprTrace in debug builds.
|
|
| 2 | +# See Note [Loading your own hi-boot file] in GHC.Iface.Load.
|
|
| 3 | +def test_one_shot_boot(name):
|
|
| 4 | + return test(name,
|
|
| 5 | + [extra_files(['Fam.hs', 'M.hs-boot', 'A.hs', 'B.hs', 'M.hs', 'Main.hs']),
|
|
| 6 | + js_skip,
|
|
| 7 | + when(compiler_debugged(), ignore_stderr),
|
|
| 8 | + use_specs(dict(stdout = 'one-shot-boot.stdout')),
|
|
| 9 | + ],
|
|
| 10 | + makefile_test,
|
|
| 11 | + [])
|
|
| 12 | + |
|
| 13 | +test_one_shot_boot('OneShotBootFamInst')
|
|
| 14 | +test_one_shot_boot('OneShotBootSameInvocation') |
| 1 | +42
|
|
| 2 | +MkT 1 |