Handle canonical types in constraints checks#129278
Open
MichalStrehovsky wants to merge 3 commits into
Open
Conversation
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
Contributor
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. |
This was referenced Jun 11, 2026
Open
Member
Author
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This was referenced Jun 12, 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 #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.