-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Virtual methods with runtime async #121443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
|
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
|
Failures look related |
jkotas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
/ba-g android timeouts |
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