-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Insert a set of known types and methods references necessary for async thunks into the mutable module #121679
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
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 adds infrastructure to insert references for known types and methods required by async thunks into the mutable module. This is preparatory work for supporting async methods in ReadyToRun compilation, though async method compilation remains disabled due to unresolved issues with AsyncMethodVariant.GetTypicalMethodDefinition.
Key Changes
- Added
AddingReferencesToR2RKnownTypesAndMethodsflag to MutableModule to allow adding references to known async-related types/methods - Implemented
InitializeKnownMethodsAndTypes()to populate known async-related types and methods from System.Private.CoreLib into the mutable module - Updated assertion logic to handle references to these known types/methods that exist outside the version bubble
- Added early exit for async variant methods in compilation (they remain unsupported for now)
- Refactored AsyncThunks.cs to declare exception type earlier for use in catch region definition
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/TypeSystem/Mutable/MutableModule.cs | Added AddingReferencesToR2RKnownTypesAndMethods flag and updated assertion to allow references during async type/method initialization |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs | Added early exit for async variants and updated token resolution logic to handle known mutable module types/methods |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/ILCompiler.ReadyToRun.csproj | Added project references to async stub files (AsyncThunks.cs, AsyncResumptionStub.cs and related files) |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/IL/ReadyToRunILProvider.cs | Added resolver parameter to InitManifestMutableModule and removed assertion that blocked async variants |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs | Updated InitManifestMutableModule call to pass the Resolver parameter |
| src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs | Implemented InitializeKnownMethodsAndTypes() to populate known async types/methods and added helper methods to check if types/methods are in the known set |
| src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncThunks.cs | Moved exception type declaration earlier to be accessible for catch region creation |
...ools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs
Outdated
Show resolved
Hide resolved
...ools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs
Outdated
Show resolved
Hide resolved
...ools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs
Outdated
Show resolved
Hide resolved
...ools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs
Outdated
Show resolved
Hide resolved
...ools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs
Outdated
Show resolved
Hide resolved
...ools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs
Outdated
Show resolved
Hide resolved
|
This is effectively creating an alternative scheme for encoding ReadyToRunHelper ( runtime/src/coreclr/inc/readytorun.h Line 307 in 0b9d2cc
I expect that we will use it for encoding higher-level helpers outside async too. For example, it would be fairly natural to use it to encode |
...ools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ModuleTokenResolver.cs
Outdated
Show resolved
Hide resolved
|
Just curious - what made you switch from the metadata encoding to the encoding via ReadyToRunHelper enum? |
Maybe I misunderstood, but I thought you were recommending this in your other comments. |
…c thunks to be inlined.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/ReadyToRunCodegenCompilation.cs
Outdated
Show resolved
Hide resolved
MichalStrehovsky
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.
This looks good to me modulo the questions, but ideally someone who knows about GetModuleTokenForMethod should have a look too.
Async thunk IL references methods and types that may not have MethodRef or TypeRef tokens in the assembly being crossgen'ed. There are some assertions to validate that any references in "faux il" version with the assembly, which isn't true for these types and methods. To work around this, we can inject these references into the mutable module, a synthetic module added to the assembly for things like this. When trying to compile an async thunk method, we check to see if all the required methods are already in the mutable module. If not, we note which methods need to be added during the single-threaded execution, and queue the method for recompilation next iteration.