Uh oh!
There was an error while loading. Please reload this page.
Handle canonical types in constraints checks - #129278
Conversation
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
There was a problem hiding this comment.
Pull request overview
This PR updates the NativeAOT/CoreCLR shared TypeSystem constraint-checking and casting helpers to correctly account for canonical definition types (__Canon, __UniversalCanon) when validating generic constraints, and wires that behavior into MakeGenericType dataflow so reflected generic instantiations can be preserved correctly under AOT/trimming.
Changes:
- Introduces canonical-aware casting (
CanCastToWithCanon) via a handler-based casting helper split (canon vs non-canon builds). - Updates
TypeSystemConstraintsHelpersconstraint validation to use canonical-aware casting and adds canon-specific handling for special/type constraints. - Adds coverage: new canonical constraint validation unit tests, and a NativeAOT trimming smoke test; also normalizes instantiations before constraints checking in
MakeGenericTypedataflow.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/nativeaot/SmokeTests/TrimmingBehaviors/Dataflow.cs | Adds a new constrained MakeGenericType + Activator.CreateInstance smoke test. |
| src/coreclr/tools/ILVerification/ILVerification.projitems | Adds NonCanon helper source inclusions for ILVerification build. |
| src/coreclr/tools/Common/TypeSystem/Common/TypeSystemConstraintsHelpers.NonCanon.cs | Provides non-canon stubs for new partial constraint-helper hooks. |
| src/coreclr/tools/Common/TypeSystem/Common/TypeSystemConstraintsHelpers.cs | Switches constraint validation to canonical-aware casting and adds canon-specific fast paths. |
| src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.NonCanon.cs | Intended NonCanon implementation of the canonical casting handler. |
| src/coreclr/tools/Common/TypeSystem/Common/CastingHelper.cs | Refactors casting logic to support handler-based canon/non-canon behavior; adds CanCastToWithCanon. |
| src/coreclr/tools/Common/TypeSystem/Canon/TypeSystemConstraintsHelpers.Canon.cs | Implements canonical-specific constraint logic for __Canon/__UniversalCanon. |
| src/coreclr/tools/Common/TypeSystem/Canon/CastingHelper.Canon.cs | Implements canonical matching semantics for casting and generic argument matching. |
| src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj | Includes new canon helper files in the ILCompiler.TypeSystem build. |
| src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/CoreTestAssembly/GenericConstraints.cs | Adds new types used to test invariant interface constraints with canonical args. |
| src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/ConstraintsValidationTest.cs | Adds a new test suite validating canonical type behavior in constraint checking. |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/HandleCallAction.cs | Normalizes instantiated types before checking constraints in MakeGenericType dependency computation. |
| src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj | Includes the canon casting handler to satisfy CanCastToWithCanon usage. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
MichalStrehovsky
commented
Jun 12, 2026
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
MichalStrehovsky
commented
Jun 18, 2026
/ba-g windows arm64 timeouts are known |
Fixes#126604 First commit is a revert of the revert. The second commit is an update to the casting logic so that we can have both casting logic that treats `__Canon` as a `class __Canon : object` and nothing else (this is compatible with how casting in CoreCLR VM works), but also another casting logic that treats `__Canon` as "some reference type, could be something that does cast". Then update constraints check to use this flavor of the casting logic.
Fixes#126604
First commit is a revert of the revert.
The second commit is an update to the casting logic so that we can have both casting logic that treats
__Canonas aclass __Canon : objectand nothing else (this is compatible with how casting in CoreCLR VM works), but also another casting logic that treats__Canonas "some reference type, could be something that does cast". Then update constraints check to use this flavor of the casting logic.