Skip to content

ghcide: implement level-aware module graph edges for GHC 9.14+#4846

Merged
fendor merged 7 commits into
haskell:masterfrom
ijatinydv:fix/ghc-914-explicit-import-levels
Feb 20, 2026
Merged

ghcide: implement level-aware module graph edges for GHC 9.14+#4846
fendor merged 7 commits into
haskell:masterfrom
ijatinydv:fix/ghc-914-explicit-import-levels

Conversation

@ijatinydv

Copy link
Copy Markdown
Contributor

Fixes #4844

This PR resolves a critical expectJust panic occurring at GHC/Unit/Module/Graph.hs:579 when the ExplicitLevelImports extension is enabled in GHC 9.14 environments.

The Problem
GHC 9.14 introduced a redesign of the ModuleGraph reachability logic. Reachability is now tracked per ImportLevel (SpliceLevel, QuoteLevel, or NormalLevel). Previously, ghcide hardcoded NormalLevel for all textual imports when reconstructing the GHC session graph. This caused mgQueryZero to fail during Template Haskell processing because the expected splice-level edges were missing from the graph.

The Fix

  • Capture: Updated getModSummaryFromImports in Compile.hs to extract the actual ImportLevel from the AST using ideclLevelSpec.
  • Propagation: Modified Rules.hs to build a multi-level mapping of dependencies. This ensures that if a module is imported at multiple levels (e.g., import splice M and import M), both edges are represented in the graph.
  • Construction: Replaced legacy mkNormalEdge with the GHC 9.14 mkModuleEdge API to satisfy internal reachability invariants.
  • Efficiency: Integrated nubOrd to maintain $O(n \log n)$ deduplication of graph edges, preventing performance degradation in large projects.

Verification
The fix has been verified against GHC 9.14.1 using a regression suite covering five critical scenarios:

  1. Basic Splices: Confirmed SpliceLevel edges prevent the expectJust panic.
  2. Dual-Level Imports: Confirmed correct edge generation for modules used as both terms and splices.
  3. Deduplication: Verified nubOrd correctly handles redundant import statements.
  4. Transitive Reachability: Confirmed Template Haskell layers typecheck across module boundaries.
  5. Backward Compatibility: Verified zero impact on pre-GHC 9.14 environments via CPP guards.
image

@ijatinydv ijatinydv requested a review from wz1000 as a code owner February 15, 2026 19:04

@fendor fendor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread ghcide/src/Development/IDE/Core/Compile.hs Outdated
Comment thread ghcide/src/Development/IDE/Core/Compile.hs
Comment thread ghcide/src/Development/IDE/Core/Rules.hs Outdated
@ijatinydv

Copy link
Copy Markdown
Contributor Author

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!

  1. Regression Test: I completely agree—I'll add a regression test specifically for GHC 9.14 in THTests.hs to ensure this behavior is preserved.
  2. convImportLevel: Good catch. I'll refactor Compile.hs to use the GHC API directly instead of my custom conversion function.
  3. Refactoring Rules.hs: I'll introduce mkLevelImportMap to deduplicate the graph construction logic as suggested.

I'm working on these updates now and will push a new commit shortly!

@ijatinydv ijatinydv requested a review from michaelpj as a code owner February 17, 2026 14:16

@fendor fendor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ghcide-test/exe/THTests.hs Outdated
@ijatinydv

Copy link
Copy Markdown
Contributor Author

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!
I've updated the test suite to use deterministic diagnostic synchronization in THTests.hs instead of a fixed timeout. I also reverted the unrelated changes to test.yml and Logic.hs and other unrelated files.

Ready for another pass whenever you have a moment.

@fendor fendor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

Some last nitpicks and the test needs to be slightly tweaked to pass.

Comment thread .github/workflows/test.yml Outdated
Comment thread ghcide-test/exe/CompletionTests.hs Outdated
Comment thread ghcide-test/exe/CodeLensTests.hs Outdated
Comment thread ghcide-test/exe/DiagnosticTests.hs Outdated
@ijatinydv

Copy link
Copy Markdown
Contributor Author

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 -Wmissing-signatures. This clears out the redundant import noise that was causing the GHC 9.14 failures.

Everything should be green now—ready for that final check!

@fendor

fendor commented Feb 19, 2026

Copy link
Copy Markdown
Collaborator

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.

@fendor fendor merged commit 52cba13 into haskell:master Feb 20, 2026
54 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants