[Async v2] Implement async method variant handling in AddMethod and UpdateMethod#125397
Open
tommcdon wants to merge 22 commits intodotnet:mainfrom
Open
[Async v2] Implement async method variant handling in AddMethod and UpdateMethod#125397tommcdon wants to merge 22 commits intodotnet:mainfrom
tommcdon wants to merge 22 commits intodotnet:mainfrom
Conversation
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
There was a problem hiding this comment.
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::AddMethodDescto accept async flags and an optional async-variant signature, and plumb that intoMethodTableBuilder::InitMethodDesc. - Add async return-type classification and async-variant creation logic to
EEClass::AddMethod. - Update
EditAndContinueModule::UpdateMethodto 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.
This was referenced Mar 10, 2026
jkotas
reviewed
Mar 11, 2026
76d4eb1 to
437f9ed
Compare
noahfalk
reviewed
Apr 2, 2026
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>
noahfalk
reviewed
Apr 3, 2026
noahfalk
reviewed
Apr 3, 2026
noahfalk
approved these changes
Apr 3, 2026
Member
noahfalk
left a comment
There was a problem hiding this comment.
Looks good 👍 Couple suggestions inline
jkotas
reviewed
Apr 5, 2026
Use GetAsyncOtherVariantNoCreate in UpdateMethod
Extract BuildAsyncVariantSignature to share async signature construction The async variant signature construction logic (stripping Task/ValueTask wrapper from the return type) was duplicated between MethodTableBuilder (initial type load) and EEClass::AddMethod (EnC add method). Extract it into a shared BuildAsyncVariantSignature helper in method.cpp. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
When adding a new async method to a generic type via EnC, the async variant MethodDesc was only created for the type definition but not for existing canonical instantiations. This caused crashes when the newly added async method was called on value type instantiations (e.g. G<int>) because the thunk could not find its async variant. Hoist the async variant signature and flags computation above the generic instantiation loop, then create the async variant for each canonical MethodTable alongside the primary thunk. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…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>
…VariantSignature Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ure async in EnC - Clarify GC violation comment to explain the specific unlikely scenario (naming collision + extern alias + hot reload while debugging) - Reject infrastructure async methods unconditionally in EnC rather than only on non-system modules, since no scenario benefits from allowing them Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…T_NOT_SUPPORTED - Rewrite GC violation comment per jkotas: the issue is unresolved TypeRef/AssemblyRef for Task/ValueTask, not type misidentification. System.Runtime is typically already resolved so this is unlikely. - Use CORDBG_E_ENC_EDIT_NOT_SUPPORTED instead of COR_E_BADIMAGEFORMAT for infrastructure async rejection, since this is an unsupported edit rather than malformed metadata. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Allocate the async variant signature from each instantiation's own LoaderAllocator instead of reusing the type definition's allocation. AddMethodDesc stores the signature as a raw pointer in AsyncMethodData, so it must be owned by the same allocator as the MethodDesc to avoid dangling pointers on collectible ALC unload. Also fix GC violation comment per jkotas feedback and use CORDBG_E_ENC_EDIT_NOT_SUPPORTED for infrastructure async rejection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Generic instantiations are guaranteed to have same or shorter lifetime than the method definition, so reusing the type definition's signature allocation is safe. Remove the unnecessary per-allocator copy. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Previously, AddMethod eagerly created async variant MethodDescs for all runtime-async methods added via EnC (on the type-def and every existing generic instantiation). This commit defers variant creation to the point of first use: - FindOrCreateAssociatedMethodDesc (genmeth.cpp): lazily creates the variant using double-check locking with m_InstMethodHashTableCrst, matching the existing NewInstantiatedMethodDesc pattern. - LoadTypicalMethodDefinition (method.cpp): triggers lazy creation when navigating from an instantiation variant back to the type-def variant. - AddAsyncVariant (class.cpp): new helper that computes the variant signature on-demand from metadata (ClassifyMethodReturnKind + BuildAsyncVariantSignature) rather than storing it on primary thunks. - ResetCodeEntryPointForEnC (method.cpp): gracefully handles the case where the variant has not been created yet (no-op). - InitMethodDesc (methodtablebuilder.cpp): restored original contract where only IsAsyncVariant methods store a signature. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
AddChunk publishes a new MethodDescChunk to a lock-free linked list that concurrent readers iterate without holding a lock. On weakly ordered architectures (ARM64), plain stores can be reordered, allowing a reader to see the new chunk pointer before the chunk's internal data (MethodDescs, flags, etc.) is fully visible. Use VolatileStore at both publish points (head and tail) to act as a release barrier, matching the pattern used elsewhere in the VM (e.g. dacenumerablehash.inl, codeversion.cpp, eehash.inl). This is a no-op on x86/x64 (strong memory model). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Gate ClassifyMethodReturnKind on IsMiAsync in AddMethod so non-async methods never hit the GC-triggering type resolution path. Updated comment to note EnC runs with threads suspended. - Fix redundant double-reset in UpdateMethod: ResetCodeEntryPointForEnC already cascades from thunk to IL-owning variant, so skip the explicit variant reset when pMethod is the thunk. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…avoidance Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The explicit reset of the paired async variant in UpdateMethod is dead code: UpdateMethod always receives the thunk (from the delta metadata token), so !IsAsyncThunkMethod() is always false and the block never fires. Even if it did, ResetCodeEntryPointForEnC already cascades from the thunk to the IL-owning variant automatically. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Consolidate the IsMiAsync handling into a single block with early return for non-task-returning methods, removing the intermediate isAsyncTaskReturning variable and separate if/else-if chain. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- AddAsyncVariant: replace standalone assert with runtime guard that returns COR_E_BADIMAGEFORMAT for non-task-returning methods in Release builds (assert inside for Debug). - FCAMD: gate lazy async variant creation on IsAsyncThunkMethod() to prevent calling AddAsyncVariant on non-async EnC methods. - GetChunks/GetNextChunk: pair VolatileStore in AddChunk with VolatileLoad on readers for proper acquire/release semantics on weak memory models. DAC paths use plain loads. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore the comment explaining that ClassifyMethodReturnKind matching by type name without verifying the assembly reference is a legitimate but corner case bug (extern alias + naming collision + hot reload), accepted as Won't Fix rather than claiming GC is safe in practice. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove pMDescInCanonMT->GetMethodTable() != pExactMT->GetCanonicalMethodTable() condition (always false since GetParallelMethodDesc searches the canonical MT). Replace with asserts to verify the invariant. - Update GC safety comment to acknowledge the ClassifyMethodReturnKind extern alias corner case as a legitimate Won't Fix bug. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- 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>
ec5469d to
fb41135
Compare
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.
This change implements a TODO item in
EEClass::AddMethodDescto support Runtime Async