Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC Commits: d4c17da2 by Hannes Siebenhandl at 2026-12-01T11:31:16+01:00 Load bytecode on demand - - - - - 5 changed files: - compiler/GHC/Driver/Main/Compile.hs-boot - compiler/GHC/Iface/Load.hs - compiler/GHC/Linker/Loader.hs - compiler/GHC/Tc/Types.hs - compiler/GHC/Unit/Home/PackageTable.hs Changes: ===================================== compiler/GHC/Driver/Main/Compile.hs-boot ===================================== @@ -1,7 +1,7 @@ module GHC.Driver.Main.Compile where import GHC.Driver.Env.Types (HscEnv) -import GHC.Linker.Types (Linkable, LinkableWith, ModuleByteCode) +import GHC.Linker.Types (Linkable) import GHC.Prelude.Basic import GHC.Types.TypeEnv (TypeEnv) import GHC.Unit.Module.Location (ModLocation) @@ -16,13 +16,6 @@ loadIfaceByteCode :: TypeEnv -> Maybe (IO Linkable) -loadIfaceByteCodeLazy :: - HscEnv -> - ModIface -> - ModLocation -> - TypeEnv -> - IO (Maybe (LinkableWith ModuleByteCode)) - data CgInteractiveGuts mkCgInteractiveGuts :: CgGuts -> CgInteractiveGuts ===================================== compiler/GHC/Iface/Load.hs ===================================== @@ -64,7 +64,6 @@ import {-# SOURCE #-} GHC.IfaceToCore import GHC.Hs.Extension (GhcPass) import GHC.Hs.Doc -import {-# SOURCE #-} GHC.Driver.Main.Compile (loadIfaceByteCodeLazy) import GHC.Driver.DynFlags import GHC.Driver.Env import GHC.Driver.Env.KnotVars @@ -136,12 +135,11 @@ import GHC.Unit.External import GHC.Unit.Finder import GHC.Unit.Home import GHC.Unit.Home.Graph qualified as HUG -import GHC.Unit.Home.ModInfo (HomeModInfo (..), HomeModLinkable (..)) +import GHC.Unit.Home.ModInfo (HomeModInfo (..), emptyHomeModInfoLinkable) import GHC.Unit.Home.PackageTable import GHC.Unit.Module import GHC.Unit.Module.Deps import GHC.Unit.Module.Graph -import GHC.Unit.Module.ModDetails (ModDetails (..)) import GHC.Unit.Module.ModIface import GHC.Unit.Module.Warnings import GHC.Unit.State @@ -844,7 +842,6 @@ loadInterface doc_str mod from then do -- TODO @fendor: document that we don't want/need 'dontLeakTheHUG' here massertPpr (moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env) (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)) - hsc_env <- getTopEnv let bad_boot = mi_boot iface == IsBoot && isJust (lookupKnotVars (if_rec_types gbl_env) mod) @@ -852,7 +849,11 @@ loadInterface doc_str mod from -- of one's own boot file! (one-shot only) -- See Note [Loading your own hi-boot file] - final_iface = stripLoadedIface "home package table" iface + final_iface = + stripLoadedIface "home package table" iface + -- We retain the 'IfaceSimplifiedCore' if it exists to later generate + -- bytecode for this on demand. + & set_mi_simplified_core (mi_simplified_core iface) warnPprTrace bad_boot "loadInterface" (ppr mod) $ do hpt <- getHpt @@ -862,11 +863,7 @@ loadInterface doc_str mod from loadHiBootSelf iface else do details <- liftIfG $ typecheckIface iface - mb_object <- liftIO $ findObjectLinkableMaybe (mi_module iface) loc - mb_bytecode <- liftIO $ loadIfaceByteCodeLazy hsc_env iface loc (md_types details) - let hm_linkable = HomeModLinkable mb_bytecode mb_object - - liftIO $ addOnDemandHomeModule hpt (HomeModInfo final_iface details hm_linkable) + liftIO $ addOnDemandHomeModule hpt (HomeModInfo final_iface details emptyHomeModInfoLinkable) else dontLeakTheHUG $ do -- Load the new ModIface into the External Package State -- ===================================== compiler/GHC/Linker/Loader.hs ===================================== @@ -48,17 +48,20 @@ import GHC.Settings import GHC.Platform import GHC.Platform.Ways +import GHC.Driver.Config.Diagnostic +import GHC.Driver.Config.Finder +import GHC.Driver.Downsweep +import GHC.Driver.Env import GHC.Driver.Errors +import GHC.Driver.Main.Compile (loadIfaceByteCode) import GHC.Driver.Phases -import GHC.Driver.Env -import GHC.Driver.Session import GHC.Driver.Ppr -import GHC.Driver.Config.Diagnostic -import GHC.Driver.Config.Finder +import GHC.Driver.Session import GHC.Tc.Utils.Monad hiding (reportDiagnostic) import GHC.Runtime.Interpreter +import qualified GHC.Runtime.Interpreter as GHCi import GHCi.BreakArray import GHCi.RemoteTypes import GHC.Iface.Load @@ -87,15 +90,16 @@ import GHC.Utils.Panic import GHC.Utils.Error import GHC.Utils.Logger import GHC.Utils.TmpFs +import GHC.Utils.Exception import GHC.Unit.Env import GHC.Unit.Home.ModInfo -import GHC.Unit.Home.PackageTable (hptLoadedByteCode) import GHC.Unit.Module -import GHC.Unit.Module.ModNodeKey import GHC.Unit.Module.Graph +import GHC.Unit.Module.ModDetails (md_types) import GHC.Unit.Module.ModIface import GHC.Unit.State as Packages +import GHC.Unit.Home.Graph (lookupHug, lookupHugByModule, unitEnv_foldWithKey) import GHC.Data.FastString import qualified GHC.Data.ShortText as ST @@ -113,6 +117,8 @@ import Data.Array import Data.ByteString (ByteString) import qualified Data.Set as Set import Data.Char (isSpace) +import qualified Data.IntMap.Strict as IM +import qualified Data.Map.Strict as M import qualified Data.Foldable as Foldable import Data.IORef import Data.List (intercalate, isPrefixOf, nub, partition, zip4) @@ -120,6 +126,7 @@ import Data.Maybe import Data.Either import Control.Concurrent.MVar import qualified Control.Monad.Catch as MC +import Foreign.Ptr (nullPtr) import System.FilePath import System.Directory @@ -130,13 +137,6 @@ import System.Environment (lookupEnv) import System.Win32.Info (getSystemDirectory) #endif -import GHC.Utils.Exception -import GHC.Unit.Home.Graph (lookupHug, unitEnv_foldWithKey) -import GHC.Driver.Downsweep -import qualified GHC.Runtime.Interpreter as GHCi -import qualified Data.IntMap.Strict as IM -import qualified Data.Map.Strict as M -import Foreign.Ptr (nullPtr) -- Note [Linkers and loaders] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -658,17 +658,18 @@ initLinkDepsOpts hsc_env = opts ldLoadByteCode mod locn = do bytecode_linkable <- findBytecodeLinkableMaybe hsc_env locn case bytecode_linkable of - Nothing -> findWholeCoreBindings hsc_env mod + Nothing -> findWholeCoreBindings hsc_env mod locn Just bco -> return (Just bco) -findWholeCoreBindings :: HscEnv -> Module -> IO (Maybe Linkable) -findWholeCoreBindings hsc_env mod = do +findWholeCoreBindings :: HscEnv -> Module -> ModLocation -> IO (Maybe Linkable) +findWholeCoreBindings hsc_env mod mod_loc = do _ <- initIfaceLoad hsc_env $ loadInterface (text "get_reachable_nodes" <+> parens (ppr mod)) mod ImportBySystem - mb_action <- hptLoadedByteCode (hsc_HPT hsc_env) mod - sequence mb_action + lookupHugByModule mod (hsc_HUG hsc_env) >>= \ case + Nothing -> pure Nothing + Just hmi -> sequenceA (loadIfaceByteCode hsc_env (hm_iface hmi) mod_loc (md_types $ hm_details hmi)) findBytecodeLinkableMaybe :: HscEnv -> ModLocation -> IO (Maybe Linkable) findBytecodeLinkableMaybe hsc_env locn = do ===================================== compiler/GHC/Tc/Types.hs ===================================== @@ -400,13 +400,13 @@ data IfGblEnv -- We need the module name so we can test when it's appropriate -- to look in this env. -- See Note [Tying the knot] in GHC.IfaceToCore + -- + -- The variable is mostly used for reading but + -- there is one case it is written to from 'loadInterface'. + -- + -- Allows a read effect, so it can be in a mutable + -- variable; c.f. handling the external package type env if_rec_types :: (KnotVars (IfG TypeEnv, TypeEnv -> IfG ())) - -- The variable is mostly used for reading but - -- there is one case it is written to from loadIface. - -- Note [Loading own hi-boot file] - -- - -- Allows a read effect, so it can be in a mutable - -- variable; c.f. handling the external package type env } data IfLclEnv ===================================== compiler/GHC/Unit/Home/PackageTable.hs ===================================== @@ -61,7 +61,6 @@ module GHC.Unit.Home.PackageTable , hptLoadedRuleBase , hptLoadedAnnEnv , hptLoadedCompleteMatches - , hptLoadedByteCode , HptStats(..) , hptLoadedStats , hptBumpDeclsOut @@ -104,8 +103,7 @@ import qualified Data.Set as Set import GHC.Core.FamInstEnv import GHC.Core.InstEnv import GHC.Core.Rules (RuleBase, extendRuleBaseList, emptyRuleBase) -import GHC.Data.Word64Set qualified as W64 -import GHC.Linker.Types (Linkable) +import qualified GHC.Data.Word64Set as W64 import GHC.Types.Annotations import GHC.Types.CompleteMatch import GHC.Types.TypeEnv @@ -155,7 +153,6 @@ data HomeLoaderState = HomeLoaderState { hls_table :: DModuleNameEnv HomeModInfo , hls_indices :: !LoaderIndices , hls_is_boot :: InstalledModuleEnv ModuleNameWithIsBoot - , hls_iface_bytecode :: !(ModuleEnv (IO Linkable)) , hls_stats :: !HptStats } @@ -193,7 +190,6 @@ emptyHomeLoaderState = { hls_table = emptyUDFM , hls_indices = emptyLoaderIndices , hls_is_boot = emptyInstalledModuleEnv - , hls_iface_bytecode = emptyModuleEnv , hls_stats = emptyHptStats } @@ -277,10 +273,6 @@ hptLoadedAnnEnv = queryOnDemandHpt emptyAnnEnv (li_ann_env . hls_indices) hptLoadedCompleteMatches :: HomePackageTable -> IO CompleteMatches hptLoadedCompleteMatches = queryOnDemandHpt [] (li_complete_matches . hls_indices) -hptLoadedByteCode :: HomePackageTable -> Module -> IO (Maybe (IO Linkable)) -hptLoadedByteCode hpt modl = - queryOnDemandHpt Nothing (\ hls -> lookupModuleEnv (hls_iface_bytecode hls) modl) hpt - hptLoadedStats :: HomePackageTable -> IO (Maybe HptStats) hptLoadedStats = queryOnDemandHpt Nothing (Just . hls_stats) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d4c17da2cfc91760922879a6e0147512... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d4c17da2cfc91760922879a6e0147512... 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
participants (1)
-
Hannes Siebenhandl (@fendor)