The icReaderEnv invariant is not being upheld
In GHCi, there's a special mechanism to recompute shadowing after importing a module. For example:
```haskell
module M where { foo = False }
-- In ghci:
> foo = 3
> foo = 4
> import M
> foo
4
> Ghci1.foo
3
```
The implementation is described in Note [icReaderEnv recalculation]: we keep track of things defined at the prompt, so that they can shadow things that are imported. The Note states the following invariant:
> INVARIANT: Every `OccName` in `igre_prompt_env` is present unqualified as well
> (else it would not be right to pass `igre_prompt_env` to `shadowNames`.)
This is because, in order to shadow imports, we only need to know the names defined in the prompt that are available unqualified.
However, currently, nothing is done to ensure that all names in `igre_prompt_env` are available unqualified. In particular, in the above example, `Ghci1.foo` will also be present in `igre_prompt_env`, even though it can't shadow anything anymore (as it has itself been shadowed).
This means we can potentially end up carrying around a much bigger `igre_prompt_env` than necessary. Test cases T14052 and T14052Type are affected.
issue