Uh oh!
There was an error while loading. Please reload this page.
Fix Crossgen2 variance validation for type constraints - #132809
Conversation
Uh oh!
There was an error while loading. Please reload this page.
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
ae7c278 to
d2bf9a8Compare|
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. |
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. |
jtschuster
commented
Sep 2, 2026
/ba-g failures unrelated |
Uh oh!
There was an error while loading. Please reload this page.
jtschuster
commented
Sep 2, 2026
/backport to release/11.0-rc1 |
Started backporting to |
jtschuster
commented
Sep 2, 2026
/backport to release/10.0 |
Started backporting to |
@jtschuster backporting to git am output$ git cherry-pick 65c1f69d9fe4758690ed0d3cedaba0aed2fadd6fAuto-merging src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.csCONFLICT (content): Merge conflict in src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cserror: could not apply 65c1f69d9fe... Fix Crossgen2 variance validation for type constraints (#132809)hint: After resolving the conflicts, mark them withhint: "git add/rm <pathspec>", then runhint: "git cherry-pick --continue".hint: You can instead skip this commit with "git cherry-pick --skip".hint: To abort and get back to the state before "git cherry-pick",hint: run "git cherry-pick --abort".hint: Disable this message with "git config set advice.mergeConflict false"
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patchApplying: Fix Crossgen2 variance validation for type constraintsUsing index info to reconstruct a base tree...M src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.csFalling back to patching base and 3-way merge...Auto-merging src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.csCONFLICT (content): Merge conflict in src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cserror: Failed to merge in the changes.hint: Use 'git am --show-current-patch=diff' to see the failed patchhint: When you have resolved this problem, run "git am --continue".hint: If you prefer to skip this patch, run "git am --skip" instead.hint: To restore the original branch and stop patching, run "git am --abort".hint: Disable this message with "git config set advice.mergeConflict false"Patch failed at 0001 Fix Crossgen2 variance validation for type constraintsError: The process '/usr/bin/git' failed with exit code 128 |
@jtschuster backporting to git am output$ git cherry-pick 65c1f69d9fe4758690ed0d3cedaba0aed2fadd6fCONFLICT (modify/delete): src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cs deleted in HEAD and modified in 65c1f69d9fe (Fix Crossgen2 variance validation for type constraints (#132809)). Version 65c1f69d9fe (Fix Crossgen2 variance validation for type constraints (#132809)) of src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cs left in tree.Auto-merging src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeValidationChecker.cserror: could not apply 65c1f69d9fe... Fix Crossgen2 variance validation for type constraints (#132809)hint: After resolving the conflicts, mark them withhint: "git add/rm <pathspec>", then runhint: "git cherry-pick --continue".hint: You can instead skip this commit with "git cherry-pick --skip".hint: To abort and get back to the state before "git cherry-pick",hint: run "git cherry-pick --abort".hint: Disable this message with "git config set advice.mergeConflict false"
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patchApplying: Fix Crossgen2 variance validation for type constraintsUsing index info to reconstruct a base tree...A src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.csM src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeValidationChecker.csFalling back to patching base and 3-way merge...CONFLICT (modify/delete): src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cs deleted in HEAD and modified in Fix Crossgen2 variance validation for type constraints. Version Fix Crossgen2 variance validation for type constraints of src/coreclr/tools/aot/ILCompiler.ReadyToRun.Tests/TestCases/R2RTestSuites.cs left in tree.Auto-merging src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/TypeValidationChecker.cserror: Failed to merge in the changes.hint: Use 'git am --show-current-patch=diff' to see the failed patchhint: When you have resolved this problem, run "git am --continue".hint: If you prefer to skip this patch, run "git am --skip" instead.hint: To restore the original branch and stop patching, run "git am --abort".hint: Disable this message with "git config set advice.mergeConflict false"Patch failed at 0001 Fix Crossgen2 variance validation for type constraintsError: The process '/usr/bin/git' failed with exit code 128 |
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.