Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC
Commits:
-
c18b3e6f
by Wolfgang Jeltsch at 2026-11-20T16:06:07+01:00
-
56cd7264
by Hannes Siebenhandl at 2026-11-20T16:06:07+01:00
21 changed files:
- compiler/GHC/Core/Opt/Monad.hs
- compiler/GHC/Core/Opt/Pipeline.hs
- compiler/GHC/Core/Opt/Simplify.hs
- compiler/GHC/Core/Opt/Specialise.hs
- compiler/GHC/Core/Rules.hs
- compiler/GHC/Driver/Env.hs
- compiler/GHC/Driver/Main/Passes.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Iface/Recomp.hs
- compiler/GHC/IfaceToCore.hs
- compiler/GHC/Linker/Deps.hs
- compiler/GHC/Tc/Instance/Family.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Tc/Utils/Env.hs
- compiler/GHC/Tc/Utils/Instantiate.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Unit/External.hs
- compiler/GHC/Unit/Home/PackageTable.hs
- compiler/GHC/Unit/Module/Env.hs
- utils/haddock/haddock-api/src/Haddock/Interface.hs
Changes:
| ... | ... | @@ -16,8 +16,8 @@ module GHC.Core.Opt.Monad ( |
| 16 | 16 | |
| 17 | 17 | -- ** Reading from the monad
|
| 18 | 18 | getModule,
|
| 19 | - initRuleEnv, getExternalRuleBase,
|
|
| 20 | - getDynFlags, getPackageFamInstEnv,
|
|
| 19 | + initRuleEnv, getExternalRuleBase, getLazyHomeRuleBase,
|
|
| 20 | + getDynFlags, getPackageFamInstEnv, getLazyHomeFamInstEnv,
|
|
| 21 | 21 | getInteractiveContext,
|
| 22 | 22 | getUniqTag,
|
| 23 | 23 | getNamePprCtx, getSrcSpanM,
|
| ... | ... | @@ -44,7 +44,7 @@ import GHC.Driver.Errors ( reportDiagnostic, reportError ) |
| 44 | 44 | import GHC.Driver.Config.Diagnostic ( initDiagOpts )
|
| 45 | 45 | import GHC.Driver.Env
|
| 46 | 46 | |
| 47 | -import GHC.Core.Rules ( RuleBase, RuleEnv, mkRuleEnv )
|
|
| 47 | +import GHC.Core.Rules ( RuleBase, RuleEnv, mkRuleEnv, unionRuleBase )
|
|
| 48 | 48 | import GHC.Core.Opt.Stats ( SimplCount, zeroSimplCount, plusSimplCount )
|
| 49 | 49 | |
| 50 | 50 | import GHC.Types.Annotations
|
| ... | ... | @@ -73,6 +73,9 @@ import Data.Dynamic |
| 73 | 73 | import Data.Maybe (listToMaybe)
|
| 74 | 74 | import Control.Monad
|
| 75 | 75 | import Control.Applicative ( Alternative(..) )
|
| 76 | +import GHC.Unit.Home.PackageTable (HomePackageTable)
|
|
| 77 | +import qualified GHC.Unit.Home.PackageTable as HomePackageTable
|
|
| 78 | +import GHC.Core.FamInstEnv
|
|
| 76 | 79 | |
| 77 | 80 | data FloatOutSwitches = FloatOutSwitches
|
| 78 | 81 | { floatOutLambdas :: Maybe Int -- ^ Just n <=> float lambdas to top level, if
|
| ... | ... | @@ -248,7 +251,10 @@ instance HasHscEnv CoreM where |
| 248 | 251 | getHscEnv = read cr_hsc_env
|
| 249 | 252 | |
| 250 | 253 | getHomeRuleBase :: CoreM RuleBase
|
| 251 | -getHomeRuleBase = read cr_rule_base
|
|
| 254 | +getHomeRuleBase = do
|
|
| 255 | + hptRules <- read cr_rule_base
|
|
| 256 | + extraRules <- getLazyHomeRuleBase
|
|
| 257 | + pure $ hptRules `unionRuleBase` extraRules
|
|
| 252 | 258 | |
| 253 | 259 | initRuleEnv :: ModGuts -> CoreM RuleEnv
|
| 254 | 260 | initRuleEnv guts
|
| ... | ... | @@ -259,6 +265,9 @@ initRuleEnv guts |
| 259 | 265 | getExternalRuleBase :: CoreM RuleBase
|
| 260 | 266 | getExternalRuleBase = eps_rule_base <$> get_eps
|
| 261 | 267 | |
| 268 | +getLazyHomeRuleBase :: CoreM RuleBase
|
|
| 269 | +getLazyHomeRuleBase = get_hpt HomePackageTable.hptLoadedRuleBase
|
|
| 270 | + |
|
| 262 | 271 | getNamePprCtx :: CoreM NamePprCtx
|
| 263 | 272 | getNamePprCtx = read cr_name_ppr_ctx
|
| 264 | 273 | |
| ... | ... | @@ -302,11 +311,20 @@ getInteractiveContext = hsc_IC <$> getHscEnv |
| 302 | 311 | getPackageFamInstEnv :: CoreM PackageFamInstEnv
|
| 303 | 312 | getPackageFamInstEnv = eps_fam_inst_env <$> get_eps
|
| 304 | 313 | |
| 314 | +getLazyHomeFamInstEnv :: CoreM FamInstEnv
|
|
| 315 | +getLazyHomeFamInstEnv = get_hpt HomePackageTable.hptLoadedFamInstEnv
|
|
| 316 | + |
|
| 305 | 317 | get_eps :: CoreM ExternalPackageState
|
| 306 | 318 | get_eps = do
|
| 307 | 319 | hsc_env <- getHscEnv
|
| 308 | 320 | liftIO $ hscEPS hsc_env
|
| 309 | 321 | |
| 322 | +get_hpt :: (HomePackageTable -> IO a) -> CoreM a
|
|
| 323 | +get_hpt f = do
|
|
| 324 | + hsc_env <- getHscEnv
|
|
| 325 | + a <- liftIO $ f $ hsc_HPT hsc_env
|
|
| 326 | + pure a
|
|
| 327 | + |
|
| 310 | 328 | {-
|
| 311 | 329 | ************************************************************************
|
| 312 | 330 | * *
|
| ... | ... | @@ -449,8 +449,9 @@ doCorePass pass guts = do |
| 449 | 449 | dflags <- getDynFlags
|
| 450 | 450 | us <- getUniqueSupplyM
|
| 451 | 451 | p_fam_env <- getPackageFamInstEnv
|
| 452 | + l_fam_env <- getLazyHomeFamInstEnv
|
|
| 452 | 453 | let platform = targetPlatform dflags
|
| 453 | - let fam_envs = (p_fam_env, mg_fam_inst_env guts)
|
|
| 454 | + let fam_envs = (p_fam_env `unionFamInstEnv` l_fam_env, mg_fam_inst_env guts)
|
|
| 454 | 455 | let updateBinds f = return $ guts { mg_binds = f (mg_binds guts) }
|
| 455 | 456 | let updateBindsM f = f (mg_binds guts) >>= \b' -> return $ guts { mg_binds = b' }
|
| 456 | 457 | let updateBindsAndRulesM f = f (mg_binds guts) (mg_rules guts) >>= \(b',r') -> return $ guts { mg_binds = b', mg_rules = r' }
|
| ... | ... | @@ -30,7 +30,7 @@ import GHC.Utils.Logger as Logger |
| 30 | 30 | import GHC.Utils.Outputable
|
| 31 | 31 | import GHC.Utils.Constants (debugIsOn)
|
| 32 | 32 | |
| 33 | -import GHC.Unit.Env ( UnitEnv, ueEPS )
|
|
| 33 | +import GHC.Unit.Env ( UnitEnv, ueEPS, ue_hpt )
|
|
| 34 | 34 | import GHC.Unit.External
|
| 35 | 35 | import GHC.Unit.Module.ModGuts
|
| 36 | 36 | |
| ... | ... | @@ -44,6 +44,7 @@ import GHC.Types.Unique.FM |
| 44 | 44 | |
| 45 | 45 | import Control.Monad
|
| 46 | 46 | import Data.Foldable ( for_ )
|
| 47 | +import GHC.Unit.Home.PackageTable (hptLoadedRuleBase, HomePackageTable)
|
|
| 47 | 48 | |
| 48 | 49 | {-
|
| 49 | 50 | ************************************************************************
|
| ... | ... | @@ -63,13 +64,14 @@ data SimplifyExprOpts = SimplifyExprOpts |
| 63 | 64 | |
| 64 | 65 | simplifyExpr :: Logger
|
| 65 | 66 | -> ExternalUnitCache
|
| 67 | + -> HomePackageTable
|
|
| 66 | 68 | -> SimplifyExprOpts
|
| 67 | 69 | -> CoreExpr
|
| 68 | 70 | -> IO CoreExpr
|
| 69 | 71 | -- ^ Simplify an expression using 'simplExprGently'.
|
| 70 | 72 | --
|
| 71 | 73 | -- See 'simplExprGently' for details.
|
| 72 | -simplifyExpr logger euc opts expr
|
|
| 74 | +simplifyExpr logger euc hpt opts expr
|
|
| 73 | 75 | = withTiming logger (text "Simplify [expr]") (const ()) $
|
| 74 | 76 | do { eps <- eucEPS euc ;
|
| 75 | 77 | ; let fam_envs = ( eps_fam_inst_env eps
|
| ... | ... | @@ -81,7 +83,8 @@ simplifyExpr logger euc opts expr |
| 81 | 83 | base_env = mkSimplEnv (se_mode opts) fam_envs
|
| 82 | 84 | top_env_cfg = se_top_env_cfg opts
|
| 83 | 85 | read_eps_rules = eps_rule_base <$> eucEPS euc
|
| 84 | - read_ruleenv = updExternalPackageRules emptyRuleEnv <$> read_eps_rules
|
|
| 86 | + read_home_rules = hptLoadedRuleBase hpt
|
|
| 87 | + read_ruleenv = (\ home_rules eps_rules -> updExternalPackageRules (updHomePackageRules emptyRuleEnv home_rules) eps_rules) <$> read_home_rules <*> read_eps_rules
|
|
| 85 | 88 | |
| 86 | 89 | ; let sz = exprSize expr
|
| 87 | 90 | |
| ... | ... | @@ -285,8 +288,11 @@ simplifyPgm logger unit_env name_ppr_ctx opts |
| 285 | 288 | ; read_eps_rules :: IO PackageRuleBase
|
| 286 | 289 | ; read_eps_rules = eps_rule_base <$> ueEPS unit_env
|
| 287 | 290 | |
| 291 | + ; read_home_rules :: IO RuleBase
|
|
| 292 | + ; read_home_rules = hptLoadedRuleBase (ue_hpt unit_env)
|
|
| 293 | + |
|
| 288 | 294 | ; read_rule_env :: IO RuleEnv
|
| 289 | - ; read_rule_env = updExternalPackageRules base_rule_env <$> read_eps_rules
|
|
| 295 | + ; read_rule_env = (\ home_rules eps_rules -> updExternalPackageRules (updHomePackageRules base_rule_env home_rules) eps_rules) <$> read_home_rules <*> read_eps_rules
|
|
| 290 | 296 | |
| 291 | 297 | ; fam_envs = (eps_fam_inst_env eps, fam_inst_env)
|
| 292 | 298 | ; simpl_env = mkSimplEnv mode fam_envs } ;
|
| ... | ... | @@ -854,7 +854,8 @@ spec_import env callers dict_binds cis@(CIS fn _) |
| 854 | 854 | -- We keep doing this in case we "page-fault in"
|
| 855 | 855 | -- more rules as we go along
|
| 856 | 856 | ; eps_rules <- getExternalRuleBase
|
| 857 | - ; let rule_env = se_rules env `updExternalPackageRules` eps_rules
|
|
| 857 | + ; home_rules <- getLazyHomeRuleBase
|
|
| 858 | + ; let rule_env = se_rules env `updHomePackageRules` home_rules `updExternalPackageRules` eps_rules
|
|
| 858 | 859 | |
| 859 | 860 | -- ; debugTraceMsg (text "specImport1" <+> vcat
|
| 860 | 861 | -- [ text "function:" <+> ppr fn
|
| ... | ... | @@ -13,8 +13,9 @@ module GHC.Core.Rules ( |
| 13 | 13 | |
| 14 | 14 | -- ** RuleBase, RuleEnv
|
| 15 | 15 | RuleBase, RuleEnv(..), mkRuleEnv, emptyRuleEnv,
|
| 16 | - updExternalPackageRules, addLocalRules, updLocalRules,
|
|
| 17 | - emptyRuleBase, mkRuleBase, extendRuleBaseList,
|
|
| 16 | + updExternalPackageRules, updHomePackageRules,
|
|
| 17 | + addLocalRules, updLocalRules,
|
|
| 18 | + emptyRuleBase, mkRuleBase, extendRuleBaseList, unionRuleBase,
|
|
| 18 | 19 | pprRuleBase,
|
| 19 | 20 | |
| 20 | 21 | -- ** Checking rule applications
|
| ... | ... | @@ -398,6 +399,10 @@ extendRuleBase rule_base rule |
| 398 | 399 | lookupRuleBase :: RuleBase -> Unique -> Maybe [CoreRule]
|
| 399 | 400 | lookupRuleBase = lookupUFM
|
| 400 | 401 | |
| 402 | +unionRuleBase :: RuleBase -> RuleBase -> RuleBase
|
|
| 403 | +unionRuleBase
|
|
| 404 | + = plusUFM
|
|
| 405 | + |
|
| 401 | 406 | pprRuleBase :: RuleBase -> SDoc
|
| 402 | 407 | pprRuleBase rules = pprUFM rules $ \rss ->
|
| 403 | 408 | vcat [ pprRules (tidyRules emptyTidyEnv rs)
|
| ... | ... | @@ -433,6 +438,10 @@ updExternalPackageRules :: RuleEnv -> RuleBase -> RuleEnv |
| 433 | 438 | updExternalPackageRules rule_env eps_rules
|
| 434 | 439 | = rule_env { re_eps_rules = eps_rules }
|
| 435 | 440 | |
| 441 | +updHomePackageRules :: RuleEnv -> RuleBase -> RuleEnv
|
|
| 442 | +updHomePackageRules rule_env eps_rules
|
|
| 443 | + = rule_env { re_home_rules = (re_home_rules rule_env ) `unionRuleBase` eps_rules }
|
|
| 444 | + |
|
| 436 | 445 | updLocalRules :: RuleEnv -> [CoreRule] -> RuleEnv
|
| 437 | 446 | -- Completely over-ride the local rules in RuleEnv
|
| 438 | 447 | updLocalRules rule_env local_rules
|
| ... | ... | @@ -98,6 +98,7 @@ import GHC.Builtin.Modules( gHC_PRIM ) |
| 98 | 98 | import Data.IORef
|
| 99 | 99 | import qualified Data.Set as Set
|
| 100 | 100 | import GHC.Types.Name.Reader (ExactRdrName(..))
|
| 101 | +import qualified GHC.Unit.Home.PackageTable as HomePackageTable
|
|
| 101 | 102 | |
| 102 | 103 | runHsc :: HscEnv -> Hsc a -> IO a
|
| 103 | 104 | runHsc hsc_env hsc = do
|
| ... | ... | @@ -348,10 +349,11 @@ prepareAnnotations hsc_env mb_guts = do |
| 348 | 349 | home_pkg_anns <- fromMaybe (hugAllAnns (hsc_unit_env hsc_env))
|
| 349 | 350 | $ uncurry (hugAnnsBelow hsc_env)
|
| 350 | 351 | . get_mod <$> mb_guts
|
| 352 | + more_home_pkg_anns <- HomePackageTable.hptLoadedAnnEnv $ hsc_HPT hsc_env
|
|
| 351 | 353 | let
|
| 352 | 354 | other_pkg_anns = eps_ann_env eps
|
| 353 | 355 | !ann_env = maybe id plusAnnEnv mb_this_module_anns $!
|
| 354 | - plusAnnEnv home_pkg_anns other_pkg_anns
|
|
| 356 | + plusAnnEnv home_pkg_anns (plusAnnEnv more_home_pkg_anns other_pkg_anns)
|
|
| 355 | 357 | return ann_env
|
| 356 | 358 | |
| 357 | 359 | -- | Find the 'TyThing' for the given 'Name' by using all the resources
|
| ... | ... | @@ -374,12 +376,9 @@ lookupTypeInPTE hsc_env pte name = ty |
| 374 | 376 | then mkHomeModule (hsc_home_unit hsc_env) (moduleName (nameModule name))
|
| 375 | 377 | else nameModule name
|
| 376 | 378 | |
| 377 | - ty = if isOneShot (ghcMode (hsc_dflags hsc_env))
|
|
| 378 | - -- in one-shot, we don't use the HPT
|
|
| 379 | - then return $! lookupNameEnv pte name
|
|
| 380 | - else HUG.lookupHugByModule mod hpt >>= \case
|
|
| 381 | - Just hm -> pure $! lookupNameEnv (md_types (hm_details hm)) name
|
|
| 382 | - Nothing -> pure $! lookupNameEnv pte name
|
|
| 379 | + ty = HUG.lookupHugByModule mod hpt >>= \case
|
|
| 380 | + Just hm -> pure $! lookupNameEnv (md_types (hm_details hm)) name
|
|
| 381 | + Nothing -> pure $! lookupNameEnv pte name
|
|
| 383 | 382 | |
| 384 | 383 | -- | Find the 'ModIface' for a 'Module', searching in both the loaded home
|
| 385 | 384 | -- and external package module information
|
| ... | ... | @@ -1546,7 +1546,7 @@ hscCompileCoreExpr' hsc_env srcspan ds_expr = do |
| 1546 | 1546 | let unit_env = hsc_unit_env hsc_env
|
| 1547 | 1547 | let simplify_expr_opts = initSimplifyExprOpts dflags ic
|
| 1548 | 1548 | |
| 1549 | - simpl_expr <- simplifyExpr logger (ue_eps unit_env) simplify_expr_opts ds_expr
|
|
| 1549 | + simpl_expr <- simplifyExpr logger (ue_eps unit_env) (ue_hpt unit_env) simplify_expr_opts ds_expr
|
|
| 1550 | 1550 | |
| 1551 | 1551 | -- Create a unique temporary binding
|
| 1552 | 1552 | --
|
| ... | ... | @@ -131,6 +131,7 @@ import GHC.Data.OrdList |
| 131 | 131 | import Data.IORef
|
| 132 | 132 | |
| 133 | 133 | import GHC.IO.Unsafe (unsafeInterleaveIO)
|
| 134 | +import qualified GHC.Unit.Home.PackageTable as HomePackageTable
|
|
| 134 | 135 | |
| 135 | 136 | {-
|
| 136 | 137 | ************************************************************************
|
| ... | ... | @@ -385,6 +386,7 @@ mkDsEnvsFromTcGbl hsc_env msg_var tcg_env |
| 385 | 386 | -- ToDo: what becomes of the values put into these ref-cells?
|
| 386 | 387 | |
| 387 | 388 | ; eps <- liftIO $ hscEPS hsc_env
|
| 389 | + ; extra_matches <- liftIO $ HomePackageTable.hptLoadedCompleteMatches $ hsc_HPT hsc_env
|
|
| 388 | 390 | ; let unit_env = hsc_unit_env hsc_env
|
| 389 | 391 | this_mod = tcg_mod tcg_env
|
| 390 | 392 | type_env = tcg_type_env tcg_env
|
| ... | ... | @@ -406,7 +408,7 @@ mkDsEnvsFromTcGbl hsc_env msg_var tcg_env |
| 406 | 408 | -- Relevant test case: MultiLayerModulesTH_Make, which regresses
|
| 407 | 409 | -- in allocations by ~5% if we don't do this.
|
| 408 | 410 | traverse (lookupCompleteMatch type_env hsc_env) =<<
|
| 409 | - localAndImportedCompleteMatches tcg_comp_env eps
|
|
| 411 | + localAndImportedCompleteMatches (tcg_comp_env ++ extra_matches) eps
|
|
| 410 | 412 | ; tcm_plugins <- liftIO $ readIORef (tcg_plugins tcg_env)
|
| 411 | 413 | |
| 412 | 414 | -- Pass the running 'TcM' plugins to the desugarer, so that the pattern-match
|
| ... | ... | @@ -469,6 +471,7 @@ initDsWithModGuts hsc_env (ModGuts { mg_module = this_mod, mg_binds = binds |
| 469 | 471 | ; statics_var <- newIORef nilOL
|
| 470 | 472 | ; known_key_maps_var <- newIORef Nothing
|
| 471 | 473 | ; eps <- liftIO $ hscEPS hsc_env
|
| 474 | + ; extra_matches <- liftIO $ HomePackageTable.hptLoadedCompleteMatches $ hsc_HPT hsc_env
|
|
| 472 | 475 | ; let unit_env = hsc_unit_env hsc_env
|
| 473 | 476 | type_env = typeEnvFromEntities ids tycons patsyns fam_insts
|
| 474 | 477 | ptc = initPromotionTickContext (hsc_dflags hsc_env)
|
| ... | ... | @@ -476,7 +479,7 @@ initDsWithModGuts hsc_env (ModGuts { mg_module = this_mod, mg_binds = binds |
| 476 | 479 | bindsToIds (Rec binds) = map fst binds
|
| 477 | 480 | ids = concatMap bindsToIds binds
|
| 478 | 481 | ; ds_complete_matches <- traverse (lookupCompleteMatch type_env hsc_env) =<<
|
| 479 | - localAndImportedCompleteMatches local_complete_matches eps
|
|
| 482 | + localAndImportedCompleteMatches (local_complete_matches ++ extra_matches) eps
|
|
| 480 | 483 | ; let
|
| 481 | 484 | tcm_plugins = emptyTcMPluginsRun
|
| 482 | 485 | envs = mkDsEnvs unit_env this_mod rdr_env type_env
|
| ... | ... | @@ -842,8 +845,8 @@ dsGetFamInstEnvs :: DsM FamInstEnvs |
| 842 | 845 | -- Gets both the external-package inst-env
|
| 843 | 846 | -- and the home-pkg inst env (includes module being compiled)
|
| 844 | 847 | dsGetFamInstEnvs
|
| 845 | - = do { eps <- getEps; env <- getGblEnv
|
|
| 846 | - ; return (eps_fam_inst_env eps, ds_fam_inst_env env) }
|
|
| 848 | + = do { eps <- getEps; env <- getGblEnv; lazy_env <- queryHpt HomePackageTable.hptLoadedFamInstEnv
|
|
| 849 | + ; return (eps_fam_inst_env eps, ds_fam_inst_env env `unionFamInstEnv` lazy_env) }
|
|
| 847 | 850 | |
| 848 | 851 | dsGetMetaEnv :: DsM (NameEnv DsMetaVal)
|
| 849 | 852 | dsGetMetaEnv = do { env <- getLclEnv; return (dsl_meta env) }
|
| ... | ... | @@ -152,6 +152,13 @@ import Data.Function ((&)) |
| 152 | 152 | import Data.Map ( toList )
|
| 153 | 153 | import System.FilePath
|
| 154 | 154 | import System.Directory
|
| 155 | +import GHC.Types.DefaultEnv (DefaultEnv)
|
|
| 156 | +import GHC.Core (CoreRule)
|
|
| 157 | +import GHC.Unit.Module.ModDetails (ModDetails(..))
|
|
| 158 | +import GHC.Unit.Home.ModInfo (HomeModInfo(..), emptyHomeModInfoLinkable)
|
|
| 159 | +import qualified Data.Set as Set
|
|
| 160 | +import qualified GHC.Unit.Home.PackageTable as HomePackageTable
|
|
| 161 | +import Control.Applicative ((<|>))
|
|
| 155 | 162 | |
| 156 | 163 | |
| 157 | 164 | {- *********************************************************************
|
| ... | ... | @@ -513,8 +520,9 @@ importDecl name |
| 513 | 520 | ; Succeeded _ -> do
|
| 514 | 521 | |
| 515 | 522 | -- Now look it up again; this time we should find it
|
| 516 | - { eps <- getEps
|
|
| 517 | - ; case lookupTypeEnv (eps_PTE eps) name of
|
|
| 523 | + { eps <- getEps -- @fendor: DONE
|
|
| 524 | + ; loaderTypeEnv <- queryHpt HomePackageTable.hptLoadedTypeEnv
|
|
| 525 | + ; case lookupTypeEnv loaderTypeEnv name <|> lookupTypeEnv (eps_PTE eps) name of
|
|
| 518 | 526 | Just thing -> return $ Succeeded thing
|
| 519 | 527 | Nothing -> return $ Failed $
|
| 520 | 528 | Can'tFindNameInInterface name
|
| ... | ... | @@ -789,7 +797,9 @@ loadInterface doc_str mod from |
| 789 | 797 | _ -> do {
|
| 790 | 798 | |
| 791 | 799 | -- READ THE MODULE IN
|
| 792 | - ; read_result <- case wantHiBootFile mhome_unit eps mod from of
|
|
| 800 | + ; hpt <- getHpt
|
|
| 801 | + ; hls <- liftIO (hptLoaderState hpt)
|
|
| 802 | + ; read_result <- case wantHiBootFile mhome_unit hls mod from of
|
|
| 793 | 803 | Failed err -> return (Failed err)
|
| 794 | 804 | Succeeded hi_boot_file -> do
|
| 795 | 805 | hsc_env <- getTopEnv
|
| ... | ... | @@ -818,108 +828,37 @@ loadInterface doc_str mod from |
| 818 | 828 | let
|
| 819 | 829 | loc_doc = text (ml_hi_file loc)
|
| 820 | 830 | in
|
| 821 | - initIfaceLcl (mi_semantic_module iface) loc_doc (mi_boot iface) $
|
|
| 822 | - |
|
| 823 | - dontLeakTheHUG $ do
|
|
| 824 | - |
|
| 825 | - -- Load the new ModIface into the External Package State
|
|
| 826 | - -- Even home-package interfaces loaded by loadInterface
|
|
| 827 | - -- (which only happens in OneShot mode; in Batch/Interactive
|
|
| 828 | - -- mode, home-package modules are loaded one by one into the HPT)
|
|
| 829 | - -- are put in the EPS.
|
|
| 830 | - --
|
|
| 831 | - -- The main thing is to add the ModIface to the PIT, but
|
|
| 832 | - -- we also take the
|
|
| 833 | - -- IfaceDecls, IfaceClsInst, IfaceFamInst, IfaceRules,
|
|
| 834 | - -- out of the ModIface and put them into the big EPS pools
|
|
| 835 | - |
|
| 836 | - -- NB: *first* we do tcIfaceDecls, so that the provenance of all the locally-defined
|
|
| 837 | - --- names is done correctly (notably, whether this is an .hi file or .hi-boot file).
|
|
| 838 | - -- If we do loadExport first the wrong info gets into the cache (unless we
|
|
| 839 | - -- explicitly tag each export which seems a bit of a bore)
|
|
| 840 | - |
|
| 841 | - -- Crucial assertion that checks if you are trying to load a HPT module into the EPS.
|
|
| 842 | - -- If you start loading HPT modules into the EPS then you get strange errors about
|
|
| 843 | - -- overlapping instances.
|
|
| 844 | - ; massertPpr
|
|
| 845 | - ((isOneShot (ghcMode (hsc_dflags hsc_env)))
|
|
| 846 | - || moduleUnitId mod `notElem` hsc_all_home_unit_ids hsc_env
|
|
| 847 | - || mod == gHC_PRIM)
|
|
| 848 | - (text "Attempting to load home package interface into the EPS" $$ ppr (HUG.allUnits hug) $$ doc_str $$ ppr mod $$ ppr (moduleUnitId mod))
|
|
| 849 | - ; ignore_prags <- goptM Opt_IgnoreInterfacePragmas
|
|
| 850 | - ; new_eps_decls <- tcIfaceDecls ignore_prags (mi_decls iface)
|
|
| 851 | - ; new_eps_insts <- mapM tcIfaceInst (mi_insts iface)
|
|
| 852 | - ; new_eps_defaults <- tcIfaceDefaults mod (mi_defaults iface)
|
|
| 853 | - ; new_eps_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts iface)
|
|
| 854 | - ; new_eps_rules <- tcIfaceRules ignore_prags (mi_rules iface)
|
|
| 855 | - ; new_eps_anns <- tcIfaceAnnotations (mi_anns iface)
|
|
| 856 | - ; new_eps_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface)
|
|
| 857 | - ; purged_hsc_env <- getTopEnv
|
|
| 858 | - |
|
| 859 | - ; let final_iface = iface
|
|
| 860 | - & set_mi_decls (panic "No mi_decls in PIT")
|
|
| 861 | - & set_mi_insts (panic "No mi_insts in PIT")
|
|
| 862 | - & set_mi_defaults (panic "No mi_defaults in PIT")
|
|
| 863 | - & set_mi_fam_insts (panic "No mi_fam_insts in PIT")
|
|
| 864 | - & set_mi_rules (panic "No mi_rules in PIT")
|
|
| 865 | - & set_mi_anns (panic "No mi_anns in PIT")
|
|
| 866 | - & set_mi_simplified_core (panic "No mi_simplified_core in PIT")
|
|
| 867 | - |
|
| 868 | - bad_boot = mi_boot iface == IsBoot
|
|
| 869 | - && isJust (lookupKnotVars (if_rec_types gbl_env) mod)
|
|
| 870 | - -- Warn against an EPS-updating import
|
|
| 871 | - -- of one's own boot file! (one-shot only)
|
|
| 872 | - -- See Note [Loading your own hi-boot file]
|
|
| 873 | - |
|
| 874 | - -- Create an IO action that loads and compiles bytecode from Core
|
|
| 875 | - -- bindings.
|
|
| 831 | + initIfaceLcl (mi_semantic_module iface) loc_doc (mi_boot iface) $ do
|
|
| 832 | + |
|
| 833 | + ; if fromMaybe False $ fmap (`isHomeModule` mod) mhome_unit -- TODO @fendor: horrible code
|
|
| 834 | + then do -- TODO @fendor: document that we don't want/need 'dontLeakTheHUG' here
|
|
| 835 | + massertPpr (moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env)
|
|
| 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))
|
|
| 837 | + tcParts <- tcPartsOfTheIface mod iface
|
|
| 838 | + addModIfacePartsToHpt gbl_env mod loc iface tcParts
|
|
| 839 | + else dontLeakTheHUG $ do
|
|
| 840 | + -- Load the new ModIface into the External Package State
|
|
| 876 | 841 | --
|
| 877 | - -- See Note [Interface Files with Core Definitions]
|
|
| 878 | - add_bytecode old
|
|
| 879 | - | Just action <- loadIfaceByteCode purged_hsc_env iface loc (mkNameEnv new_eps_decls)
|
|
| 880 | - = extendModuleEnv old mod action
|
|
| 881 | - -- Don't add an entry if the iface doesn't have 'extra_decls'
|
|
| 882 | - -- so 'get_link_deps' knows that it should load object code.
|
|
| 883 | - | otherwise
|
|
| 884 | - = old
|
|
| 885 | - |
|
| 886 | - ; warnPprTrace bad_boot "loadInterface" (ppr mod) $
|
|
| 887 | - updateEps_ $ \ eps ->
|
|
| 888 | - if elemModuleEnv mod (eps_PIT eps) || is_external_sig mhome_unit iface
|
|
| 889 | - then eps
|
|
| 890 | - else if bad_boot
|
|
| 891 | - -- See Note [Loading your own hi-boot file]
|
|
| 892 | - then eps { eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls }
|
|
| 893 | - else
|
|
| 894 | - eps {
|
|
| 895 | - eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
|
|
| 896 | - eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls,
|
|
| 897 | - eps_iface_bytecode = add_bytecode (eps_iface_bytecode eps),
|
|
| 898 | - eps_rule_base = extendRuleBaseList (eps_rule_base eps)
|
|
| 899 | - new_eps_rules,
|
|
| 900 | - eps_complete_matches
|
|
| 901 | - = eps_complete_matches eps ++ new_eps_complete_matches,
|
|
| 902 | - eps_inst_env = extendInstEnvList (eps_inst_env eps)
|
|
| 903 | - new_eps_insts,
|
|
| 904 | - eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
|
|
| 905 | - new_eps_fam_insts,
|
|
| 906 | - eps_ann_env = extendAnnEnvList (eps_ann_env eps)
|
|
| 907 | - new_eps_anns,
|
|
| 908 | - eps_mod_fam_inst_env
|
|
| 909 | - = let
|
|
| 910 | - fam_inst_env =
|
|
| 911 | - extendFamInstEnvList emptyFamInstEnv
|
|
| 912 | - new_eps_fam_insts
|
|
| 913 | - in
|
|
| 914 | - extendModuleEnv (eps_mod_fam_inst_env eps)
|
|
| 915 | - mod
|
|
| 916 | - fam_inst_env,
|
|
| 917 | - eps_stats = addEpsInStats (eps_stats eps)
|
|
| 918 | - (length new_eps_decls)
|
|
| 919 | - (length new_eps_insts)
|
|
| 920 | - (length new_eps_rules),
|
|
| 921 | - eps_defaults = extendModuleEnv (eps_defaults eps) mod new_eps_defaults
|
|
| 922 | - }
|
|
| 842 | + -- The main thing is to add the ModIface to the PIT, but
|
|
| 843 | + -- we also take the
|
|
| 844 | + -- IfaceDecls, IfaceClsInst, IfaceFamInst, IfaceRules,
|
|
| 845 | + -- out of the ModIface and put them into the big EPS pools
|
|
| 846 | + |
|
| 847 | + -- NB: *first* we do tcIfaceDecls, so that the provenance of all the locally-defined
|
|
| 848 | + --- names is done correctly (notably, whether this is an .hi file or .hi-boot file).
|
|
| 849 | + -- If we do loadExport first the wrong info gets into the cache (unless we
|
|
| 850 | + -- explicitly tag each export which seems a bit of a bore)
|
|
| 851 | + |
|
| 852 | + -- Crucial assertion that checks if you are trying to load a HPT module into the EPS.
|
|
| 853 | + -- If you start loading HPT modules into the EPS then you get strange errors about
|
|
| 854 | + -- overlapping instances.
|
|
| 855 | + |
|
| 856 | + massertPpr
|
|
| 857 | + (moduleUnitId mod `Set.notMember` hsc_all_home_unit_ids hsc_env
|
|
| 858 | + || mod == gHC_PRIM)
|
|
| 859 | + (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 | + tcParts <- tcPartsOfTheIface mod iface
|
|
| 861 | + addModIfacePartsToEps gbl_env mod loc iface tcParts
|
|
| 923 | 862 | |
| 924 | 863 | ; -- invoke plugins with *full* interface, not final_iface, to ensure
|
| 925 | 864 | -- that plugins have access to declarations, etc.
|
| ... | ... | @@ -927,6 +866,134 @@ loadInterface doc_str mod from |
| 927 | 866 | ; return (Succeeded res)
|
| 928 | 867 | }}}}
|
| 929 | 868 | |
| 869 | +tcPartsOfTheIface :: Module -> ModIface -> IfL ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], CompleteMatches)
|
|
| 870 | +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)
|
|
| 879 | + 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
|
|
| 887 | + )
|
|
| 888 | + |
|
| 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
|
|
| 892 | + ; let details = ModDetails
|
|
| 893 | + { md_types = mkNameEnv new_eps_decls
|
|
| 894 | + , md_exports = mi_exports iface
|
|
| 895 | + , md_defaults = new_eps_defaults
|
|
| 896 | + , md_insts = mkInstEnv new_eps_insts
|
|
| 897 | + , md_fam_insts = new_eps_fam_insts
|
|
| 898 | + , md_rules = new_eps_rules
|
|
| 899 | + , md_anns = new_eps_anns
|
|
| 900 | + , md_complete_matches = new_eps_complete_matches
|
|
| 901 | + }
|
|
| 902 | + ; let final_iface = iface
|
|
| 903 | + & set_mi_decls (panic "No mi_decls in HomeLoaderState")
|
|
| 904 | + & set_mi_insts (panic "No mi_insts in HomeLoaderState")
|
|
| 905 | + & set_mi_defaults (panic "No mi_defaults in HomeLoaderState")
|
|
| 906 | + & set_mi_fam_insts (panic "No mi_fam_insts in HomeLoaderState")
|
|
| 907 | + & set_mi_rules (panic "No mi_rules in HomeLoaderState")
|
|
| 908 | + & set_mi_anns (panic "No mi_anns in HomeLoaderState")
|
|
| 909 | + & set_mi_simplified_core (panic "No mi_simplified_core in HomeLoaderState")
|
|
| 910 | + |
|
| 911 | + bad_boot = mi_boot iface == IsBoot
|
|
| 912 | + && isJust (lookupKnotVars (if_rec_types gbl_env) mod)
|
|
| 913 | + -- Warn against an HPT-updating import
|
|
| 914 | + -- of one's own boot file! (one-shot only)
|
|
| 915 | + -- See Note [Loading your own hi-boot file]
|
|
| 916 | + |
|
| 917 | + ; warnPprTrace bad_boot "loadInterface" (ppr mod) $ do
|
|
| 918 | + hpt <- getHpt
|
|
| 919 | + -- Create an IO action that loads and compiles bytecode from Core
|
|
| 920 | + -- bindings.
|
|
| 921 | + --
|
|
| 922 | + -- See Note [Interface Files with Core Definitions]
|
|
| 923 | + let lazy_bytecode = loadIfaceByteCode hsc_env iface loc (mkNameEnv new_eps_decls)
|
|
| 924 | + liftIO $ addHomeModInfoToHpt (HomeModInfo iface details emptyHomeModInfoLinkable) hpt
|
|
| 925 | + liftIO $ addOnDemandHomeModule hpt mod final_iface 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
|
|
| 926 | + |
|
| 927 | +addModIfacePartsToEps :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL ()
|
|
| 928 | +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
|
|
| 929 | + ; purged_hsc_env <- getTopEnv
|
|
| 930 | + |
|
| 931 | + ; let final_iface = iface
|
|
| 932 | + & set_mi_decls (panic "No mi_decls in PIT")
|
|
| 933 | + & set_mi_insts (panic "No mi_insts in PIT")
|
|
| 934 | + & set_mi_defaults (panic "No mi_defaults in PIT")
|
|
| 935 | + & set_mi_fam_insts (panic "No mi_fam_insts in PIT")
|
|
| 936 | + & set_mi_rules (panic "No mi_rules in PIT")
|
|
| 937 | + & set_mi_anns (panic "No mi_anns in PIT")
|
|
| 938 | + & set_mi_simplified_core (panic "No mi_simplified_core in PIT")
|
|
| 939 | + |
|
| 940 | + bad_boot = mi_boot iface == IsBoot
|
|
| 941 | + && isJust (lookupKnotVars (if_rec_types gbl_env) mod)
|
|
| 942 | + -- Warn against an EPS-updating import
|
|
| 943 | + -- of one's own boot file! (one-shot only)
|
|
| 944 | + -- See Note [Loading your own hi-boot file]
|
|
| 945 | + |
|
| 946 | + -- Create an IO action that loads and compiles bytecode from Core
|
|
| 947 | + -- bindings.
|
|
| 948 | + --
|
|
| 949 | + -- See Note [Interface Files with Core Definitions]
|
|
| 950 | + add_bytecode old
|
|
| 951 | + | Just action <- loadIfaceByteCode purged_hsc_env iface loc (mkNameEnv new_eps_decls)
|
|
| 952 | + = extendModuleEnv old mod action
|
|
| 953 | + -- Don't add an entry if the iface doesn't have 'extra_decls'
|
|
| 954 | + -- so 'get_link_deps' knows that it should load object code.
|
|
| 955 | + | otherwise
|
|
| 956 | + = old
|
|
| 957 | + ; let mhome_unit = ue_homeUnit (hsc_unit_env purged_hsc_env)
|
|
| 958 | + ; warnPprTrace bad_boot "loadInterface" (ppr mod) $
|
|
| 959 | + updateEps_ $ \ eps ->
|
|
| 960 | + if elemModuleEnv mod (eps_PIT eps) || is_external_sig mhome_unit iface
|
|
| 961 | + then eps
|
|
| 962 | + else if bad_boot
|
|
| 963 | + -- See Note [Loading your own hi-boot file]
|
|
| 964 | + then eps { eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls }
|
|
| 965 | + else
|
|
| 966 | + eps {
|
|
| 967 | + eps_PIT = extendModuleEnv (eps_PIT eps) mod final_iface,
|
|
| 968 | + eps_PTE = addDeclsToPTE (eps_PTE eps) new_eps_decls,
|
|
| 969 | + eps_iface_bytecode = add_bytecode (eps_iface_bytecode eps),
|
|
| 970 | + eps_rule_base = extendRuleBaseList (eps_rule_base eps)
|
|
| 971 | + new_eps_rules,
|
|
| 972 | + eps_complete_matches
|
|
| 973 | + = eps_complete_matches eps ++ new_eps_complete_matches,
|
|
| 974 | + eps_inst_env = extendInstEnvList (eps_inst_env eps)
|
|
| 975 | + new_eps_insts,
|
|
| 976 | + eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps)
|
|
| 977 | + new_eps_fam_insts,
|
|
| 978 | + eps_ann_env = extendAnnEnvList (eps_ann_env eps)
|
|
| 979 | + new_eps_anns,
|
|
| 980 | + eps_mod_fam_inst_env
|
|
| 981 | + = let
|
|
| 982 | + fam_inst_env =
|
|
| 983 | + extendFamInstEnvList emptyFamInstEnv
|
|
| 984 | + new_eps_fam_insts
|
|
| 985 | + in
|
|
| 986 | + extendModuleEnv (eps_mod_fam_inst_env eps)
|
|
| 987 | + mod
|
|
| 988 | + fam_inst_env,
|
|
| 989 | + eps_stats = addEpsInStats (eps_stats eps)
|
|
| 990 | + (length new_eps_decls)
|
|
| 991 | + (length new_eps_insts)
|
|
| 992 | + (length new_eps_rules),
|
|
| 993 | + eps_defaults = extendModuleEnv (eps_defaults eps) mod new_eps_defaults
|
|
| 994 | + }
|
|
| 995 | + |
|
| 996 | + |
|
| 930 | 997 | {- Note [Loading your own hi-boot file]
|
| 931 | 998 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 932 | 999 | Generally speaking, when compiling module M, we should not
|
| ... | ... | @@ -1142,10 +1209,10 @@ moduleFreeHolesPrecise doc_str mod |
| 1142 | 1209 | return (Succeeded (renameFreeHoles ifhs insts))
|
| 1143 | 1210 | Failed err -> return (Failed err)
|
| 1144 | 1211 | |
| 1145 | -wantHiBootFile :: Maybe HomeUnit -> ExternalPackageState -> Module -> WhereFrom
|
|
| 1212 | +wantHiBootFile :: Maybe HomeUnit -> HomeLoaderState -> Module -> WhereFrom
|
|
| 1146 | 1213 | -> MaybeErr MissingInterfaceError IsBootInterface
|
| 1147 | 1214 | -- Figure out whether we want Foo.hi or Foo.hi-boot
|
| 1148 | -wantHiBootFile mhome_unit eps mod from
|
|
| 1215 | +wantHiBootFile mhome_unit hls mod from
|
|
| 1149 | 1216 | = case from of
|
| 1150 | 1217 | ImportByUser usr_boot
|
| 1151 | 1218 | | usr_boot == IsBoot && notHomeModuleMaybe mhome_unit mod
|
| ... | ... | @@ -1164,8 +1231,8 @@ wantHiBootFile mhome_unit eps mod from |
| 1164 | 1231 | -- We never import boot modules from other packages!
|
| 1165 | 1232 | |
| 1166 | 1233 | | otherwise
|
| 1167 | - -> case lookupInstalledModuleEnv (eps_is_boot eps) (toUnitId <$> mod) of
|
|
| 1168 | - Just (GWIB { gwib_isBoot = is_boot }) ->
|
|
| 1234 | + -> case hlsIsBoot hls (toUnitId <$> mod) of
|
|
| 1235 | + Just is_boot ->
|
|
| 1169 | 1236 | Succeeded is_boot
|
| 1170 | 1237 | Nothing ->
|
| 1171 | 1238 | Succeeded NotBoot
|
| ... | ... | @@ -93,6 +93,7 @@ import GHC.ByteCode.Serialize (ModuleByteCode, gbc_hash) |
| 93 | 93 | import GHC.Unit.Home.Graph (lookupHugByModule)
|
| 94 | 94 | import GHC.Unit.Home.ModInfo (HomeModLinkable(..), HomeModInfo (..))
|
| 95 | 95 | import GHC.Linker.Types (linkableParts)
|
| 96 | +import GHC.Unit.Home.PackageTable
|
|
| 96 | 97 | |
| 97 | 98 | {-
|
| 98 | 99 | -----------------------------------------------
|
| ... | ... | @@ -427,7 +428,8 @@ checkVersions hsc_env mod_summary iface self_recomp |
| 427 | 428 | -- case we'll compile the module from scratch anyhow).
|
| 428 | 429 | |
| 429 | 430 | when (isOneShot (ghcMode (hsc_dflags hsc_env))) $ do {
|
| 430 | - ; updateEps_ $ \eps -> eps { eps_is_boot = mkModDeps $ dep_boot_mods (mi_deps iface) }
|
|
| 431 | + ; hpt <- getHpt
|
|
| 432 | + ; liftIO $ hlsSetBootInfo hpt (mkModDeps $ dep_boot_mods (mi_deps iface))
|
|
| 431 | 433 | }
|
| 432 | 434 | ; recomp <- checkList [checkModUsage (hsc_FC hsc_env) u
|
| 433 | 435 | | u <- mi_sr_usages self_recomp]
|
| ... | ... | @@ -137,6 +137,7 @@ import Language.Haskell.Syntax.BooleanFormula (BooleanFormula) |
| 137 | 137 | import Language.Haskell.Syntax.BooleanFormula qualified as BF(BooleanFormula(..))
|
| 138 | 138 | import Language.Haskell.Syntax.Extension (NoExtField (NoExtField))
|
| 139 | 139 | import GHC.Builtin.KnownKeys (ioTyConKey)
|
| 140 | +import GHC.Unit.Home.PackageTable
|
|
| 140 | 141 | |
| 141 | 142 | {-
|
| 142 | 143 | This module takes
|
| ... | ... | @@ -631,12 +632,13 @@ tcHiBootIface hsc_src mod |
| 631 | 632 | -- current module, which either means a module loop (not
|
| 632 | 633 | -- a SOURCE import) or that our hi-boot file has mysteriously
|
| 633 | 634 | -- disappeared.
|
| 634 | - do { eps <- getEps
|
|
| 635 | - ; case lookupInstalledModuleEnv (eps_is_boot eps) (toUnitId <$> mod) of
|
|
| 635 | + do { hpt <- getHpt
|
|
| 636 | + ; hls <- liftIO $ hptLoaderState hpt
|
|
| 637 | + ; case hlsIsBoot hls (toUnitId <$> mod) of
|
|
| 636 | 638 | -- The typical case
|
| 637 | 639 | Nothing -> return NoSelfBoot
|
| 638 | 640 | -- error cases
|
| 639 | - Just (GWIB { gwib_isBoot = is_boot }) -> case is_boot of
|
|
| 641 | + Just is_boot -> case is_boot of
|
|
| 640 | 642 | IsBoot ->
|
| 641 | 643 | let diag = Can'tFindInterface err
|
| 642 | 644 | (LookingForHiBoot mod)
|
| ... | ... | @@ -157,8 +157,8 @@ get_link_deps opts pls maybe_normal_osuf span mods = do |
| 157 | 157 | else homeModInfoObject hmi <|> homeModInfoByteCode hmi
|
| 158 | 158 | |
| 159 | 159 | get_linkable osuf mod -- A home-package module
|
| 160 | - = HUG.lookupHugByModule mod (ue_home_unit_graph unit_env) >>= \case
|
|
| 161 | - Just mod_info -> adjust_linkable (expectJust (homeModLinkable mod_info))
|
|
| 160 | + = lookupHomeLinkable mod (ue_home_unit_graph unit_env) >>= \ case
|
|
| 161 | + Just home_linkable -> adjust_linkable home_linkable
|
|
| 162 | 162 | Nothing -> do
|
| 163 | 163 | -- It's not in the HPT because we are in one shot mode,
|
| 164 | 164 | -- so use the Finder to get a ModLocation...
|
| ... | ... | @@ -175,6 +175,10 @@ get_link_deps opts pls maybe_normal_osuf span mods = do |
| 175 | 175 | maybe (fallback_no_bytecode home_unit mod) pure from_bc
|
| 176 | 176 | _ -> fallback_no_bytecode home_unit mod
|
| 177 | 177 | where
|
| 178 | + lookupHomeLinkable mod hug =
|
|
| 179 | + HUG.lookupHugByModule mod hug >>= \case
|
|
| 180 | + Just mod_info -> pure $ homeModLinkable mod_info
|
|
| 181 | + Nothing -> pure Nothing
|
|
| 178 | 182 | |
| 179 | 183 | fallback_no_bytecode home_unit mod = do
|
| 180 | 184 | let fc = ldFinderCache opts
|
| ... | ... | @@ -57,6 +57,8 @@ import Data.Function ( on ) |
| 57 | 57 | import qualified GHC.LanguageExtensions as LangExt
|
| 58 | 58 | import Data.List (sortOn)
|
| 59 | 59 | import qualified GHC.Unit.Home.Graph as HUG
|
| 60 | +import qualified GHC.Unit.Home.PackageTable as HomePackageTable
|
|
| 61 | +import Control.Applicative ((<|>))
|
|
| 60 | 62 | |
| 61 | 63 | |
| 62 | 64 | {- Note [The type family instance consistency story]
|
| ... | ... | @@ -407,8 +409,9 @@ getFamInsts hpt_fam_insts mod |
| 407 | 409 | | Just env <- lookupModuleEnv hpt_fam_insts mod = return env
|
| 408 | 410 | | otherwise = do { _ <- initIfaceTcRn (loadSysInterface doc mod)
|
| 409 | 411 | ; eps <- getEps
|
| 412 | + ; hpt_extra_mod_fam_insts <- queryHpt HomePackageTable.hptLoadedModFamInstEnv
|
|
| 410 | 413 | ; return (expectJust $
|
| 411 | - lookupModuleEnv (eps_mod_fam_inst_env eps) mod) }
|
|
| 414 | + lookupModuleEnv hpt_extra_mod_fam_insts mod <|> lookupModuleEnv (eps_mod_fam_inst_env eps) mod) }
|
|
| 412 | 415 | where
|
| 413 | 416 | doc = ppr mod <+> text "is a family-instance module"
|
| 414 | 417 | |
| ... | ... | @@ -615,7 +618,8 @@ addLocalFamInst (home_fie, my_fis) fam_inst |
| 615 | 618 | -- by the current module, rather than every instance
|
| 616 | 619 | -- we've ever seen. Fixing this is part of #13102.
|
| 617 | 620 | ; eps <- getEps
|
| 618 | - ; let inst_envs = (eps_fam_inst_env eps, home_fie)
|
|
| 621 | + ; extra <- queryHpt HomePackageTable.hptLoadedFamInstEnv
|
|
| 622 | + ; let inst_envs = (eps_fam_inst_env eps `unionFamInstEnv` extra, home_fie)
|
|
| 619 | 623 | home_fie' = extendFamInstEnv home_fie fam_inst
|
| 620 | 624 | |
| 621 | 625 | -- Check for conflicting instance decls and injectivity violations
|
| ... | ... | @@ -948,7 +952,7 @@ tcGetFamInstEnvs :: TcM FamInstEnvs |
| 948 | 952 | -- Gets both the external-package inst-env
|
| 949 | 953 | -- and the home-pkg inst env (includes module being compiled)
|
| 950 | 954 | tcGetFamInstEnvs
|
| 951 | - = do { eps <- getEps; env <- getGblEnv
|
|
| 955 | + = do { eps <- getEps; env <- getGblEnv; !extra <- queryHpt HomePackageTable.hptLoadedFamInstEnv
|
|
| 952 | 956 | ; let !pkg_env = eps_fam_inst_env eps
|
| 953 | 957 | !home_env = tcg_fam_inst_env env
|
| 954 | - ; return (pkg_env, home_env) } |
|
| 958 | + ; return (pkg_env, home_env `unionFamInstEnv` extra) } |
| ... | ... | @@ -157,7 +157,6 @@ import GHC.Types.SourceFile |
| 157 | 157 | import qualified GHC.LanguageExtensions as LangExt
|
| 158 | 158 | |
| 159 | 159 | import GHC.Unit.Env as UnitEnv
|
| 160 | -import GHC.Unit.External
|
|
| 161 | 160 | import GHC.Unit.Types
|
| 162 | 161 | import GHC.Unit.State
|
| 163 | 162 | import GHC.Unit.Home
|
| ... | ... | @@ -192,6 +191,7 @@ import qualified Data.Map as M |
| 192 | 191 | import Data.Foldable ( for_ )
|
| 193 | 192 | import Data.Traversable ( for )
|
| 194 | 193 | import Data.IORef( newIORef )
|
| 194 | +import GHC.Unit.Home.PackageTable (hlsSetBootInfo)
|
|
| 195 | 195 | |
| 196 | 196 | {-
|
| 197 | 197 | ************************************************************************
|
| ... | ... | @@ -513,7 +513,8 @@ tcRnImports hsc_env import_decls |
| 513 | 513 | -- visible to loadHiBootInterface in tcRnSrcDecls,
|
| 514 | 514 | -- and any other incrementally-performed imports
|
| 515 | 515 | ; when (isOneShot (ghcMode (hsc_dflags hsc_env))) $ do {
|
| 516 | - updateEps_ $ \eps -> eps { eps_is_boot = imp_boot_mods imports }
|
|
| 516 | + ; hpt <- getHpt
|
|
| 517 | + ; liftIO $ hlsSetBootInfo hpt (imp_boot_mods imports)
|
|
| 517 | 518 | }
|
| 518 | 519 | |
| 519 | 520 | -- Update the gbl env
|
| ... | ... | @@ -152,6 +152,7 @@ import Control.Monad |
| 152 | 152 | import Data.IORef
|
| 153 | 153 | import Data.List ( intercalate )
|
| 154 | 154 | import qualified Data.List.NonEmpty as NE
|
| 155 | +import qualified GHC.Unit.Home.PackageTable as HomePackageTable
|
|
| 155 | 156 | |
| 156 | 157 | {- *********************************************************************
|
| 157 | 158 | * *
|
| ... | ... | @@ -385,7 +386,8 @@ tcGetClsDefaults :: [Module] -> TcM [DefaultEnv] |
| 385 | 386 | tcGetClsDefaults mods = do
|
| 386 | 387 | hug <- hsc_HUG <$> getTopEnv
|
| 387 | 388 | module_env_defaults <- eps_defaults <$> getEps
|
| 388 | - liftIO $ mapMaybeM (lookupClsDefault hug module_env_defaults) mods
|
|
| 389 | + more_env_defaults <- queryHpt HomePackageTable.hptLoadedDefaults
|
|
| 390 | + liftIO $ mapMaybeM (lookupClsDefault hug (module_env_defaults `plusModuleEnv` more_env_defaults)) mods
|
|
| 389 | 391 | |
| 390 | 392 | lookupClsDefault :: HomeUnitGraph -> ModuleEnv DefaultEnv -> Module -> IO (Maybe DefaultEnv)
|
| 391 | 393 | lookupClsDefault hug module_env_defaults mod =
|
| ... | ... | @@ -398,8 +400,9 @@ tcGetInstEnvs :: TcM InstEnvs |
| 398 | 400 | -- and the home-pkg inst env (includes module being compiled)
|
| 399 | 401 | tcGetInstEnvs = do { eps <- getEps
|
| 400 | 402 | ; env <- getGblEnv
|
| 403 | + ; extra <- queryHpt HomePackageTable.hptLoadedInstEnv
|
|
| 401 | 404 | ; return (InstEnvs { ie_global = eps_inst_env eps
|
| 402 | - , ie_local = tcg_inst_env env
|
|
| 405 | + , ie_local = tcg_inst_env env `unionInstEnv` extra
|
|
| 403 | 406 | , ie_visible = tcVisibleOrphanMods env }) }
|
| 404 | 407 | |
| 405 | 408 | -- Illegal term-level use of type things
|
| ... | ... | @@ -88,6 +88,7 @@ import Data.List ( mapAccumL ) |
| 88 | 88 | import qualified Data.List.NonEmpty as NE
|
| 89 | 89 | import Control.Monad( when, unless )
|
| 90 | 90 | import Data.Function ( on )
|
| 91 | +import qualified GHC.Unit.Home.PackageTable as HomePackageTable
|
|
| 91 | 92 | |
| 92 | 93 | {-
|
| 93 | 94 | ************************************************************************
|
| ... | ... | @@ -922,6 +923,7 @@ addLocalInst (home_ie, my_insts) ispec |
| 922 | 923 | -- 'dups' are those 'matches' that are equal to the new one
|
| 923 | 924 | ; isGHCi <- getIsGHCi
|
| 924 | 925 | ; eps <- getEps
|
| 926 | + ; extra_inst_env <- queryHpt HomePackageTable.hptLoadedInstEnv
|
|
| 925 | 927 | ; tcg_env <- getGblEnv
|
| 926 | 928 | |
| 927 | 929 | -- In GHCi, we *override* any identical instances
|
| ... | ... | @@ -933,7 +935,7 @@ addLocalInst (home_ie, my_insts) ispec |
| 933 | 935 | |
| 934 | 936 | global_ie = eps_inst_env eps
|
| 935 | 937 | inst_envs = InstEnvs { ie_global = global_ie
|
| 936 | - , ie_local = home_ie'
|
|
| 938 | + , ie_local = home_ie' `unionInstEnv` extra_inst_env
|
|
| 937 | 939 | , ie_visible = tcVisibleOrphanMods tcg_env }
|
| 938 | 940 | |
| 939 | 941 | -- Check for inconsistent functional dependencies
|
| ... | ... | @@ -945,6 +947,13 @@ addLocalInst (home_ie, my_insts) ispec |
| 945 | 947 | ; let (_tvs, cls, tys) = instanceHead ispec
|
| 946 | 948 | (matches, _, _) = lookupInstEnv False inst_envs cls tys
|
| 947 | 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)
|
|
| 948 | 957 | ; unless (null dups) $
|
| 949 | 958 | dupInstErr ispec (head dups)
|
| 950 | 959 |
| ... | ... | @@ -30,7 +30,7 @@ module GHC.Tc.Utils.Monad( |
| 30 | 30 | getEpsVar,
|
| 31 | 31 | getEps,
|
| 32 | 32 | updateEps, updateEps_,
|
| 33 | - getHpt, getEpsAndHug,
|
|
| 33 | + getHpt, queryHpt, getEpsAndHug,
|
|
| 34 | 34 | |
| 35 | 35 | -- * Initialising TcM plugins
|
| 36 | 36 | TcMPluginHandling(..),
|
| ... | ... | @@ -261,6 +261,7 @@ import Control.Monad.Catch ( bracket_, finally, onException, mask, mask_, MonadC |
| 261 | 261 | import Data.Foldable (traverse_)
|
| 262 | 262 | import Data.IORef
|
| 263 | 263 | import qualified Data.Map as Map
|
| 264 | +import qualified GHC.Unit.Home.PackageTable as HomePackageTable
|
|
| 264 | 265 | |
| 265 | 266 | {-
|
| 266 | 267 | ************************************************************************
|
| ... | ... | @@ -740,6 +741,11 @@ updateEps_ upd_fn = updateEps (\eps -> (upd_fn eps, ())) |
| 740 | 741 | getHpt :: TcRnIf gbl lcl HomePackageTable
|
| 741 | 742 | getHpt = do { env <- getTopEnv; return (hsc_HPT env) }
|
| 742 | 743 | |
| 744 | +queryHpt :: (HomePackageTable -> IO a) -> TcRnIf gbl lcl a
|
|
| 745 | +queryHpt f = do
|
|
| 746 | + hpt <- getHpt
|
|
| 747 | + liftIO $ f hpt
|
|
| 748 | + |
|
| 743 | 749 | getEpsAndHug :: TcRnIf gbl lcl (ExternalPackageState, HomeUnitGraph)
|
| 744 | 750 | getEpsAndHug = do { env <- getTopEnv; eps <- liftIO $ hscEPS env
|
| 745 | 751 | ; return (eps, hsc_HUG env) }
|
| ... | ... | @@ -2740,8 +2746,9 @@ getCompleteMatchesTcM |
| 2740 | 2746 | = do { hsc_env <- getTopEnv
|
| 2741 | 2747 | ; eps <- liftIO $ hscEPS hsc_env
|
| 2742 | 2748 | ; tcg_env <- getGblEnv
|
| 2749 | + ; extra_matches <- queryHpt HomePackageTable.hptLoadedCompleteMatches
|
|
| 2743 | 2750 | ; let tcg_comps = tcg_complete_match_env tcg_env
|
| 2744 | - ; liftIO $ localAndImportedCompleteMatches tcg_comps eps
|
|
| 2751 | + ; liftIO $ localAndImportedCompleteMatches (tcg_comps ++ extra_matches) eps
|
|
| 2745 | 2752 | }
|
| 2746 | 2753 | |
| 2747 | 2754 | localAndImportedCompleteMatches :: CompleteMatches -> ExternalPackageState -> IO CompleteMatches
|
| ... | ... | @@ -71,8 +71,7 @@ eucEPS = readIORef . euc_eps |
| 71 | 71 | |
| 72 | 72 | initExternalPackageState :: ExternalPackageState
|
| 73 | 73 | initExternalPackageState = EPS
|
| 74 | - { eps_is_boot = emptyInstalledModuleEnv
|
|
| 75 | - , eps_PIT = emptyPackageIfaceTable
|
|
| 74 | + { eps_PIT = emptyPackageIfaceTable
|
|
| 76 | 75 | , eps_free_holes = emptyInstalledModuleEnv
|
| 77 | 76 | , eps_PTE = emptyTypeEnv
|
| 78 | 77 | , eps_iface_bytecode = emptyModuleEnv
|
| ... | ... | @@ -101,19 +100,6 @@ initExternalPackageState = EPS |
| 101 | 100 | -- their interface files
|
| 102 | 101 | data ExternalPackageState
|
| 103 | 102 | = EPS {
|
| 104 | - eps_is_boot :: !(InstalledModuleEnv ModuleNameWithIsBoot),
|
|
| 105 | - -- ^ In OneShot mode (only), home-package modules
|
|
| 106 | - -- accumulate in the external package state, and are
|
|
| 107 | - -- sucked in lazily. For these home-pkg modules
|
|
| 108 | - -- (only) we need to record which are boot modules.
|
|
| 109 | - -- We set this field after loading all the
|
|
| 110 | - -- explicitly-imported interfaces, but before doing
|
|
| 111 | - -- anything else
|
|
| 112 | - --
|
|
| 113 | - -- The 'ModuleName' part is not necessary, but it's useful for
|
|
| 114 | - -- debug prints, and it's convenient because this field comes
|
|
| 115 | - -- direct from 'GHC.Tc.Utils.imp_dep_mods'
|
|
| 116 | - |
|
| 117 | 103 | eps_PIT :: !PackageIfaceTable,
|
| 118 | 104 | -- ^ The 'ModIface's for modules in external packages
|
| 119 | 105 | -- whose interfaces we have opened.
|
| ... | ... | @@ -23,9 +23,12 @@ |
| 23 | 23 | -- 'hptCollectObjects'...
|
| 24 | 24 | module GHC.Unit.Home.PackageTable
|
| 25 | 25 | (
|
| 26 | - HomePackageTable(..)
|
|
| 26 | + HomePackageTable
|
|
| 27 | 27 | , emptyHomePackageTable
|
| 28 | 28 | |
| 29 | + , HomeLoaderState -- TODO: should this be opaque? Probably
|
|
| 30 | + , emptyHomeLoaderState
|
|
| 31 | + |
|
| 29 | 32 | -- * Lookups in the HPT
|
| 30 | 33 | , lookupHpt
|
| 31 | 34 | , lookupHptByModule
|
| ... | ... | @@ -33,6 +36,7 @@ module GHC.Unit.Home.PackageTable |
| 33 | 36 | -- * Extending the HPT
|
| 34 | 37 | , addHomeModInfoToHpt
|
| 35 | 38 | , addHomeModInfosToHpt
|
| 39 | + , addOnDemandHomeModule
|
|
| 36 | 40 | |
| 37 | 41 | -- * Restrict the HPT
|
| 38 | 42 | , restrictHpt
|
| ... | ... | @@ -42,6 +46,18 @@ module GHC.Unit.Home.PackageTable |
| 42 | 46 | , hptAllInstances
|
| 43 | 47 | , hptAllFamInstances
|
| 44 | 48 | , hptAllAnnotations
|
| 49 | + , hlsIsModuleNameWithBoot
|
|
| 50 | + , hlsIsBoot
|
|
| 51 | + , hlsSetBootInfo
|
|
| 52 | + , hptLoadedIsBoot
|
|
| 53 | + , hptLoadedTypeEnv
|
|
| 54 | + , hptLoadedInstEnv
|
|
| 55 | + , hptLoadedFamInstEnv
|
|
| 56 | + , hptLoadedModFamInstEnv
|
|
| 57 | + , hptLoadedRuleBase
|
|
| 58 | + , hptLoadedAnnEnv
|
|
| 59 | + , hptLoadedCompleteMatches
|
|
| 60 | + , hptLoadedDefaults
|
|
| 45 | 61 | |
| 46 | 62 | -- ** More Traversal-based queries
|
| 47 | 63 | , hptCollectDependencies
|
| ... | ... | @@ -64,7 +80,7 @@ module GHC.Unit.Home.PackageTable |
| 64 | 80 | -- it is not sufficient to go through the intended insert-only API.
|
| 65 | 81 | , hptInternalTableRef
|
| 66 | 82 | , hptInternalTableFromRef
|
| 67 | - |
|
| 83 | + , hptLoaderState
|
|
| 68 | 84 | -- * Legacy API
|
| 69 | 85 | --
|
| 70 | 86 | -- | This API is deprecated and meant to be removed.
|
| ... | ... | @@ -80,8 +96,14 @@ import qualified Data.Set as Set |
| 80 | 96 | |
| 81 | 97 | import GHC.Core.FamInstEnv
|
| 82 | 98 | import GHC.Core.InstEnv
|
| 99 | +import GHC.Core.Rules (RuleBase, extendRuleBaseList, emptyRuleBase)
|
|
| 100 | +import GHC.Data.Word64Set qualified as W64
|
|
| 101 | +import GHC.Linker.Types (Linkable)
|
|
| 83 | 102 | import GHC.Types.Annotations
|
| 84 | 103 | import GHC.Types.CompleteMatch
|
| 104 | +import GHC.Types.TypeEnv
|
|
| 105 | +import GHC.Types.TyThing
|
|
| 106 | +import GHC.Types.Unique (getKey, getUnique)
|
|
| 85 | 107 | import GHC.Types.Unique.DFM
|
| 86 | 108 | import GHC.Unit.Home.ModInfo
|
| 87 | 109 | import GHC.Unit.Module
|
| ... | ... | @@ -89,13 +111,15 @@ import GHC.Unit.Module.Deps |
| 89 | 111 | import GHC.Unit.Module.ModDetails
|
| 90 | 112 | import GHC.Unit.Module.ModIface
|
| 91 | 113 | import GHC.Utils.Outputable
|
| 92 | -import GHC.Types.Unique (getUnique, getKey)
|
|
| 93 | -import qualified GHC.Data.Word64Set as W64
|
|
| 114 | +import GHC.Types.Name
|
|
| 115 | +import GHC.Types.Name.Env (extendNameEnvList)
|
|
| 116 | +import GHC.Types.DefaultEnv (DefaultEnv)
|
|
| 117 | +import GHC.Core
|
|
| 94 | 118 | |
| 95 | 119 | -- | Helps us find information about modules in the home package
|
| 96 | -newtype HomePackageTable = HPT {
|
|
| 120 | +data HomePackageTable = HPT {
|
|
| 97 | 121 | |
| 98 | - table :: IORef (DModuleNameEnv HomeModInfo)
|
|
| 122 | + table :: IORef (DModuleNameEnv HomeModInfo),
|
|
| 99 | 123 | -- ^ Domain = modules in this home unit
|
| 100 | 124 | --
|
| 101 | 125 | -- This is an IORef because we want to avoid leaking HPTs (see the particularly bad #25511).
|
| ... | ... | @@ -109,6 +133,7 @@ newtype HomePackageTable = HPT { |
| 109 | 133 | -- to temporarily violate the HPT monotonicity.
|
| 110 | 134 | --
|
| 111 | 135 | -- The elements of this table may be updated (e.g. on rehydration).
|
| 136 | + loader :: IORef HomeLoaderState
|
|
| 112 | 137 | }
|
| 113 | 138 | |
| 114 | 139 | -- | Create a new 'HomePackageTable'.
|
| ... | ... | @@ -120,7 +145,38 @@ emptyHomePackageTable :: IO HomePackageTable |
| 120 | 145 | -- romes:todo: use a MutableArray directly?
|
| 121 | 146 | emptyHomePackageTable = do
|
| 122 | 147 | table <- newIORef emptyUDFM
|
| 123 | - return HPT{table}
|
|
| 148 | + loader <- newIORef emptyHomeLoaderState
|
|
| 149 | + return HPT{table, loader}
|
|
| 150 | + |
|
| 151 | +data HomeLoaderState = HomeLoaderState
|
|
| 152 | + { hls_is_boot :: InstalledModuleEnv ModuleNameWithIsBoot
|
|
| 153 | + , hls_iface_table :: ModuleEnv ModIface
|
|
| 154 | + , hls_type_env :: !TypeEnv
|
|
| 155 | + , hls_iface_bytecode :: !(ModuleEnv (IO Linkable))
|
|
| 156 | + , hls_inst_env :: !InstEnv
|
|
| 157 | + , hls_fam_inst_env :: !FamInstEnv
|
|
| 158 | + , hls_mod_fam_inst_env :: !(ModuleEnv FamInstEnv)
|
|
| 159 | + , hls_rule_base :: !RuleBase
|
|
| 160 | + , hls_ann_env :: !AnnEnv
|
|
| 161 | + , hls_complete_matches :: !CompleteMatches
|
|
| 162 | + , hls_defaults :: ModuleEnv DefaultEnv
|
|
| 163 | + }
|
|
| 164 | + |
|
| 165 | +emptyHomeLoaderState :: HomeLoaderState
|
|
| 166 | +emptyHomeLoaderState =
|
|
| 167 | + HomeLoaderState
|
|
| 168 | + { hls_is_boot = emptyInstalledModuleEnv
|
|
| 169 | + , hls_iface_table = emptyModuleEnv
|
|
| 170 | + , hls_type_env = emptyTypeEnv
|
|
| 171 | + , hls_iface_bytecode = emptyModuleEnv
|
|
| 172 | + , hls_inst_env = emptyInstEnv
|
|
| 173 | + , hls_fam_inst_env = emptyFamInstEnv
|
|
| 174 | + , hls_mod_fam_inst_env = emptyModuleEnv
|
|
| 175 | + , hls_rule_base = emptyRuleBase
|
|
| 176 | + , hls_ann_env = emptyAnnEnv
|
|
| 177 | + , hls_complete_matches = []
|
|
| 178 | + , hls_defaults = emptyModuleEnv
|
|
| 179 | + }
|
|
| 124 | 180 | |
| 125 | 181 | --------------------------------------------------------------------------------
|
| 126 | 182 | -- * Lookups in the HPT
|
| ... | ... | @@ -139,6 +195,36 @@ lookupHptByModule hpt mod |
| 139 | 195 | Just hm | mi_module (hm_iface hm) == mod -> Just hm
|
| 140 | 196 | _otherwise -> Nothing
|
| 141 | 197 | |
| 198 | +hptLoaderState :: HomePackageTable -> IO HomeLoaderState
|
|
| 199 | +hptLoaderState = readIORef . loader
|
|
| 200 | + |
|
| 201 | +hptLoadedIsBoot :: HomePackageTable -> IO (InstalledModuleEnv ModuleNameWithIsBoot)
|
|
| 202 | +hptLoadedIsBoot hpt = hls_is_boot <$> readIORef (loader hpt)
|
|
| 203 | + |
|
| 204 | +hptLoadedTypeEnv :: HomePackageTable -> IO TypeEnv
|
|
| 205 | +hptLoadedTypeEnv hpt = hls_type_env <$> readIORef (loader hpt)
|
|
| 206 | + |
|
| 207 | +hptLoadedInstEnv :: HomePackageTable -> IO InstEnv
|
|
| 208 | +hptLoadedInstEnv hpt = hls_inst_env <$> readIORef (loader hpt)
|
|
| 209 | + |
|
| 210 | +hptLoadedFamInstEnv :: HomePackageTable -> IO FamInstEnv
|
|
| 211 | +hptLoadedFamInstEnv hpt = hls_fam_inst_env <$> readIORef (loader hpt)
|
|
| 212 | + |
|
| 213 | +hptLoadedModFamInstEnv :: HomePackageTable -> IO (ModuleEnv FamInstEnv)
|
|
| 214 | +hptLoadedModFamInstEnv hpt = hls_mod_fam_inst_env <$> readIORef (loader hpt)
|
|
| 215 | + |
|
| 216 | +hptLoadedRuleBase :: HomePackageTable -> IO RuleBase
|
|
| 217 | +hptLoadedRuleBase hpt = hls_rule_base <$> readIORef (loader hpt)
|
|
| 218 | + |
|
| 219 | +hptLoadedAnnEnv :: HomePackageTable -> IO AnnEnv
|
|
| 220 | +hptLoadedAnnEnv hpt = hls_ann_env <$> readIORef (loader hpt)
|
|
| 221 | + |
|
| 222 | +hptLoadedCompleteMatches :: HomePackageTable -> IO CompleteMatches
|
|
| 223 | +hptLoadedCompleteMatches hpt = hls_complete_matches <$> readIORef (loader hpt)
|
|
| 224 | + |
|
| 225 | +hptLoadedDefaults :: HomePackageTable -> IO (ModuleEnv DefaultEnv)
|
|
| 226 | +hptLoadedDefaults hpt = hls_defaults <$> readIORef (loader hpt)
|
|
| 227 | + |
|
| 142 | 228 | --------------------------------------------------------------------------------
|
| 143 | 229 | -- * Extending the HPT
|
| 144 | 230 | --------------------------------------------------------------------------------
|
| ... | ... | @@ -186,6 +272,56 @@ restrictHpt HPT{table=hptr} hmis = |
| 186 | 272 | addListToHpt :: HomePackageTable -> [(ModuleName, HomeModInfo)] -> IO ()
|
| 187 | 273 | addListToHpt hpt = mapM_ (uncurry (addToHpt hpt))
|
| 188 | 274 | |
| 275 | +addOnDemandHomeModule :: HomePackageTable -> Module -> ModIface -> Bool -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> Maybe (IO Linkable) -> IO ()
|
|
| 276 | +addOnDemandHomeModule hpt mn iface 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 ->
|
|
| 278 | + ( if mn `elemModuleEnv` hls_iface_table hls
|
|
| 279 | + then hls -- If already loaded, don't add twice
|
|
| 280 | + else
|
|
| 281 | + if bad_boot
|
|
| 282 | + then addHomeModTypeEnv hls
|
|
| 283 | + else addHomeModData hls
|
|
| 284 | + , ()
|
|
| 285 | + )
|
|
| 286 | + where
|
|
| 287 | + addHomeModTypeEnv hls = hls
|
|
| 288 | + { hls_type_env = extendNameEnvList (hls_type_env hls) new_hls_decls
|
|
| 289 | + }
|
|
| 290 | + |
|
| 291 | + addHomeModData hls = hls {
|
|
| 292 | + hls_iface_table = extendModuleEnv (hls_iface_table hls) mn iface,
|
|
| 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,
|
|
| 297 | + hls_rule_base = extendRuleBaseList (hls_rule_base hls)
|
|
| 298 | + new_hls_rules,
|
|
| 299 | + hls_complete_matches
|
|
| 300 | + = hls_complete_matches hls ++ new_hls_complete_matches,
|
|
| 301 | + hls_inst_env = extendInstEnvList (hls_inst_env hls)
|
|
| 302 | + new_hls_insts,
|
|
| 303 | + hls_fam_inst_env = extendFamInstEnvList (hls_fam_inst_env hls)
|
|
| 304 | + new_hls_fam_insts,
|
|
| 305 | + hls_ann_env = extendAnnEnvList (hls_ann_env hls)
|
|
| 306 | + new_hls_anns,
|
|
| 307 | + hls_mod_fam_inst_env
|
|
| 308 | + =
|
|
| 309 | + let
|
|
| 310 | + fam_inst_env =
|
|
| 311 | + extendFamInstEnvList emptyFamInstEnv
|
|
| 312 | + new_hls_fam_insts
|
|
| 313 | + in
|
|
| 314 | + extendModuleEnv (hls_mod_fam_inst_env hls)
|
|
| 315 | + mn
|
|
| 316 | + fam_inst_env,
|
|
| 317 | + hls_defaults = extendModuleEnv (hls_defaults hls) mn new_hls_defaults
|
|
| 318 | + }
|
|
| 319 | + |
|
| 320 | +hlsSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO ()
|
|
| 321 | +hlsSetBootInfo hpt is_boot_env =
|
|
| 322 | + atomicModifyIORef' (loader hpt) $ \ hls ->
|
|
| 323 | + (hls { hls_is_boot = is_boot_env }, ())
|
|
| 324 | + |
|
| 189 | 325 | ----------------------------------------------------------------------------------
|
| 190 | 326 | ---- * Queries
|
| 191 | 327 | ----------------------------------------------------------------------------------
|
| ... | ... | @@ -216,6 +352,11 @@ hptAllFamInstances = fmap mkModuleEnv . concatHpt (\hmi -> [(hmiModule hmi, hmiF |
| 216 | 352 | hptAllAnnotations :: HomePackageTable -> IO AnnEnv
|
| 217 | 353 | hptAllAnnotations = fmap mkAnnEnv . concatHpt (md_anns . hm_details)
|
| 218 | 354 | |
| 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
|
|
| 219 | 360 | |
| 220 | 361 | --------------------------------------------------------------------------------
|
| 221 | 362 | -- * Traversal-based queries
|
| ... | ... | @@ -315,7 +456,8 @@ hptInternalTableRef = table |
| 315 | 456 | -- Use with care, only if you can really justify going around the intended insert-only API.
|
| 316 | 457 | hptInternalTableFromRef :: IORef (DModuleNameEnv HomeModInfo) -> IO HomePackageTable
|
| 317 | 458 | hptInternalTableFromRef ref = do
|
| 459 | + loader <- newIORef emptyHomeLoaderState
|
|
| 318 | 460 | return HPT {
|
| 319 | - table = ref
|
|
| 461 | + table = ref,
|
|
| 462 | + loader
|
|
| 320 | 463 | } |
| 321 | - |
| ... | ... | @@ -13,7 +13,12 @@ module GHC.Unit.Module.Env |
| 13 | 13 | , extendModuleEnvWith, filterModuleEnv, mapMaybeModuleEnv
|
| 14 | 14 | |
| 15 | 15 | -- * ModuleName mappings
|
| 16 | - , ModuleNameEnv, DModuleNameEnv
|
|
| 16 | + , ModuleNameEnv
|
|
| 17 | + , extendModuleNameEnv
|
|
| 18 | + , emptyModuleNameEnv
|
|
| 19 | + , lookupModuleNameEnv
|
|
| 20 | + , unionModuleNameEnv
|
|
| 21 | + , DModuleNameEnv
|
|
| 17 | 22 | |
| 18 | 23 | -- * Sets of Modules
|
| 19 | 24 | , ModuleSet
|
| ... | ... | @@ -234,6 +239,17 @@ UniqFM. |
| 234 | 239 | -- | A map keyed off of 'ModuleName's (actually, their 'Unique's)
|
| 235 | 240 | type ModuleNameEnv elt = UniqFM ModuleName elt
|
| 236 | 241 | |
| 242 | +extendModuleNameEnv :: ModuleNameEnv elt -> ModuleName -> elt -> ModuleNameEnv elt
|
|
| 243 | +extendModuleNameEnv = addToUFM
|
|
| 244 | + |
|
| 245 | +emptyModuleNameEnv :: ModuleNameEnv elt
|
|
| 246 | +emptyModuleNameEnv = emptyUFM
|
|
| 247 | + |
|
| 248 | +lookupModuleNameEnv :: ModuleNameEnv elt -> ModuleName -> Maybe elt
|
|
| 249 | +lookupModuleNameEnv = lookupUFM
|
|
| 250 | + |
|
| 251 | +unionModuleNameEnv :: ModuleNameEnv elt -> ModuleNameEnv elt -> ModuleNameEnv elt
|
|
| 252 | +unionModuleNameEnv = unionModuleNameEnv
|
|
| 237 | 253 | |
| 238 | 254 | -- | A map keyed off of 'ModuleName's (actually, their 'Unique's)
|
| 239 | 255 | -- Has deterministic folds and can be deterministically converted to a list
|
| ... | ... | @@ -56,21 +56,25 @@ import GHC.Driver.Monad |
| 56 | 56 | import GHC.Driver.Make
|
| 57 | 57 | import GHC.Driver.Main
|
| 58 | 58 | import GHC.Core.InstEnv
|
| 59 | +import GHC.Core.FamInstEnv
|
|
| 59 | 60 | import qualified GHC.Driver.DynFlags as DynFlags
|
| 60 | 61 | import qualified GHC.Utils.Outputable as Outputable
|
| 61 | 62 | import GHC.Driver.Session hiding (verbosity)
|
| 62 | 63 | import GHC.Driver.Phases
|
| 63 | 64 | import GHC.Driver.Pipeline (compileFile)
|
| 64 | 65 | import GHC.HsToCore.Docs (getMainDeclBinder)
|
| 65 | -import GHC.Iface.Load (loadSysInterface)
|
|
| 66 | -import GHC.IfaceToCore (tcIfaceInst, tcIfaceFamInst)
|
|
| 67 | -import GHC.Tc.Utils.Monad (initIfaceLoad, initIfaceLcl)
|
|
| 66 | +import GHC.Iface.Load (findAndReadIface)
|
|
| 67 | +import GHC.IfaceToCore (tcIfaceDecls, tcIfaceInst, tcIfaceFamInst)
|
|
| 68 | +import GHC.Tc.Utils.Monad (goptM, updateEps_, initIfaceLoad, initIfaceLcl)
|
|
| 68 | 69 | import GHC.Tc.Utils.Env (lookupGlobal_maybe)
|
| 69 | 70 | import GHC.Types.Error (mkUnknownDiagnostic)
|
| 70 | 71 | import GHC.Types.Name.Occurrence (emptyOccEnv)
|
| 72 | +import GHC.Types.Name.Env (extendNameEnvList)
|
|
| 71 | 73 | import GHC.Unit.Finder (findImportedModule, runFinderM, ModuleLookupScope(..), FindResult(Found))
|
| 72 | 74 | import GHC.Unit.Home.ModInfo
|
| 73 | 75 | import GHC.Unit.Home.PackageTable
|
| 76 | +import GHC.Unit.External (eps_PTE, eps_inst_env, eps_fam_inst_env)
|
|
| 77 | +import GHC.Unit.Module (getModuleInstantiation)
|
|
| 74 | 78 | import GHC.Unit.Module.Graph (ModuleGraphNode (..), ModuleNodeInfo(..))
|
| 75 | 79 | import GHC.Unit.Module.ModDetails
|
| 76 | 80 | import GHC.Unit.Module.ModIface (mi_semantic_module, mi_boot)
|
| ... | ... | @@ -254,19 +258,29 @@ dropErr :: MaybeErr e a -> Maybe a |
| 254 | 258 | dropErr (Succeeded a) = Just a
|
| 255 | 259 | dropErr (Failed _) = Nothing
|
| 256 | 260 | |
| 257 | -loadHiFile :: HscEnv -> Outputable.SDoc -> Module -> IO (ModIface, ([ClsInst], [FamInst]))
|
|
| 258 | -loadHiFile hsc_env doc theModule = initIfaceLoad hsc_env $ do
|
|
| 259 | - |
|
| 260 | - mod_iface <- loadSysInterface doc theModule
|
|
| 261 | - |
|
| 262 | - insts <- initIfaceLcl (mi_semantic_module mod_iface) doc (mi_boot mod_iface) $ do
|
|
| 263 | - |
|
| 264 | - new_eps_insts <- mapM tcIfaceInst (mi_insts mod_iface)
|
|
| 265 | - new_eps_fam_insts <- mapM tcIfaceFamInst (mi_fam_insts mod_iface)
|
|
| 266 | - |
|
| 267 | - pure (new_eps_insts, new_eps_fam_insts)
|
|
| 268 | - |
|
| 269 | - pure (mod_iface, insts)
|
|
| 261 | +loadHiFile :: Verbosity -> HscEnv -> Outputable.SDoc -> Module -> IO (ModIface, ([ClsInst], [FamInst]))
|
|
| 262 | +loadHiFile verbosity hsc_env doc requested = initIfaceLoad hsc_env $ do
|
|
| 263 | + let installed = fst (getModuleInstantiation requested)
|
|
| 264 | + iface_fetch_result <- liftIO $ findAndReadIface hsc_env doc installed requested NotBoot
|
|
| 265 | + case iface_fetch_result of
|
|
| 266 | + Failed _ -> do
|
|
| 267 | + out verbosity normal $ "Loading interface for " ++
|
|
| 268 | + moduleNameString (moduleName requested) ++
|
|
| 269 | + " failed"
|
|
| 270 | + liftIO exitFailure
|
|
| 271 | + Succeeded (mod_iface, _) -> do
|
|
| 272 | + all_insts <- initIfaceLcl (mi_semantic_module mod_iface) doc (mi_boot mod_iface) $ do
|
|
| 273 | + ignore_iface_pragmas <- goptM Opt_IgnoreInterfacePragmas
|
|
| 274 | + decls <- tcIfaceDecls ignore_iface_pragmas (mi_decls mod_iface)
|
|
| 275 | + insts <- mapM tcIfaceInst (mi_insts mod_iface)
|
|
| 276 | + fam_insts <- mapM tcIfaceFamInst (mi_fam_insts mod_iface)
|
|
| 277 | + updateEps_ $ \ eps -> eps {
|
|
| 278 | + eps_PTE = extendNameEnvList (eps_PTE eps) decls,
|
|
| 279 | + eps_inst_env = extendInstEnvList (eps_inst_env eps) insts,
|
|
| 280 | + eps_fam_inst_env = extendFamInstEnvList (eps_fam_inst_env eps) fam_insts
|
|
| 281 | + }
|
|
| 282 | + pure (insts, fam_insts)
|
|
| 283 | + pure (mod_iface, all_insts)
|
|
| 270 | 284 | |
| 271 | 285 | processModule :: Verbosity -> ModSummary -> [Flag] -> IfaceMap -> InstIfaceMap -> WarningMap -> Ghc (Maybe Interface)
|
| 272 | 286 | processModule verbosity modSummary flags ifaceMap instIfaceMap warningMap = do
|
| ... | ... | @@ -279,7 +293,7 @@ processModule verbosity modSummary flags ifaceMap instIfaceMap warningMap = do |
| 279 | 293 | unit_state = hsc_units hsc_env
|
| 280 | 294 | |
| 281 | 295 | (mod_iface, insts) <- if Flag_NoCompilation `elem` flags
|
| 282 | - then liftIO $ loadHiFile hsc_env doc $ ms_mod modSummary
|
|
| 296 | + then liftIO $ loadHiFile verbosity hsc_env doc $ ms_mod modSummary
|
|
| 283 | 297 | else do
|
| 284 | 298 | hmi <- liftIO $ lookupHpt (hsc_HPT hsc_env) (moduleName $ ms_mod modSummary) >>= \case
|
| 285 | 299 | Nothing -> error "processModule: All modules should be loaded into the HPT by this point"
|
| ... | ... | @@ -376,7 +390,7 @@ createOneShotIface verbosity flags instIfaceMap moduleNameStr = do |
| 376 | 390 | |
| 377 | 391 | let oneShotUnit = stringToUnit (unitIdString (homeUnitId_ dflags))
|
| 378 | 392 | |
| 379 | - (iface, insts) <- liftIO $ loadHiFile hsc_env doc $ mkModule oneShotUnit moduleNm
|
|
| 393 | + (iface, insts) <- liftIO $ loadHiFile verbosity hsc_env doc $ mkModule oneShotUnit moduleNm
|
|
| 380 | 394 | |
| 381 | 395 | -- Update the DynFlags with the extensions from the source file (as stored in the interface file)
|
| 382 | 396 | -- This is instead of ms_hspp_opts from ModSummary, which is not available in one-shot mode.
|