New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for GHC 9.4.1 #152
Conversation
I really liked how @brandon-leapyear did it last time: instead of adding That being said, it is much more important to get the library to work against GHC-9.4.1 than to make the code look nice, so perhaps you can focus on making it work and then I can worry about refactoring the code to the shims style :) |
Yeah, the plan is to make it work first. Currently everything compiles, but none of the test pass because it doesn’t load the modules. Once that’s sorted I’ll refactor to use shims. |
FYI I found this other technique to minimize the number of #if macros even more, if you're interested in it: https://github.com/brandonchinn178/tasty-autocollect/blob/main/src/Test/Tasty/AutoCollect/GHC/Shim.hs |
I had to add the following
|
I don’t know, once those packages are upgraded the |
@christiaanb I doubt you have time to address this, but do you have any sense of what's wrong / a way to fix it you could share with us? |
Right, the issue is that this context storing and restoring: Lines 126 to 134 in 42afe81
is no longer sufficient. And I haven't figure out how to implement it in the GHC 9.4 API. This means that Lines 414 to 419 in 42afe81
|
At the moment with this, I got unit test failures on ghc 9.4.2:
|
Otherwise the package seems to compile without running these. |
Compiling is not sufficient; the failing tests indicate that hint cannot load modules, which is a key functionality we can't ship without. |
Yes of course, I didn't need that feature for my particular project so I'm not suggesting it goes in, only that I have an override set. |
Hi, is ghc 9.4 support on the horizon for hint? |
I have not had much time for open source projects recently, but thanks for reminding me about this, it helps me to prioritize which issues to focus on when I do find the time! |
This seems to come down to behavioral changes in
|
Thanks for tracking this down! However, there is still something I don't understand. Immediately above the code where hint calls LoadUpTo, there is a comment which says:
Then there are calls to
That doesn't make much sense though, since your test case demonstrates that ghc's behavior has changed. Maybe an even older version of GHC was behaving like GHC 9.4 in that regard? Or maybe the comment isn't saying that the modules get unloaded, instead it is saying that they are still loaded but that they need to be imported again? |
I'm pretty sure this is it. There's still a chance I'm chasing a red herring though, so I'll implement a patch for GHC and see if it fixes Hint's issues. |
That sounds like a lot of work! Personally, I would start with approach 1, trying to change Hint to not rely on this behavior. After all, we know exactly what modules should be in scope, so it shouldn't be too hard to list them all if that's what the new GHC API requires. |
It's quite alright, I found the process relatively straightforward. I implemented two patches; one fixing a straight up bug in Unfortunately, the trick:
doesn't work anymore for newer GHCs, presumably because references aren't valid after calling |
b41a38b
to
ecc84b4
Compare
All tests pass now, and I've added testing on GHC 9.4 to CI. All that remains is some cleaning up and we should be able to make a new release. |
Excellent news thanks so much @christiaanb @martijnbastiaan + co! |
src/Hint/Context.hs
Outdated
#if MIN_VERSION_ghc(9,4,0) | ||
res <- runGhc $ GHC.load GHC.LoadAllTargets | ||
#else | ||
res <- runGhc $ GHC.load (GHC.LoadUpTo m) | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we use LoadAllTargets
for all GHC versions now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps... I guess I can try on the oldest supported version.
Since this test is specifically about checking that hint can pass on package-db flags to GHC correctly, it makes sense to disable the environment file in this test using `-package-env -` so that the package-db is not used implicitly as a result of the environment file.
@gelisam I've cleaned up the PR, could you give it another review, and if everything looks good to you merge the PR into |
@@ -128,7 +125,7 @@ addPhantomModule mod_text = | |||
(old_top, old_imps) <- runGhc getContext | |||
-- | |||
runGhc $ GHC.addTarget t | |||
res <- runGhc $ GHC.load (GHC.LoadUpTo m) | |||
res <- runGhc $ GHC.loadPhantomModule m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. With ghc-9.4, loadPhantomModule m
is defined as GHC.load GHC.LoadAllTargets
, which does not mention m
. So where does m
get loaded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this comment says that calling getContext
and then setContext
does not work anymore, because the saved context refers to the modules using some internal IDs which are no longer valid after calling LoadAllTargets
. So why is the code still using getContext
and setContext
? Is the comment wrong, and setContext
does work after all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now think that setContext
does fail, but then the caller fixes it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where does
m
get loaded?
I now understand that addTarget t
followed by LoadAllTargets
does load t
🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried removing the allegedly-broken getContext
and setContext
calls, but that broke the test_work_in_main
test. I was thus wrong: the caller does not fix setContext
, and in fact, setContext
does work fine.
Sorry it took me so long to find the time to review this! @christiaanb since you obviously care about the library and you clearly have more time to dedicate to it than I do, would you like to take over as maintainer? |
mkGhcError :: (GHC.SDoc -> String) -> GHC.SrcSpan -> GHC.Message -> GhcError | ||
mkGhcError render src_span msg = GhcError{errMsg = niceErrMsg} | ||
where niceErrMsg = render $ GHC.mkLocMessage GHC.SevError src_span msg | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for moving all this stuff to the shims file!
@martijnbastiaan what made you conclude that this trick doesn't work anymore? It seems on the contrary that the trick works and is essential for the |
I now think that the main change in ghc-9.4 isn't to |
released as hint-0.9.0.7 |
I believe it - I probably got confused at some point while hacking on Hint. |
This is work in progress