[cDAC] Fix IsSharedByGenericInstantiations for non-shared canonical MTs#129721
Merged
Conversation
…shared canonical MTs The cDAC's IsSharedByGenericInstantiations fell back to `IsCanonMT && HasInstantiation`, which is too permissive: a value-type generic instantiation like ArraySortHelper<int> is its own canonical MT (value-type instantiations don't share with __Canon), so the check returned true and GetGenericContextLoc reported InstArgMethodTable for methods that don't actually need an inst arg. Mirror the runtime's MethodTable::IsSharedByGenericInstantiations (methodtable.inl:1044): GenericsMask bits == enum_flag_GenericsMask_SharedInst. The cDAC's MethodTableFlags_1 was missing the SharedInst (0x20) value of the GenericsMask bits; add it (the GenericInst 0x10 value is not used by the contract so left out per usual cDAC convention) and use it directly. Methods now correctly classified (previously reported a spurious TYPE_PARAM): ArraySortHelper<int>.cctor() / .CreateArraySortHelper() ArraySortHelper<ulong>.cctor() / .CreateArraySortHelper() ReadOnlySpan<char>.ToString() Dictionary.CollectionsMarshalHelper.GetValueRefOrAddDefault(...) Update docs/design/datacontracts/RuntimeTypeSystem.md to reflect the new flag value and the simplified IsSharedByGenericInstantiations implementation. Update the [cDAC] [RuntimeTypeSystem] dependency comment in src/coreclr/vm/methodtable.h to also call out enum_flag_GenericsMask_SharedInst. Surfaced by the cdacstress ArgIterator sub-check (DOTNET_CdacStress=0x201). > [!NOTE] > This commit was authored with assistance from GitHub Copilot. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
hoyosjs
approved these changes
Jun 23, 2026
hoyosjs
left a comment
Member
There was a problem hiding this comment.
From a bug fix perspective, makes sense
Contributor
There was a problem hiding this comment.
Pull request overview
This PR corrects the cDAC RuntimeTypeSystem contract’s notion of “shared by generic instantiations” by using the runtime’s GenericsMask == SharedInst bit pattern instead of the broader IsCanonMT && HasInstantiation heuristic, and aligns documentation/comments with the updated contract flag value.
Changes:
- Add
GenericsMask_SharedInst (0x20)to the contract’sMethodTableFlags_1and exposeIsSharedByGenericInstantiations. - Update
RuntimeTypeSystem_1.IsSharedByGenericInstantiationsto use the new flag-derived property. - Update RuntimeTypeSystem contract documentation and the CoreCLR dependency comment to reflect the new flag value.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/RuntimeTypeSystemHelpers/MethodTableFlags_1.cs | Adds GenericsMask_SharedInst and a corresponding IsSharedByGenericInstantiations helper to match runtime semantics. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs | Switches shared-generic detection to the new flag-based check for correct GetGenericContextLoc classification. |
| src/coreclr/vm/methodtable.h | Updates the [cDAC] [RuntimeTypeSystem] dependency comment to include SharedInst. |
| docs/design/datacontracts/RuntimeTypeSystem.md | Documents the new flag value and the simplified shared-generic detection logic. |
This was referenced Jun 23, 2026
Member
Author
|
/ba-g known issue: #129705 |
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
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.
The cDAC's
IsSharedByGenericInstantiationsfell back toIsCanonMT && HasInstantiation, which is too permissive: a value-type generic instantiation likeArraySortHelper<int>is its own canonical MT (value-type instantiations don't share with__Canon), so the check returnedtrueandGetGenericContextLocreportedInstArgMethodTablefor methods that don't actually need an inst arg.This mirrors the runtime's
MethodTable::IsSharedByGenericInstantiations(methodtable.inl:1044):GenericsMaskbits ==enum_flag_GenericsMask_SharedInst. The cDAC'sMethodTableFlags_1was missing theSharedInst(0x20) value of theGenericsMaskbits; this adds it (theGenericInst0x10value is not used by the contract so left out per usual cDAC convention) and uses it directly.Methods now correctly classified (previously reported a spurious
TYPE_PARAM):ArraySortHelper<int>.cctor()/.CreateArraySortHelper()ArraySortHelper<ulong>.cctor()/.CreateArraySortHelper()ReadOnlySpan<char>.ToString()Dictionary.CollectionsMarshalHelper.GetValueRefOrAddDefault(...)Also updates
docs/design/datacontracts/RuntimeTypeSystem.mdto reflect the new flag value and the simplified implementation, and the[cDAC] [RuntimeTypeSystem]dependency comment insrc/coreclr/vm/methodtable.h.Surfaced by the cdacstress
ArgIteratorsub-check (DOTNET_CdacStress=0x201).Note
This PR description was authored with assistance from GitHub Copilot.