Uh oh!
There was an error while loading. Please reload this page.
[cDAC] Fix IsSharedByGenericInstantiations for non-shared canonical MTs - #129721
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
left a comment
There was a problem hiding this comment.
From a bug fix perspective, makes sense
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. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
max-charlamb
commented
Jun 23, 2026
/ba-g known issue: #129705 |
Uh oh!
There was an error while loading. Please reload this page.
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
…Ts (#129721) 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. This mirrors 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; this adds it (the `GenericInst` `0x10` value 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.md` to reflect the new flag value and the simplified implementation, and the `[cDAC] [RuntimeTypeSystem]` dependency comment in `src/coreclr/vm/methodtable.h`. Surfaced by the cdacstress `ArgIterator` sub-check (`DOTNET_CdacStress=0x201`). > [!NOTE] > This PR description was authored with assistance from GitHub Copilot. Co-authored-by: Max Charlamb <maxcharlamb@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.