Skip to content

JIT: Create suspensions/resumptions separately from processing calls in async transformation#125497

Merged
jakobbotsch merged 9 commits intodotnet:mainfrom
jakobbotsch:refactor-async-suspension-layouts
Mar 16, 2026
Merged

JIT: Create suspensions/resumptions separately from processing calls in async transformation#125497
jakobbotsch merged 9 commits intodotnet:mainfrom
jakobbotsch:refactor-async-suspension-layouts

Conversation

@jakobbotsch
Copy link
Member

This refactors the async transformation to collect all continuation information before generating the suspensions/resumptions themselves. This allows reusing continuation layouts across multiple suspension points and will allow experimenting with strategies where we only allocate one continuation, and then reuse it for all future suspensions.

Some minor diffs expected where locals are allocated in different orders, leading to different stack frame encodings.

Copilot AI review requested due to automatic review settings March 12, 2026 14:37
@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 12, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
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 refactors CoreCLR JIT async transformation so it first collects continuation requirements (live locals, optional fields, return shapes) and then materializes suspension/resumption blocks and continuation layouts afterwards, enabling future sharing/reuse of continuation layouts across multiple suspension points.

Changes:

  • Add a const overload for jitstd::vector::data() to support const access patterns introduced by the refactor.
  • Introduce ContinuationLayoutBuilder, AsyncState, and new return-shape tracking (ReturnTypeInfo/ReturnInfo) to decouple “what’s needed” from “how it’s laid out/encoded”.
  • Delay creation of suspension/resumption IR until all states are recorded (CreateResumptionsAndSuspensions), and update layout/materialization logic to use per-state “sub-layout” membership checks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/coreclr/jit/jitstd/vector.h Adds const T* data() const needed for new const usage patterns (e.g., binary search over const vectors).
src/coreclr/jit/async.h Introduces builder/state/layout refactor types (ContinuationLayoutBuilder, AsyncState, return info structs) and updates AsyncTransformation plumbing accordingly.
src/coreclr/jit/async.cpp Implements the new builder-based workflow, delayed IR creation, return-slot handling, and layout finalization (including GC bitmap/type allocation).

Copilot AI review requested due to automatic review settings March 12, 2026 14:47
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

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

Copilot AI review requested due to automatic review settings March 12, 2026 16:41
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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (2)

src/coreclr/jit/async.cpp:1

  • ContinuationLayoutBuilder::Create() declares a local ClassLayout* layout; inside the locals loop, which shadows the outer ContinuationLayout* layout variable. This is very error-prone and (depending on the exact code as compiled) can lead to passing the wrong layout pointer type/value into bitmapBuilder.SetType(...), producing an incorrect GC bitmap (or even a compile-time type mismatch if overloads differ). Rename one of these variables (e.g., ContinuationLayout* contLayout for the outer one and ClassLayout* structLayout for the per-local layout), and ensure SetType receives the per-local ClassLayout* for structs (and nullptr otherwise).
// Licensed to the .NET Foundation under one or more agreements.

src/coreclr/jit/async.cpp:1

  • FillInDataOnSuspension gates OSR IL offset emission on the compiler OSR/patchpoint checks instead of the already-computed subLayout.NeedsOSRILOffset() (used elsewhere for flags). Using subLayout.NeedsOSRILOffset() here would keep the logic consistent with the builder’s decisions and reduce the chance of future divergence as layout-sharing strategies evolve.
// Licensed to the .NET Foundation under one or more agreements.

@jakobbotsch jakobbotsch marked this pull request as ready for review March 12, 2026 19:33
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

Minor diffs. Only because some things are happening in different orders and that results in different local allocation order, leading to different stack frame encodings. Otherwise this shouldn't have functional changes.

Looks like superpmi-diffs is broken. I can take a look tomorrow.

@jakobbotsch
Copy link
Member Author

/ba-g Deadletter and missing SPMI collection due to azdo pool issue

@jakobbotsch jakobbotsch merged commit 0f80728 into dotnet:main Mar 16, 2026
134 of 143 checks passed
@jakobbotsch jakobbotsch deleted the refactor-async-suspension-layouts branch March 16, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI runtime-async

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants