Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

Before we start generating native code using RyuJIT, we do an IL scanning pass where we build the whole program view. The whole program view builds a dependency graph that is similar to the one we create during code generation.

Instead of generating code, we look at method IL and generate whatever dependency nodes are going to be needed for real codegen (ConstructedEETypeNode for newobj, more scanned method nodes for calls, etc.).

This PR adds support for scanning methods that compile into state machine. It also suppresses some of the whole program optimizations around the special Continuation type.

Cc @dotnet/ilc-contrib (@jakobbotsch for the impMatchTaskAwaitPattern copy)

Before we start generating native code using RyuJIT, we do an IL scanning pass where we build the whole program view. The whole program view builds a dependency graph that is similar to the one we create during code generation.

Instead of generating code, we look at method IL and generate whatever dependency nodes are going to be needed for real codegen (ConstructedEETypeNode for newobj, more scanned method nodes for calls, etc.).

This PR adds support for scanning methods that compile into state machine. It also suppresses some of the whole program optimizations around the special `Continuation` type.
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a 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 support for runtime async in the IL scanner phase of Native AOT compilation. The scanner builds a whole program view by analyzing method IL and generating dependency nodes before actual code generation begins.

Key Changes:

  • Added pattern matching to detect task await patterns in async methods during IL scanning
  • Introduced infrastructure to track and add async-related dependencies (continuation types, async helpers, resumption stubs)
  • Refactored continuation type access to use a centralized property to improve code maintainability

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
ILImporter.Scanner.cs Implements async pattern detection (MatchTaskAwaitPattern) and adds dependencies for async infrastructure when scanning calls to async methods from async state machines
ILScanner.cs Prevents devirtualization optimizations on continuation types since they're dynamically generated and not well tracked
CorInfoImpl.cs Refactors to use the new centralized ContinuationType property instead of directly calling GetKnownType
CompilerTypeSystemContext.Async.cs Introduces public ContinuationType property for centralized access to the base continuation type and refactors internal hashtable to use it

@MichalStrehovsky
Copy link
Member Author

@dotnet/ilc-contrib this is ready for another round of reviews. This might be the last thing we need to start running src/tests/async (I do have the async tree passing locally already).

@jkotas
Copy link
Member

jkotas commented Nov 18, 2025

@jakobbotsch Could you please review that this matches the JIT importer behavior? (Also, any changes in that behavior will need to be reflected here going forward.)

@MichalStrehovsky MichalStrehovsky merged commit 1395bb6 into dotnet:main Nov 19, 2025
94 of 96 checks passed
@MichalStrehovsky MichalStrehovsky deleted the optimizedasync branch November 19, 2025 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants