Skip to content

fix(Quotations): Remove NRE under concurrent initialization - #21035

Open
bartelink wants to merge 3 commits into
dotnet:mainfrom
bartelink:fix/quotations-conc
Open

bartelink wants to merge 3 commits into
dotnet:mainfrom
bartelink:fix/quotations-conc

Conversation

@bartelink

Copy link
Copy Markdown
Contributor

Resolves #14225

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ Release notes checked


✅ Found changes and release notes in following paths:

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

@bartelink

Copy link
Copy Markdown
Contributor Author

I'm informed that:

The closest clone is  src/Compiler/Interactive/fsi.fs:1820,1926 :  FsiDynamicCompiler  has a  static let mutable dynamicAssemblyId , incremented with  Interlocked.Increment  for emitted assembly IDs.

Other stamp-like counters use module-level mutable state rather than a static type holder:  src/Compiler/TypedTree/CompilerGlobalState.fs:137-144  ( uniqueCount ,  stampCount ) and  src/Compiler/Checking/CheckRecordSyntaxHelpers.fs:177-180  ( bindId ). I found no other match combining  static let mutable  with  Interlocked.Increment .

@bartelink
bartelink marked this pull request as ready for review November 27, 2026 14:41
@bartelink
bartelink requested a review from a team as a code owner November 27, 2026 14:41
Copilot AI balanced review requested due to automatic review settings November 27, 2026 14:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The initialization comment misleadingly claims independence from file initialization order, although supported --realsig- builds still delegate initialization to the file initializer.

1 open issue
What changed in this PR

Addresses #14225’s intermittent NullReferenceException during concurrent quotation deserialization in FSharp.Core.

Changes:

  • Replaces the stamp-allocation closure with a dedicated holder using an atomic counter.
  • Adds a 32-thread regression test checking successful deserialization and unique variable stamps.
  • Documents the fix in the FSharp.Core release notes.
File Description
tests/​FSharp.Compiler.ComponentTests/​Language/​CodeQuotationTests.fs Adds concurrent quotation deserialization coverage.
src/​FSharp.Core/​quotations.fs Moves variable stamp allocation into a dedicated holder.
docs/​release-notes/​.FSharp.Core/​11.0.200.md Records the concurrent-startup fix.

Review effort: Balanced

Comment thread src/FSharp.Core/quotations.fs Outdated

open Helpers

// Keep stamp allocation in an explicit type initializer, independent of this file's initialization order.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Suggested rewording applied. Leaving for resolution by real reviewer!

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.

Crash when using code quotations in tests

2 participants