Virtual methods with runtime async#121443
Merged
MichalStrehovsky merged 4 commits intodotnet:mainfrom Nov 8, 2025
Merged
Conversation
This makes virtual methods work with runtime async. Depends on dotnet#121438. Runtime async methods can be virtually called two ways: as Task-returning, or as runtime-async. We can even end up in situation where Task-returning non-runtime-async virtual methods get called as runtime-async. The easiest way to solve this is to give each Task-returning method two separate virtual slots. We still track the slot use so unused slots will not get generated. The `VirtualMethodAlgorithm` abstraction that we added for universal shared generics comes in handy because it lets us centralize where all of this work happens. As a result, we don't need to teach pretty much any node dealing with virtuals about runtime async, it just falls out. This doesn't make generic virtual methods yet, those need more fixes.
Contributor
|
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the compiler type system context to support async-aware virtual method resolution. The key changes introduce a custom AsyncAwareVirtualMethodResolutionAlgorithm that handles async variant methods during virtual method dispatch, replacing the basic MetadataVirtualMethodAlgorithm in the AOT compilation path while maintaining the simple algorithm for ReadyToRun.
Key Changes:
- Implements async-aware virtual method resolution algorithm that properly handles async variant methods during virtual dispatch
- Adds support for EmitAsyncMethodThunk to generate thunks for async calling conventions
- Fixes the
IsAsyncVariantextension method to properly check method definitions
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| ReadyToRunCompilerContext.cs | Adds MetadataVirtualMethodAlgorithm field to ReadyToRun compiler context partial class |
| CompilerTypeSystemContext.Aot.cs | Adds AsyncAwareVirtualMethodResolutionAlgorithm field initialization for AOT scenarios |
| CompilerTypeSystemContext.cs | Removes the base MetadataVirtualMethodAlgorithm field (moved to specific contexts) |
| CompilerTypeSystemContext.Async.cs | Implements AsyncAwareVirtualMethodResolutionAlgorithm and GetTargetOfAsyncVariantMethod helper |
| AsyncThunks.cs | Adds EmitAsyncMethodThunk method to generate async thunks (currently throws NotSupportedException) |
| NativeAotILProvider.cs | Replaces TODO with call to EmitAsyncMethodThunk for async variant implementations |
| AsyncMethodVariant.cs | Fixes IsAsyncVariant to check method definition instead of instance type |
jtschuster
reviewed
Nov 7, 2025
This was referenced Nov 7, 2025
Open
Member
|
Failures look related |
Member
Author
|
/ba-g android timeouts |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This makes virtual methods work with runtime async. Depends on #121438.
Runtime async methods can be virtually called two ways: as Task-returning, or as runtime-async. We can even end up in situation where Task-returning non-runtime-async virtual methods get called as runtime-async.
The easiest way to solve this is to give each Task-returning method two separate virtual slots. We still track the slot use so unused slots will not get generated.
The
VirtualMethodAlgorithmabstraction that we added for universal shared generics comes in handy because it lets us centralize where all of this work happens. As a result, we don't need to teach pretty much any node dealing with virtuals about runtime async, it just falls out.This doesn't make generic virtual methods yet, those need more fixes.
Cc @dotnet/ilc-contrib