Intern provided namespaces to fix parallel-compilation resolution race#20021
Open
T-Gro wants to merge 2 commits into
Open
Intern provided namespaces to fix parallel-compilation resolution race#20021T-Gro wants to merge 2 commits into
T-Gro wants to merge 2 commits into
Conversation
Contributor
❗ Release notes requiredYou can open this PR in browser to add release notes: open in github.dev
|
Contributor
|
🔍 Tooling Safety Check — Affects-Compiler-Output, Affects-Design-Time
|
Follow-up to dotnet#19969, which interned provided *type* entities behind a lock-free CAS append + entitiesVersion design. The namespace entities on a provided type's path never got the same treatment: AddModuleOrNamespaceByMutation appended non-atomically (losing updates that race AddProvidedTypeEntity's CAS append) and the two namespace-materialization sites deduped with a non-atomic check-then-act, so two threads could each build a disjoint namespace subtree and strand the provided types interned under the orphan (spurious FS0001/FS0039). Make the namespace append atomic (shared AppendEntityByMutation CAS loop) and add GetOrInternNamespaceEntity, reusing the single providedEntitiesByMangledName intern table (one mangled name -> one entity per parent). Its factory reuses any pre-existing module/namespace of that name before creating, so a provider extending a real namespace no longer forks a duplicate. Both injection sites route through it. modulesByDemangledNameCache is now version-stamped since namespace appends can run concurrently with ModulesAndNamespacesByDemangledName reads. Fixes dotnet#20020 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
b9d2f04 to
7986396
Compare
…o sites The provided-entity interning added for dotnet#20020 hand-rolled the ConcurrentDictionary<_, Lazy<_>> + GetOrAdd(key, fun _ -> lazy f).Value compute-once idiom that already recurs in StableNiceNameGenerator, AnonTypeGenerationTable and the FSI xmlDoc cache. Factor it into a single GetOrAddLazy extension in illib and route all four sites through it. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
abonie
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20020
Under graph-based (parallel) type checking, the namespace entities on a
provided type's path were appended non-atomically and deduplicated with a
racy check-then-act, so concurrent linking from multiple files could build
disjoint namespace subtrees and strand provided types (spurious FS0001 /
FS0039). Namespace entities are now interned and appended with the same
lock-free CAS design already used for provided-type entities.
The compute-once
ConcurrentDictionary<_, Lazy<_>>idiom the interningrelies on is factored into a shared
GetOrAddLazyhelper and reused by theexisting name-generation and codegen caches.