Skip to content

Commit e35028f

Browse files
committed
Clear the mi_globals field when generating an iface
GHC populates the mi_global field in interfaces for GHCi if we are using the bytecode interpreter. However, this field is expensive in terms of heap usage, and we don't use it in HLS anywhere. So we zero it out. The field is not serialized or deserialised from disk, so we don't need to remove it while reading an iface from disk, only if we just generated an iface in memory
1 parent f94385e commit e35028f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

ghcide/src/Development/IDE/Core/Compile.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,23 @@ tcRnModule hsc_env tc_helpers pmod = do
427427
tc_gbl_env = tc_gbl_env' { tcg_ann_env = extendAnnEnvList (tcg_ann_env tc_gbl_env') mod_env_anns }
428428
pure (TcModuleResult pmod rn_info tc_gbl_env splices False mod_env)
429429

430+
431+
-- Note [Clearing mi_globals after generating an iface]
432+
-- GHC populates the mi_global field in interfaces for GHCi if we are using the bytecode
433+
-- interpreter.
434+
-- However, this field is expensive in terms of heap usage, and we don't use it in HLS
435+
-- anywhere. So we zero it out.
436+
-- The field is not serialized or deserialised from disk, so we don't need to remove it
437+
-- while reading an iface from disk, only if we just generated an iface in memory
438+
430439
mkHiFileResultNoCompile :: HscEnv -> TcModuleResult -> IO HiFileResult
431440
mkHiFileResultNoCompile session tcm = do
432441
let hsc_env_tmp = hscSetFlags (ms_hspp_opts ms) session
433442
ms = pm_mod_summary $ tmrParsed tcm
434443
tcGblEnv = tmrTypechecked tcm
435444
details <- makeSimpleDetails hsc_env_tmp tcGblEnv
436445
sf <- finalSafeMode (ms_hspp_opts ms) tcGblEnv
437-
iface <- mkIfaceTc hsc_env_tmp sf details ms tcGblEnv
446+
iface <- (mkIfaceTc hsc_env_tmp sf details ms tcGblEnv){ mi_globals = Nothing } -- ^ See Note [Clearing mi_globals after generating an iface]
438447
pure $! mkHiFileResult ms iface details (tmrRuntimeModules tcm) Nothing
439448

440449
mkHiFileResultCompile
@@ -467,15 +476,16 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
467476
#endif
468477
simplified_guts
469478

470-
final_iface <- mkFullIface session partial_iface Nothing
479+
final_iface' <- mkFullIface session partial_iface Nothing
471480
#if MIN_VERSION_ghc(9,4,2)
472481
Nothing
473482
#endif
474483

475484
#else
476485
let !partial_iface = force (mkPartialIface session details simplified_guts)
477-
final_iface <- mkFullIface session partial_iface
486+
final_iface' <- mkFullIface session partial_iface
478487
#endif
488+
let final_iface = final_iface' {mi_globals = Nothing} -- ^ See Note [Clearing mi_globals after generating an iface]
479489

480490
-- Write the core file now
481491
core_file <- case mguts of

0 commit comments

Comments
 (0)