Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@ public MethodDesc GetTargetOfAsyncVariantMethod(MethodDesc asyncVariantMethod)
public MethodDesc GetAsyncVariantMethod(MethodDesc taskReturningMethod)
{
Debug.Assert(taskReturningMethod.Signature.ReturnsTaskOrValueTask());
MethodDesc asyncMetadataMethodDef = taskReturningMethod.GetTypicalMethodDefinition();
MethodDesc result = _asyncVariantHashtable.GetOrCreateValue((EcmaMethod)asyncMetadataMethodDef);
MethodDesc taskReturningMethodDefinition = taskReturningMethod.GetTypicalMethodDefinition();
MethodDesc result = _asyncVariantHashtable.GetOrCreateValue((EcmaMethod)taskReturningMethodDefinition);

if (asyncMetadataMethodDef != taskReturningMethod)
if (taskReturningMethodDefinition != taskReturningMethod)
{
TypeDesc owningType = taskReturningMethod.OwningType;
if (owningType.HasInstantiation)
if (owningType != taskReturningMethodDefinition.OwningType)
result = GetMethodForInstantiatedType(result, (InstantiatedType)owningType);

if (taskReturningMethod.HasInstantiation)
if (taskReturningMethod.HasInstantiation && !taskReturningMethod.IsMethodDefinition)
result = GetInstantiatedMethod(result, taskReturningMethod.Instantiation);
}

Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,9 @@ private object GetRuntimeDeterminedObjectForToken(ref CORINFO_RESOLVED_TOKEN pRe
if (pResolvedToken.tokenType == CorInfoTokenKind.CORINFO_TOKENKIND_Newarr)
result = ((TypeDesc)result).MakeArrayType();

if (pResolvedToken.tokenType == CorInfoTokenKind.CORINFO_TOKENKIND_Await)
result = _compilation.TypeSystemContext.GetAsyncVariantMethod((MethodDesc)result);

return result;
}

Expand Down Expand Up @@ -3774,7 +3777,7 @@ private bool getTailCallHelpers(ref CORINFO_RESOLVED_TOKEN callToken, CORINFO_SI
#if READYTORUN
throw new NotImplementedException("Crossgen2 does not support runtime-async yet");
#else
_asyncResumptionStub ??= new AsyncResumptionStub(MethodBeingCompiled);
_asyncResumptionStub ??= new AsyncResumptionStub(MethodBeingCompiled, _compilation.TypeSystemContext.GeneratedAssembly.GetGlobalModuleType());

entryPoint = (void*)ObjectToHandle(_compilation.NodeFactory.MethodEntrypoint(_asyncResumptionStub));
return ObjectToHandle(_asyncResumptionStub);
Expand Down
23 changes: 22 additions & 1 deletion src/coreclr/tools/Common/TypeSystem/IL/NativeAotILProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public override MethodIL GetMethodIL(MethodDesc method)
{
if (asyncVariantImpl.IsAsync)
{
return EcmaMethodIL.Create(asyncVariantImpl.Target);
return new AsyncEcmaMethodIL(asyncVariantImpl, EcmaMethodIL.Create(asyncVariantImpl.Target));
}
else
{
Expand All @@ -387,5 +387,26 @@ public override MethodIL GetMethodIL(MethodDesc method)
return null;
}
}

private sealed class AsyncEcmaMethodIL : MethodIL
{
private readonly AsyncMethodVariant _variant;
private readonly EcmaMethodIL _ecmaIL;

public AsyncEcmaMethodIL(AsyncMethodVariant variant, EcmaMethodIL ecmaIL)
=> (_variant, _ecmaIL) = (variant, ecmaIL);

// This is the reason we need this class - the method that owns the IL is the variant.
public override MethodDesc OwningMethod => _variant;

// Everything else dispatches to EcmaMethodIL
public override MethodDebugInformation GetDebugInfo() => _ecmaIL.GetDebugInfo();
public override ILExceptionRegion[] GetExceptionRegions() => _ecmaIL.GetExceptionRegions();
public override byte[] GetILBytes() => _ecmaIL.GetILBytes();
public override LocalVariableDefinition[] GetLocals() => _ecmaIL.GetLocals();
public override object GetObject(int token, NotFoundBehavior notFoundBehavior = NotFoundBehavior.Throw) => _ecmaIL.GetObject(token, notFoundBehavior);
public override bool IsInitLocals => _ecmaIL.IsInitLocals;
public override int MaxStack => _ecmaIL.MaxStack;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ILCompiler
{
public partial class AsyncResumptionStub : ILStubMethod, IPrefixMangledMethod
{
MethodDesc IPrefixMangledMethod.BaseMethod => _owningMethod;
MethodDesc IPrefixMangledMethod.BaseMethod => _targetMethod;

string IPrefixMangledMethod.Prefix => "Resume";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public partial class AsyncResumptionStub : ILStubMethod

protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
{
return comparer.Compare(_owningMethod, ((AsyncResumptionStub)other)._owningMethod);
return comparer.Compare(_targetMethod, ((AsyncResumptionStub)other)._targetMethod);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,25 @@ namespace ILCompiler
{
public partial class AsyncResumptionStub : ILStubMethod
{
private readonly MethodDesc _owningMethod;
private readonly MethodDesc _targetMethod;
private readonly TypeDesc _owningType;
private MethodSignature _signature;

public AsyncResumptionStub(MethodDesc owningMethod)
public AsyncResumptionStub(MethodDesc targetMethod, TypeDesc owningType)
{
Debug.Assert(owningMethod.IsAsyncVariant()
|| (owningMethod.IsAsync && !owningMethod.Signature.ReturnsTaskOrValueTask()));
_owningMethod = owningMethod;
Debug.Assert(targetMethod.IsAsyncCall());
_targetMethod = targetMethod;
_owningType = owningType;
}

public override ReadOnlySpan<byte> Name => _owningMethod.Name;
public override string DiagnosticName => _owningMethod.DiagnosticName;
public override ReadOnlySpan<byte> Name => _targetMethod.Name;
public override string DiagnosticName => _targetMethod.DiagnosticName;

public override TypeDesc OwningType => _owningMethod.OwningType;
public override TypeDesc OwningType => _owningType;

public override MethodSignature Signature => _signature ??= InitializeSignature();

public override TypeSystemContext Context => _owningMethod.Context;
public override TypeSystemContext Context => _targetMethod.Context;

private MethodSignature InitializeSignature()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,7 @@ private void embedGenericHandle(ref CORINFO_RESOLVED_TOKEN pResolvedToken, bool
helperId = ReadyToRunHelperId.MethodHandle;
else
{
Debug.Assert(pResolvedToken.tokenType == CorInfoTokenKind.CORINFO_TOKENKIND_Method);
Debug.Assert((pResolvedToken.tokenType & CorInfoTokenKind.CORINFO_TOKENKIND_Method) != 0);
helperId = ReadyToRunHelperId.MethodDictionary;
}

Expand Down
Loading