ghci readily resets package state
Summary
Using GHC 9.0.1 and Cabal 3.4.0.0, a lot of "changes" will cause GHC to forget which modules were loaded in ghci. With GHC 8.10 it was a lot more robust. The frequent loss of loaded modules means tools like ghcid
are a lot less useful.
Steps to reproduce
$ cabal init
$ cabal repl
Now create an empty file Foo.hs
, and a file .ghci
with the contents:
:load Foo.hs
:set -DMAGIC
Using GHC 8.10.3, running cabal exec ghci
leaves me with a GHCi session with Foo.hs
loaded. However, with GHC 9.0.1:
C:\Neil\temp\ghci-bug>cabal exec ghci
Warning: The package list for 'hackage.haskell.org' is 22 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Loaded package environment from C:\Neil\temp\ghci-bug\dist-newstyle\tmp\environment.-11172\.ghc.environment.x86_64-mingw32-9.0.1
GHCi, version 9.0.1: https://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( Foo.hs, interpreted )
Ok, one module loaded.
Loaded package environment from C:\Neil\temp\ghci-bug\dist-newstyle\tmp\environment.-11172\.ghc.environment.x86_64-mingw32-9.0.1
Loaded package environment from C:\Neil\temp\ghci-bug\dist-newstyle\tmp\environment.-11172\.ghc.environment.x86_64-mingw32-9.0.1
package flags have changed, resetting and loading new packages...
Loaded GHCi configuration from C:\Neil\temp\ghci-bug\.ghci
ghci> :show modules
ghci>
So something about the environment changed, so it threw away all my loaded modules. In practice, a lot of things seem to make the environment change - turning on/off exceptions on breakpoints does it too. This makes ghci
a whole lot less useful.
Using ghci
alone it doesn't seem to reset the modules. However, in practice, using ghci
alone is now very difficult as it no longer allows global installs. There are also magic environment files which are hard to avoid, so alas, this bug report is in the intersection - but given keeping Cabal constant and changing GHC causes the bug, reporting for GHC 9.0.1.
Expected behavior
Don't throw away the loaded modules so freely.
Environment
- GHC version used: GHC 9.0.1
- Operating System: Windows
- System Architecture: x86_64