Skip to content

Never compute the DocMap with stale data#4936

Open
fendor wants to merge 3 commits into
haskell:masterfrom
fendor:wip/overlapping-instances
Open

Never compute the DocMap with stale data#4936
fendor wants to merge 3 commits into
haskell:masterfrom
fendor:wip/overlapping-instances

Conversation

@fendor
Copy link
Copy Markdown
Collaborator

@fendor fendor commented May 15, 2026

As the regression test 'eps-pollution' demonstrates, changing the
imports of a module with class instances can poison the HLS session.

To fix this, we simply shouldn't use stale results for computing the
DocMap.

Frankly, there is no reason to use stale results when we are not even
using the PositionMapping, this sounds like a recipe for disaster in
general. Especially, since the source locations matter in this instance.

The test has been contributed by @mniip and claude, thank you very much for identifying the issue!
I removed simplified the tests slightly, removing irrelevant details, but it is more or less the same.

I also refactored checkHover to add an additional assertion to the test.
This gets rid of a couple of lines of code, which is nice.

Should close #3694

@fendor fendor requested a review from wz1000 as a code owner May 15, 2026 15:15
@fendor fendor force-pushed the wip/overlapping-instances branch from f18d717 to c383e1c Compare May 15, 2026 16:39
claude and others added 3 commits May 16, 2026 11:47
GetDocMap reads TypeCheck, GhcSessionDeps and GetHieAst via independent
useWithStale_ calls. An edit that breaks typechecking lets GhcSessionDeps
re-evaluate with a fresh (narrower) HPT while TypeCheck and GetHieAst fall
back to their last-successful values. mkDocMap then runs with a fresh
HscEnv whose HPT is missing modules that the stale RefMap still references;
getDocsBatch calls loadSysInterface on those modules; loadInterface,
finding them absent from the HUG, puts the home-module interfaces -- with
their instance environments -- into the shared EPS IORef. The EPS never
evicts, so subsequent typechecks that legitimately have those modules in
the HPT see each ClsInst twice (via ie_global from the EPS and ie_local
from hptInstancesBelow) and GHC reports "Overlapping instance" with both
matches pointing at the same source location.

The test edits away an import to provoke the pollution, then restores the
import and asserts the repaired file typechecks without an overlapping-
instance diagnostic. Wrapped in expectFailBecause so CI stays green until
a fix lands.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
As the regression test 'eps-pollution' demonstrates, changing the
imports of a module with class instances can poison the HLS session.

To fix this, we simply shouldn't use stale results for computing the
`DocMap`.

Frankly, there is no reason to use stale results when we are not even
using the `PositionMapping`, this sounds like a recipe for disaster in
general. Especially, since the source locations matter.
@fendor fendor force-pushed the wip/overlapping-instances branch from c383e1c to 05b03ab Compare May 16, 2026 10:59
@fendor
Copy link
Copy Markdown
Collaborator Author

fendor commented May 16, 2026

Interesting data point, the test doesn't fail on GHC 9.14.1, but it fails on GHC 9.10.3 🤔

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.

Incorrect overlapping instances errors

2 participants