Matthew Pickering pushed to branch wip/gdc-files at Glasgow Haskell Compiler / GHC
Commits:
-
64a09647
by Matthew Pickering at 2025-08-18T14:35:00+01:00
12 changed files:
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Driver/Pipeline.hs
- compiler/GHC/Unit/Module/Status.hs
- testsuite/driver/testlib.py
- testsuite/tests/driver/T5313.hs
- testsuite/tests/ghc-api/T10052/T10052.hs
- testsuite/tests/ghc-api/T8639_api.hs
- testsuite/tests/ghc-api/apirecomp001/myghc.hs
- testsuite/tests/ghci/linking/dyn/T3372.hs
- testsuite/tests/ghci/should_run/PackedDataCon/packeddatacon.T
- testsuite/tests/ghci/should_run/UnboxedTuples/unboxedtuples.T
- testsuite/tests/ghci/should_run/UnliftedDataTypeInterp/unlifteddatatypeinterp.T
Changes:
| ... | ... | @@ -849,15 +849,14 @@ hscRecompStatus |
| 849 | 849 | return $ HscRecompNeeded $ fmap mi_iface_hash mb_checked_iface
|
| 850 | 850 | UpToDateItem checked_iface -> do
|
| 851 | 851 | let lcl_dflags = ms_hspp_opts mod_summary
|
| 852 | - mod_details <- initModDetails hsc_env checked_iface
|
|
| 853 | 852 | if | not (backendGeneratesCode (backend lcl_dflags)) -> do
|
| 854 | 853 | -- No need for a linkable, we're good to go
|
| 855 | 854 | msg UpToDate
|
| 856 | - return $ HscUpToDate (HomeModInfo checked_iface mod_details emptyHomeModInfoLinkable)
|
|
| 855 | + return $ HscUpToDate checked_iface emptyHomeModInfoLinkable
|
|
| 857 | 856 | | not (backendGeneratesCodeForHsBoot (backend lcl_dflags))
|
| 858 | 857 | , IsBoot <- isBootSummary mod_summary -> do
|
| 859 | 858 | msg UpToDate
|
| 860 | - return $ HscUpToDate (HomeModInfo checked_iface mod_details emptyHomeModInfoLinkable)
|
|
| 859 | + return $ HscUpToDate checked_iface emptyHomeModInfoLinkable
|
|
| 861 | 860 | |
| 862 | 861 | -- Always recompile with the JS backend when TH is enabled until
|
| 863 | 862 | -- #23013 is fixed.
|
| ... | ... | @@ -874,7 +873,7 @@ hscRecompStatus |
| 874 | 873 | -- 2. The bytecode object file
|
| 875 | 874 | bc_obj_linkable <- checkByteCodeFromObject hsc_env mod_summary
|
| 876 | 875 | -- 3. Bytecode from an interface whole core bindings.
|
| 877 | - bc_core_linkable <- checkByteCodeFromCoreBindings hsc_env checked_iface mod_details mod_summary
|
|
| 876 | + bc_core_linkable <- checkByteCodeFromCoreBindings hsc_env checked_iface mod_summary
|
|
| 878 | 877 | -- 4. The object file.
|
| 879 | 878 | obj_linkable <- liftIO $ checkObjects lcl_dflags (homeMod_object old_linkable) mod_summary
|
| 880 | 879 | trace_if (hsc_logger hsc_env)
|
| ... | ... | @@ -885,7 +884,7 @@ hscRecompStatus |
| 885 | 884 | |
| 886 | 885 | let just_o = justObjects <$> obj_linkable
|
| 887 | 886 | |
| 888 | - definitely_both_os = case (definitely_bc, obj_linkable) of
|
|
| 887 | + definitely_both_os = case (bc_result, obj_linkable) of
|
|
| 889 | 888 | (UpToDateItem bc, UpToDateItem o) -> UpToDateItem (bytecodeAndObjects bc o)
|
| 890 | 889 | -- If missing object code, just say we need to recompile because of object code.
|
| 891 | 890 | (_, OutOfDateItem reason _) -> OutOfDateItem reason Nothing
|
| ... | ... | @@ -898,17 +897,26 @@ hscRecompStatus |
| 898 | 897 | definitely_bc = bc_obj_linkable `prefer` bc_in_memory_linkable
|
| 899 | 898 | |
| 900 | 899 | -- If not -fwrite-byte-code, then we could use core bindings or object code if that's available.
|
| 901 | - maybe_bc = ((bc_obj_linkable `choose` bc_core_linkable) `prefer` bc_in_memory_linkable)
|
|
| 902 | - `choose` obj_linkable
|
|
| 900 | + maybe_bc = bc_in_memory_linkable `choose`
|
|
| 901 | + bc_obj_linkable `choose`
|
|
| 902 | + bc_core_linkable `choose`
|
|
| 903 | + obj_linkable
|
|
| 903 | 904 | |
| 905 | + bc_result = if gopt Opt_WriteByteCode lcl_dflags
|
|
| 906 | + -- If the byte-code artifact needs to be produced, then we certainly need bytecode.
|
|
| 907 | + then definitely_bc
|
|
| 908 | + else maybe_bc
|
|
| 909 | + |
|
| 910 | + trace_if (hsc_logger hsc_env)
|
|
| 911 | + (vcat [text "definitely_bc", ppr definitely_bc
|
|
| 912 | + , text "maybe_bc", ppr maybe_bc
|
|
| 913 | + , text "definitely_both_os", ppr definitely_both_os
|
|
| 914 | + , text "just_o", ppr just_o])
|
|
| 904 | 915 | -- pprTraceM "recomp" (ppr just_bc <+> ppr just_o)
|
| 905 | 916 | -- 2. Decide which of the products we will need
|
| 906 | 917 | let recomp_linkable_result = case () of
|
| 907 | 918 | _ | backendCanReuseLoadedCode (backend lcl_dflags) ->
|
| 908 | - if gopt Opt_WriteByteCode lcl_dflags
|
|
| 909 | - -- If the byte-code artifact needs to be produced, then we certainly need bytecode.
|
|
| 910 | - then justBytecode <$> definitely_bc
|
|
| 911 | - else justBytecode <$> maybe_bc
|
|
| 919 | + justBytecode <$> bc_result
|
|
| 912 | 920 | -- Need object files for making object files
|
| 913 | 921 | | backendWritesFiles (backend lcl_dflags) ->
|
| 914 | 922 | if gopt Opt_ByteCodeAndObjectCode lcl_dflags
|
| ... | ... | @@ -921,7 +929,7 @@ hscRecompStatus |
| 921 | 929 | case recomp_linkable_result of
|
| 922 | 930 | UpToDateItem linkable -> do
|
| 923 | 931 | msg $ UpToDate
|
| 924 | - return $ HscUpToDate (HomeModInfo checked_iface mod_details linkable)
|
|
| 932 | + return $ HscUpToDate checked_iface linkable
|
|
| 925 | 933 | OutOfDateItem reason _ -> do
|
| 926 | 934 | msg $ NeedsRecompile reason
|
| 927 | 935 | return $ HscRecompNeeded $ Just $ mi_iface_hash $ checked_iface
|
| ... | ... | @@ -1010,19 +1018,20 @@ checkByteCodeFromObject hsc_env mod_sum = do |
| 1010 | 1018 | |
| 1011 | 1019 | -- | Attempt to load bytecode from whole core bindings in the interface if they exist.
|
| 1012 | 1020 | -- This is a legacy code-path, these days it should be preferred to use the bytecode object linkable.
|
| 1013 | -checkByteCodeFromCoreBindings :: HscEnv -> ModIface -> ModDetails -> ModSummary -> IO (MaybeValidated Linkable)
|
|
| 1014 | -checkByteCodeFromCoreBindings hsc_env iface mod_details mod_sum = do
|
|
| 1021 | +checkByteCodeFromCoreBindings :: HscEnv -> ModIface -> ModSummary -> IO (MaybeValidated Linkable)
|
|
| 1022 | +checkByteCodeFromCoreBindings _hsc_env iface mod_sum = do
|
|
| 1015 | 1023 | let
|
| 1016 | 1024 | this_mod = ms_mod mod_sum
|
| 1017 | 1025 | if_date = fromJust $ ms_iface_date mod_sum
|
| 1018 | 1026 | case iface_core_bindings iface (ms_location mod_sum) of
|
| 1019 | 1027 | Just fi -> do
|
| 1020 | - ~(bco, fos) <- unsafeInterleaveIO $
|
|
| 1021 | - compileWholeCoreBindings hsc_env (md_types mod_details) fi
|
|
| 1022 | - let bco' = LazyBCOs bco fos
|
|
| 1023 | - return $ UpToDateItem (Linkable if_date this_mod (NE.singleton bco'))
|
|
| 1028 | + return $ UpToDateItem (Linkable if_date this_mod (NE.singleton (CoreBindings fi)))
|
|
| 1024 | 1029 | _ -> return $ outOfDateItemBecause MissingBytecode Nothing
|
| 1025 | 1030 | |
| 1031 | +-- 970 let fi = WholeCoreBindings extra_decls this_mod (ms_location mod_sum)
|
|
| 1032 | +-- 971 (mi_foreign iface)
|
|
| 1033 | +-- 972 return (UpToDateItem (Linkable if_date this_mod (NE.singleton (CoreBindings fi))))
|
|
| 1034 | + |
|
| 1026 | 1035 | --------------------------------------------------------------
|
| 1027 | 1036 | -- Compilers
|
| 1028 | 1037 | --------------------------------------------------------------
|
| ... | ... | @@ -244,11 +244,11 @@ compileOne' mHscMessage |
| 244 | 244 | status <- hscRecompStatus mHscMessage plugin_hsc_env upd_summary
|
| 245 | 245 | mb_old_iface mb_old_linkable (mod_index, nmods)
|
| 246 | 246 | let pipeline = hscPipeline pipe_env (setDumpPrefix pipe_env plugin_hsc_env, upd_summary, status)
|
| 247 | - runPipeline (hsc_hooks plugin_hsc_env) pipeline
|
|
| 247 | + (iface, linkable) <- runPipeline (hsc_hooks plugin_hsc_env) pipeline
|
|
| 248 | 248 | -- See Note [ModDetails and --make mode]
|
| 249 | - -- details <- initModDetails plugin_hsc_env iface
|
|
| 250 | - -- linkable' <- traverse (initWholeCoreBindings plugin_hsc_env iface details) (homeMod_bytecode linkable)
|
|
| 251 | - -- return $! HomeModInfo iface details (linkable { homeMod_bytecode = linkable' })
|
|
| 249 | + details <- initModDetails plugin_hsc_env iface
|
|
| 250 | + linkable' <- traverse (initWholeCoreBindings plugin_hsc_env iface details) (homeMod_bytecode linkable)
|
|
| 251 | + return $! HomeModInfo iface details (linkable { homeMod_bytecode = linkable' })
|
|
| 252 | 252 | |
| 253 | 253 | where lcl_dflags = ms_hspp_opts summary
|
| 254 | 254 | location = ms_location summary
|
| ... | ... | @@ -757,7 +757,7 @@ preprocessPipeline pipe_env hsc_env input_fn = do |
| 757 | 757 | $ phaseIfFlag hsc_env flag def action
|
| 758 | 758 | |
| 759 | 759 | -- | The complete compilation pipeline, from start to finish
|
| 760 | -fullPipeline :: P m => PipeEnv -> HscEnv -> FilePath -> HscSource -> m HomeModInfo
|
|
| 760 | +fullPipeline :: P m => PipeEnv -> HscEnv -> FilePath -> HscSource -> m (ModIface, HomeModLinkable)
|
|
| 761 | 761 | fullPipeline pipe_env hsc_env pp_fn src_flavour = do
|
| 762 | 762 | (dflags, input_fn) <- preprocessPipeline pipe_env hsc_env pp_fn
|
| 763 | 763 | let hsc_env' = hscSetFlags dflags hsc_env
|
| ... | ... | @@ -766,16 +766,15 @@ fullPipeline pipe_env hsc_env pp_fn src_flavour = do |
| 766 | 766 | hscPipeline pipe_env (hsc_env_with_plugins, mod_sum, hsc_recomp_status)
|
| 767 | 767 | |
| 768 | 768 | -- | Everything after preprocess
|
| 769 | -hscPipeline :: P m => PipeEnv -> ((HscEnv, ModSummary, HscRecompStatus)) -> m HomeModInfo
|
|
| 769 | +hscPipeline :: P m => PipeEnv -> ((HscEnv, ModSummary, HscRecompStatus)) -> m (ModIface, HomeModLinkable)
|
|
| 770 | 770 | hscPipeline pipe_env (hsc_env_with_plugins, mod_sum, hsc_recomp_status) = do
|
| 771 | 771 | case hsc_recomp_status of
|
| 772 | - HscUpToDate hmi -> return hmi
|
|
| 772 | + HscUpToDate iface linkable -> return (iface, linkable)
|
|
| 773 | 773 | HscRecompNeeded mb_old_hash -> do
|
| 774 | 774 | (tc_result, warnings) <- use (T_Hsc hsc_env_with_plugins mod_sum)
|
| 775 | 775 | hscBackendAction <- use (T_HscPostTc hsc_env_with_plugins mod_sum tc_result warnings mb_old_hash )
|
| 776 | 776 | (iface, linkable) <-hscBackendPipeline pipe_env hsc_env_with_plugins mod_sum hscBackendAction
|
| 777 | - details <- liftIO $ initModDetails hsc_env_with_plugins iface
|
|
| 778 | - return $! HomeModInfo iface details linkable
|
|
| 777 | + return $! (iface, linkable)
|
|
| 779 | 778 | |
| 780 | 779 | hscBackendPipeline :: P m => PipeEnv -> HscEnv -> ModSummary -> HscBackendAction -> m (ModIface, HomeModLinkable)
|
| 781 | 780 | hscBackendPipeline pipe_env hsc_env mod_sum result =
|
| ... | ... | @@ -924,7 +923,7 @@ pipelineStart pipe_env hsc_env input_fn mb_phase = |
| 924 | 923 | liftIO (showPass logger msg)
|
| 925 | 924 | liftIO (copyWithHeader line_prag out_fn final_fn)
|
| 926 | 925 | return Nothing
|
| 927 | - _ -> objFromLinkable . hm_linkable <$> fullPipeline pipe_env hsc_env input_fn sf
|
|
| 926 | + _ -> objFromLinkable . snd <$> fullPipeline pipe_env hsc_env input_fn sf
|
|
| 928 | 927 | c :: P m => Phase -> m (Maybe FilePath)
|
| 929 | 928 | c phase = viaCPipeline phase pipe_env hsc_env Nothing input_fn
|
| 930 | 929 | as :: P m => Bool -> m (Maybe FilePath)
|
| ... | ... | @@ -16,7 +16,7 @@ import GHC.Unit.Home.ModInfo |
| 16 | 16 | -- | Status of a module in incremental compilation
|
| 17 | 17 | data HscRecompStatus
|
| 18 | 18 | -- | Nothing to do because code already exists.
|
| 19 | - = HscUpToDate HomeModInfo
|
|
| 19 | + = HscUpToDate ModIface HomeModLinkable
|
|
| 20 | 20 | -- | Recompilation of module, or update of interface is required. Optionally
|
| 21 | 21 | -- pass the old interface hash to avoid updating the existing interface when
|
| 22 | 22 | -- it has not changed.
|
| ... | ... | @@ -549,10 +549,12 @@ only_ghci = only_ways([WayName('ghci'), WayName('ghci-opt')]) |
| 549 | 549 | # -----
|
| 550 | 550 | |
| 551 | 551 | def valid_way( way: WayName ) -> bool:
|
| 552 | - if way in {'ghci', 'ghci-opt', 'ghci-ext'}:
|
|
| 552 | + if way in {'ghci', 'ghci-opt'}:
|
|
| 553 | 553 | return config.have_RTS_linker
|
| 554 | - if way == 'ghci-ext-prof':
|
|
| 555 | - return config.have_RTS_linker and config.have_profiling
|
|
| 554 | + if way in {'ghci-ext'}:
|
|
| 555 | + return config.have_ext_interp
|
|
| 556 | + if way in {'ghci-ext-prof'}:
|
|
| 557 | + return config.have_ext_interp and config.have_profiling
|
|
| 556 | 558 | return True
|
| 557 | 559 | |
| 558 | 560 | def extra_ways( ways: List[WayName] ):
|
| ... | ... | @@ -7,7 +7,7 @@ main = do |
| 7 | 7 | -- begin initialize
|
| 8 | 8 | df0 <- GHC.getSessionDynFlags
|
| 9 | 9 | let df1 = df0{GHC.ghcMode = GHC.CompManager,
|
| 10 | - GHC.backend = GHC.interpreterBackend,
|
|
| 10 | + GHC.backend = GHC.bytecodeBackend,
|
|
| 11 | 11 | GHC.ghcLink = GHC.LinkInMemory,
|
| 12 | 12 | GHC.verbosity = 0}
|
| 13 | 13 | _ <- GHC.setSessionDynFlags df1
|
| ... | ... | @@ -24,7 +24,7 @@ runGhc' args act = do |
| 24 | 24 | logger <- getLogger
|
| 25 | 25 | (dflags1, _leftover, _warns) <- parseDynamicFlags logger dflags0 flags
|
| 26 | 26 | let dflags2 = dflags1 {
|
| 27 | - backend = interpreterBackend
|
|
| 27 | + backend = bytecodeBackend
|
|
| 28 | 28 | , ghcLink = LinkInMemory
|
| 29 | 29 | , verbosity = 1
|
| 30 | 30 | }
|
| ... | ... | @@ -11,7 +11,7 @@ main |
| 11 | 11 | = do { [libdir] <- getArgs
|
| 12 | 12 | ; runGhc (Just libdir) $ do
|
| 13 | 13 | flags <- getSessionDynFlags
|
| 14 | - setSessionDynFlags (flags{ backend = interpreterBackend, ghcLink = LinkInMemory})
|
|
| 14 | + setSessionDynFlags (flags{ backend = bytecodeBackend, ghcLink = LinkInMemory})
|
|
| 15 | 15 | target <- guessTarget "T8639_api_a.hs" Nothing Nothing
|
| 16 | 16 | setTargets [target]
|
| 17 | 17 | load LoadAllTargets
|
| ... | ... | @@ -37,7 +37,7 @@ main = do |
| 37 | 37 | prn "target nothing: ok"
|
| 38 | 38 | |
| 39 | 39 | dflags <- getSessionDynFlags
|
| 40 | - setSessionDynFlags $ dflags { backend = interpreterBackend }
|
|
| 40 | + setSessionDynFlags $ dflags { backend = bytecodeBackend }
|
|
| 41 | 41 | ok <- load LoadAllTargets
|
| 42 | 42 | when (failed ok) $ error "Couldn't load A.hs in interpreted mode"
|
| 43 | 43 | prn "target interpreted: ok"
|
| ... | ... | @@ -44,7 +44,7 @@ newGhcServer = do (libdir:_) <- getArgs |
| 44 | 44 | where ghc action libdir = GHC.runGhc (Just libdir) (init >> action)
|
| 45 | 45 | init = do df <- GHC.getSessionDynFlags
|
| 46 | 46 | GHC.setSessionDynFlags df{GHC.ghcMode = GHC.CompManager,
|
| 47 | - GHC.backend = GHC.interpreterBackend,
|
|
| 47 | + GHC.backend = GHC.bytecodeBackend,
|
|
| 48 | 48 | GHC.ghcLink = GHC.LinkInMemory,
|
| 49 | 49 | GHC.verbosity = 0}
|
| 50 | 50 |
| ... | ... | @@ -2,9 +2,8 @@ test('PackedDataCon', |
| 2 | 2 | [ extra_files(['Obj.hs', 'ByteCode.hs', 'Types.hs', 'Common.hs-incl']),
|
| 3 | 3 | req_interp,
|
| 4 | 4 | req_bco,
|
| 5 | - extra_ways(['ghci']),
|
|
| 6 | - when(config.have_ext_interp, extra_ways(['ghci', 'ghci-ext'])),
|
|
| 7 | - when(config.have_ext_interp and config.have_profiling, extra_ways(['ghci', 'ghci-ext', 'ghci-ext-prof']))
|
|
| 5 | + extra_ways(ghci_ways),
|
|
| 6 | + only_ways(ghci_ways),
|
|
| 8 | 7 | ],
|
| 9 | 8 | compile_and_run,
|
| 10 | 9 | ['']
|
| 1 | +print(ghci_ways)
|
|
| 2 | + |
|
| 1 | 3 | test('UnboxedTuples',
|
| 2 | 4 | [ extra_files(['Obj.hs', 'ByteCode.hs', 'Common.hs-incl']),
|
| 3 | 5 | req_interp,
|
| 4 | 6 | req_bco,
|
| 5 | - extra_ways(['ghci']),
|
|
| 6 | - when(config.have_ext_interp, extra_ways(['ghci', 'ghci-ext'])),
|
|
| 7 | - when(config.have_ext_interp and config.have_profiling, extra_ways(['ghci', 'ghci-ext', 'ghci-ext-prof']))
|
|
| 7 | + only_ways(ghci_ways),
|
|
| 8 | + extra_ways(ghci_ways),
|
|
| 8 | 9 | ],
|
| 9 | 10 | compile_and_run,
|
| 10 | 11 | ['']
|
| ... | ... | @@ -2,9 +2,8 @@ test('UnliftedDataTypeInterp', |
| 2 | 2 | [ extra_files(['Obj.hs', 'ByteCode.hs', 'Types.hs', 'Common.hs-incl']),
|
| 3 | 3 | req_interp,
|
| 4 | 4 | req_bco,
|
| 5 | - extra_ways(['ghci']),
|
|
| 6 | - when(config.have_ext_interp, extra_ways(['ghci', 'ghci-ext'])),
|
|
| 7 | - when(config.have_ext_interp and config.have_profiling, extra_ways(['ghci', 'ghci-ext', 'ghci-ext-prof']))
|
|
| 5 | + only_ways(ghci_ways),
|
|
| 6 | + extra_ways(ghci_ways),
|
|
| 8 | 7 | ],
|
| 9 | 8 | compile_and_run,
|
| 10 | 9 | ['']
|