Remove async method inlining restrictions in crossgen2#125472
Merged
jtschuster merged 23 commits intodotnet:mainfrom Apr 6, 2026
Merged
Remove async method inlining restrictions in crossgen2#125472jtschuster merged 23 commits intodotnet:mainfrom
jtschuster merged 23 commits intodotnet:mainfrom
Conversation
Remove four restrictions that prevented async methods from being inlined during ReadyToRun compilation: 1. CanInline() rejected IsAsyncThunk()/IsAsyncCall() callees 2. CrossModuleInlineableUncached() rejected async variants/thunks 3. reportInlining() threw when async methods were cross-module inlined 4. InliningInfoNode skipped recording inlining info for async thunks All 69 async tests pass with both crossgen2 and composite R2R modes. Fixes dotnet#124665 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
|
/azp run runtime-coreclr crossgen2 |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull request overview
Removes restrictions that prevented async methods from being inlined during ReadyToRun (crossgen2) compilation, fixing #124665.
Changes:
- Removed four separate guards that blocked inlining of async methods (thunks, variants, calls) in R2R compilation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| CorInfoImpl.ReadyToRun.cs | Removed exception throw for async method inlining |
| ReadyToRunCompilationModuleGroupBase.cs | Removed cross-module inlining restriction for async methods |
| ReadyToRunCodegenCompilation.cs | Removed CanInline restriction for async thunks/calls |
| InliningInfoNode.cs | Removed skip of async thunks in inlining info emission |
This was referenced Mar 12, 2026
Member
Author
|
/azp run runtime-coreclr crossgen2 |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
/azp run runtime-coreclr crossgen2 |
|
Azure Pipelines successfully started running 1 pipeline(s). |
When crossgen2 emits CHECK_IL_BODY fixups for cross-module inlined async methods (miAsync), the runtime crashes with a MayHaveILHeader() precondition failure. This happens because the runtime marks the original MethodDesc as an async thunk, and MayHaveILHeader() returns false for thunks. However, the IL bytes are still present at the method's RVA in the PE. Runtime fix: Add GetILHeaderForStandaloneMetadata() helper that bypasses MayHaveILHeader() for async thunk methods by accessing the IL directly via Module::GetIL(GetRVA()). Crossgen2 fix: Separate ILBodyFixupSignature into _ilMethod (EcmaMethod for IL body hash computation) and _signatureMethod (MethodDesc for method identity encoding), making the different roles explicit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Split GetModuleToken into GetILModuleToken (for IL hash and fixup module context) and GetSignatureModuleToken (for method identity encoding). Use _signatureMethod.GetTypicalMethodDefinition() for EmitMethodSignature so the correct method identity is encoded when IL source and signature method differ (e.g. runtime-async inlinees). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The IL and signature methods always resolve to the same module token, so a single GetModuleToken suffices. Add Debug.Assert that signatureMethod.GetPrimaryMethodDesc() == ilMethod to enforce the invariant that both refer to the same underlying EcmaMethod. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…gnature is created
In order to resolve the async method (which has a non-thunk IL body) from the CheckILBody fixup, separate out the signature MethodDesc from the IL providing MethodDesc inf ILBodyFixupSignature. The IL is retrieved for the EcmaMethod resolved from the _signatureMethod.GetPrimaryMethodDesc(), which is always an EcmaMethod for the TypicalMethodDefinitions allowed. At runtime, the correct method is resolved and the IL body is properly validated.
...ols/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRun/ILBodyFixupSignature.cs
Show resolved
Hide resolved
This was referenced Mar 31, 2026
Open
Member
Author
|
/azp run runtime-coreclr crossgen2 |
|
Azure Pipelines successfully started running 1 pipeline(s). |
davidwrighton
approved these changes
Apr 3, 2026
radekdoulik
pushed a commit
to radekdoulik/runtime
that referenced
this pull request
Apr 9, 2026
Remove restrictions that prevented async methods from being inlined during ReadyToRun compilation. All 69 async tests pass with both crossgen2 and composite R2R. Output of the src/tests/async/execution-context/execution-context.cs was validated manually to ensure inlining is happening for async calls to methods without awaits. In `Test()`, these two calls were inlined as expected. https://github.com/dotnet/runtime/blob/b7973489277b74bc5da9d36a0a2883eaa987328f/src/tests/async/execution-context/execution-context.cs#L110-L121 Fixes dotnet#124665 --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Remove restrictions that prevented async methods from being inlined during ReadyToRun compilation.
All 69 async tests pass with both crossgen2 and composite R2R.
Output of the src/tests/async/execution-context/execution-context.cs was validated manually to ensure inlining is happening for async calls to methods without awaits. In
Test(), these two calls were inlined as expected.runtime/src/tests/async/execution-context/execution-context.cs
Lines 110 to 121 in b797348
Fixes #124665