-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add AsyncMethodDesc to managed type system #120858
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
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6658d8b
Pass async jit flag to jit in aot tools
jtschuster 1f917e9
Add IsRuntimeAsync override to instantiated MethodDescs
jtschuster 431bfaa
Update src/coreclr/tools/Common/TypeSystem/Common/InstantiatedMethod.cs
jkotas 3a4ffbc
Rename IsRuntimeAsync to IsAsync, add override in MethodDelegator
jtschuster 1030acb
Add AsyncMethodDesc for AsyncCallConv methods
jtschuster 4cc1f5f
Merge branch 'main' of https://github.com/dotnet/runtime into AsyncMe…
jtschuster 7516cba
Remove comments from AsyncMethodDesc
jtschuster 42e1157
Use MethodSignatureBuilder and assert for expected invariants
jtschuster 429f910
Use throwing cast instead of 'as' cast
jtschuster 4e0d53d
Fix assert
jtschuster c75c536
Add getter to Flags for |=
jtschuster e8ef453
Implement getAsyncInfo in ILCompiler
jtschuster 5ff7bc6
Use Dictionary instead of ConcurrentDictionary for AsyncMethodDescFac…
jtschuster e5ea4ce
Refactor AsyncMethodDesc for clarity and efficiency
jtschuster 0cf52dc
Update src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
jtschuster de10bb5
Update Signature and delete GetOtherAsyncMethod
jtschuster ff2712d
Remove IsAsync requirement from AsyncMethodDesc
jtschuster 9749653
Formatting and remove unused accessor
jtschuster c2e3c48
Merge branch 'GetAsyncInfoR2R' into AsyncMethodDesc
jtschuster bada361
Delete old UnboxingMethodDescFactory, move AsyncMethodDescFactory to …
jtschuster 2aace2c
Rename ReturnsTaskLike to IsTaskReturning
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
109 changes: 109 additions & 0 deletions
109
src/coreclr/tools/Common/JitInterface/AsyncMethodDesc.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,109 @@ | ||
| // 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; | ||
|
|
||
| namespace Internal.JitInterface | ||
| { | ||
| /// <summary> | ||
| /// Represents the async-callable (CORINFO_CALLCONV_ASYNCCALL) variant of a Task/ValueTask returning method. | ||
| /// The wrapper should be short‑lived and only used while interacting with the JIT interface. | ||
| /// </summary> | ||
| internal sealed class AsyncMethodDesc : MethodDelegator, IJitHashableOnly | ||
| { | ||
| private readonly AsyncMethodDescFactory _factory; | ||
| private readonly int _jitVisibleHashCode; | ||
|
|
||
| public MethodDesc Target => _wrappedMethod; | ||
|
|
||
| public AsyncMethodDesc(MethodDesc wrappedMethod, AsyncMethodDescFactory factory) | ||
| : base(wrappedMethod) | ||
| { | ||
| Debug.Assert(wrappedMethod.IsTaskReturning()); | ||
| _factory = factory; | ||
| // Salt with arbitrary constant so hash space differs from underlying method. | ||
| _jitVisibleHashCode = HashCode.Combine(wrappedMethod.GetHashCode(), 0x51C0A54); | ||
| } | ||
|
|
||
| public override MethodDesc GetCanonMethodTarget(CanonicalFormKind kind) | ||
| { | ||
| MethodDesc realCanonTarget = _wrappedMethod.GetCanonMethodTarget(kind); | ||
| if (realCanonTarget != _wrappedMethod) | ||
| return _factory.GetAsyncMethod(realCanonTarget); | ||
| return this; | ||
| } | ||
|
|
||
| public override MethodDesc GetMethodDefinition() | ||
| { | ||
| MethodDesc real = _wrappedMethod.GetMethodDefinition(); | ||
| if (real != _wrappedMethod) | ||
| return _factory.GetAsyncMethod(real); | ||
| return this; | ||
| } | ||
|
|
||
| public override MethodDesc GetTypicalMethodDefinition() | ||
| { | ||
| MethodDesc real = _wrappedMethod.GetTypicalMethodDefinition(); | ||
| if (real != _wrappedMethod) | ||
| return _factory.GetAsyncMethod(real); | ||
| return this; | ||
| } | ||
|
|
||
| public override MethodDesc InstantiateSignature(Instantiation typeInstantiation, Instantiation methodInstantiation) | ||
| { | ||
| MethodDesc real = _wrappedMethod.InstantiateSignature(typeInstantiation, methodInstantiation); | ||
| if (real != _wrappedMethod) | ||
| return _factory.GetAsyncMethod(real); | ||
| return this; | ||
| } | ||
|
|
||
| public override MethodSignature Signature | ||
| { | ||
| get | ||
| { | ||
| MethodSignature wrappedSignature = _wrappedMethod.Signature; | ||
| MetadataType md = (MetadataType)wrappedSignature.ReturnType; | ||
| MethodSignatureBuilder builder = new MethodSignatureBuilder(wrappedSignature); | ||
| builder.ReturnType = md.HasInstantiation ? md.Instantiation[0] : this.Context.GetWellKnownType(WellKnownType.Void); | ||
| builder.Flags = wrappedSignature.Flags | MethodSignatureFlags.AsyncCallConv; | ||
| return builder.ToSignature(); | ||
| } | ||
| } | ||
|
|
||
| #if !SUPPORT_JIT | ||
| // Same pattern as UnboxingMethodDesc: these should not escape JIT hashing scope. | ||
| protected override int ClassCode => throw new NotImplementedException(); | ||
| protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer) => throw new NotImplementedException(); | ||
| protected override int ComputeHashCode() => _jitVisibleHashCode; | ||
| int IJitHashableOnly.GetJitVisibleHashCode() => _jitVisibleHashCode; | ||
| #else | ||
| int IJitHashableOnly.GetJitVisibleHashCode() => _jitVisibleHashCode; | ||
| #endif | ||
| } | ||
|
|
||
| internal static class AsyncMethodDescExtensions | ||
| { | ||
| /// <summary> | ||
| /// Returns true if the method returns Task, Task<T>, ValueTask, or ValueTask<T>, otherwise false. | ||
| /// </summary> | ||
| public static bool IsTaskReturning(this MethodDesc method) | ||
| { | ||
| TypeDesc ret = method.GetTypicalMethodDefinition().Signature.ReturnType; | ||
|
|
||
| if (ret is MetadataType md | ||
| && md.Module == method.Context.SystemModule | ||
| && md.Namespace.SequenceEqual("System.Threading.Tasks"u8)) | ||
| { | ||
| ReadOnlySpan<byte> name = md.Name; | ||
| if (name.SequenceEqual("Task"u8) || name.SequenceEqual("Task`1"u8) | ||
| || name.SequenceEqual("ValueTask"u8) || name.SequenceEqual("ValueTask`1"u8)) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
src/coreclr/tools/Common/JitInterface/AsyncMethodDescFactory.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,24 @@ | ||
| // 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.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using Internal.TypeSystem; | ||
|
|
||
| namespace Internal.JitInterface | ||
| { | ||
| internal class AsyncMethodDescFactory : Dictionary<MethodDesc, AsyncMethodDesc> | ||
| { | ||
| public AsyncMethodDesc GetAsyncMethod(MethodDesc method) | ||
| { | ||
| if (!TryGetValue(method, out AsyncMethodDesc result)) | ||
| { | ||
| result = new AsyncMethodDesc(method, this); | ||
| Add(method, result); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
| } |
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
30 changes: 0 additions & 30 deletions
30
src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/UnboxingMethodDescFactory.cs
This file was deleted.
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.