-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Async continuations for native AOT #121398
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
7 commits
Select commit
Hold shift + click to select a range
67df3da
Async continuations for native AOT
MichalStrehovsky 1499754
Update AsyncHelpers.CoreCLR.cs
MichalStrehovsky 6cb4870
Update src/coreclr/nativeaot/System.Private.CoreLib/src/System.Privat…
MichalStrehovsky 47b65a9
Merge branch 'main' into continuations
MichalStrehovsky bf84ab1
FB
MichalStrehovsky efc25d7
Update CompilerTypeSystemContext.Async.cs
MichalStrehovsky 1759adb
Rename async variant hashtable
MichalStrehovsky 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
85 changes: 85 additions & 0 deletions
85
src/coreclr/tools/Common/Compiler/AsyncContinuationType.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,85 @@ | ||
| // 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 System.Text; | ||
|
|
||
| using Internal.TypeSystem; | ||
|
|
||
| namespace ILCompiler | ||
| { | ||
| /// <summary> | ||
| /// An async continuation type. The code generator will request this to store local state | ||
| /// through an async suspension/resumption. We only identify these using a <see cref="GCPointerMap"/> | ||
| /// since that's all the code generator cares about - size of the type, and where the GC pointers are. | ||
| /// </summary> | ||
| public sealed partial class AsyncContinuationType : MetadataType | ||
| { | ||
| private readonly MetadataType _continuationBaseType; | ||
| public GCPointerMap PointerMap { get; } | ||
|
|
||
| public override DefType[] ExplicitlyImplementedInterfaces => []; | ||
| public override ReadOnlySpan<byte> Name => Encoding.UTF8.GetBytes(DiagnosticName); | ||
| public override ReadOnlySpan<byte> Namespace => []; | ||
|
|
||
| // We don't lay these out using MetadataType metadata. | ||
| // Autolayout (which we'd get due to GC pointers) would likely not match what codegen expects. | ||
| public override bool IsExplicitLayout => throw new NotImplementedException(); | ||
| public override bool IsSequentialLayout => throw new NotImplementedException(); | ||
| public override bool IsExtendedLayout => throw new NotImplementedException(); | ||
| public override bool IsAutoLayout => throw new NotImplementedException(); | ||
| public override ClassLayoutMetadata GetClassLayout() => throw new NotImplementedException(); | ||
|
|
||
| public override bool IsBeforeFieldInit => false; | ||
| public override ModuleDesc Module => _continuationBaseType.Module; | ||
| public override MetadataType BaseType => _continuationBaseType; | ||
| public override bool IsSealed => true; | ||
| public override bool IsAbstract => false; | ||
| public override MetadataType ContainingType => null; | ||
| public override PInvokeStringFormat PInvokeStringFormat => default; | ||
| public override string DiagnosticName => $"ContinuationType_{PointerMap}"; | ||
MichalStrehovsky marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public override string DiagnosticNamespace => ""; | ||
| protected override int ClassCode => 0x528741a; | ||
| public override TypeSystemContext Context => _continuationBaseType.Context; | ||
|
|
||
| public AsyncContinuationType(MetadataType continuationBaseType, GCPointerMap pointerMap) | ||
| => (_continuationBaseType, PointerMap) = (continuationBaseType, pointerMap); | ||
|
|
||
| public override bool HasCustomAttribute(string attributeNamespace, string attributeName) => false; | ||
| public override IEnumerable<MetadataType> GetNestedTypes() => []; | ||
| public override MetadataType GetNestedType(string name) => null; | ||
| protected override MethodImplRecord[] ComputeVirtualMethodImplsForType() => []; | ||
| public override MethodImplRecord[] FindMethodsImplWithMatchingDeclName(ReadOnlySpan<byte> name) => []; | ||
|
|
||
| protected override int CompareToImpl(TypeDesc other, TypeSystemComparer comparer) | ||
| { | ||
| Debug.Assert(_continuationBaseType == ((AsyncContinuationType)other)._continuationBaseType); | ||
| GCPointerMap otherPointerMap = ((AsyncContinuationType)other).PointerMap; | ||
| return PointerMap.CompareTo(otherPointerMap); | ||
| } | ||
|
|
||
| public override int GetHashCode() => PointerMap.GetHashCode(); | ||
|
|
||
| protected override TypeFlags ComputeTypeFlags(TypeFlags mask) | ||
| { | ||
| TypeFlags flags = 0; | ||
|
|
||
| if ((mask & TypeFlags.HasGenericVarianceComputed) != 0) | ||
| { | ||
| flags |= TypeFlags.HasGenericVarianceComputed; | ||
| } | ||
|
|
||
| if ((mask & TypeFlags.CategoryMask) != 0) | ||
| { | ||
| flags |= TypeFlags.Class; | ||
| } | ||
|
|
||
| flags |= TypeFlags.HasFinalizerComputed; | ||
| flags |= TypeFlags.AttributeCacheComputed; | ||
|
|
||
| return flags; | ||
| } | ||
| } | ||
| } | ||
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
15 changes: 15 additions & 0 deletions
15
src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.Mangling.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,15 @@ | ||
| // 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.Stubs; | ||
| using Internal.TypeSystem; | ||
|
|
||
| namespace ILCompiler | ||
| { | ||
| public partial class AsyncResumptionStub : ILStubMethod, IPrefixMangledMethod | ||
| { | ||
| MethodDesc IPrefixMangledMethod.BaseMethod => _owningMethod; | ||
|
|
||
| string IPrefixMangledMethod.Prefix => "Resume"; | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.Sorting.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,18 @@ | ||
| // 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.Stubs; | ||
| using Internal.TypeSystem; | ||
|
|
||
| namespace ILCompiler | ||
| { | ||
| public partial class AsyncResumptionStub : ILStubMethod | ||
| { | ||
| protected override int ClassCode => 0x773ab1; | ||
|
|
||
| protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer) | ||
| { | ||
| return comparer.Compare(_owningMethod, ((AsyncResumptionStub)other)._owningMethod); | ||
| } | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
src/coreclr/tools/Common/TypeSystem/IL/Stubs/AsyncResumptionStub.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,53 @@ | ||
| // 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 Internal.IL; | ||
| using Internal.IL.Stubs; | ||
| using Internal.TypeSystem; | ||
|
|
||
| using Debug = System.Diagnostics.Debug; | ||
|
|
||
| namespace ILCompiler | ||
| { | ||
| public partial class AsyncResumptionStub : ILStubMethod | ||
| { | ||
| private readonly MethodDesc _owningMethod; | ||
| private MethodSignature _signature; | ||
|
|
||
| public AsyncResumptionStub(MethodDesc owningMethod) | ||
| { | ||
| Debug.Assert(owningMethod.IsAsyncVariant() | ||
| || (owningMethod.IsAsync && !owningMethod.Signature.ReturnsTaskOrValueTask())); | ||
jkotas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _owningMethod = owningMethod; | ||
| } | ||
|
|
||
| public override ReadOnlySpan<byte> Name => _owningMethod.Name; | ||
| public override string DiagnosticName => _owningMethod.DiagnosticName; | ||
|
|
||
| public override TypeDesc OwningType => _owningMethod.OwningType; | ||
|
|
||
| public override MethodSignature Signature => _signature ??= InitializeSignature(); | ||
|
|
||
| public override TypeSystemContext Context => _owningMethod.Context; | ||
|
|
||
| private MethodSignature InitializeSignature() | ||
| { | ||
| TypeDesc objectType = Context.GetWellKnownType(WellKnownType.Object); | ||
| TypeDesc byrefByte = Context.GetWellKnownType(WellKnownType.Byte).MakeByRefType(); | ||
| return _signature = new MethodSignature(0, 0, objectType, [objectType, byrefByte]); | ||
| } | ||
|
|
||
| public override MethodIL EmitIL() | ||
| { | ||
| var emitter = new ILEmitter(); | ||
| ILCodeStream codeStream = emitter.NewCodeStream(); | ||
|
|
||
| // TODO: match getAsyncResumptionStub from CoreCLR VM | ||
| codeStream.EmitCallThrowHelper(emitter, Context.GetHelperEntryPoint("ThrowHelpers"u8, "ThrowNotSupportedException"u8)); | ||
|
|
||
| return emitter.Link(this); | ||
| } | ||
| } | ||
| } | ||
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.