summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-10-08 10:18:13 +0100
committerMatthew Pickering <matthewtpickering@gmail.com>2021-10-11 22:50:42 +0100
commit0aa38ce7650b8602ed7ee1975ccffb6db59e0ce3 (patch)
treedbf8594070096f7ceaed90439a6085ba8921b141
parentc3e9cc2b887fe748eaa254fb58a6652111b1d568 (diff)
downloadhaskell-0aa38ce7650b8602ed7ee1975ccffb6db59e0ce3.tar.gz
driver: Filter out HPT modules **before** typecheck loop
It's better to remove the modules first before performing the typecheckLoop as otherwise you can end up with thunks which reference stale HomeModInfo which are difficult to force due to the knot-tie.
-rw-r--r--compiler/GHC/Driver/Make.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/compiler/GHC/Driver/Make.hs b/compiler/GHC/Driver/Make.hs
index 6138fb423a..24ad1a581a 100644
--- a/compiler/GHC/Driver/Make.hs
+++ b/compiler/GHC/Driver/Make.hs
@@ -1255,8 +1255,6 @@ function GHC.IfaceToCore.typecheckIface does exactly that.
Following this fix, GHC can compile itself with --make -O2.
-}
--- NB: sometimes mods has duplicates; this is harmless because
--- any duplicates get clobbered in addListToHpt and never get forced.
typecheckLoop :: HscEnv -> [HomeModInfo] -> IO [(ModuleName, HomeModInfo)]
typecheckLoop hsc_env hmis = do
debugTraceMsg logger 2 $
@@ -1265,6 +1263,7 @@ typecheckLoop hsc_env hmis = do
let new_hpt = addListToHpt old_hpt new_mods
let new_hsc_env = hscUpdateHPT (const new_hpt) hsc_env
-- Crucial, crucial: initIfaceLoad clears the if_rec_types field.
+ -- See [KnotVars invariants]
mds <- initIfaceLoad new_hsc_env $
mapM (typecheckIface . hm_iface) hmis
let new_mods = [ (mn,hmi{ hm_details = details })
@@ -1274,7 +1273,10 @@ typecheckLoop hsc_env hmis = do
where
logger = hsc_logger hsc_env
- old_hpt = hsc_HPT hsc_env
+ to_delete = (map (moduleName . mi_module . hm_iface) hmis)
+ -- Filter out old modules before tying the knot, otherwise we can end
+ -- up with a thunk which keeps reference to the old HomeModInfo.
+ !old_hpt = foldl' delFromHpt (hsc_HPT hsc_env) to_delete
-- ---------------------------------------------------------------------------
--