-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Implement getAsyncInfo in ILCompiler #120859
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
base: main
Are you sure you want to change the base?
Conversation
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 implements the getAsyncInfo
callback in the ILCompiler's JIT interface to support async method compilation in ReadyToRun scenarios. The implementation aligns with CoreCLR's definition by expanding the CORINFO_ASYNC_INFO
structure and providing concrete field and method handle lookups.
Key Changes:
- Extended
CORINFO_ASYNC_INFO
structure with additional fields for async state management - Implemented the
getAsyncInfo
method to populate async continuation and context management handles - Added support for execution context capture/restore operations in async workflows
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs |
Extended CORINFO_ASYNC_INFO structure with new fields for Resume, State, Flags, execution context methods, and continuation context handling |
src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs |
Implemented getAsyncInfo method to populate async info structure with handles for Continuation class fields and AsyncHelpers methods |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This will change a bit after #120411 cc @jakobbotsch |
Yes, the shape of the info will change with "flat continuations". |
private void getAsyncInfo(ref CORINFO_ASYNC_INFO pAsyncInfoOut) | ||
{ | ||
throw new NotImplementedException(); | ||
DefType continuation = MethodBeingCompiled.Context.SystemModule.GetType("System.Runtime.CompilerServices"u8, "Continuation"u8); |
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.
(Same comment for all GetType
uses below.)
GetType
can return null and we'd nullref,GetKnownType
won't return null and will print a better error message if e.g. CoreLib is mismatched.- Nit: context is available through a non-virtual path on
_compilation.TypeSystemContext
.
DefType continuation = MethodBeingCompiled.Context.SystemModule.GetType("System.Runtime.CompilerServices"u8, "Continuation"u8); | |
DefType continuation = _compilation.TypeSystemContext.SystemModule.GetKnownType("System.Runtime.CompilerServices"u8, "Continuation"u8); |
pAsyncInfoOut.continuationsNeedMethodHandle = false; | ||
DefType asyncHelpers = MethodBeingCompiled.Context.SystemModule.GetType("System.Runtime.CompilerServices"u8, "AsyncHelpers"u8); | ||
DefType executionContext = MethodBeingCompiled.Context.SystemModule.GetType("System.Threading"u8, "ExecutionContext"u8); | ||
DefType @void = MethodBeingCompiled.Context.GetWellKnownType(WellKnownType.Void); |
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.
Doesn't seem used?
DefType continuation = MethodBeingCompiled.Context.SystemModule.GetType("System.Runtime.CompilerServices"u8, "Continuation"u8); | ||
pAsyncInfoOut.continuationClsHnd = ObjectToHandle(continuation); | ||
// 'Next' field | ||
pAsyncInfoOut.continuationNextFldHnd = ObjectToHandle(continuation.GetField("Next"u8)); |
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.
Also a better exception if corelib is mismatched (same comment for other GetField
below).
pAsyncInfoOut.continuationNextFldHnd = ObjectToHandle(continuation.GetField("Next"u8)); | |
pAsyncInfoOut.continuationNextFldHnd = ObjectToHandle(continuation.GetKnownField("Next"u8)); |
DefType executionContext = MethodBeingCompiled.Context.SystemModule.GetType("System.Threading"u8, "ExecutionContext"u8); | ||
DefType @void = MethodBeingCompiled.Context.GetWellKnownType(WellKnownType.Void); | ||
// Method handle for AsyncHelpers.CaptureExecutionContext | ||
pAsyncInfoOut.captureExecutionContextMethHnd = ObjectToHandle(asyncHelpers.GetMethod("CaptureExecutionContext"u8, null)); |
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.
pAsyncInfoOut.captureExecutionContextMethHnd = ObjectToHandle(asyncHelpers.GetMethod("CaptureExecutionContext"u8, null)); | |
pAsyncInfoOut.captureExecutionContextMethHnd = ObjectToHandle(asyncHelpers.GetKnownMethod("CaptureExecutionContext"u8, null)); |
I merged #120411 so as pointed out above the shape of |
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.
Needs to be adapted to #120411
Updates the definition of CORINFO_ASYNC_INFO to match CoreCLRs definition, and adds an implementation for the
getAsyncInfo
jit callback in ReadyToRun.