Uh oh!
There was an error while loading. Please reload this page.
[release/11.0-rc1] Fix Crossgen2 variance validation for type constraints - #133117
Open
jtschuster wants to merge 2 commits into
Open
[release/11.0-rc1] Fix Crossgen2 variance validation for type constraints#133117jtschuster wants to merge 2 commits into
jtschuster wants to merge 2 commits into
Conversation
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: - removes the invalid variance check for type-owned generic constraints - aligns interface method signature validation with the VM by checking all instance methods and virtual methods, including static virtual and static abstract declarations - adds a ReadyToRun regression test based on the reported constraint pattern Fixesdotnet#132724 > [!NOTE] > This pull request was created with GitHub Copilot.
Retain the release/11.0-rc1 test condition while backporting the generic variance regression. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 142b5bce-0d17-49b6-95b8-3e4f236c1dd6
|
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.
🟢 Approval recommended
The behavioral change is narrowly scoped, matches the CoreCLR loader’s documented variance-check condition, and includes a targeted regression test for the reported scenario.
Pull request overview
Backport to release/11.0-rc1 that corrects Crossgen2 ReadyToRun type validation so generic variance rules are applied consistently with the CoreCLR type loader—specifically avoiding variance checks on a generic type’s own constraints while still validating interface method signatures appropriately.
Changes:
- Adjust interface method-signature variance validation to match the runtime’s rule: validate all instance methods and virtual methods, while skipping non-virtual static methods.
- Remove variance validation for a generic type’s own parameter constraints (per ECMA-335 II.9.7) to avoid false validation errors and preserve
READYTORUN_FLAG_SkipTypeValidation. - Add a ReadyToRun regression test that asserts the generated image sets
READYTORUN_FLAG_SkipTypeValidationfor the reported constraint pattern.
File summaries
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeValidationChecker.cs | Aligns Crossgen2 variance validation rules with the runtime (method-signature condition) and removes invalid variance checking on type-owned constraints. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/TypeValidation/GenericTypeConstraints.cs | New minimal source for the constraint/variance pattern used by the regression test. |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cs | Adds a regression test asserting the R2R header retains SkipTypeValidation under automatic validation. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Lite
This was referenced Sep 3, 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 freeto 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.
Backport of #132809 to release/11.0-rc1
Customer Impact
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, disabling the perf optimization.
This change:
Fixes#132724
Regression
Yes. #120459 introduced the regression.
Testing
A new test was added to ILCompiler.ReadyToRun.Tests that reproduced the issue. The test passes with the changes.
Risk
Low. The change makes the validation match the ECMA spec and matches the validation in the runtime.