summaryrefslogtreecommitdiff
path: root/compiler/GHC/Driver/Env.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/GHC/Driver/Env.hs')
-rw-r--r--compiler/GHC/Driver/Env.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/compiler/GHC/Driver/Env.hs b/compiler/GHC/Driver/Env.hs
index 8bc1f516bf..0d52ecc7cc 100644
--- a/compiler/GHC/Driver/Env.hs
+++ b/compiler/GHC/Driver/Env.hs
@@ -32,6 +32,7 @@ module GHC.Driver.Env
, hptSomeThingsBelowUs
, hptRules
, prepareAnnotations
+ , discardIC
, lookupType
, lookupIfaceByModule
, mainModIs
@@ -421,3 +422,27 @@ hscSetActiveUnitId uid e = e
hscActiveUnitId :: HscEnv -> UnitId
hscActiveUnitId e = ue_currentUnit (hsc_unit_env e)
+
+-- | Discard the contents of the InteractiveContext, but keep the DynFlags and
+-- the loaded plugins. It will also keep ic_int_print and ic_monad if their
+-- names are from external packages.
+discardIC :: HscEnv -> HscEnv
+discardIC hsc_env
+ = hsc_env { hsc_IC = empty_ic { ic_int_print = new_ic_int_print
+ , ic_monad = new_ic_monad
+ , ic_plugins = old_plugins
+ } }
+ where
+ -- Force the new values for ic_int_print and ic_monad to avoid leaking old_ic
+ !new_ic_int_print = keep_external_name ic_int_print
+ !new_ic_monad = keep_external_name ic_monad
+ !old_plugins = ic_plugins old_ic
+ dflags = ic_dflags old_ic
+ old_ic = hsc_IC hsc_env
+ empty_ic = emptyInteractiveContext dflags
+ keep_external_name ic_name
+ | nameIsFromExternalPackage home_unit old_name = old_name
+ | otherwise = ic_name empty_ic
+ where
+ home_unit = hsc_home_unit hsc_env
+ old_name = ic_name old_ic