Skip to content

Transparent compiler should recheck dependent files when an evicted upstream file result is recomputed - #20643

Open
michaelglass wants to merge 2 commits into
dotnet:mainfrom
michaelglass:fix-tc-intermediate-cache-identity
Open

michaelglass wants to merge 2 commits into
dotnet:mainfrom
michaelglass:fix-tc-intermediate-cache-identity

Conversation

@michaelglass

@michaelglass michaelglass commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Before this PR

  • With the transparent compiler, if an earlier file's cached check result is garbage collected while later files' results stay cached, checking a file can fail with a type that doesn't match itself:
// A.fs
module A
type T = { X: int }

// B.fs
module B
let value : A.T = { X = 1 }

// C.fs
module C
let ok : A.T = B.value
let checker =
    FSharpChecker.Create(
        useTransparentCompiler = true,
        transparentCompilerCacheSizes = { CacheSizes.Create 100 with TcIntermediateKeepStrongly = 1 })

checker.ParseAndCheckFileInProject("B.fs", snapshot) // caches results for A and B
GC.Collect()                                         // A's result was only weakly held and is freed
checker.ParseAndCheckFileInProject("C.fs", snapshot) // A is checked again; B's cached result is reused
C.fs: error FS0001: This expression was expected to have type 'A.T' but here has type 'A.T'

Checking A again declares a new copy of T, while B's cached result still refers to the old copy.

After this PR

  • C.fs checks clean. Each file's cache key includes the identity of the earlier results it was built from, so recomputing A also recomputes B.

Regression test: Recomputing a collected upstream file result does not mix it with cached downstream results in tests/FSharp.Compiler.ComponentTests/FSharpChecker/TransparentCompiler.fs.

Related: #20644 fixes a separate AsyncMemoize race that can also leave two copies of a file's types in use. The fixes are independent; either can merge first.

Written with Claude Code (Opus 5.5).

Checklist

  • Test cases added
  • Performance benchmarks added in case of performance changes
  • Release notes entry updated

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ Release notes checked


✅ Found changes and release notes in following paths:

Change path Release notes path Description
`src/Compiler` docs/release-notes/.FSharp.Compiler.Service/11.0.200.md

@michaelglass michaelglass changed the title Transparent compiler: fix "expected type 'T' but here has type 'T'" after cache eviction Transparent compiler should recheck dependent files when an evicted upstream file result is recomputed Sep 26, 2026
michaelglass added a commit to michaelglass/fsharp that referenced this pull request Sep 26, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the ⚠️ Affects-Design-Time Tooling check: PR touches type providers or dependency manager label Sep 26, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions github-actions Bot added the AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files label Sep 27, 2026
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Design-Time
Affects-Design-Time: Changes FCS project checking behavior.

Generated by PR Tooling Safety Check · gpt56 2.5M · ◷

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 🕵️ LGTM

@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label Sep 29, 2026
@T-Gro
T-Gro self-requested a review September 29, 2026 09:33
@T-Gro

T-Gro commented Oct 9, 2026

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

@michaelglass

Copy link
Copy Markdown
Contributor Author

for these types of release note conflicts, I shouldn't resolve them myself right? (because it'll dismiss the existing AI review?)

@T-Gro

T-Gro commented Oct 13, 2026

Copy link
Copy Markdown
Member

Ideally use the skill to avoid them. If not, then please do resolve - if I resolve it and I am the latest pusher, my approval will no longer count.

michaelglass added a commit to michaelglass/fsharp that referenced this pull request Oct 15, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@michaelglass
michaelglass force-pushed the fix-tc-intermediate-cache-identity branch from 74a5345 to 4dddeae Compare October 15, 2026 08:57
@michaelglass

Copy link
Copy Markdown
Contributor Author

@T-Gro thanks! Didn't catch the skill. Now I used it on this and #20644

@T-Gro
T-Gro enabled auto-merge (squash) October 19, 2026 13:31
michaelglass and others added 2 commits October 22, 2026 12:19
…they used

The cached type-check result of a file was keyed by the source up to that
file, not by the results of the earlier files it was checked against. When
an earlier file's result was garbage collected and recomputed, it declared
new entities, while cached results of later files still referred to the old
ones. Checking a file that combined both reported errors like "This
expression was expected to have type 'A.T' but here has type 'A.T'".

Each computed result now gets a unique id, the state passed to a file
records the ids of the results it was built from, and those ids are part of
the file's cache key, so results that depend on a recomputed one are
recomputed too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
auto-merge was automatically disabled October 22, 2026 10:21

Head branch was pushed to by a user without write access

@michaelglass
michaelglass force-pushed the fix-tc-intermediate-cache-identity branch from 4dddeae to dc71aa5 Compare October 22, 2026 10:21
@michaelglass

Copy link
Copy Markdown
Contributor Author

@T-Gro I forced pushed to resolve the merge conflict

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚠️ Affects-Design-Time Tooling check: PR touches type providers or dependency manager AI-reviewed PR reviewed by AI review council AI-Tooling-Check-Scanned-Clean Tooling check: diff analyzed, no interesting infrastructure files

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants