Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC

Commits:

5 changed files:

Changes:

  • compiler/GHC/Driver/Main/Compile.hs-boot
    1 1
     module GHC.Driver.Main.Compile where
    
    2 2
     
    
    3 3
     import GHC.Driver.Env.Types (HscEnv)
    
    4
    -import GHC.Linker.Types (Linkable, LinkableWith, ModuleByteCode)
    
    4
    +import GHC.Linker.Types (Linkable)
    
    5 5
     import GHC.Prelude.Basic
    
    6 6
     import GHC.Types.TypeEnv (TypeEnv)
    
    7 7
     import GHC.Unit.Module.Location (ModLocation)
    
    ... ... @@ -16,13 +16,6 @@ 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
    -
    
    26 19
     data CgInteractiveGuts
    
    27 20
     
    
    28 21
     mkCgInteractiveGuts :: CgGuts -> CgInteractiveGuts
    

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -64,7 +64,6 @@ import {-# SOURCE #-} GHC.IfaceToCore
    64 64
     import GHC.Hs.Extension (GhcPass)
    
    65 65
     import GHC.Hs.Doc
    
    66 66
     
    
    67
    -import {-# SOURCE #-} GHC.Driver.Main.Compile (loadIfaceByteCodeLazy)
    
    68 67
     import GHC.Driver.DynFlags
    
    69 68
     import GHC.Driver.Env
    
    70 69
     import GHC.Driver.Env.KnotVars
    
    ... ... @@ -136,12 +135,11 @@ import GHC.Unit.External
    136 135
     import GHC.Unit.Finder
    
    137 136
     import GHC.Unit.Home
    
    138 137
     import GHC.Unit.Home.Graph qualified as HUG
    
    139
    -import GHC.Unit.Home.ModInfo (HomeModInfo (..), HomeModLinkable (..))
    
    138
    +import GHC.Unit.Home.ModInfo (HomeModInfo (..), emptyHomeModInfoLinkable)
    
    140 139
     import GHC.Unit.Home.PackageTable
    
    141 140
     import GHC.Unit.Module
    
    142 141
     import GHC.Unit.Module.Deps
    
    143 142
     import GHC.Unit.Module.Graph
    
    144
    -import GHC.Unit.Module.ModDetails (ModDetails (..))
    
    145 143
     import GHC.Unit.Module.ModIface
    
    146 144
     import GHC.Unit.Module.Warnings
    
    147 145
     import GHC.Unit.State
    
    ... ... @@ -844,7 +842,6 @@ loadInterface doc_str mod from
    844 842
                 then do -- TODO @fendor: document that we don't want/need 'dontLeakTheHUG' here
    
    845 843
                   massertPpr (moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env)
    
    846 844
                           (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))
    
    847
    -              hsc_env <- getTopEnv
    
    848 845
                   let
    
    849 846
                     bad_boot = mi_boot iface == IsBoot
    
    850 847
                                   && isJust (lookupKnotVars (if_rec_types gbl_env) mod)
    
    ... ... @@ -852,7 +849,11 @@ loadInterface doc_str mod from
    852 849
                                     -- of one's own boot file! (one-shot only)
    
    853 850
                                     -- See Note [Loading your own hi-boot file]
    
    854 851
     
    
    855
    -                final_iface = stripLoadedIface "home package table" iface
    
    852
    +                final_iface =
    
    853
    +                  stripLoadedIface "home package table" iface
    
    854
    +                    -- We retain the 'IfaceSimplifiedCore' if it exists to later generate
    
    855
    +                    -- bytecode for this on demand.
    
    856
    +                    & set_mi_simplified_core (mi_simplified_core iface)
    
    856 857
     
    
    857 858
                   warnPprTrace bad_boot "loadInterface" (ppr mod) $ do
    
    858 859
                     hpt <- getHpt
    
    ... ... @@ -862,11 +863,7 @@ loadInterface doc_str mod from
    862 863
                           loadHiBootSelf iface
    
    863 864
                       else do
    
    864 865
                         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)
    
    866
    +                    liftIO $ addOnDemandHomeModule hpt (HomeModInfo final_iface details emptyHomeModInfoLinkable)
    
    870 867
                 else dontLeakTheHUG $ do
    
    871 868
                   --      Load the new ModIface into the External Package State
    
    872 869
                   --
    

  • compiler/GHC/Linker/Loader.hs
    ... ... @@ -48,17 +48,20 @@ import GHC.Settings
    48 48
     import GHC.Platform
    
    49 49
     import GHC.Platform.Ways
    
    50 50
     
    
    51
    +import GHC.Driver.Config.Diagnostic
    
    52
    +import GHC.Driver.Config.Finder
    
    53
    +import GHC.Driver.Downsweep
    
    54
    +import GHC.Driver.Env
    
    51 55
     import GHC.Driver.Errors
    
    56
    +import GHC.Driver.Main.Compile (loadIfaceByteCode)
    
    52 57
     import GHC.Driver.Phases
    
    53
    -import GHC.Driver.Env
    
    54
    -import GHC.Driver.Session
    
    55 58
     import GHC.Driver.Ppr
    
    56
    -import GHC.Driver.Config.Diagnostic
    
    57
    -import GHC.Driver.Config.Finder
    
    59
    +import GHC.Driver.Session
    
    58 60
     
    
    59 61
     import GHC.Tc.Utils.Monad hiding (reportDiagnostic)
    
    60 62
     
    
    61 63
     import GHC.Runtime.Interpreter
    
    64
    +import qualified GHC.Runtime.Interpreter as GHCi
    
    62 65
     import GHCi.BreakArray
    
    63 66
     import GHCi.RemoteTypes
    
    64 67
     import GHC.Iface.Load
    
    ... ... @@ -87,15 +90,16 @@ import GHC.Utils.Panic
    87 90
     import GHC.Utils.Error
    
    88 91
     import GHC.Utils.Logger
    
    89 92
     import GHC.Utils.TmpFs
    
    93
    +import GHC.Utils.Exception
    
    90 94
     
    
    91 95
     import GHC.Unit.Env
    
    92 96
     import GHC.Unit.Home.ModInfo
    
    93
    -import GHC.Unit.Home.PackageTable (hptLoadedByteCode)
    
    94 97
     import GHC.Unit.Module
    
    95
    -import GHC.Unit.Module.ModNodeKey
    
    96 98
     import GHC.Unit.Module.Graph
    
    99
    +import GHC.Unit.Module.ModDetails (md_types)
    
    97 100
     import GHC.Unit.Module.ModIface
    
    98 101
     import GHC.Unit.State as Packages
    
    102
    +import GHC.Unit.Home.Graph (lookupHug, lookupHugByModule, unitEnv_foldWithKey)
    
    99 103
     
    
    100 104
     import GHC.Data.FastString
    
    101 105
     import qualified GHC.Data.ShortText as ST
    
    ... ... @@ -113,6 +117,8 @@ import Data.Array
    113 117
     import Data.ByteString (ByteString)
    
    114 118
     import qualified Data.Set as Set
    
    115 119
     import Data.Char (isSpace)
    
    120
    +import qualified Data.IntMap.Strict as IM
    
    121
    +import qualified Data.Map.Strict as M
    
    116 122
     import qualified Data.Foldable as Foldable
    
    117 123
     import Data.IORef
    
    118 124
     import Data.List (intercalate, isPrefixOf, nub, partition, zip4)
    
    ... ... @@ -120,6 +126,7 @@ import Data.Maybe
    120 126
     import Data.Either
    
    121 127
     import Control.Concurrent.MVar
    
    122 128
     import qualified Control.Monad.Catch as MC
    
    129
    +import Foreign.Ptr (nullPtr)
    
    123 130
     
    
    124 131
     import System.FilePath
    
    125 132
     import System.Directory
    
    ... ... @@ -130,13 +137,6 @@ import System.Environment (lookupEnv)
    130 137
     import System.Win32.Info (getSystemDirectory)
    
    131 138
     #endif
    
    132 139
     
    
    133
    -import GHC.Utils.Exception
    
    134
    -import GHC.Unit.Home.Graph (lookupHug, unitEnv_foldWithKey)
    
    135
    -import GHC.Driver.Downsweep
    
    136
    -import qualified GHC.Runtime.Interpreter as GHCi
    
    137
    -import qualified Data.IntMap.Strict as IM
    
    138
    -import qualified Data.Map.Strict as M
    
    139
    -import Foreign.Ptr (nullPtr)
    
    140 140
     
    
    141 141
     -- Note [Linkers and loaders]
    
    142 142
     -- ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -658,17 +658,18 @@ initLinkDepsOpts hsc_env = opts
    658 658
         ldLoadByteCode mod locn = do
    
    659 659
           bytecode_linkable <-  findBytecodeLinkableMaybe hsc_env locn
    
    660 660
           case bytecode_linkable of
    
    661
    -        Nothing -> findWholeCoreBindings hsc_env mod
    
    661
    +        Nothing -> findWholeCoreBindings hsc_env mod locn
    
    662 662
             Just bco -> return (Just bco)
    
    663 663
     
    
    664
    -findWholeCoreBindings :: HscEnv -> Module -> IO (Maybe Linkable)
    
    665
    -findWholeCoreBindings hsc_env mod = do
    
    664
    +findWholeCoreBindings :: HscEnv -> Module -> ModLocation -> IO (Maybe Linkable)
    
    665
    +findWholeCoreBindings hsc_env mod mod_loc = do
    
    666 666
           _ <- initIfaceLoad hsc_env $
    
    667 667
                  loadInterface (text "get_reachable_nodes" <+> parens (ppr mod))
    
    668 668
                      mod ImportBySystem
    
    669
    -      mb_action <- hptLoadedByteCode (hsc_HPT hsc_env) mod
    
    670
    -      sequence mb_action
    
    671 669
     
    
    670
    +      lookupHugByModule mod (hsc_HUG hsc_env) >>= \ case
    
    671
    +        Nothing -> pure Nothing
    
    672
    +        Just hmi -> sequenceA (loadIfaceByteCode hsc_env (hm_iface hmi) mod_loc (md_types $ hm_details hmi))
    
    672 673
     
    
    673 674
     findBytecodeLinkableMaybe :: HscEnv -> ModLocation -> IO (Maybe Linkable)
    
    674 675
     findBytecodeLinkableMaybe hsc_env locn = do
    

  • compiler/GHC/Tc/Types.hs
    ... ... @@ -400,13 +400,13 @@ 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
    +        --
    
    404
    +        -- The variable is mostly used for reading but
    
    405
    +        -- there is one case it is written to from 'loadInterface'.
    
    406
    +        --
    
    407
    +        -- Allows a read effect, so it can be in a mutable
    
    408
    +        -- variable; c.f. handling the external package type env
    
    403 409
             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
    -                --
    
    408
    -                -- Allows a read effect, so it can be in a mutable
    
    409
    -                -- variable; c.f. handling the external package type env
    
    410 410
         }
    
    411 411
     
    
    412 412
     data IfLclEnv
    

  • compiler/GHC/Unit/Home/PackageTable.hs
    ... ... @@ -61,7 +61,6 @@ module GHC.Unit.Home.PackageTable
    61 61
       , hptLoadedRuleBase
    
    62 62
       , hptLoadedAnnEnv
    
    63 63
       , hptLoadedCompleteMatches
    
    64
    -  , hptLoadedByteCode
    
    65 64
       , HptStats(..)
    
    66 65
       , hptLoadedStats
    
    67 66
       , hptBumpDeclsOut
    
    ... ... @@ -104,8 +103,7 @@ import qualified Data.Set as Set
    104 103
     import GHC.Core.FamInstEnv
    
    105 104
     import GHC.Core.InstEnv
    
    106 105
     import GHC.Core.Rules (RuleBase, extendRuleBaseList, emptyRuleBase)
    
    107
    -import GHC.Data.Word64Set qualified as W64
    
    108
    -import GHC.Linker.Types (Linkable)
    
    106
    +import qualified GHC.Data.Word64Set as W64
    
    109 107
     import GHC.Types.Annotations
    
    110 108
     import GHC.Types.CompleteMatch
    
    111 109
     import GHC.Types.TypeEnv
    
    ... ... @@ -155,7 +153,6 @@ data HomeLoaderState = HomeLoaderState
    155 153
       { hls_table            :: DModuleNameEnv HomeModInfo
    
    156 154
       , hls_indices          :: !LoaderIndices
    
    157 155
       , hls_is_boot          :: InstalledModuleEnv ModuleNameWithIsBoot
    
    158
    -  , hls_iface_bytecode   :: !(ModuleEnv (IO Linkable))
    
    159 156
       , hls_stats            :: !HptStats
    
    160 157
       }
    
    161 158
     
    
    ... ... @@ -193,7 +190,6 @@ emptyHomeLoaderState =
    193 190
         { hls_table = emptyUDFM
    
    194 191
         , hls_indices = emptyLoaderIndices
    
    195 192
         , hls_is_boot = emptyInstalledModuleEnv
    
    196
    -    , hls_iface_bytecode = emptyModuleEnv
    
    197 193
         , hls_stats = emptyHptStats
    
    198 194
         }
    
    199 195
     
    
    ... ... @@ -277,10 +273,6 @@ hptLoadedAnnEnv = queryOnDemandHpt emptyAnnEnv (li_ann_env . hls_indices)
    277 273
     hptLoadedCompleteMatches :: HomePackageTable -> IO CompleteMatches
    
    278 274
     hptLoadedCompleteMatches = queryOnDemandHpt [] (li_complete_matches . hls_indices)
    
    279 275
     
    
    280
    -hptLoadedByteCode :: HomePackageTable -> Module -> IO (Maybe (IO Linkable))
    
    281
    -hptLoadedByteCode hpt modl =
    
    282
    -  queryOnDemandHpt Nothing (\ hls -> lookupModuleEnv (hls_iface_bytecode hls) modl) hpt
    
    283
    -
    
    284 276
     hptLoadedStats :: HomePackageTable -> IO (Maybe HptStats)
    
    285 277
     hptLoadedStats = queryOnDemandHpt Nothing (Just . hls_stats)
    
    286 278