-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Long-lived AsyncMethodVariant in MethodWithGCInfo/MethodWithToken #121357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MichalStrehovsky
merged 18 commits into
dotnet:main
from
jtschuster:LongAsyncMethodVariant
Nov 5, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8ed26f2
Checkout AsyncThunkMethodDescs branch
jtschuster a7e3d25
Make AsyncMethodVariant long-lived
jtschuster d94de0c
Implement GetMethodDefinition, etc on AsyncMethodVariant
jtschuster ca5829b
Undo changes to InstantiatedMethod.cs
jtschuster 8a0e756
Remove unnecessary API surfaces, undo deopt
jtschuster 14d29fe
Remove AsyncMethodKind, use different AsyncMethodVariantFactory
jtschuster a1901e4
Other misc cleanup
jtschuster 2dc6b2b
Undo extra change in MethodForInstantiatedType.cs
jtschuster d013145
Undo extra changes
jtschuster bc82b74
Remove extra newline
jtschuster fc9532d
Undo extra changes
jtschuster 3cf7d3b
PR Feedback
jtschuster 4a6dda7
Revert extra changes
jtschuster 846d99e
Update src/coreclr/tools/Common/Compiler/AsyncMethodVariant.cs
jkotas 11eb284
Merge branch 'LongAsyncMethodVariant' of https://github.com/jtschuste…
jtschuster f3729ae
Forgot to save this file, revert sln changes.
jtschuster dd7380d
isAsyncCallConv -> isAsyncCall
jtschuster 975aacd
Update comments for CORINFO_CALLCONV_ASYNCCALL
jtschuster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Diagnostics; | ||
| using Internal.TypeSystem; | ||
| using Internal.TypeSystem.Ecma; | ||
|
|
||
| namespace ILCompiler | ||
| { | ||
| /// <summary> | ||
| /// MethodDesc that represents async calling convention entrypoint of a Task-returning method. | ||
| /// </summary> | ||
| public partial class AsyncMethodVariant : MethodDelegator | ||
| { | ||
| private MethodSignature _asyncSignature; | ||
|
|
||
| public AsyncMethodVariant(EcmaMethod wrappedMethod) | ||
| : base(wrappedMethod) | ||
| { | ||
| Debug.Assert(wrappedMethod.Signature.ReturnsTaskOrValueTask()); | ||
| } | ||
|
|
||
| public EcmaMethod Target => (EcmaMethod)_wrappedMethod; | ||
|
|
||
| public override MethodSignature Signature | ||
| { | ||
| get | ||
| { | ||
| return _asyncSignature ?? InitializeSignature(); | ||
| } | ||
| } | ||
|
|
||
| private MethodSignature InitializeSignature() | ||
| { | ||
| var signature = _wrappedMethod.Signature; | ||
| Debug.Assert(!signature.IsAsyncCall); | ||
| Debug.Assert(signature.ReturnsTaskOrValueTask()); | ||
| TypeDesc md = signature.ReturnType; | ||
| MethodSignatureBuilder builder = new MethodSignatureBuilder(signature); | ||
| builder.ReturnType = md.HasInstantiation ? md.Instantiation[0] : this.Context.GetWellKnownType(WellKnownType.Void); | ||
| builder.Flags = signature.Flags | MethodSignatureFlags.AsyncCall; | ||
| return (_asyncSignature = builder.ToSignature()); | ||
| } | ||
|
|
||
| public override MethodDesc GetCanonMethodTarget(CanonicalFormKind kind) | ||
| { | ||
| // We should not be calling GetCanonMethodTarget on generic definitions of anything | ||
| // and this MethodDesc is a generic definition. | ||
| Debug.Assert(!HasInstantiation && !OwningType.HasInstantiation); | ||
| return this; | ||
| } | ||
|
|
||
| public override MethodDesc GetMethodDefinition() | ||
| { | ||
| return this; | ||
| } | ||
|
|
||
| public override MethodDesc GetTypicalMethodDefinition() | ||
| { | ||
| return this; | ||
jtschuster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| public override MethodDesc InstantiateSignature(Instantiation typeInstantiation, Instantiation methodInstantiation) | ||
| { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| public override string ToString() => $"Async variant: " + _wrappedMethod.ToString(); | ||
|
|
||
| protected override int ClassCode => unchecked((int)0xd0fd1c1fu); | ||
|
|
||
| protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer) | ||
| { | ||
| var asyncOther = (AsyncMethodVariant)other; | ||
| return comparer.Compare(_wrappedMethod, asyncOther._wrappedMethod); | ||
| } | ||
| } | ||
|
|
||
| public static class AsyncMethodVariantExtensions | ||
| { | ||
| /// <summary> | ||
| /// Returns true if this MethodDesc is an AsyncMethodVariant, which should not escape the jit interface. | ||
| /// </summary> | ||
| public static bool IsAsyncVariant(this MethodDesc method) | ||
| { | ||
| return method is AsyncMethodVariant; | ||
| } | ||
| } | ||
| } | ||
44 changes: 44 additions & 0 deletions
44
src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.Async.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Internal.IL; | ||
| using Internal.TypeSystem; | ||
| using Internal.TypeSystem.Ecma; | ||
|
|
||
| using Debug = System.Diagnostics.Debug; | ||
|
|
||
| namespace ILCompiler | ||
| { | ||
| public partial class CompilerTypeSystemContext | ||
| { | ||
| public MethodDesc GetAsyncVariantMethod(MethodDesc taskReturningMethod) | ||
| { | ||
| Debug.Assert(taskReturningMethod.Signature.ReturnsTaskOrValueTask()); | ||
| MethodDesc asyncMetadataMethodDef = taskReturningMethod.GetTypicalMethodDefinition(); | ||
| MethodDesc result = _asyncVariantImplHashtable.GetOrCreateValue((EcmaMethod)asyncMetadataMethodDef); | ||
|
|
||
| if (asyncMetadataMethodDef != taskReturningMethod) | ||
| { | ||
| TypeDesc owningType = taskReturningMethod.OwningType; | ||
| if (owningType.HasInstantiation) | ||
| result = GetMethodForInstantiatedType(result, (InstantiatedType)owningType); | ||
|
|
||
| if (taskReturningMethod.HasInstantiation) | ||
| result = GetInstantiatedMethod(result, taskReturningMethod.Instantiation); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| private sealed class AsyncVariantImplHashtable : LockFreeReaderHashtable<EcmaMethod, AsyncMethodVariant> | ||
| { | ||
| protected override int GetKeyHashCode(EcmaMethod key) => key.GetHashCode(); | ||
| protected override int GetValueHashCode(AsyncMethodVariant value) => value.Target.GetHashCode(); | ||
| protected override bool CompareKeyToValue(EcmaMethod key, AsyncMethodVariant value) => key == value.Target; | ||
| protected override bool CompareValueToValue(AsyncMethodVariant value1, AsyncMethodVariant value2) | ||
| => value1.Target == value2.Target; | ||
| protected override AsyncMethodVariant CreateValueFromKey(EcmaMethod key) => new AsyncMethodVariant(key); | ||
| } | ||
| private AsyncVariantImplHashtable _asyncVariantImplHashtable = new AsyncVariantImplHashtable(); | ||
| } | ||
| } |
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
109 changes: 0 additions & 109 deletions
109
src/coreclr/tools/Common/JitInterface/AsyncMethodDesc.cs
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
src/coreclr/tools/Common/JitInterface/AsyncMethodDescFactory.cs
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.