Skip to content

Check each project with its own options when imports are cached - #20977

Open
michaelglass wants to merge 6 commits into
dotnet:mainfrom
michaelglass:fix-tcglobals-reuse-options
Open

michaelglass wants to merge 6 commits into
dotnet:mainfrom
michaelglass:fix-tcglobals-reuse-options

Conversation

@michaelglass

@michaelglass michaelglass commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Description

Before this PR

  • Projects with the same framework references share one cached TcGlobals, and it carries the compiler options of whichever project was checked first: --reflectionfree, --quotations-debug, --nodebugdata, and its script resolution rules. A project that references another in memory is checked wrongly even on a fresh checker:
// Library (no options)
let s = sprintf "%A" 1

// App (--reflectionfree, references Library in memory)
let t : string = Library.s
checker.ParseAndCheckFileInProject("App.fs", snapshot)
App.fs: This expression was expected to have type 'string' but here has type 'obj'

Library is type-checked with App's --reflectionfree, so its %A fails format checking and s recovers as obj. Between unrelated projects on one checker, a project without the option reports the %A error when a --reflectionfree project was checked before it, and in the other order the --reflectionfree project loses that error.

After this PR

  • Each project is checked with its own options, in both the background compiler and the transparent compiler.
  • TcGlobals takes every option it reads from TcConfig as one record, TcGlobalsOptions, built by one function. Both compilers reuse the cached instance only when its record equals the project's, and otherwise build one from the cached framework values. An option added later is a new record field, so it is compared without anyone having to remember a list.

Regression tests: ReflectionFree.fs and ScriptResolutionRules.fs in tests/FSharp.Compiler.ComponentTests/FSharpChecker/.

Related: this extends #20476, which fixed #20474. That PR fixed the same sharing for --pathmap by rebuilding the cached TcGlobals when a project's path map differs from the cached one. The other options were still copied from the cached instance; the path map is now one field of the same record.

Checklist

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

…ts are reused

The TcGlobals cached with the framework imports was rebuilt for a project only when langVersion, realsig or pathMap differed, and the rebuilt instance copied useReflectionFreeCodeGen, emitDebugInfoInQuotations, noDebugAttributes and isInteractive from the project that filled the cache. The background and the transparent compiler each had their own copy of that comparison and of the TcGlobals construction.

Both now call one function, TcGlobalsForTcConfig, which reuses the cached TcGlobals only when it carries all of the project's options and otherwise builds one from its framework values and the project's TcConfig. That construction is also the one BuildFrameworkTcImports uses, so an option added to TcGlobals later is taken from TcConfig in one place.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 14, 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 marked this pull request as draft November 14, 2026 07:15
michaelglass and others added 3 commits November 14, 2026 08:24
Also name the script resolution rules, which the fix covers.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
TcGlobals took nine TcConfig options as separate constructor arguments, and TcGlobalsForTcConfig decided whether a cached TcGlobals could be reused by comparing eight of them by hand. An option added to TcGlobals later would be missed by that comparison unless someone remembered to extend it.

The options are now one record, TcGlobalsOptions, which TcGlobals takes as a single argument and exposes as g.options. tcGlobalsOptionsOf builds it from TcConfig, and reuse is g.options = tcGlobalsOptionsOf tcConfig. A record expression must assign every field and record equality compares every field, so a new option cannot be built without taking it from TcConfig, nor left out of the comparison. checkNullness is now compared too, so the comment excusing it is gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015vTs7XwyE4i4iEpQis6Sad
@michaelglass
michaelglass marked this pull request as ready for review November 14, 2026 07:51

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

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

FrameworkImportsCache lends the first project's --pathmap to every project of the framework set

1 participant