summaryrefslogtreecommitdiff
path: root/compiler/GHC/Tc/Module.hs
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2021-10-15 10:38:23 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-10-19 03:30:52 -0400
commit7271bf78a9ffd865e590f1ce3f3ae975f5dc1a49 (patch)
tree4c1eb9dbf7c3698f4462ae9fa7d7ac13ef89eb9e /compiler/GHC/Tc/Module.hs
parent753b921da52c0b7da21856c5fe0bf4604505c7b3 (diff)
downloadhaskell-7271bf78a9ffd865e590f1ce3f3ae975f5dc1a49.tar.gz
InteractiveContext: Smarter caching when rebuilding the ic_rn_gbl_env
The GlobalRdrEnv of a GHCI session changes in odd ways: New bindings are not just added "to the end", but also "in the middle", namely when changing the set of imports: These are treated as if they happened before all bindings from the prompt, even those that happened earlier. Previously, this meant that the `ic_rn_gbl_env` is recalculated from the `ic_tythings`. But this wasteful if `ic_tythings` has many entries that define the same unqualified name. By separately keeping track of a `GlobalRdrEnv` of all the locally defined things we can speed this operation up significantly. This change improves `T14052Type` by 60% (It used to be 70%, but it looks that !6723 already reaped some of the rewards). But more importantly, it hopefully unblocks #20455, becaues with this smarter caching, the change needed to fix that issue will no longer make `T14052` explode. I hope. It does regress `T14052` by 30%; caching isn’t free. Oh well. Metric Decrease: T14052Type Metric Increase: T14052
Diffstat (limited to 'compiler/GHC/Tc/Module.hs')
-rw-r--r--compiler/GHC/Tc/Module.hs8
1 files changed, 4 insertions, 4 deletions
diff --git a/compiler/GHC/Tc/Module.hs b/compiler/GHC/Tc/Module.hs
index 8739c33ec5..53ee34ed9e 100644
--- a/compiler/GHC/Tc/Module.hs
+++ b/compiler/GHC/Tc/Module.hs
@@ -2040,8 +2040,8 @@ runTcInteractive hsc_env thing_inside
do { traceTc "setInteractiveContext" $
vcat [ text "ic_tythings:" <+> vcat (map ppr (ic_tythings icxt))
, text "ic_insts:" <+> vcat (map (pprBndr LetBind . instanceDFunId) ic_insts)
- , text "ic_rn_gbl_env (LocalDef)" <+>
- vcat (map ppr [ local_gres | gres <- nonDetOccEnvElts (ic_rn_gbl_env icxt)
+ , text "icReaderEnv (LocalDef)" <+>
+ vcat (map ppr [ local_gres | gres <- nonDetOccEnvElts (icReaderEnv icxt)
, let local_gres = filter isLocalGRE gres
, not (null local_gres) ]) ]
@@ -2063,7 +2063,7 @@ runTcInteractive hsc_env thing_inside
; (gbl_env, lcl_env) <- getEnvs
; let gbl_env' = gbl_env {
- tcg_rdr_env = ic_rn_gbl_env icxt
+ tcg_rdr_env = icReaderEnv icxt
, tcg_type_env = type_env
, tcg_inst_env = extendInstEnvList
(extendInstEnvList (tcg_inst_env gbl_env) ic_insts)
@@ -2910,7 +2910,7 @@ loadUnqualIfaces hsc_env ictxt
home_unit = hsc_home_unit hsc_env
unqual_mods = [ nameModule name
- | gre <- globalRdrEnvElts (ic_rn_gbl_env ictxt)
+ | gre <- globalRdrEnvElts (icReaderEnv ictxt)
, let name = greMangledName gre
, nameIsFromExternalPackage home_unit name
, isTcOcc (nameOccName name) -- Types and classes only