Skip to content
Merged
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
39 changes: 29 additions & 10 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,7 +1546,7 @@ static CORINFO_RESOLVED_TOKEN CreateResolvedTokenFromMethod(CorInfoImpl jitInter
{
method = method.GetTargetOfAsyncVariant();
}
else if (method.Signature.ReturnsTaskOrValueTask())
else if (HasCallableAsyncVariant(method))
{
method = method.GetAsyncVariant();
}
Expand Down Expand Up @@ -1874,15 +1874,7 @@ private void resolveToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken)

if (pResolvedToken.tokenType is CorInfoTokenKind.CORINFO_TOKENKIND_Await)
{
// in rare cases a method that returns Task is not actually TaskReturning (i.e. returns T).
// we cannot resolve to an Async variant in such case.
// return NULL, so that caller would re-resolve as a regular method call
bool allowAsyncVariant = method.GetTypicalMethodDefinition().Signature.ReturnsTaskOrValueTask();

// Don't get async variant of Delegate.Invoke method; the pointed to method is not an async variant either.
allowAsyncVariant = allowAsyncVariant && !method.OwningType.IsDelegate;

method = allowAsyncVariant
method = HasCallableAsyncVariant(method)
? _compilation.TypeSystemContext.GetAsyncVariantMethod(method)
: null;
}
Expand Down Expand Up @@ -1955,6 +1947,33 @@ private void resolveToken(ref CORINFO_RESOLVED_TOKEN pResolvedToken)
pResolvedToken.cbMethodSpec = 0;
}

private static bool HasCallableAsyncVariant(MethodDesc method)
{
// In some cases a method that returns Task is not actually
// TaskReturning (i.e. it might return T). We cannot resolve to an
// async variant in such case.
if (!method.GetTypicalMethodDefinition().Signature.ReturnsTaskOrValueTask())
{
return false;
}

// Don't get async variant of Delegate.Invoke method; the pointed
// to method is not an async variant either.
if (method.OwningType.IsDelegate)
{
return false;
}

// Don't get async variant of ComImport methods since we do not
// generate any runtime async entry points for them.
if (method.OwningType.IsComImport)
{
return false;
}
Comment thread
jakobbotsch marked this conversation as resolved.

return true;
}

private void findSig(CORINFO_MODULE_STRUCT_* module, uint sigTOK, CORINFO_CONTEXT_STRUCT* context, CORINFO_SIG_INFO* sig)
{
var methodIL = HandleToObject(module);
Expand Down
Loading