Hannes Siebenhandl pushed to branch wip/fendor/linkable-usage at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Driver/Main.hs
    ... ... @@ -865,7 +865,7 @@ hscRecompStatus
    865 865
                | otherwise -> do
    
    866 866
                    -- Check the status of all the linkable types we might need.
    
    867 867
                    -- 1. The in-memory linkable we had at hand.
    
    868
    -               bc_in_memory_linkable <- checkByteCodeInMemory hsc_env mod_summary (homeModLinkableByteCode old_linkable)
    
    868
    +               bc_in_memory_linkable <- checkByteCodeInMemory hsc_env mod_summary (homeMod_bytecode old_linkable)
    
    869 869
                    -- 2. The bytecode object file
    
    870 870
                    bc_obj_linkable <- checkByteCodeFromObject hsc_env mod_summary
    
    871 871
                    -- 3. Bytecode from an interface's whole core bindings.
    
    ... ... @@ -984,23 +984,22 @@ checkObjects dflags mb_old_linkable summary = do
    984 984
     -- | Check to see if we can reuse the old linkable, by this point we will
    
    985 985
     -- have just checked that the old interface matches up with the source hash, so
    
    986 986
     -- no need to check that again here
    
    987
    -checkByteCodeInMemory :: HscEnv -> ModSummary -> Maybe Linkable -> IO (MaybeValidated Linkable)
    
    987
    +checkByteCodeInMemory :: HscEnv -> ModSummary -> Maybe (LinkableWith ModuleByteCode) -> IO (MaybeValidated (LinkableWith ModuleByteCode))
    
    988 988
     checkByteCodeInMemory hsc_env mod_sum mb_old_linkable =
    
    989 989
       case mb_old_linkable of
    
    990 990
         Just old_linkable
    
    991
    -      | not (linkableIsNativeCodeOnly old_linkable)
    
    992 991
           -- If `-fwrite-byte-code` is enabled, then check that the .gbc file is
    
    993 992
           -- up-to-date with the linkable we have in our hand.
    
    994 993
           -- If ms_bytecode_date is Nothing, then the .gbc file does not exist yet.
    
    995 994
           -- Otherwise, check that the date matches the linkable date exactly.
    
    996
    -      , if gopt Opt_WriteByteCode (hsc_dflags hsc_env)
    
    995
    +      | if gopt Opt_WriteByteCode (hsc_dflags hsc_env)
    
    997 996
               then maybe False (linkableTime old_linkable ==) (ms_bytecode_date mod_sum)
    
    998 997
               else True
    
    999 998
           -> return $ (UpToDateItem old_linkable)
    
    1000 999
         _ -> return $ outOfDateItemBecause MissingBytecode Nothing
    
    1001 1000
     
    
    1002 1001
     -- | Load bytecode from a ".gbc" object file if it exists and is up-to-date
    
    1003
    -checkByteCodeFromObject :: HscEnv -> ModSummary -> IO (MaybeValidated Linkable)
    
    1002
    +checkByteCodeFromObject :: HscEnv -> ModSummary -> IO (MaybeValidated (LinkableWith ModuleByteCode))
    
    1004 1003
     checkByteCodeFromObject hsc_env mod_sum = do
    
    1005 1004
       let
    
    1006 1005
         obj_fn = ml_bytecode_file (ms_location mod_sum)
    
    ... ... @@ -1013,7 +1012,7 @@ checkByteCodeFromObject hsc_env mod_sum = do
    1013 1012
               -- that the one we have on disk would be suitable as well.
    
    1014 1013
               linkable <- unsafeInterleaveIO $ do
    
    1015 1014
                 bco <- ByteCode.readBinByteCode hsc_env obj_fn
    
    1016
    -            return $ mkModuleByteCodeLinkable obj_date bco
    
    1015
    +            return $ mkOnlyModuleByteCodeLinkable obj_date bco
    
    1017 1016
               return $ UpToDateItem linkable
    
    1018 1017
         _ -> return $ outOfDateItemBecause MissingBytecode Nothing
    
    1019 1018
     
    

  • compiler/GHC/Unit/Module/Status.hs
    ... ... @@ -18,12 +18,11 @@ import GHC.Unit.Home.ModInfo
    18 18
     import GHC.Unit.Module.ModGuts
    
    19 19
     import GHC.Unit.Module.ModIface
    
    20 20
     
    
    21
    -import GHC.Linker.Types ( Linkable, WholeCoreBindingsLinkable, linkableIsNativeCodeOnly, ModuleByteCode, LinkableWith, linkableModuleByteCodes )
    
    21
    +import GHC.Linker.Types ( Linkable, WholeCoreBindingsLinkable, linkableIsNativeCodeOnly, ModuleByteCode, LinkableWith )
    
    22 22
     
    
    23 23
     import GHC.Utils.Fingerprint
    
    24 24
     import GHC.Utils.Outputable
    
    25 25
     import GHC.Utils.Panic
    
    26
    -import GHC.Stack.Types (HasCallStack)
    
    27 26
     
    
    28 27
     -- | Status of a module in incremental compilation
    
    29 28
     data HscRecompStatus
    
    ... ... @@ -84,14 +83,9 @@ emptyRecompLinkables = RecompLinkables (NormalLinkable Nothing) Nothing
    84 83
     safeCastHomeModLinkable :: HomeModLinkable -> RecompLinkables
    
    85 84
     safeCastHomeModLinkable (HomeModLinkable bc o) = RecompLinkables (NormalLinkable bc) o
    
    86 85
     
    
    87
    -justBytecode :: Either Linkable WholeCoreBindingsLinkable -> RecompLinkables
    
    86
    +justBytecode :: Either (LinkableWith ModuleByteCode) WholeCoreBindingsLinkable -> RecompLinkables
    
    88 87
     justBytecode = \case
    
    89
    -  Left lm ->
    
    90
    -    let
    
    91
    -      mbc = expectSingletonGbcLinkable lm
    
    92
    -    in
    
    93
    -    assertPpr (not (linkableIsNativeCodeOnly lm)) (ppr lm)
    
    94
    -      $ emptyRecompLinkables { recompLinkables_bytecode = NormalLinkable (Just mbc) }
    
    88
    +  Left lm -> emptyRecompLinkables { recompLinkables_bytecode = NormalLinkable (Just lm) }
    
    95 89
       Right lm -> emptyRecompLinkables { recompLinkables_bytecode = WholeCoreBindingsLinkable lm }
    
    96 90
     
    
    97 91
     justObjects :: Linkable -> RecompLinkables
    
    ... ... @@ -99,20 +93,11 @@ justObjects lm =
    99 93
       assertPpr (linkableIsNativeCodeOnly lm) (ppr lm)
    
    100 94
         $ emptyRecompLinkables { recompLinkables_object = Just lm }
    
    101 95
     
    
    102
    -bytecodeAndObjects :: Either Linkable WholeCoreBindingsLinkable -> Linkable -> RecompLinkables
    
    96
    +bytecodeAndObjects :: Either (LinkableWith ModuleByteCode) WholeCoreBindingsLinkable -> Linkable -> RecompLinkables
    
    103 97
     bytecodeAndObjects either_bc o = case either_bc of
    
    104 98
       Left bc ->
    
    105
    -    let
    
    106
    -      mbc = expectSingletonGbcLinkable bc
    
    107
    -    in
    
    108
    -      assertPpr (not (linkableIsNativeCodeOnly bc) && linkableIsNativeCodeOnly o) (ppr bc $$ ppr o)
    
    109
    -        $ RecompLinkables (NormalLinkable (Just mbc)) (Just o)
    
    99
    +    assertPpr (linkableIsNativeCodeOnly o) (ppr o)
    
    100
    +      $ RecompLinkables (NormalLinkable (Just bc)) (Just o)
    
    110 101
       Right bc ->
    
    111 102
         assertPpr (linkableIsNativeCodeOnly o) (ppr o)
    
    112 103
           $ RecompLinkables (WholeCoreBindingsLinkable bc) (Just o)
    113
    -
    
    114
    -expectSingletonGbcLinkable :: HasCallStack => Linkable -> LinkableWith ModuleByteCode
    
    115
    -expectSingletonGbcLinkable lm = case linkableModuleByteCodes lm of
    
    116
    -  [] -> pprPanic "Expected 1 DotGBC in Linkable" (ppr lm)
    
    117
    -  [mbc] -> mbc <$ lm
    
    118
    -  _ -> pprPanic "Expected 1 DotGBC in Linkable" (ppr lm)