Skip to content

Commit 8efbf77

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 8efbf77

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

Diff for: ghcide/src/Development/IDE/Core/Compile.hs

+14-3
Original file line numberDiff line numberDiff line change
@@ -427,14 +427,24 @@ 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
447+
let iface = iface' { mi_globals = Nothing } -- See Note [Clearing mi_globals after generating an iface]
438448
pure $! mkHiFileResult ms iface details (tmrRuntimeModules tcm) Nothing
439449

440450
mkHiFileResultCompile
@@ -467,15 +477,16 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
467477
#endif
468478
simplified_guts
469479

470-
final_iface <- mkFullIface session partial_iface Nothing
480+
final_iface' <- mkFullIface session partial_iface Nothing
471481
#if MIN_VERSION_ghc(9,4,2)
472482
Nothing
473483
#endif
474484

475485
#else
476486
let !partial_iface = force (mkPartialIface session details simplified_guts)
477-
final_iface <- mkFullIface session partial_iface
487+
final_iface' <- mkFullIface session partial_iface
478488
#endif
489+
let final_iface = final_iface' {mi_globals = Nothing} -- See Note [Clearing mi_globals after generating an iface]
479490

480491
-- Write the core file now
481492
core_file <- case mguts of

0 commit comments

Comments
 (0)