Repository navigation
Fix NativeAOT dispatch to covariant return GVM overrides - #137707
Merged
MichalStrehovsky merged 5 commits intoNov 24, 2026
Merged
MichalStrehovsky merged 5 commits into
MichalStrehovsky merged 5 commits into
Conversation
A C# covariant return override of a generic virtual method is emitted as a newslot virtual method with a MethodImpl pointing at the base slot. Such a method is its own slot defining method, so EETypeNode.AnalyzeVirtualMethods did not mark the type as interesting for dynamic dependency analysis. As a result GVMDependenciesNode never resolved the base GVM on that type and the override body (or its async variant / return dropping thunk) was never compiled. At runtime the call either went to the base implementation or failed fast with "Failed to create generic virtual method implementation". Also consider non-interface MethodImpls with a generic body when computing InterestingForDynamicDependencies. Co-authored-by: Copilot App <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 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
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
Abstract bodies have no code to compile, so they don't make a type interesting for dynamic GVM analysis. Co-authored-by: Copilot App <[email protected]>
After the MethodImpl check sets InterestingForDynamicDependencies, all flags are set and the interface scan can't add anything. Co-authored-by: Copilot App <[email protected]>
…erride Co-authored-by: Copilot App <[email protected]>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the NativeAOT generic covariant dispatch changes.
No open issues 🎉
What changed in this PR
This PR fixes NativeAOT dispatch to covariant-return generic virtual method overrides that are reachable only through a base slot. It extends dependency discovery so those override implementations are compiled.
Changes:
- Recognizes concrete generic MethodImpl bodies when selecting types for dynamic dependency analysis.
- Adds NativeAOT smoke coverage for class and interface dispatch, generic types, shared code, and awaited calls.
- Adds type-system tests for resolving generic covariant overrides across inheritance chains.
| File | Description |
|---|---|
src/tests/nativeaot/SmokeTests/UnitTests/Generics.cs |
Adds and registers covariant generic virtual dispatch regression scenarios. |
src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/VirtualFunctionOverrideTests.cs |
Tests override resolution for generic definitions and instantiated methods. |
src/coreclr/tools/aot/ILCompiler.TypeSystem.Tests/CoreTestAssembly/VirtualFunctionOverride.cs |
Adds generic covariant methods to existing inheritance fixtures. |
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs |
Includes MethodImpl-based generic overrides in dynamic dependency discovery. |
Review effort: Balanced
Co-authored-by: Copilot App <[email protected]>
MichalStrehovsky
approved these changes
Nov 20, 2026
This was referenced Nov 20, 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.
In NativeAOT, a C# covariant-return override of a generic virtual method is not called when the override is only reachable through the base slot. The call goes to the base implementation, or hits a FailFast ("Failed to create generic virtual method implementation"). CoreCLR behaves correctly.
Roslyn emits covariant overrides as
newslotwith a.overrideMethodImpl, so the override is its own slot-defining method.EETypeNode.AnalyzeVirtualMethodsonly marks a type as interesting for dynamic GVM dependency analysis when one of its GVMs has a different slot-defining method, so these types never reachGVMDependenciesNode.SearchDynamicDependenciesand the override bodies are never compiled. The fix also marks types whose non-interface MethodImpls have a generic body.Added a NativeAOT smoke test: it fails without the fix (15 scenarios: class, interface, generic types, shared code, awaited calls) and passes with it. Also added TypeSystem tests for resolving generic covariant overrides.
Note
This PR description was generated with GitHub Copilot.