From 6469fea7c78408db679898168a8e9c50c8c7c5ce Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Mon, 26 Dec 2022 09:56:39 +0000 Subject: Don't write o-boot files in Interactive mode We should not be producing object files when in interactive mode but we still produced the dummy o-boot files. These never made it into a `Linkable` but then confused the recompilation checker. Fixes #22669 --- compiler/GHC/Driver/Pipeline/Execute.hs | 42 +++++++++++++++++++++------------ testsuite/tests/driver/Makefile | 6 +++++ testsuite/tests/driver/T22669.hs | 1 + testsuite/tests/driver/T22669.hs-boot | 1 + testsuite/tests/driver/all.T | 1 + 5 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 testsuite/tests/driver/T22669.hs create mode 100644 testsuite/tests/driver/T22669.hs-boot diff --git a/compiler/GHC/Driver/Pipeline/Execute.hs b/compiler/GHC/Driver/Pipeline/Execute.hs index 04b641c5d9..75f33834e2 100644 --- a/compiler/GHC/Driver/Pipeline/Execute.hs +++ b/compiler/GHC/Driver/Pipeline/Execute.hs @@ -578,21 +578,33 @@ runHscBackendPhase pipe_env hsc_env mod_name src_flavour location result = do next_phase = hscPostBackendPhase src_flavour (backend dflags) case result of HscUpdate iface -> - do - case src_flavour of - HsigFile -> do - -- We need to create a REAL but empty .o file - -- because we are going to attempt to put it in a library - let input_fn = expectJust "runPhase" (ml_hs_file location) - basename = dropExtension input_fn - compileEmptyStub dflags hsc_env basename location mod_name - - -- In the case of hs-boot files, generate a dummy .o-boot - -- stamp file for the benefit of Make - HsBootFile -> touchObjectFile logger dflags o_file - HsSrcFile -> panic "HscUpdate not relevant for HscSrcFile" - - return ([], iface, emptyHomeModInfoLinkable, o_file) + if | not (backendGeneratesCode (backend dflags)) -> + panic "HscUpdate not relevant for NoBackend" + | not (backendGeneratesCodeForHsBoot (backend dflags)) -> do + -- In Interpreter way, there is just no linkable for hs-boot files + -- and we don't want to write an empty `o-boot` file when we're not + -- supposed to be writing any .o files (#22669) + return ([], iface, emptyHomeModInfoLinkable, o_file) + | otherwise -> do + case src_flavour of + HsigFile -> do + -- We need to create a REAL but empty .o file + -- because we are going to attempt to put it in a library + let input_fn = expectJust "runPhase" (ml_hs_file location) + basename = dropExtension input_fn + compileEmptyStub dflags hsc_env basename location mod_name + + -- In the case of hs-boot files, generate a dummy .o-boot + -- stamp file for the benefit of Make + HsBootFile -> touchObjectFile logger dflags o_file + HsSrcFile -> panic "HscUpdate not relevant for HscSrcFile" + + -- MP: I wonder if there are any lurking bugs here because we + -- return Linkable == emptyHomeModInfoLinkable, despite the fact that there is a + -- linkable (.o-boot) which we check for in `Iface/Recomp.hs` and + -- then will carry around the linkable if we're doing + -- recompilation. + return ([], iface, emptyHomeModInfoLinkable, o_file) HscRecomp { hscs_guts = cgguts, hscs_mod_location = mod_location, hscs_partial_iface = partial_iface, diff --git a/testsuite/tests/driver/Makefile b/testsuite/tests/driver/Makefile index 7c9625570a..77e87c9e6f 100644 --- a/testsuite/tests/driver/Makefile +++ b/testsuite/tests/driver/Makefile @@ -786,4 +786,10 @@ T22044: # Test the file exists and is preprocessed "$(TEST_HC)" $(TEST_HC_OPTS) -v0 T22044.hs +.PHONY: T22669 +T22669: + echo ":q" | "$(TEST_HC)" $(TEST_HC_OPTS) -v0 --interactive T22669 + ! test -f T22669.o-boot + + diff --git a/testsuite/tests/driver/T22669.hs b/testsuite/tests/driver/T22669.hs new file mode 100644 index 0000000000..33ee925790 --- /dev/null +++ b/testsuite/tests/driver/T22669.hs @@ -0,0 +1 @@ +module T22669 where diff --git a/testsuite/tests/driver/T22669.hs-boot b/testsuite/tests/driver/T22669.hs-boot new file mode 100644 index 0000000000..33ee925790 --- /dev/null +++ b/testsuite/tests/driver/T22669.hs-boot @@ -0,0 +1 @@ +module T22669 where diff --git a/testsuite/tests/driver/all.T b/testsuite/tests/driver/all.T index 5592e51e44..ddc0039b55 100644 --- a/testsuite/tests/driver/all.T +++ b/testsuite/tests/driver/all.T @@ -319,3 +319,4 @@ test('T21869', [js_broken(22261), when(unregisterised(), skip)], makefile_test, test('T22044', normal, makefile_test, []) test('T22048', [only_ways(['normal']), grep_errmsg("_rule")], compile, ["-O -fomit-interface-pragmas -ddump-simpl"]) test('T21722', normal, compile_fail, ['-fno-show-error-context']) +test('T22669', normal, makefile_test, []) -- cgit v1.2.1