Fix Crossgen2 variance validation for type constraints - #132809
Open
jtschuster wants to merge 1 commit into
Open
Fix Crossgen2 variance validation for type constraints#132809jtschuster wants to merge 1 commit into
jtschuster wants to merge 1 commit into
Conversation
jtschuster
commented
Aug 27, 2026
| @@ -310,7 +309,7 @@ Task<bool> ValidateTypeWorkerHelper(TypeDesc typeToCheckForSkipValidation) | |||
|
|
|||
|
|
|||
| // Validate that generic variance is properly respected in method signatures | |||
| if (type.IsInterface && method.IsVirtual && !method.Signature.IsStatic && type.HasInstantiation) | |||
| if (type.IsInterface && type.HasInstantiation && (method.IsVirtual || !method.Signature.IsStatic)) | |||
Member
Author
There was a problem hiding this comment.
We should validate static virtuals and static abstract methods according the runtime's ECMA augments.
Do not apply method constraint variance rules to a generic type's own constraints. Validate static virtual interface method signatures and add coverage for emitting SkipTypeValidation for valid type constraints. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 87038ccf-f45b-40d3-a2d4-ee7d3d7f7a7f
jtschuster
force-pushed
the
fix-crossgen2-variance
branch
from
August 27, 2026 01:14
ae7c278 to
d2bf9a8
Compare
jtschuster
marked this pull request as ready for review
August 27, 2026 01:14
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Crossgen2’s ReadyToRun type validation logic to better match CoreCLR’s variance validation behavior and to avoid incorrectly rejecting valid generic type-parameter constraints, and adds a regression test to prevent future regressions.
Changes:
- Removes variance validation for a generic type’s own parameter constraints (leaving constraint usage unrestricted as intended).
- Aligns interface method signature variance validation with the VM by validating all instance methods and all virtual methods (including static virtual/abstract).
- Adds a ReadyToRun regression test covering the reported “variant type parameter used in a type-owned constraint” pattern.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeValidationChecker.cs | Fixes variance validation rules to match VM behavior and avoids invalid checks on type-owned constraints. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/TypeValidation/GenericTypeConstraints.cs | Adds a minimal source test case that exercises the constraint + variance pattern. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cs | Adds a test that runs Crossgen2 with automatic type validation and asserts the resulting image sets READYTORUN_FLAG_SkipTypeValidation. |
This was referenced Aug 27, 2026
Open
davidwrighton
approved these changes
Aug 27, 2026
jkoritzinsky
approved these changes
Aug 27, 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.
Summary
Crossgen2 applied method generic-constraint variance rules to a generic type's own constraints. ECMA-335 II.9.7 explicitly leaves type-owned constraints unrestricted, so valid variant interfaces could fail automatic validation and omit
READYTORUN_FLAG_SkipTypeValidation.This change:
Fixes #132724
Note
This pull request was created with GitHub Copilot.