`LoadUpTo` implicitly unloads on GHC>=9.4
Summary
The following (pseudo-)code behaves differently for 9.2 and 9.4:
-- Adding Foo as a target, and executing 'LoadAllTargets'..
fooTarget <- guessTarget "Foo.hs"
Ghc.addTarget fooTarget
Ghc.load Ghc.LoadAllTargets
-- Adding Bar as a target, and executing 'LoadUpTo m'..
barTarget <- guessTarget "Bar.hs"
Ghc.addTarget barTarget
m <- mkModule "Bar"
Ghc.load (Ghc.LoadUpTo m)
After this snippet, GHC <9.4 would have to modules loaded: Foo
and Bar
. GHC >= 9.4 behaves differently, with only Bar
being loaded. The real code includes some faffin about with CPP which I've published over here:
- https://github.com/martijnbastiaan/hint-debug/tree/6698c39b0631bc1af8f192ceca9d980722995410
- https://github.com/martijnbastiaan/hint-debug/blob/6698c39b0631bc1af8f192ceca9d980722995410/bin/Main.hs#L49-L60
Steps to reproduce
Clone the reproducer:
git clone https://github.com/martijnbastiaan/hint-debug.git
cd hint-debug
git checkout 6698c39b0631bc1af8f192ceca9d980722995410
Execute with different compilers:
cabal run --with-compiler=ghc-9.2.7
cabal run --with-compiler=ghc-9.4.5
Expected behavior
I don't necessarily expect one or the other, but the new behavior makes it hard to port over Hint to GHC >= 9.4.
Potential solution
Add LoadAllTargetsUpTo HomeUnitModule
to LoadHowMuch
. I.e.,
| LoadAllTargetsUpTo HomeUnitModule
-- ^ Load all targets, except @HomeUnitModule@. If @HomeUnitModule@ is a
-- dependency of another target, it will get loaded anyway.
..and backport it to GHC 9.4 / 9.6. I'm willing to implement this.
Environment
N/A