Skip to content

Commit

Permalink
[NativeAOT][8.0] Make casting logic closer to CoreCLR (#90234)
Browse files Browse the repository at this point in the history
* Refactored AssignmentVariation

* refactored similar to coreclr

* fix build

* simpler selection of runtime helpers for casts

* add a codegen test
  • Loading branch information
VSadov authored Aug 9, 2023
1 parent 9a5fa74 commit 41bc935
Show file tree
Hide file tree
Showing 9 changed files with 735 additions and 660 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ internal static unsafe class CastHelpers
return ChkCastClassSpecial(toTypeHnd, obj);
}

// Optimized helper for classes. Assumes that the trivial cases
// has been taken care of by the inlined check
[DebuggerHidden]
[StackTraceHidden]
[DebuggerStepThrough]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static unsafe void RhUnboxAny(object? o, ref byte data, EETypePtr pUnboxT
}
else
{
if (o != null && (TypeCast.IsInstanceOf(ptrUnboxToEEType, o) == null))
if (o != null && (TypeCast.IsInstanceOfAny(ptrUnboxToEEType, o) == null))
{
throw ptrUnboxToEEType->GetClasslibException(ExceptionIDs.InvalidCast);
}
Expand Down Expand Up @@ -392,26 +392,18 @@ internal static unsafe IntPtr RhGetRuntimeHelperForType(MethodTable* pEEType, Ru
return (IntPtr)(delegate*<MethodTable*, object>)&InternalCalls.RhpNewFast;

case RuntimeHelperKind.IsInst:
if (pEEType->IsArray)
return (IntPtr)(delegate*<MethodTable*, object, object>)&TypeCast.IsInstanceOfArray;
else if (pEEType->HasGenericVariance)
return (IntPtr)(delegate*<MethodTable*, object, object>)&TypeCast.IsInstanceOf;
if (pEEType->HasGenericVariance || pEEType->IsParameterizedType || pEEType->IsFunctionPointerType)
return (IntPtr)(delegate*<MethodTable*, object, object?>)&TypeCast.IsInstanceOfAny;
else if (pEEType->IsInterface)
return (IntPtr)(delegate*<MethodTable*, object?, object?>)&TypeCast.IsInstanceOfInterface;
else if (pEEType->IsParameterizedType || pEEType->IsFunctionPointerType)
return (IntPtr)(delegate*<MethodTable*, object, object>)&TypeCast.IsInstanceOf; // Array handled above; pointers and byrefs handled here
else
return (IntPtr)(delegate*<MethodTable*, object?, object?>)&TypeCast.IsInstanceOfClass;

case RuntimeHelperKind.CastClass:
if (pEEType->IsArray)
return (IntPtr)(delegate*<MethodTable*, object, object>)&TypeCast.CheckCastArray;
else if (pEEType->HasGenericVariance)
return (IntPtr)(delegate*<MethodTable*, object, object>)&TypeCast.CheckCast;
if (pEEType->HasGenericVariance || pEEType->IsParameterizedType || pEEType->IsFunctionPointerType)
return (IntPtr)(delegate*<MethodTable*, object, object>)&TypeCast.CheckCastAny;
else if (pEEType->IsInterface)
return (IntPtr)(delegate*<MethodTable*, object, object>)&TypeCast.CheckCastInterface;
else if (pEEType->IsParameterizedType || pEEType->IsFunctionPointerType)
return (IntPtr)(delegate*<MethodTable*, object, object>)&TypeCast.CheckCast; // Array handled above; pointers and byrefs handled here
else
return (IntPtr)(delegate*<MethodTable*, object, object>)&TypeCast.CheckCastClass;

Expand Down
Loading

0 comments on commit 41bc935

Please sign in to comment.