Fix dataflow analysis of lambdas in async methods#122450
Merged
MichalStrehovsky merged 1 commit intodotnet:mainfrom Dec 13, 2025
Merged
Fix dataflow analysis of lambdas in async methods#122450MichalStrehovsky merged 1 commit intodotnet:mainfrom
MichalStrehovsky merged 1 commit intodotnet:mainfrom
Conversation
When we enter ILLinker part of the ILC codebase, we need to switch to the mode where async variants don't exist and async methods have mismatched bodies. There was a spot where we didn't do the switch here: https://github.com/dotnet/runtime/blob/d31e5990b896447bfc3dbe98cfe6ec3b169a4896/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs#L939-L949 The fix is to do the switch early in `FlowAnnotations` so that the `ILProvider` `FlowAnnotations` use (and other parts take advantage of) is already ILLinkerified. Fixes the situation shown in the regression test (we were analyzing the IL of the async variant of `RuntimeAsyncWithLambda` and missed analyzing the lambda completely).
Contributor
|
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a dataflow analysis bug where lambdas inside async methods were not being properly analyzed. The issue occurred because the async IL masking transformation wasn't applied consistently across all dataflow analysis components.
- Centralized AsyncMaskingILProvider wrapping in FlowAnnotations constructor
- Removed duplicate wrapping from TypeAnnotationsHashtable and MethodBodyScanner
- Added regression test for lambda analysis in async methods
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs | Wraps the ILProvider with AsyncMaskingILProvider at construction time, ensuring all consumers use the masked version; removes duplicate wrapping from TypeAnnotationsHashtable |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/MethodBodyScanner.cs | Removes duplicate AsyncMaskingILProvider wrapping since FlowAnnotations now provides a pre-wrapped ILProvider |
| src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/RuntimeAsyncMethods.cs | Adds ExpectedNoWarnings attribute and new test case RuntimeAsyncWithLambda to verify lambdas in async methods are properly analyzed for dataflow warnings |
This was referenced Dec 11, 2025
jtschuster
approved these changes
Dec 12, 2025
MichalStrehovsky
added a commit
to MichalStrehovsky/runtime
that referenced
this pull request
Dec 17, 2025
To the same tune as dotnet#122450. This is a bug farm, as expected, but likely still better than trying to teach the code that is shared with ILLink and Roslyn analyzer about async variants.
MichalStrehovsky
added a commit
that referenced
this pull request
Dec 22, 2025
To the same tune as #122450. This is a bug farm, as expected, but likely still better than trying to teach the code that is shared with ILLink and Roslyn analyzer about async variants. Cc @dotnet/ilc-contrib
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.
When we enter ILLinker part of the ILC codebase, we need to switch to the mode where async variants don't exist and async methods have mismatched bodies. There was a spot where we didn't do the switch here:
runtime/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/UsageBasedMetadataManager.cs
Lines 939 to 949 in d31e599
The fix is to do the switch early in
FlowAnnotationsso that theILProviderFlowAnnotationsuse (and other parts take advantage of) is already ILLinkerified.Fixes the situation shown in the regression test (we were analyzing the IL of the async variant of
RuntimeAsyncWithLambdaand missed analyzing the lambda completely).Cc @dotnet/ilc-contrib