Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC
Commits:
-
f52db864
by Hannes Siebenhandl at 2026-11-30T17:46:49+01:00
8 changed files:
- compiler/GHC/Driver/Main/Compile.hs-boot
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/IfaceToCore.hs
- compiler/GHC/IfaceToCore.hs-boot
- compiler/GHC/Tc/Types.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Unit/Home/PackageTable.hs
Changes:
| 1 | 1 | module GHC.Driver.Main.Compile where
|
| 2 | 2 | |
| 3 | 3 | import GHC.Driver.Env.Types (HscEnv)
|
| 4 | -import GHC.Linker.Types (Linkable)
|
|
| 4 | +import GHC.Linker.Types (Linkable, LinkableWith, ModuleByteCode)
|
|
| 5 | 5 | import GHC.Prelude.Basic
|
| 6 | 6 | import GHC.Types.TypeEnv (TypeEnv)
|
| 7 | 7 | import GHC.Unit.Module.Location (ModLocation)
|
| ... | ... | @@ -16,6 +16,13 @@ loadIfaceByteCode :: |
| 16 | 16 | TypeEnv ->
|
| 17 | 17 | Maybe (IO Linkable)
|
| 18 | 18 | |
| 19 | +loadIfaceByteCodeLazy ::
|
|
| 20 | + HscEnv ->
|
|
| 21 | + ModIface ->
|
|
| 22 | + ModLocation ->
|
|
| 23 | + TypeEnv ->
|
|
| 24 | + IO (Maybe (LinkableWith ModuleByteCode))
|
|
| 25 | + |
|
| 19 | 26 | data CgInteractiveGuts
|
| 20 | 27 | |
| 21 | 28 | mkCgInteractiveGuts :: CgGuts -> CgInteractiveGuts
|
| ... | ... | @@ -24,4 +31,4 @@ generateFreshByteCodeLinkable :: HscEnv |
| 24 | 31 | -> ModuleName
|
| 25 | 32 | -> CgInteractiveGuts
|
| 26 | 33 | -> ModLocation
|
| 27 | - -> IO Linkable |
|
| \ No newline at end of file | ||
| 34 | + -> IO Linkable |
| ... | ... | @@ -560,10 +560,15 @@ mkDsEnvs unit_env mod rdr_env type_env fam_inst_env tcm_plugins ptc msg_var |
| 560 | 560 | -- of all the interactive modules.
|
| 561 | 561 | -- See Note [Why is KnotVars not a ModuleEnv]
|
| 562 | 562 | |
| 563 | - knot_var_fun :: Module -> Maybe (IfG TypeEnv)
|
|
| 563 | + knot_var_fun :: Module -> Maybe (IfG TypeEnv, TypeEnv -> IfG ())
|
|
| 564 | 564 | knot_var_fun that_mod
|
| 565 | - | that_mod == mod || isInteractiveModule mod = Just (return type_env)
|
|
| 566 | - | otherwise = Nothing
|
|
| 565 | + | that_mod == mod || isInteractiveModule mod =
|
|
| 566 | + Just
|
|
| 567 | + ( return type_env
|
|
| 568 | + , panic "mkDsEnvs:knotVars: attempting to write to type env variable"
|
|
| 569 | + )
|
|
| 570 | + | otherwise =
|
|
| 571 | + Nothing
|
|
| 567 | 572 | |
| 568 | 573 | if_lenv = mkIfLclEnv mod (text "GHC error in desugarer lookup in" <+> ppr mod)
|
| 569 | 574 | NotBoot
|
| ... | ... | @@ -37,6 +37,7 @@ module GHC.Iface.Load ( |
| 37 | 37 | flagsToIfCompression,
|
| 38 | 38 | moduleFreeHolesPrecise,
|
| 39 | 39 | needWiredInHomeIface, loadWiredInHomeIface,
|
| 40 | + lookupInKnotVars,
|
|
| 40 | 41 | |
| 41 | 42 | WhereFrom(..),
|
| 42 | 43 | ModuleLookupScope(..),
|
| ... | ... | @@ -56,17 +57,19 @@ import GHC.Data.FastString (fastStringToShortText) |
| 56 | 57 | |
| 57 | 58 | import {-# SOURCE #-} GHC.IfaceToCore
|
| 58 | 59 | ( tcIfaceDecls, tcIfaceRules, tcIfaceInst, tcIfaceFamInst
|
| 59 | - , tcIfaceAnnotations, tcIfaceCompleteMatches, tcIfaceDefaults)
|
|
| 60 | + , tcIfaceAnnotations, tcIfaceCompleteMatches, tcIfaceDefaults
|
|
| 61 | + , typecheckIface
|
|
| 62 | + )
|
|
| 60 | 63 | |
| 61 | 64 | import GHC.Hs.Extension (GhcPass)
|
| 62 | 65 | import GHC.Hs.Doc
|
| 63 | 66 | |
| 67 | +import {-# SOURCE #-} GHC.Driver.Main.Compile (loadIfaceByteCodeLazy)
|
|
| 64 | 68 | import GHC.Driver.DynFlags
|
| 65 | 69 | import GHC.Driver.Env
|
| 66 | 70 | import GHC.Driver.Env.KnotVars
|
| 67 | 71 | import GHC.Driver.Errors.Types
|
| 68 | 72 | import GHC.Driver.Hooks
|
| 69 | -import {-# source #-} GHC.Driver.Main.Compile (loadIfaceByteCode)
|
|
| 70 | 73 | import GHC.Driver.Plugins
|
| 71 | 74 | |
| 72 | 75 | import GHC.Iface.Warnings
|
| ... | ... | @@ -100,7 +103,6 @@ import GHC.Builtin.PrimOps.Ids |
| 100 | 103 | import GHC.Builtin.WiredIn.Prim
|
| 101 | 104 | import GHC.Builtin.WiredIn.Ids( seqId )
|
| 102 | 105 | |
| 103 | -import GHC.Core (CoreRule)
|
|
| 104 | 106 | import GHC.Core.FamInstEnv
|
| 105 | 107 | import GHC.Core.InstEnv
|
| 106 | 108 | import GHC.Core.Rules
|
| ... | ... | @@ -110,7 +112,6 @@ import GHC.Parser.Annotation (noAnn, noLocA) |
| 110 | 112 | |
| 111 | 113 | import GHC.Types.Annotations
|
| 112 | 114 | import GHC.Types.Avail
|
| 113 | -import GHC.Types.DefaultEnv (DefaultEnv)
|
|
| 114 | 115 | import GHC.Types.Fixity
|
| 115 | 116 | import GHC.Types.Fixity.Env
|
| 116 | 117 | import GHC.Types.Id
|
| ... | ... | @@ -135,9 +136,8 @@ import GHC.Unit.External |
| 135 | 136 | import GHC.Unit.Finder
|
| 136 | 137 | import GHC.Unit.Home
|
| 137 | 138 | import GHC.Unit.Home.Graph qualified as HUG
|
| 138 | -import GHC.Unit.Home.ModInfo (HomeModInfo (..), emptyHomeModInfoLinkable)
|
|
| 139 | +import GHC.Unit.Home.ModInfo (HomeModInfo (..), HomeModLinkable (..))
|
|
| 139 | 140 | import GHC.Unit.Home.PackageTable
|
| 140 | -import GHC.Unit.Home.PackageTable qualified as HomePackageTable
|
|
| 141 | 141 | import GHC.Unit.Module
|
| 142 | 142 | import GHC.Unit.Module.Deps
|
| 143 | 143 | import GHC.Unit.Module.Graph
|
| ... | ... | @@ -151,7 +151,6 @@ import GHC.Data.Maybe |
| 151 | 151 | |
| 152 | 152 | import Language.Haskell.Syntax.Lit (StringLiteral(..))
|
| 153 | 153 | |
| 154 | -import Control.Applicative ((<|>))
|
|
| 155 | 154 | import Control.Monad
|
| 156 | 155 | import Data.Foldable qualified as Foldable
|
| 157 | 156 | import Data.Function ((&))
|
| ... | ... | @@ -392,24 +391,14 @@ loadGlobalName :: forall lcl. |
| 392 | 391 | -> Module -- Use this for non-External Names (maybe Backpack-related?)
|
| 393 | 392 | -> IfM lcl (MaybeErr IfaceMessage TyThing)
|
| 394 | 393 | -- Only works for External Names that have a Module
|
| 395 | -loadGlobalName name mod
|
|
| 394 | +loadGlobalName name _mod
|
|
| 396 | 395 | = do { env <- getGblEnv
|
| 397 | - ; case lookupKnotVars (if_rec_types env) mod of
|
|
| 398 | - -- Note [Tying the knot]
|
|
| 399 | - Just get_type_env
|
|
| 400 | - -> do -- It's defined in a module in the hs-boot loop
|
|
| 401 | - { type_env <- setLclEnv () get_type_env -- yuk
|
|
| 402 | - ; traceIf (text "loadGlobalName1" <+> ppr name)
|
|
| 403 | - ; case lookupNameEnv type_env name of
|
|
| 404 | - Just thing -> do { traceIf (text "loadGlobalName2" <+> ppr thing)
|
|
| 405 | - ; return (Succeeded thing) }
|
|
| 406 | - -- See Note [Knot-tying fallback on boot]
|
|
| 407 | - Nothing -> do { traceIf (text "loadGlobalName3" <+> ppr name)
|
|
| 408 | - ; via_external }
|
|
| 409 | - }
|
|
| 410 | - |
|
| 411 | - _ -> do { traceIf (text "loadGlobalName4" <+> ppr name $$ ppr (if_rec_types env) $$ text "stack" <+> callStackDoc)
|
|
| 412 | - ; via_external } }
|
|
| 396 | + ; res <- lookupInKnotVars name
|
|
| 397 | + ; case res of
|
|
| 398 | + Just thing -> pure $ Succeeded thing
|
|
| 399 | + Nothing ->
|
|
| 400 | + do { traceIf (text "loadGlobalName4" <+> ppr name $$ ppr (if_rec_types env) $$ text "stack" <+> callStackDoc)
|
|
| 401 | + ; via_external } }
|
|
| 413 | 402 | where
|
| 414 | 403 | via_external = do { hsc_env <- getTopEnv
|
| 415 | 404 | ; mb_thing <- liftIO (lookupType hsc_env name)
|
| ... | ... | @@ -417,6 +406,19 @@ loadGlobalName name mod |
| 417 | 406 | Just thing -> return (Succeeded thing)
|
| 418 | 407 | Nothing -> importDecl name }
|
| 419 | 408 | |
| 409 | +lookupInKnotVars :: Name -> IfM lcl (Maybe TyThing)
|
|
| 410 | +lookupInKnotVars name = do
|
|
| 411 | + env <- getGblEnv
|
|
| 412 | + case lookupKnotVars (if_rec_types env) =<< (nameModule_maybe name) of -- Note [Tying the knot]
|
|
| 413 | + Just (get_type_env, _) -> do
|
|
| 414 | + -- It's defined in a module in the hs-boot loop
|
|
| 415 | + type_env <- setLclEnv () get_type_env -- yuk
|
|
| 416 | + case lookupNameEnv type_env name of
|
|
| 417 | + Just thing -> pure (Just thing)
|
|
| 418 | + -- See Note [Knot-tying fallback on boot]
|
|
| 419 | + Nothing -> pure Nothing
|
|
| 420 | + Nothing -> pure Nothing
|
|
| 421 | + |
|
| 420 | 422 | -- Note [Tying the knot]
|
| 421 | 423 | -- ~~~~~~~~~~~~~~~~~~~~~
|
| 422 | 424 | -- The if_rec_types field is used when we are compiling M.hs, which indirectly
|
| ... | ... | @@ -511,7 +513,10 @@ importDecl name |
| 511 | 513 | do { logger <- getLogger
|
| 512 | 514 | ; liftIO $ trace_if logger nd_doc
|
| 513 | 515 | |
| 514 | - -- Load the interface, which should populate the PTE
|
|
| 516 | + -- Load the interface, which will end up in one of three places.
|
|
| 517 | + -- 1. KnotVar
|
|
| 518 | + -- 2. HPT
|
|
| 519 | + -- 3. PTE
|
|
| 515 | 520 | ; mb_iface <- assertPpr (isExternalName name) (ppr name) $
|
| 516 | 521 | loadInterface nd_doc (nameModule name) ImportBySystem
|
| 517 | 522 | ; case mb_iface of
|
| ... | ... | @@ -520,13 +525,18 @@ importDecl name |
| 520 | 525 | ; Succeeded _ -> do
|
| 521 | 526 | |
| 522 | 527 | -- Now look it up again; this time we should find it
|
| 523 | - { eps <- getEps -- @fendor: DONE
|
|
| 524 | - ; mb_home_thing <- queryHpt (`HomePackageTable.hptLookupLoadedType` name)
|
|
| 525 | - ; case mb_home_thing <|> lookupTypeEnv (eps_PTE eps) name of
|
|
| 528 | + { res <- lookupInKnotVars name
|
|
| 529 | + ; case res of
|
|
| 526 | 530 | Just thing -> return $ Succeeded thing
|
| 527 | - Nothing -> return $ Failed $
|
|
| 528 | - Can'tFindNameInInterface name
|
|
| 529 | - (filter is_interesting $ nonDetNameEnvElts $ eps_PTE eps)
|
|
| 531 | + Nothing -> do
|
|
| 532 | + hsc_env <- getTopEnv
|
|
| 533 | + eps <- getEps
|
|
| 534 | + res <- liftIO $ lookupType hsc_env name
|
|
| 535 | + case res of
|
|
| 536 | + Just thing -> return $ Succeeded thing
|
|
| 537 | + Nothing -> return $ Failed $
|
|
| 538 | + Can'tFindNameInInterface name
|
|
| 539 | + (filter is_interesting $ nonDetNameEnvElts $ eps_PTE eps)
|
|
| 530 | 540 | }}}
|
| 531 | 541 | where
|
| 532 | 542 | nd_doc = text "Need decl for" <+> ppr name
|
| ... | ... | @@ -834,8 +844,29 @@ loadInterface doc_str mod from |
| 834 | 844 | then do -- TODO @fendor: document that we don't want/need 'dontLeakTheHUG' here
|
| 835 | 845 | massertPpr (moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env)
|
| 836 | 846 | (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))
|
| 837 | - tcParts <- tcPartsOfTheIface mod iface
|
|
| 838 | - addModIfacePartsToHpt gbl_env mod loc iface tcParts
|
|
| 847 | + hsc_env <- getTopEnv
|
|
| 848 | + let
|
|
| 849 | + bad_boot = mi_boot iface == IsBoot
|
|
| 850 | + && isJust (lookupKnotVars (if_rec_types gbl_env) mod)
|
|
| 851 | + -- Warn against an HPT-updating import
|
|
| 852 | + -- of one's own boot file! (one-shot only)
|
|
| 853 | + -- See Note [Loading your own hi-boot file]
|
|
| 854 | + |
|
| 855 | + final_iface = stripLoadedIface "home package table" iface
|
|
| 856 | + |
|
| 857 | + warnPprTrace bad_boot "loadInterface" (ppr mod) $ do
|
|
| 858 | + hpt <- getHpt
|
|
| 859 | + if bad_boot
|
|
| 860 | + then
|
|
| 861 | + initIfaceLcl (mi_semantic_module iface) (text (ml_hi_file loc)) (mi_boot iface) $ do
|
|
| 862 | + loadHiBootSelf iface
|
|
| 863 | + else do
|
|
| 864 | + details <- liftIfG $ typecheckIface iface
|
|
| 865 | + mb_object <- liftIO $ findObjectLinkableMaybe (mi_module iface) loc
|
|
| 866 | + mb_bytecode <- liftIO $ loadIfaceByteCodeLazy hsc_env iface loc (md_types details)
|
|
| 867 | + let hm_linkable = HomeModLinkable mb_bytecode mb_object
|
|
| 868 | + |
|
| 869 | + liftIO $ addOnDemandHomeModule hpt (HomeModInfo final_iface details hm_linkable)
|
|
| 839 | 870 | else dontLeakTheHUG $ do
|
| 840 | 871 | -- Load the new ModIface into the External Package State
|
| 841 | 872 | --
|
| ... | ... | @@ -856,8 +887,7 @@ loadInterface doc_str mod from |
| 856 | 887 | massertPpr
|
| 857 | 888 | (moduleUnitId mod `Set.notMember` hsc_all_home_unit_ids hsc_env)
|
| 858 | 889 | (text "Attempting to load home package interface into the EPS" $$ ppr (HUG.allUnits $ hsc_HUG hsc_env) $$ doc_str $$ ppr mod $$ ppr (moduleUnitId mod))
|
| 859 | - tcParts <- tcPartsOfTheIface mod iface
|
|
| 860 | - addModIfacePartsToEps mod iface tcParts
|
|
| 890 | + addModIfacePartsToEps mod iface
|
|
| 861 | 891 | |
| 862 | 892 | ; -- invoke plugins with *full* interface, not final_iface, to ensure
|
| 863 | 893 | -- that plugins have access to declarations, etc.
|
| ... | ... | @@ -865,8 +895,25 @@ loadInterface doc_str mod from |
| 865 | 895 | ; return (Succeeded res)
|
| 866 | 896 | }}}}
|
| 867 | 897 | |
| 868 | -tcPartsOfTheIface :: Module -> ModIface -> IfL ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], CompleteMatches)
|
|
| 869 | -tcPartsOfTheIface mod iface = do
|
|
| 898 | +loadHiBootSelf :: ModIface -> IfL ()
|
|
| 899 | +loadHiBootSelf iface
|
|
| 900 | + = do { env <- getGblEnv
|
|
| 901 | + ; ignore_prags <- goptM Opt_IgnoreInterfacePragmas
|
|
| 902 | + ; new_eps_decls <- tcIfaceDecls ignore_prags (mi_decls iface)
|
|
| 903 | + ; case lookupKnotVars (if_rec_types env) (mi_module iface) of
|
|
| 904 | + Just (get_types, write_types) -> liftIfG $ do
|
|
| 905 | + ty_env <- get_types
|
|
| 906 | + write_types (addDeclsToPTE ty_env new_eps_decls)
|
|
| 907 | + Nothing -> pprPanic "Could not load self-boot" (ppr (mi_module iface))
|
|
| 908 | + }
|
|
| 909 | + |
|
| 910 | +liftIfG :: IfG a -> IfM lcl a
|
|
| 911 | +liftIfG x = setLclEnv () x
|
|
| 912 | + |
|
| 913 | +addModIfacePartsToEps :: Module -> ModIface -> IfL ()
|
|
| 914 | +addModIfacePartsToEps mod iface = do
|
|
| 915 | + purged_hsc_env <- getTopEnv
|
|
| 916 | + |
|
| 870 | 917 | ignore_prags <- goptM Opt_IgnoreInterfacePragmas
|
| 871 | 918 | new_decls <- tcIfaceDecls ignore_prags (mi_decls iface)
|
| 872 | 919 | new_insts <- mapM tcIfaceInst (mi_insts iface)
|
| ... | ... | @@ -875,50 +922,6 @@ tcPartsOfTheIface mod iface = do |
| 875 | 922 | new_rules <- tcIfaceRules ignore_prags (mi_rules iface)
|
| 876 | 923 | new_anns <- tcIfaceAnnotations (mi_anns iface)
|
| 877 | 924 | new_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface)
|
| 878 | - pure
|
|
| 879 | - ( new_decls
|
|
| 880 | - , new_insts
|
|
| 881 | - , new_defaults
|
|
| 882 | - , new_fam_insts
|
|
| 883 | - , new_rules
|
|
| 884 | - , new_anns
|
|
| 885 | - , new_complete_matches
|
|
| 886 | - )
|
|
| 887 | - |
|
| 888 | -addModIfacePartsToHpt :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL ()
|
|
| 889 | -addModIfacePartsToHpt gbl_env mod loc iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
|
|
| 890 | - hsc_env <- getTopEnv
|
|
| 891 | - let
|
|
| 892 | - details = ModDetails
|
|
| 893 | - { md_types = mkNameEnv new_decls
|
|
| 894 | - , md_exports = mi_exports iface
|
|
| 895 | - , md_defaults = new_defaults
|
|
| 896 | - , md_insts = mkInstEnv new_insts
|
|
| 897 | - , md_fam_insts = new_fam_insts
|
|
| 898 | - , md_rules = new_rules
|
|
| 899 | - , md_anns = new_anns
|
|
| 900 | - , md_complete_matches = new_complete_matches
|
|
| 901 | - }
|
|
| 902 | - |
|
| 903 | - bad_boot = mi_boot iface == IsBoot
|
|
| 904 | - && isJust (lookupKnotVars (if_rec_types gbl_env) mod)
|
|
| 905 | - -- Warn against an HPT-updating import
|
|
| 906 | - -- of one's own boot file! (one-shot only)
|
|
| 907 | - -- See Note [Loading your own hi-boot file]
|
|
| 908 | - |
|
| 909 | - mb_bytecode = loadIfaceByteCode hsc_env iface loc (md_types details)
|
|
| 910 | - |
|
| 911 | - final_iface = stripLoadedIface "home package table" iface
|
|
| 912 | - |
|
| 913 | - warnPprTrace bad_boot "loadInterface" (ppr mod) $ do
|
|
| 914 | - hpt <- getHpt
|
|
| 915 | - liftIO $ if bad_boot
|
|
| 916 | - then hptAddOwnBootTypes hpt new_decls
|
|
| 917 | - else addOnDemandHomeModule hpt (HomeModInfo final_iface details emptyHomeModInfoLinkable) mb_bytecode
|
|
| 918 | - |
|
| 919 | -addModIfacePartsToEps :: Module -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL ()
|
|
| 920 | -addModIfacePartsToEps mod iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do
|
|
| 921 | - purged_hsc_env <- getTopEnv
|
|
| 922 | 925 | |
| 923 | 926 | let
|
| 924 | 927 | final_iface = stripLoadedIface "PIT" iface
|
| ... | ... | @@ -2044,7 +2044,7 @@ tcUnfoldingRhs is_compulsory toplvl name expr |
| 2044 | 2044 | get_in_scope
|
| 2045 | 2045 | = do { (gbl_env, lcl_env) <- getEnvs
|
| 2046 | 2046 | ; let type_envs = knotVarElems (if_rec_types gbl_env)
|
| 2047 | - ; top_level_vars <- concat <$> mapM (fmap typeEnvIds . setLclEnv ()) type_envs
|
|
| 2047 | + ; top_level_vars <- concat <$> mapM (fmap typeEnvIds . setLclEnv () . fst) type_envs
|
|
| 2048 | 2048 | ; return (bindingsVars (if_tv_env lcl_env) `unionVarSet`
|
| 2049 | 2049 | bindingsVars (if_id_env lcl_env) `unionVarSet`
|
| 2050 | 2050 | mkVarSet top_level_vars) }
|
| ... | ... | @@ -4,7 +4,7 @@ import GHC.Prelude |
| 4 | 4 | import GHC.Iface.Syntax ( IfaceDecl, IfaceDefault, IfaceClsInst, IfaceFamInst, IfaceRule
|
| 5 | 5 | , IfaceAnnotation, IfaceCompleteMatch )
|
| 6 | 6 | import GHC.Types.TyThing ( TyThing )
|
| 7 | -import GHC.Tc.Types ( IfL )
|
|
| 7 | +import GHC.Tc.Types ( IfL, IfG )
|
|
| 8 | 8 | import GHC.Core.InstEnv ( ClsInst )
|
| 9 | 9 | import GHC.Core.FamInstEnv ( FamInst )
|
| 10 | 10 | import GHC.Core ( CoreRule )
|
| ... | ... | @@ -13,6 +13,8 @@ import GHC.Types.Annotations ( Annotation ) |
| 13 | 13 | import GHC.Types.DefaultEnv ( DefaultEnv )
|
| 14 | 14 | import GHC.Types.Name
|
| 15 | 15 | import GHC.Unit.Types ( Module )
|
| 16 | +import GHC.Unit.Module.ModIface ( ModIface )
|
|
| 17 | +import GHC.Unit.Module.ModDetails ( ModDetails )
|
|
| 16 | 18 | import GHC.Fingerprint.Type
|
| 17 | 19 | |
| 18 | 20 | |
| ... | ... | @@ -24,3 +26,5 @@ tcIfaceFamInst :: IfaceFamInst -> IfL FamInst |
| 24 | 26 | tcIfaceAnnotations :: [IfaceAnnotation] -> IfL [Annotation]
|
| 25 | 27 | tcIfaceCompleteMatches :: [IfaceCompleteMatch] -> IfL CompleteMatches
|
| 26 | 28 | tcIfaceDecls :: Bool -> [(Fingerprint, IfaceDecl)] -> IfL [(Name,TyThing)]
|
| 29 | + |
|
| 30 | +typecheckIface :: ModIface -> IfG ModDetails |
| ... | ... | @@ -400,7 +400,11 @@ data IfGblEnv |
| 400 | 400 | -- We need the module name so we can test when it's appropriate
|
| 401 | 401 | -- to look in this env.
|
| 402 | 402 | -- See Note [Tying the knot] in GHC.IfaceToCore
|
| 403 | - if_rec_types :: KnotVars (IfG TypeEnv)
|
|
| 403 | + if_rec_types :: (KnotVars (IfG TypeEnv, TypeEnv -> IfG ()))
|
|
| 404 | + -- The variable is mostly used for reading but
|
|
| 405 | + -- there is one case it is written to from loadIface.
|
|
| 406 | + -- Note [Loading own hi-boot file]
|
|
| 407 | + --
|
|
| 404 | 408 | -- Allows a read effect, so it can be in a mutable
|
| 405 | 409 | -- variable; c.f. handling the external package type env
|
| 406 | 410 | }
|
| ... | ... | @@ -2589,7 +2589,7 @@ initIfaceTcRn thing_inside |
| 2589 | 2589 | if_env = IfGblEnv { if_doc = text "initIfaceTcRn"
|
| 2590 | 2590 | , if_rec_types = if is_instantiate
|
| 2591 | 2591 | then emptyKnotVars
|
| 2592 | - else readTcRef <$> knot_vars }
|
|
| 2592 | + else mkTypeEnvLens <$> knot_vars }
|
|
| 2593 | 2593 | |
| 2594 | 2594 | ; setEnvs (if_env, ()) thing_inside }
|
| 2595 | 2595 | |
| ... | ... | @@ -2610,7 +2610,7 @@ initIfaceLoadModule :: HscEnv -> Module -> IfG a -> IO a |
| 2610 | 2610 | initIfaceLoadModule hsc_env this_mod do_this
|
| 2611 | 2611 | = do let gbl_env = IfGblEnv {
|
| 2612 | 2612 | if_doc = text "initIfaceLoadModule",
|
| 2613 | - if_rec_types = readTcRef <$> knotVarsWithout this_mod (hsc_type_env_vars hsc_env)
|
|
| 2613 | + if_rec_types = mkTypeEnvLens <$> knotVarsWithout this_mod (hsc_type_env_vars hsc_env)
|
|
| 2614 | 2614 | }
|
| 2615 | 2615 | initTcRnIf IfaceTag hsc_env gbl_env () do_this
|
| 2616 | 2616 | |
| ... | ... | @@ -2620,7 +2620,7 @@ initIfaceCheck :: SDoc -> HscEnv -> IfG a -> IO a |
| 2620 | 2620 | initIfaceCheck doc hsc_env do_this
|
| 2621 | 2621 | = do let gbl_env = IfGblEnv {
|
| 2622 | 2622 | if_doc = text "initIfaceCheck" <+> doc,
|
| 2623 | - if_rec_types = readTcRef <$> hsc_type_env_vars hsc_env
|
|
| 2623 | + if_rec_types = mkTypeEnvLens <$> hsc_type_env_vars hsc_env
|
|
| 2624 | 2624 | }
|
| 2625 | 2625 | initTcRnIf IfaceTag hsc_env gbl_env () do_this
|
| 2626 | 2626 | |
| ... | ... | @@ -2638,6 +2638,9 @@ initIfaceLclWithSubst mod loc_doc hi_boot_file nsubst thing_inside |
| 2638 | 2638 | getIfModule :: IfL Module
|
| 2639 | 2639 | getIfModule = do { env <- getLclEnv; return (if_mod env) }
|
| 2640 | 2640 | |
| 2641 | +mkTypeEnvLens :: IORef TypeEnv -> (IfG TypeEnv, TypeEnv -> IfG ())
|
|
| 2642 | +mkTypeEnvLens ref = (readTcRef ref, writeTcRef ref)
|
|
| 2643 | + |
|
| 2641 | 2644 | --------------------
|
| 2642 | 2645 | failIfM :: HasDebugCallStack => SDoc -> IfL a
|
| 2643 | 2646 | -- The Iface monad doesn't have a place to accumulate errors, so we
|
| ... | ... | @@ -42,7 +42,6 @@ module GHC.Unit.Home.PackageTable |
| 42 | 42 | , addHomeModInfoToHpt
|
| 43 | 43 | , addHomeModInfosToHpt
|
| 44 | 44 | , addOnDemandHomeModule
|
| 45 | - , hptAddOwnBootTypes
|
|
| 46 | 45 | |
| 47 | 46 | -- * Restrict the HPT
|
| 48 | 47 | , restrictHpt
|
| ... | ... | @@ -120,7 +119,6 @@ import GHC.Unit.Module.ModDetails |
| 120 | 119 | import GHC.Unit.Module.ModIface
|
| 121 | 120 | import GHC.Utils.Outputable
|
| 122 | 121 | import GHC.Types.Name
|
| 123 | -import GHC.Types.Name.Env (extendNameEnvList)
|
|
| 124 | 122 | |
| 125 | 123 | -- | Helps us find information about modules in the home package
|
| 126 | 124 | data HomePackageTable
|
| ... | ... | @@ -157,7 +155,6 @@ data HomeLoaderState = HomeLoaderState |
| 157 | 155 | { hls_table :: DModuleNameEnv HomeModInfo
|
| 158 | 156 | , hls_indices :: !LoaderIndices
|
| 159 | 157 | , hls_is_boot :: InstalledModuleEnv ModuleNameWithIsBoot
|
| 160 | - , hls_boot_type_env :: !TypeEnv
|
|
| 161 | 158 | , hls_iface_bytecode :: !(ModuleEnv (IO Linkable))
|
| 162 | 159 | , hls_stats :: !HptStats
|
| 163 | 160 | }
|
| ... | ... | @@ -196,7 +193,6 @@ emptyHomeLoaderState = |
| 196 | 193 | { hls_table = emptyUDFM
|
| 197 | 194 | , hls_indices = emptyLoaderIndices
|
| 198 | 195 | , hls_is_boot = emptyInstalledModuleEnv
|
| 199 | - , hls_boot_type_env = emptyTypeEnv
|
|
| 200 | 196 | , hls_iface_bytecode = emptyModuleEnv
|
| 201 | 197 | , hls_stats = emptyHptStats
|
| 202 | 198 | }
|
| ... | ... | @@ -252,13 +248,13 @@ hptLoadedIsBoot = queryOnDemandHpt emptyInstalledModuleEnv hls_is_boot |
| 252 | 248 | |
| 253 | 249 | hptLookupLoadedType :: HomePackageTable -> Name -> IO (Maybe TyThing)
|
| 254 | 250 | hptLookupLoadedType HPT_Make{} _ = pure Nothing
|
| 255 | -hptLookupLoadedType hpt@HPT_OneShot{loader} name = do
|
|
| 251 | +hptLookupLoadedType hpt@HPT_OneShot{} name = do
|
|
| 256 | 252 | mb_hmi <- case nameModule_maybe name of
|
| 257 | 253 | Just modl -> lookupHptByModule hpt modl
|
| 258 | 254 | Nothing -> pure Nothing
|
| 259 | 255 | case mb_hmi of
|
| 260 | 256 | Just hmi -> pure $! lookupTypeEnv (md_types (hm_details hmi)) name
|
| 261 | - Nothing -> (`lookupTypeEnv` name) . hls_boot_type_env <$> readIORef loader
|
|
| 257 | + Nothing -> pure Nothing
|
|
| 262 | 258 | |
| 263 | 259 | hptLoadedModFamInsts :: HomePackageTable -> Module -> IO (Maybe FamInstEnv)
|
| 264 | 260 | hptLoadedModFamInsts HPT_Make{} _ = pure Nothing
|
| ... | ... | @@ -386,24 +382,14 @@ restrictHpt HPT_OneShot{} _ = pure () |
| 386 | 382 | addListToHpt :: HomePackageTable -> [(ModuleName, HomeModInfo)] -> IO ()
|
| 387 | 383 | addListToHpt hpt = mapM_ (uncurry (addToHpt hpt))
|
| 388 | 384 | |
| 389 | -addOnDemandHomeModule :: HomePackageTable -> HomeModInfo -> Maybe (IO Linkable) -> IO ()
|
|
| 390 | -addOnDemandHomeModule hpt@HPT_Make{} hmi _ = addHomeModInfoToHpt hmi hpt
|
|
| 391 | -addOnDemandHomeModule HPT_OneShot{loader} hmi mb_bytecode =
|
|
| 385 | +addOnDemandHomeModule :: HomePackageTable -> HomeModInfo -> IO ()
|
|
| 386 | +addOnDemandHomeModule hpt@HPT_Make{} hmi = addHomeModInfoToHpt hmi hpt
|
|
| 387 | +addOnDemandHomeModule HPT_OneShot{loader} hmi =
|
|
| 392 | 388 | atomicModifyIORef' loader $ \hls ->
|
| 393 | - let hls' = insertLoadedHomeModInfo (moduleName modl) hmi hls
|
|
| 394 | - in ( case mb_bytecode of
|
|
| 395 | - Nothing -> hls'
|
|
| 396 | - Just action -> hls' { hls_iface_bytecode = extendModuleEnv (hls_iface_bytecode hls') modl action }
|
|
| 397 | - , () )
|
|
| 389 | + (insertLoadedHomeModInfo (moduleName modl) hmi hls , () )
|
|
| 398 | 390 | where
|
| 399 | 391 | modl = mi_module (hm_iface hmi)
|
| 400 | 392 | |
| 401 | -hptAddOwnBootTypes :: HomePackageTable -> [(Name, TyThing)] -> IO ()
|
|
| 402 | -hptAddOwnBootTypes HPT_Make{} _ = pure ()
|
|
| 403 | -hptAddOwnBootTypes HPT_OneShot{loader} decls =
|
|
| 404 | - atomicModifyIORef' loader $ \hls ->
|
|
| 405 | - (hls { hls_boot_type_env = extendNameEnvList (hls_boot_type_env hls) decls }, ())
|
|
| 406 | - |
|
| 407 | 393 | hptSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO ()
|
| 408 | 394 | hptSetBootInfo HPT_Make{} _ = pure ()
|
| 409 | 395 | hptSetBootInfo HPT_OneShot{loader} is_boot_env =
|