ghcide: implement level-aware module graph edges for GHC 9.14+#4846
Conversation
fendor
left a comment
There was a problem hiding this comment.
Hi! Thank you for your contribution this looks reasonable to me!
Do you think we can add a regression test for this only on GHC 9.14 so this doesn't break again?
Hi @fendor, thank you for the review and the helpful suggestions!
I'm working on these updates now and will push a new commit shortly! |
fendor
left a comment
There was a problem hiding this comment.
Thank you for the test!
We need one more change to the test suite, I hope I explained it sufficiently in the review.
Also, please undo the changes to test.yml, Logic.hs and similar files that are unrelated to this change.
The CI is unfortunately slightly flaky, I restart jobs from time to time, and if a test seemingly unrelated to your patch fails, I recommend ignoring this test until someone from the HLS team says the test failure is genuine. Apologies for this inconvenience, but we are working on it.
thanks for the feedback! Ready for another pass whenever you have a moment. |
fendor
left a comment
There was a problem hiding this comment.
LGTM, thank you!
Some last nitpicks and the test needs to be slightly tweaked to pass.
all set! I’ve added those final newlines back and updated the tests to use Everything should be green now—ready for that final check! |
|
Looks good to me, the failing tests are flaky and I dont think require your attention, I will rerun the jobs and merge. If anything comes up, Ill ping you. |
Fixes #4844
This PR resolves a critical
expectJustpanic occurring atGHC/Unit/Module/Graph.hs:579when theExplicitLevelImportsextension is enabled in GHC 9.14 environments.The Problem
GHC 9.14 introduced a redesign of the
ModuleGraphreachability logic. Reachability is now tracked perImportLevel(SpliceLevel,QuoteLevel, orNormalLevel). Previously,ghcidehardcodedNormalLevelfor all textual imports when reconstructing the GHC session graph. This causedmgQueryZeroto fail during Template Haskell processing because the expected splice-level edges were missing from the graph.The Fix
getModSummaryFromImportsinCompile.hsto extract the actualImportLevelfrom the AST usingideclLevelSpec.Rules.hsto build a multi-level mapping of dependencies. This ensures that if a module is imported at multiple levels (e.g.,import splice Mandimport M), both edges are represented in the graph.mkNormalEdgewith the GHC 9.14mkModuleEdgeAPI to satisfy internal reachability invariants.nubOrdto maintainVerification
The fix has been verified against GHC 9.14.1 using a regression suite covering five critical scenarios:
SpliceLeveledges prevent theexpectJustpanic.nubOrdcorrectly handles redundant import statements.