summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-01-27 18:03:27 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-01-30 14:13:41 -0500
commita3d995fa18079ac31623febc8f41297c9acfb6a5 (patch)
treefecfdd90fe8e491573ee119d05f17c27c0acc55c
parent69cab37ae89db16cfd0b734d7fc657e56402a255 (diff)
downloadhaskell-a3d995fa18079ac31623febc8f41297c9acfb6a5.tar.gz
Fix -dynamic-too with wired-in modules (#19264)
See T19264 for a tricky corner case when explicitly importing GHC.Num.BigNat and another module. With -dynamic-too, the FinderCache contains paths for non-dynamic interfaces so they must be loaded first, which is usually the case, except for some interfaces loaded in the backend (e.g. in CorePrep). So we must run the backend for the non-dynamic way first for -dynamic-too to work as it is but I broke this invariant in c85f4928d4dbb2eb2cf906d08bfe7620d6f04ca5 by mistakenly making the backend run for the dynamic way first.
-rw-r--r--compiler/GHC/Driver/Pipeline.hs35
-rw-r--r--testsuite/tests/lib/integer/T19264.hs4
-rw-r--r--testsuite/tests/lib/integer/T19264b.hs1
-rw-r--r--testsuite/tests/lib/integer/all.T3
4 files changed, 31 insertions, 12 deletions
diff --git a/compiler/GHC/Driver/Pipeline.hs b/compiler/GHC/Driver/Pipeline.hs
index 5f79306e7e..7adde31d73 100644
--- a/compiler/GHC/Driver/Pipeline.hs
+++ b/compiler/GHC/Driver/Pipeline.hs
@@ -896,22 +896,33 @@ pipeLoop phase input_fn = do
case phase of
HscOut {} -> do
+ -- Depending on the dynamic-too state, we first run the
+ -- backend to generate the non-dynamic objects and then
+ -- re-run it to generate the dynamic ones.
let noDynToo = do
(next_phase, output_fn) <- runHookedPhase phase input_fn
pipeLoop next_phase output_fn
let dynToo = do
- -- if Opt_BuildDynamicToo is set and if the platform
- -- supports it, we first run the backend to generate
- -- the dynamic objects and then re-run it to generate
- -- the non-dynamic ones.
- let dflags' = setDynamicNow dflags -- set "dynamicNow"
- setDynFlags dflags'
- (next_phase, output_fn) <- runHookedPhase phase input_fn
- _ <- pipeLoop next_phase output_fn
- -- TODO: we probably shouldn't ignore the result of
- -- the dynamic compilation
- setDynFlags dflags -- restore flags without "dynamicNow" set
- noDynToo
+ -- we must run the non-dynamic way before the dynamic
+ -- one because there may be interfaces loaded only in
+ -- the backend (e.g., in CorePrep). See #19264
+ r <- noDynToo
+
+ -- we must check the dynamic-too state again, because
+ -- we may have failed to load a dynamic interface in
+ -- the backend.
+ dynamicTooState dflags >>= \case
+ DT_OK -> do
+ let dflags' = setDynamicNow dflags -- set "dynamicNow"
+ setDynFlags dflags'
+ (next_phase, output_fn) <- runHookedPhase phase input_fn
+ _ <- pipeLoop next_phase output_fn
+ -- TODO: we probably shouldn't ignore the result of
+ -- the dynamic compilation
+ setDynFlags dflags -- restore flags without "dynamicNow" set
+ return r
+ _ -> return r
+
dynamicTooState dflags >>= \case
DT_Dont -> noDynToo
DT_Failed -> noDynToo
diff --git a/testsuite/tests/lib/integer/T19264.hs b/testsuite/tests/lib/integer/T19264.hs
new file mode 100644
index 0000000000..87390c47fb
--- /dev/null
+++ b/testsuite/tests/lib/integer/T19264.hs
@@ -0,0 +1,4 @@
+module T19264 where
+
+import T19264b -- needed (compiled before this module and triggering the failure)
+import GHC.Num.BigNat (bigNatFromWordList)
diff --git a/testsuite/tests/lib/integer/T19264b.hs b/testsuite/tests/lib/integer/T19264b.hs
new file mode 100644
index 0000000000..3bea6669db
--- /dev/null
+++ b/testsuite/tests/lib/integer/T19264b.hs
@@ -0,0 +1 @@
+module T19264b where
diff --git a/testsuite/tests/lib/integer/all.T b/testsuite/tests/lib/integer/all.T
index c132ca24dd..740fa0e606 100644
--- a/testsuite/tests/lib/integer/all.T
+++ b/testsuite/tests/lib/integer/all.T
@@ -15,6 +15,9 @@ test('bignumMatch', [], compile, [''])
test('T18813', [], compile_and_run, [''])
test('T19170', [], compile_and_run, [''])
+# skipped on Windows (doesn't support `-dynamic-too`)
+test('T19264', [when(opsys('mingw32'),skip),extra_files(['T19264b.hs'])], compile, ['-dynamic-too --make -v0'])
+
# skip ghci as it doesn't support unboxed tuples
test('integerImportExport', [omit_ways(['ghci'])], compile_and_run, [''])