[Git][ghc/ghc][master] Force module recompilation if '*' prefix was used to load modules in ghci (#8042)
Marge Bot
gitlab at gitlab.haskell.org
Thu Dec 17 18:56:06 UTC 2020
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
09f28390 by nineonine at 2020-12-17T13:55:59-05:00
Force module recompilation if '*' prefix was used to load modules in ghci (#8042)
Usually pre-compiled code is preferred to be loaded in ghci if available, which means
that if we try to load module with '*' prefix and compilation artifacts are available
on disc (.o and .hi files) or the source code was untouched, the driver would think
no recompilation is required. Therefore, we need to force recompilation so that desired
byte-code is generated and loaded. Forcing in this case should be ok, since this is what
happens for interpreted code anyways when reloading modules.
- - - - -
4 changed files:
- compiler/GHC/Driver/Pipeline.hs
- + testsuite/tests/ghci/scripts/T8042recomp.script
- + testsuite/tests/ghci/scripts/T8042recomp.stdout
- testsuite/tests/ghci/scripts/all.T
Changes:
=====================================
compiler/GHC/Driver/Pipeline.hs
=====================================
@@ -339,14 +339,18 @@ compileOne' m_tc_result mHscMessage
current_dir = takeDirectory basename
old_paths = includePaths dflags2
!prevailing_dflags = hsc_dflags hsc_env0
+ loadAsByteCode
+ | Just (Target _ obj _) <- findTarget summary (hsc_targets hsc_env0)
+ , not obj
+ = True
+ | otherwise = False
-- Figure out which backend we're using
(bcknd, dflags3)
-- #8042: When module was loaded with `*` prefix in ghci, but DynFlags
-- suggest to generate object code (which may happen in case -fobject-code
-- was set), force it to generate byte-code. This is NOT transitive and
-- only applies to direct targets.
- | Just (Target _ obj _) <- findTarget summary (hsc_targets hsc_env0)
- , not obj
+ | loadAsByteCode
= (Interpreter, dflags2 { backend = Interpreter })
| otherwise
= (backend dflags, dflags2)
@@ -362,7 +366,10 @@ compileOne' m_tc_result mHscMessage
-- -fforce-recomp should also work with --make
force_recomp = gopt Opt_ForceRecomp dflags
source_modified
- | force_recomp = SourceModified
+ -- #8042: Usually pre-compiled code is preferred to be loaded in ghci
+ -- if available. So, if the "*" prefix was used, force recompilation
+ -- to make sure byte-code is loaded.
+ | force_recomp || loadAsByteCode = SourceModified
| otherwise = source_modified0
always_do_basic_recompilation_check = case bcknd of
=====================================
testsuite/tests/ghci/scripts/T8042recomp.script
=====================================
@@ -0,0 +1,7 @@
+:set -v1
+System.IO.writeFile "T8042B.hs" "module T8042B where { fooB = \"T8042B\"; }"
+System.IO.writeFile "T8042A.hs" "module T8042A where { import T8042B; run = putStrLn fooB }"
+:set -fobject-code
+:load T8042A
+:load *T8042A
+:break run
=====================================
testsuite/tests/ghci/scripts/T8042recomp.stdout
=====================================
@@ -0,0 +1,6 @@
+[1 of 2] Compiling T8042B ( T8042B.hs, T8042B.o )
+[2 of 2] Compiling T8042A ( T8042A.hs, T8042A.o )
+Ok, two modules loaded.
+[2 of 2] Compiling T8042A ( T8042A.hs, interpreted )
+Ok, two modules loaded.
+Breakpoint 0 activated at T8042A.hs:1:44-56
=====================================
testsuite/tests/ghci/scripts/all.T
=====================================
@@ -175,6 +175,7 @@ test('T7873', normal, ghci_script, ['T7873.script'])
test('T7939', normal, ghci_script, ['T7939.script'])
test('T7894', normal, ghci_script, ['T7894.script'])
test('T8042', normal, ghci_script, ['T8042.script'])
+test('T8042recomp', normal, ghci_script, ['T8042recomp.script'])
test('T8116', normal, ghci_script, ['T8116.script'])
test('T8113', normal, ghci_script, ['T8113.script'])
test('T8172', when(opsys('mingw32'), normalise_drive_letter),
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/09f2839086d43483066e45fe15bb7a0b39f8d1dc
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/09f2839086d43483066e45fe15bb7a0b39f8d1dc
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20201217/3c9ca0ed/attachment-0001.html>
More information about the ghc-commits
mailing list