diff options
author | Joachim Breitner <mail@joachim-breitner.de> | 2021-12-12 15:47:29 +0100 |
---|---|---|
committer | Joachim Breitner <mail@joachim-breitner.de> | 2021-12-12 15:47:29 +0100 |
commit | 29c02ea032921a890b1b9412bcc51f0729d648f0 (patch) | |
tree | f76eec1cadbbc3bb53354525328a8f62479f8259 /compiler/GHC/Tc/Module.hs | |
parent | 93783e6a8765e1410d0a14fd5249a995c6759308 (diff) | |
download | haskell-wip/joachim/T20455.tar.gz |
Ghci environment: Do not remove shadowed idswip/joachim/T20455
Names defined earier but shadowed need to be kept around, e.g. for type
signatures:
```
ghci> data T = T
ghci> let t = T
ghci> data T = T
ghci> :t t
t :: Ghci1.T
```
and indeed they can be used:
```
ghci> let t2 = Ghci1.T :: Ghci1.T
ghci> :t t2
t2 :: Ghci1.T
```
However, previously this did not happen for ids (non-types), although they
are still around under the qualified name internally:
```
ghci> let t = "other t"
ghci> t'
<interactive>:8:1: error:
• Variable not in scope: t'
• Perhaps you meant one of these:
‘Ghci2.t’ (imported from Ghci2), ‘t’ (line 7), ‘t2’ (line 5)
ghci> Ghci2.t
<interactive>:9:1: error:
• GHC internal error: ‘Ghci2.t’ is not in scope during type checking, but it passed the renamer
tcl_env of environment: []
• In the expression: Ghci2.t
In an equation for ‘it’: it = Ghci2.t
```
This fixes the problem by simply removing the code that tries to remove
shadowed ids from the environment. Now you can refer to shadowed ids using
`Ghci2.t`, just like you can do for data and type constructors. This
simplifies the code, makes terms and types more similar, and also
fixes #20455.
Now all names ever defined in GHCi are in `ic_tythings`, which is printed by
`:show bindings`. But for that commands, it seems to be more ergonomic
to only list those bindings that are not shadowed. Or, even if it is not
more ergonomic, it’s the current behavour. So let's restore that by filtering
in `icInScopeTTs`.
Of course a single `TyThing` can be associated with many names. We keep
it it in the bindings if _any_ of its names are still visible
unqualifiedly. It's a judgement call.
This commit also turns a rather old comment into a test files.
The comment is is rather stale and things are better explained
elsewhere. Fixes #925.
Two test cases are regressing:
T14052(ghci) ghc/alloc 2749444288.0 12192109912.0 +343.4% BAD
T14052Type(ghci) ghc/alloc 7365784616.0 10767078344.0 +46.2% BAD
This is not unexpected; the `ic_tythings list grows` a lot more if we
don’t remove shadowed Ids. I tried to alleviate it a bit with earlier
MRs, but couldn’t make up for it completely.
Metric Increase:
T14052
T14052Type
Diffstat (limited to 'compiler/GHC/Tc/Module.hs')
-rw-r--r-- | compiler/GHC/Tc/Module.hs | 19 |
1 files changed, 0 insertions, 19 deletions
diff --git a/compiler/GHC/Tc/Module.hs b/compiler/GHC/Tc/Module.hs index 6dfcf5d357..06270c1848 100644 --- a/compiler/GHC/Tc/Module.hs +++ b/compiler/GHC/Tc/Module.hs @@ -2171,25 +2171,6 @@ tcRnStmt hsc_env rdr_stmt global_ids <- mapM (externaliseAndTidyId this_mod) zonked_ids ; -- Note [Interactively-bound Ids in GHCi] in GHC.Driver.Env -{- --------------------------------------------- - At one stage I removed any shadowed bindings from the type_env; - they are inaccessible but might, I suppose, cause a space leak if we leave them there. - However, with Template Haskell they aren't necessarily inaccessible. Consider this - GHCi session - Prelude> let f n = n * 2 :: Int - Prelude> fName <- runQ [| f |] - Prelude> $(return $ AppE fName (LitE (IntegerL 7))) - 14 - Prelude> let f n = n * 3 :: Int - Prelude> $(return $ AppE fName (LitE (IntegerL 7))) - In the last line we use 'fName', which resolves to the *first* 'f' - in scope. If we delete it from the type env, GHCi crashes because - it doesn't expect that. - - Hence this code is commented out - --------------------------------------------------- -} - traceOptTcRn Opt_D_dump_tc (vcat [text "Bound Ids" <+> pprWithCommas ppr global_ids, text "Typechecked expr" <+> ppr zonked_expr]) ; |