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

Commits:

11 changed files:

Changes:

  • compiler/GHC/Driver/Env.hs
    ... ... @@ -300,7 +300,7 @@ hugInstancesBelow unit_env uid mnwib = do
    300 300
     -- Note: Don't expose this function. This is a footgun if exposed!
    
    301 301
     hugSomeThingsBelowUs :: (HomeModInfo -> [a]) -> Bool -> UnitEnv -> UnitId -> ModuleNameWithIsBoot -> IO [[a]]
    
    302 302
     -- An explicit check to see if we are in one-shot mode to avoid poking the ModuleGraph thunk
    
    303
    --- These things are currently stored in the HPT's loader state for home packages. (See #25795 for
    
    303
    +-- These things are currently stored in the EPS for home packages. (See #25795 for
    
    304 304
     -- progress in removing these kind of checks; and making these functions of
    
    305 305
     -- `UnitEnv` rather than `HscEnv`)
    
    306 306
     -- See Note [The ModuleGraph]
    

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -887,9 +887,6 @@ tcPartsOfTheIface mod iface = do
    887 887
     
    
    888 888
     addModIfacePartsToHpt :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule],  [Annotation], [CompleteMatch]) -> IfL ()
    
    889 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
    -  -- NB: this is the full 'HscEnv', not one purged by 'dontLeakTheHUG':
    
    891
    -  -- compiling the Core bindings to bytecode typechecks them, which may need
    
    892
    -  -- to look up other home modules, and those live in the HPT.
    
    893 890
       hsc_env <- getTopEnv
    
    894 891
       let
    
    895 892
         details = ModDetails
    
    ... ... @@ -909,10 +906,6 @@ addModIfacePartsToHpt gbl_env mod loc iface (new_decls, new_insts, new_defaults,
    909 906
                         -- of one's own boot file! (one-shot only)
    
    910 907
                         -- See Note [Loading your own hi-boot file]
    
    911 908
     
    
    912
    -    -- Create an IO action that loads and compiles bytecode from Core
    
    913
    -    -- bindings, if the interface has any.
    
    914
    -    --
    
    915
    -    -- See Note [Interface Files with Core Definitions]
    
    916 909
         mb_bytecode = loadIfaceByteCode hsc_env iface loc (md_types details)
    
    917 910
     
    
    918 911
         final_iface = stripLoadedIface "home package table" iface
    

  • compiler/GHC/Linker/Loader.hs
    ... ... @@ -661,11 +661,6 @@ initLinkDepsOpts hsc_env = opts
    661 661
             Nothing -> findWholeCoreBindings hsc_env mod
    
    662 662
             Just bco -> return (Just bco)
    
    663 663
     
    
    664
    --- | Compile the Core bindings stored in the interface of a home module to
    
    665
    --- bytecode, if the interface has any. Only used in one-shot mode, where home
    
    666
    --- modules are loaded on demand into the 'HomePackageTable'.
    
    667
    ---
    
    668
    --- See Note [Interface Files with Core Definitions]
    
    669 664
     findWholeCoreBindings :: HscEnv -> Module -> IO (Maybe Linkable)
    
    670 665
     findWholeCoreBindings hsc_env mod = do
    
    671 666
           _ <- initIfaceLoad hsc_env $
    

  • compiler/GHC/Unit/Home/PackageTable.hs
    ... ... @@ -159,9 +159,6 @@ data HomeLoaderState = HomeLoaderState
    159 159
       , hls_is_boot          :: InstalledModuleEnv ModuleNameWithIsBoot
    
    160 160
       , hls_boot_type_env    :: !TypeEnv
    
    161 161
       , hls_iface_bytecode   :: !(ModuleEnv (IO Linkable))
    
    162
    -    -- ^ Actions that compile the Core bindings stored in a loaded interface
    
    163
    -    -- to bytecode, for modules whose interface has Core bindings.
    
    164
    -    -- See Note [Interface Files with Core Definitions]
    
    165 162
       , hls_stats            :: !HptStats
    
    166 163
       }
    
    167 164
     
    
    ... ... @@ -284,11 +281,6 @@ hptLoadedAnnEnv = queryOnDemandHpt emptyAnnEnv (li_ann_env . hls_indices)
    284 281
     hptLoadedCompleteMatches :: HomePackageTable -> IO CompleteMatches
    
    285 282
     hptLoadedCompleteMatches = queryOnDemandHpt [] (li_complete_matches . hls_indices)
    
    286 283
     
    
    287
    --- | The action that compiles the Core bindings of an on-demand loaded home
    
    288
    --- module to bytecode, if its interface contains Core bindings.
    
    289
    --- Always 'Nothing' for a 'HPT_Make' table.
    
    290
    ---
    
    291
    --- See Note [Interface Files with Core Definitions]
    
    292 284
     hptLoadedByteCode :: HomePackageTable -> Module -> IO (Maybe (IO Linkable))
    
    293 285
     hptLoadedByteCode hpt modl =
    
    294 286
       queryOnDemandHpt Nothing (\ hls -> lookupModuleEnv (hls_iface_bytecode hls) modl) hpt
    

  • compiler/GHC/Unit/Module/WholeCoreBindings.hs
    ... ... @@ -84,18 +84,21 @@ settings.
    84 84
     2. In oneshot mode, which compiles individual modules without a shared home unit
    
    85 85
        graph, a previously compiled module is not reprocessed as described for make
    
    86 86
        mode above.
    
    87
    -   Instead, home modules are loaded on demand by 'loadInterface' into the
    
    88
    -   one-shot 'HomePackageTable' (its 'HomeLoaderState').
    
    89 87
        When 'get_link_deps' encounters a dependency on a local module, it requests
    
    90
    -   its bytecode from there via 'findWholeCoreBindings', which loads the
    
    91
    -   interface on-demand.
    
    88
    +   its bytecode from the External Package State, who loads the interface
    
    89
    +   on-demand.
    
    92 90
     
    
    93
    -   When a home interface with Core bindings is loaded, we store an IO action
    
    94
    -   that compiles them to bytecode in 'hls_iface_bytecode', rather than
    
    95
    -   compiling eagerly.
    
    91
    +   Since the EPS stores interfaces for all package dependencies in addition to
    
    92
    +   local modules in oneshot mode, it has a substantial memory footprint.
    
    93
    +   We try to curtail that by extracting important data into specialized fields
    
    94
    +   in the EPS, and retaining only a few fields of 'ModIface' by overwriting the
    
    95
    +   others with bottom values.
    
    96
    +
    
    97
    +   In order to avoid keeping around all of the interface's components needed for
    
    98
    +   compiling bytecode, we instead store an IO action in 'eps_iface_bytecode'.
    
    96 99
        When 'get_link_deps' evaluates this action, the result is not retained in the
    
    97
    -   home package table, but stored in 'LoaderState', where it may eventually get
    
    98
    -   evicted to free up the memory.
    
    100
    +   EPS, but stored in 'LoaderState', where it may eventually get evicted to free
    
    101
    +   up the memory.
    
    99 102
        This IO action retains the dehydrated Core bindings from the interface in its
    
    100 103
        closure.
    
    101 104
        Like the bytecode 'Linkable' stored in 'LoaderState', this is preferable to
    

  • testsuite/tests/bytecode/T25090/Makefile
    ... ... @@ -16,9 +16,11 @@ T25090a:
    16 16
     	'$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A.o -o exe
    
    17 17
     	./exe
    
    18 18
     
    
    19
    -# Like T25090a, but without .gbc files: the bytecode for the splice has to be
    
    20
    -# compiled from the Core stored in the interface files
    
    21
    -# (-fwrite-if-simplified-core). See Note [Interface Files with Core Definitions].
    
    19
    +T25090b:
    
    20
    +	'$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A -o exe -v0
    
    21
    +	./exe
    
    22
    +
    
    23
    +# Like T25090a, but get bytecode for splicing from simplified core in the interface files.
    
    22 24
     T25090c:
    
    23 25
     	'$(TEST_HC)' -c -fwrite-if-simplified-core C.hs-boot
    
    24 26
     	'$(TEST_HC)' -c -fwrite-if-simplified-core B.hs
    
    ... ... @@ -31,7 +33,3 @@ T25090c:
    31 33
     	'$(TEST_HC)' -c -fwrite-if-simplified-core -fprefer-byte-code A.hs
    
    32 34
     	'$(TEST_HC)' A.o -o exe
    
    33 35
     	./exe
    34
    -
    
    35
    -T25090b:
    
    36
    -	'$(TEST_HC)' -fbyte-code-and-object-code -fprefer-byte-code A -o exe -v0
    
    37
    -	./exe

  • testsuite/tests/driver/one-shot-boot/A.hs
    ... ... @@ -4,5 +4,4 @@ module A where
    4 4
     import Fam
    
    5 5
     import {-# SOURCE #-} M (T)
    
    6 6
     
    
    7
    --- This instance mentions 'T' from M's boot file.
    
    8 7
     type instance F T = Int

  • testsuite/tests/driver/one-shot-boot/B.hs
    ... ... @@ -3,8 +3,4 @@ module B where
    3 3
     
    
    4 4
     import Fam
    
    5 5
     
    
    6
    --- A second family-instance module for 'F', so that compiling M has to check
    
    7
    --- the consistency of A's and B's instances. That check forces 'T', which
    
    8
    --- makes GHC load M.hi-boot while compiling M itself.
    
    9
    --- See Note [Loading your own hi-boot file] in GHC.Iface.Load.
    
    10 6
     type instance F Bool = Char

  • testsuite/tests/driver/one-shot-boot/M.hs
    ... ... @@ -7,11 +7,8 @@ import B ()
    7 7
     
    
    8 8
     data T = MkT Int
    
    9 9
     
    
    10
    --- Also declared in M.hs-boot: loading M.hi-boot while compiling M must not
    
    11
    --- cause a duplicate instance error.
    
    12 10
     instance Show T where
    
    13 11
       show (MkT n) = "MkT " ++ show n
    
    14 12
     
    
    15
    --- Not part of M.hs-boot. Needs A's instance of 'F' to typecheck.
    
    16 13
     onlyInM :: F T
    
    17 14
     onlyInM = 42

  • testsuite/tests/driver/one-shot-boot/Makefile
    ... ... @@ -2,9 +2,6 @@ TOP=../../..
    2 2
     include $(TOP)/mk/boilerplate.mk
    
    3 3
     include $(TOP)/mk/test.mk
    
    4 4
     
    
    5
    -# One-shot compilation of a SOURCE-import cycle where type family instances
    
    6
    -# mention the type from the boot file. Every module is compiled by its own
    
    7
    -# invocation of GHC.
    
    8 5
     OneShotBootFamInst:
    
    9 6
     	'$(TEST_HC)' $(TEST_HC_OPTS) -c Fam.hs
    
    10 7
     	'$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs-boot
    
    ... ... @@ -15,9 +12,6 @@ OneShotBootFamInst:
    15 12
     	'$(TEST_HC)' $(TEST_HC_OPTS) Fam.o A.o B.o M.o Main.o -o main
    
    16 13
     	./main
    
    17 14
     
    
    18
    -# Like OneShotBootFamInst, but M and Main are compiled by the same invocation.
    
    19
    -# Compiling M loads M.hi-boot (see Note [Loading your own hi-boot file]); that
    
    20
    -# must not make Main see the boot interface of M instead of the real one.
    
    21 15
     OneShotBootSameInvocation:
    
    22 16
     	'$(TEST_HC)' $(TEST_HC_OPTS) -c Fam.hs
    
    23 17
     	'$(TEST_HC)' $(TEST_HC_OPTS) -c M.hs-boot
    

  • testsuite/tests/driver/one-shot-boot/all.T
    1
    -# Compiling M loads M.hi-boot, which triggers a warnPprTrace in debug builds.
    
    2
    -# See Note [Loading your own hi-boot file] in GHC.Iface.Load.
    
    3 1
     def test_one_shot_boot(name):
    
    4 2
         return test(name,
    
    5 3
                     [extra_files(['Fam.hs', 'M.hs-boot', 'A.hs', 'B.hs', 'M.hs', 'Main.hs']),