summaryrefslogtreecommitdiff
path: root/compiler/GHC/Driver
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-10-08 10:18:13 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-10-12 19:17:15 -0400
commitff0409d0847a24bdbd76c358960c86263b219179 (patch)
tree6dd4de5cdd5110427177fb2d3920fda5c397ae3e /compiler/GHC/Driver
parent0d7117916541d6bb0041200e128ce4088086a973 (diff)
downloadhaskell-ff0409d0847a24bdbd76c358960c86263b219179.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.
Diffstat (limited to 'compiler/GHC/Driver')
-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 7f740f0123..362303a5c8 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
-- ---------------------------------------------------------------------------
--