Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC Commits: a479d7d8 by fendor at 2026-11-30T15:40:59+01:00 Fewer comments - - - - - 11 changed files: - compiler/GHC/Driver/Env.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Linker/Loader.hs - compiler/GHC/Unit/Home/PackageTable.hs - compiler/GHC/Unit/Module/WholeCoreBindings.hs - testsuite/tests/bytecode/T25090/Makefile - testsuite/tests/driver/one-shot-boot/A.hs - testsuite/tests/driver/one-shot-boot/B.hs - testsuite/tests/driver/one-shot-boot/M.hs - testsuite/tests/driver/one-shot-boot/Makefile - testsuite/tests/driver/one-shot-boot/all.T Changes: ===================================== compiler/GHC/Driver/Env.hs ===================================== @@ -300,7 +300,7 @@ hugInstancesBelow unit_env uid mnwib = do -- Note: Don't expose this function. This is a footgun if exposed! hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO [[a]] -- An explicit check to see if we are in one-shot mode to avoid poking the ModuleGraph thunk --- These things are currently stored in the HPT's loader state for home packages. (See #25795 for +-- These things are currently stored in the EPS for home packages. (See #25795 for -- progress in removing these kind of checks; and making these functions of -- `UnitEnv` rather than `HscEnv`) -- See Note [The ModuleGraph] ===================================== compiler/GHC/Iface/Load.hs ===================================== @@ -887,9 +887,6 @@ tcPartsOfTheIface mod iface = do addModIfacePartsToHpt :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL () addModIfacePartsToHpt gbl_env mod loc iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do - -- NB: this is the full 'HscEnv', not one purged by 'dontLeakTheHUG': - -- compiling the Core bindings to bytecode typechecks them, which may need - -- to look up other home modules, and those live in the HPT. hsc_env <- getTopEnv let details = ModDetails @@ -909,10 +906,6 @@ addModIfacePartsToHpt gbl_env mod loc iface (new_decls, new_insts, new_defaults, -- of one's own boot file! (one-shot only) -- See Note [Loading your own hi-boot file] - -- Create an IO action that loads and compiles bytecode from Core - -- bindings, if the interface has any. - -- - -- See Note [Interface Files with Core Definitions] mb_bytecode = loadIfaceByteCode hsc_env iface loc (md_types details) final_iface = stripLoadedIface "home package table" iface ===================================== compiler/GHC/Linker/Loader.hs ===================================== @@ -661,11 +661,6 @@ initLinkDepsOpts hsc_env = opts Nothing -> findWholeCoreBindings hsc_env mod Just bco -> return (Just bco) --- | Compile the Core bindings stored in the interface of a home module to --- bytecode, if the interface has any. Only used in one-shot mode, where home --- modules are loaded on demand into the 'HomePackageTable'. --- --- See Note [Interface Files with Core Definitions] findWholeCoreBindings :: HscEnv -> Module -> IO (Maybe Linkable) findWholeCoreBindings hsc_env mod = do _ <- initIfaceLoad hsc_env $ ===================================== compiler/GHC/Unit/Home/PackageTable.hs ===================================== @@ -159,9 +159,6 @@ data HomeLoaderState = HomeLoaderState , hls_is_boot :: InstalledModuleEnv ModuleNameWithIsBoot , hls_boot_type_env :: !TypeEnv , hls_iface_bytecode :: !(ModuleEnv (IO Linkable)) - -- ^ Actions that compile the Core bindings stored in a loaded interface - -- to bytecode, for modules whose interface has Core bindings. - -- See Note [Interface Files with Core Definitions] , hls_stats :: !HptStats } @@ -284,11 +281,6 @@ hptLoadedAnnEnv = queryOnDemandHpt emptyAnnEnv (li_ann_env . hls_indices) hptLoadedCompleteMatches :: HomePackageTable -> IO CompleteMatches hptLoadedCompleteMatches = queryOnDemandHpt [] (li_complete_matches . hls_indices) --- | The action that compiles the Core bindings of an on-demand loaded home --- module to bytecode, if its interface contains Core bindings. --- Always 'Nothing' for a 'HPT_Make' table. --- --- See Note [Interface Files with Core Definitions] hptLoadedByteCode :: HomePackageTable -> Module -> IO (Maybe (IO Linkable)) hptLoadedByteCode hpt modl = queryOnDemandHpt Nothing (\ hls -> lookupModuleEnv (hls_iface_bytecode hls) modl) hpt ===================================== compiler/GHC/Unit/Module/WholeCoreBindings.hs ===================================== @@ -84,18 +84,21 @@ settings. 2. In oneshot mode, which compiles individual modules without a shared home unit graph, a previously compiled module is not reprocessed as described for make mode above. - Instead, home modules are loaded on demand by 'loadInterface' into the - one-shot 'HomePackageTable' (its 'HomeLoaderState'). When 'get_link_deps' encounters a dependency on a local module, it requests - its bytecode from there via 'findWholeCoreBindings', which loads the - interface on-demand. + its bytecode from the External Package State, who loads the interface + on-demand. - When a home interface with Core bindings is loaded, we store an IO action - that compiles them to bytecode in 'hls_iface_bytecode', rather than - compiling eagerly. + Since the EPS stores interfaces for all package dependencies in addition to + local modules in oneshot mode, it has a substantial memory footprint. + We try to curtail that by extracting important data into specialized fields + in the EPS, and retaining only a few fields of 'ModIface' by overwriting the + others with bottom values. + + In order to avoid keeping around all of the interface's components needed for + compiling bytecode, we instead store an IO action in 'eps_iface_bytecode'. When 'get_link_deps' evaluates this action, the result is not retained in the - home package table, but stored in 'LoaderState', where it may eventually get - evicted to free up the memory. + EPS, but stored in 'LoaderState', where it may eventually get evicted to free + up the memory. This IO action retains the dehydrated Core bindings from the interface in its closure. Like the bytecode 'Linkable' stored in 'LoaderState', this is preferable to ===================================== testsuite/tests/bytecode/T25090/Makefile ===================================== @@ -16,9 +16,11 @@ T25090a: '$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A.o -o exe ./exe -# Like T25090a, but without .gbc files: the bytecode for the splice has to be -# compiled from the Core stored in the interface files -# (-fwrite-if-simplified-core). See Note [Interface Files with Core Definitions]. +T25090b: + '$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A -o exe -v0 + ./exe + +# Like T25090a, but get bytecode for splicing from simplified core in the interface files. T25090c: '$(TEST_HC)' -c -fwrite-if-simplified-core C.hs-boot '$(TEST_HC)' -c -fwrite-if-simplified-core B.hs @@ -31,7 +33,3 @@ T25090c: '$(TEST_HC)' -c -fwrite-if-simplified-core -fprefer-byte-code A.hs '$(TEST_HC)' A.o -o exe ./exe - -T25090b: - '$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A -o exe -v0 - ./exe ===================================== testsuite/tests/driver/one-shot-boot/A.hs ===================================== @@ -4,5 +4,4 @@ module A where import Fam import {-# SOURCE #-} M (T) --- This instance mentions 'T' from M's boot file. type instance F T = Int ===================================== testsuite/tests/driver/one-shot-boot/B.hs ===================================== @@ -3,8 +3,4 @@ module B where import Fam --- A second family-instance module for 'F', so that compiling M has to check --- the consistency of A's and B's instances. That check forces 'T', which --- makes GHC load M.hi-boot while compiling M itself. --- See Note [Loading your own hi-boot file] in GHC.Iface.Load. type instance F Bool = Char ===================================== testsuite/tests/driver/one-shot-boot/M.hs ===================================== @@ -7,11 +7,8 @@ import B () data T = MkT Int --- Also declared in M.hs-boot: loading M.hi-boot while compiling M must not --- cause a duplicate instance error. instance Show T where show (MkT n) = "MkT " ++ show n --- Not part of M.hs-boot. Needs A's instance of 'F' to typecheck. onlyInM :: F T onlyInM = 42 ===================================== testsuite/tests/driver/one-shot-boot/Makefile ===================================== @@ -2,9 +2,6 @@ TOP=../../.. include $(TOP)/mk/boilerplate.mk include $(TOP)/mk/test.mk -# One-shot compilation of a SOURCE-import cycle where type family instances -# mention the type from the boot file. Every module is compiled by its own -# invocation of GHC. OneShotBootFamInst: '$(TEST_HC)' $(TEST_HC_OPTS) -c Fam.hs '$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs-boot @@ -15,9 +12,6 @@ OneShotBootFamInst: '$(TEST_HC)' $(TEST_HC_OPTS) Fam.o A.o B.o M.o Main.o -o main ./main -# Like OneShotBootFamInst, but M and Main are compiled by the same invocation. -# Compiling M loads M.hi-boot (see Note [Loading your own hi-boot file]); that -# must not make Main see the boot interface of M instead of the real one. OneShotBootSameInvocation: '$(TEST_HC)' $(TEST_HC_OPTS) -c Fam.hs '$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs-boot ===================================== testsuite/tests/driver/one-shot-boot/all.T ===================================== @@ -1,5 +1,3 @@ -# Compiling M loads M.hi-boot, which triggers a warnPprTrace in debug builds. -# See Note [Loading your own hi-boot file] in GHC.Iface.Load. def test_one_shot_boot(name): return test(name, [extra_files(['Fam.hs', 'M.hs-boot', 'A.hs', 'B.hs', 'M.hs', 'Main.hs']), View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a479d7d82cdc3e318536ec1daa886913... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a479d7d82cdc3e318536ec1daa886913... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help