Skip to content

[Async v2] Implement async method variant handling in AddMethod and UpdateMethod#125397

Merged
tommcdon merged 29 commits intodotnet:mainfrom
tommcdon:dev/tommcdon/implement_addmethoddesc
Apr 23, 2026
Merged

[Async v2] Implement async method variant handling in AddMethod and UpdateMethod#125397
tommcdon merged 29 commits intodotnet:mainfrom
tommcdon:dev/tommcdon/implement_addmethoddesc

Conversation

@tommcdon
Copy link
Copy Markdown
Member

This change implements a TODO item in EEClass::AddMethodDesc to support Runtime Async

@tommcdon tommcdon added this to the 11.0.0 milestone Mar 10, 2026
@tommcdon tommcdon self-assigned this Mar 10, 2026
Copilot AI review requested due to automatic review settings March 10, 2026 18:34
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
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 implements runtime-async method variant support in the Edit-and-Continue (EnC) path by extending EEClass::AddMethodDesc/EEClass::AddMethod to carry async metadata (flags + optional alternate signature) and by updating EnC method update logic to consider async method variants.

Changes:

  • Extend EEClass::AddMethodDesc to accept async flags and an optional async-variant signature, and plumb that into MethodTableBuilder::InitMethodDesc.
  • Add async return-type classification and async-variant creation logic to EEClass::AddMethod.
  • Update EditAndContinueModule::UpdateMethod to also reset the entrypoint for the method’s async counterpart.

Reviewed changes

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

File Description
src/coreclr/vm/encee.cpp Resets entrypoints for async counterparts during EnC method updates.
src/coreclr/vm/class.h Extends AddMethodDesc signature to accept async flags and optional async signature.
src/coreclr/vm/class.cpp Implements async return classification and passes async flags/signature into EnC-added MethodDesc creation.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/coreclr/vm/class.cpp
Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/encee.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
@tommcdon tommcdon force-pushed the dev/tommcdon/implement_addmethoddesc branch from 76d4eb1 to 437f9ed Compare March 20, 2026 20:08
@tommcdon tommcdon marked this pull request as ready for review March 20, 2026 20:09
Copilot AI review requested due to automatic review settings March 20, 2026 20:09
Copy link
Copy Markdown
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 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/class.cpp
Comment thread src/coreclr/vm/encee.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/encee.cpp
tommcdon added a commit to tommcdon/runtime that referenced this pull request Apr 3, 2026
…ejection, generic UpdateMethod comment

- class.cpp:579: Update GC violation comment to acknowledge the
  extern-alias edge case as Won't Fix per reviewer feedback
- class.cpp:597: Reject infrastructure async methods (IsMiAsync but
  not task-returning) on non-system modules with COR_E_BADIMAGEFORMAT,
  mirroring MethodTableBuilder validation
- encee.cpp:388: Add comment explaining that ResetCodeEntryPointForEnC
  cascades from thunk to async variant automatically, so generic
  UpdateMethod path does not need explicit async variant handling

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 3, 2026 00:50
Copy link
Copy Markdown
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 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/vm/method.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
Copy link
Copy Markdown
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍 Couple suggestions inline

Copilot AI review requested due to automatic review settings April 4, 2026 23:20
Copy link
Copy Markdown
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 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
Copilot AI review requested due to automatic review settings April 5, 2026 02:41
tommcdon and others added 2 commits April 16, 2026 20:15
- Update AsyncVariantLookup enum values: AsyncOtherVariant -> Async,
  MatchingAsyncVariant -> Ordinary
- Update ClassifyMethodReturnKind calls to pass new elementTypeLength param
- Update FindOrCreateAssociatedMethodDesc call to match new parameter order
  (AsyncVariantLookup moved before forceRemotableMethod)
- Update debugger.cpp: HasAsyncOtherVariant -> IsAsyncThunkMethod,
  GetAsyncOtherVariantNoCreate -> GetAsyncVariantNoCreate
- Add missing variable declarations in methodtablebuilder.cpp
- Remove tautological assert in FCAMD lazy creation block

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…cation

Reverts the unnecessary variable declaration reordering in
EnumerateClassMethods that fell out of the rebase conflict resolution.
Keeps the improved comment in InitMethodDesc that clarifies primary
thunks use the original metadata signature and do not store one.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 17, 2026 01:11
@tommcdon tommcdon force-pushed the dev/tommcdon/implement_addmethoddesc branch from ec5469d to fb41135 Compare April 17, 2026 01:11
Copy link
Copy Markdown
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 9 out of 9 changed files in this pull request and generated no new comments.

Instead of lazily creating async variant MethodDescs in
FindOrCreateAssociatedMethodDesc, create them eagerly alongside the
primary thunk in EEClass::AddMethod. The variant signature is computed
once from metadata and then AddMethodDesc (GC_NOTRIGGER) creates both
MethodDescs. For generic types, each existing instantiation gets its
own sig copy from its loader allocator.

This eliminates:
- Lazy creation block in FCAMD (double-check locking, GCX_COOP, lock)
- LoadTypicalMethodDefinition fallback for async variants
- EEClass::AddAsyncVariant helper (no longer needed)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/method.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/debug/ee/debugger.cpp Outdated
Comment thread src/coreclr/debug/ee/debugger.cpp Outdated
tommcdon and others added 3 commits April 21, 2026 11:15
Previously AddMethod only created async variants for IsMiAsync methods.
Normal type loading (MethodTableBuilder::EnumerateClassMethods) creates
variants for all task-returning methods regardless of IsMiAsync. This
change aligns EnC with that behavior:

- IsMiAsync: primary is thunk, async variant owns the IL
- Non-IsMiAsync: primary owns IL, async variant is a thunk

Also removes per-instantiation signature copy for generic types since
instantiations cannot have longer lifetime than the definition.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace inline NonGenericTask and GenericTask signature rewriting in
MethodTableBuilder::EnumerateClassMethods with calls to the shared
BuildAsyncVariantSignature function. The ReturnDroppingThunk case
(rare covariant override scenario) remains inline since it has
unique logic not applicable to the EnC path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
For task-returning methods with async variants, detect when the primary
MethodDesc is a thunk and switch to the async variant that owns the user
code before planting remap breakpoints. This eliminates the duplicated
breakpoint-planting loop that previously handled the async variant
separately.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 16:33
Copy link
Copy Markdown
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 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/coreclr/vm/class.cpp Outdated
Comment thread src/coreclr/vm/class.cpp
Comment thread src/coreclr/debug/ee/debugger.cpp Outdated
Comment thread src/coreclr/vm/genmeth.cpp Outdated
Comment thread src/coreclr/vm/methodtablebuilder.cpp
Comment thread src/coreclr/vm/class.cpp
Comment thread src/coreclr/vm/genmeth.cpp Outdated
Comment thread src/coreclr/vm/class.cpp Outdated
tommcdon and others added 3 commits April 23, 2026 14:35
Per reviewer feedback, inline the sig construction directly in
EEClass::AddMethod instead of using a shared BuildAsyncVariantSignature
function. Remove the function from method.cpp/method.hpp. Revert all
changes to genmeth.cpp and methodtablebuilder.cpp as no modifications
are needed in the normal type loading path for the EnC feature.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Per reviewer feedback, return S_OK instead of falling through when
GetAsyncVariantNoCreate() returns NULL for an async thunk. There is
no user code to plant remap breakpoints on in this case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Re-add comment explaining the Won't Fix corner cases around the
CONTRACT_VIOLATION(GCViolation) in EnC async variant creation:
type identity may not match well-known types, and the call may
trigger GC even for well-known types.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@tommcdon
Copy link
Copy Markdown
Member Author

/ba-g failures are pre-existing/unrelated

@tommcdon tommcdon merged commit bd6bb0d into dotnet:main Apr 23, 2026
104 of 109 checks passed
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.

5 participants