Skip to content

Commit

Permalink
Convert RuntimeTypeHandle.SatisfiesConstraints() to QCall.
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronRobinsonMSFT committed Dec 11, 2024
1 parent 94cfb16 commit f9ff74a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -845,8 +845,8 @@ internal bool ContainsGenericVariables()
return ContainsGenericVariables(GetRuntimeTypeChecked());
}

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool SatisfiesConstraints(RuntimeType paramType, IntPtr* pTypeContext, int typeContextLength, IntPtr* pMethodContext, int methodContextLength, RuntimeType toType);
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "RuntimeTypeHandle_SatisfiesConstraints")]
private static partial Interop.BOOL SatisfiesConstraints(QCallTypeHandle paramType, IntPtr* pTypeContext, int typeContextLength, IntPtr* pMethodContext, int methodContextLength, QCallTypeHandle toType);

internal static bool SatisfiesConstraints(RuntimeType paramType, RuntimeType[]? typeContext, RuntimeType[]? methodContext, RuntimeType toType)
{
Expand All @@ -855,7 +855,7 @@ internal static bool SatisfiesConstraints(RuntimeType paramType, RuntimeType[]?

fixed (IntPtr* pTypeContextHandles = typeContextHandles, pMethodContextHandles = methodContextHandles)
{
bool result = SatisfiesConstraints(paramType, pTypeContextHandles, typeContextLength, pMethodContextHandles, methodContextLength, toType);
bool result = SatisfiesConstraints(new QCallTypeHandle(ref paramType), pTypeContextHandles, typeContextLength, pMethodContextHandles, methodContextLength, new QCallTypeHandle(ref toType)) != Interop.BOOL.FALSE;

GC.KeepAlive(typeContext);
GC.KeepAlive(methodContext);
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ FCFuncStart(gCOMTypeHandleFuncs)
FCFuncElement("GetGenericVariableIndex", RuntimeTypeHandle::GetGenericVariableIndex)
FCFuncElement("IsGenericVariable", RuntimeTypeHandle::IsGenericVariable)
FCFuncElement("ContainsGenericVariables", RuntimeTypeHandle::ContainsGenericVariables)
FCFuncElement("SatisfiesConstraints", RuntimeTypeHandle::SatisfiesConstraints)
FCFuncElement("IsUnmanagedFunctionPointer", RuntimeTypeHandle::IsUnmanagedFunctionPointer)
FCFuncElement("CompareCanonicalHandles", RuntimeTypeHandle::CompareCanonicalHandles)
FCFuncElement("GetRuntimeTypeFromHandleIfExists", RuntimeTypeHandle::GetRuntimeTypeFromHandleIfExists)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/qcallentrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ static const Entry s_QCall[] =
DllImportEntry(RuntimeTypeHandle_ConstructName)
DllImportEntry(RuntimeTypeHandle_GetInterfaces)
DllImportEntry(RuntimeTypeHandle_CanCastToSlow)
DllImportEntry(RuntimeTypeHandle_SatisfiesConstraints)
DllImportEntry(RuntimeTypeHandle_GetInstantiation)
DllImportEntry(RuntimeTypeHandle_Instantiate)
DllImportEntry(RuntimeTypeHandle_GetGenericTypeDefinition)
Expand Down
45 changes: 18 additions & 27 deletions src/coreclr/vm/runtimehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,47 +1050,38 @@ extern "C" BOOL QCALLTYPE RuntimeTypeHandle_CanCastToSlow(QCall::TypeHandle type
return retVal;
}

FCIMPL6(FC_BOOL_RET, RuntimeTypeHandle::SatisfiesConstraints, PTR_ReflectClassBaseObject pParamTypeUNSAFE, TypeHandle *typeContextArgs, INT32 typeContextCount, TypeHandle *methodContextArgs, INT32 methodContextCount, PTR_ReflectClassBaseObject pArgumentTypeUNSAFE);
extern "C" BOOL QCALLTYPE RuntimeTypeHandle_SatisfiesConstraints(QCall::TypeHandle paramType, TypeHandle* typeContextArgs, INT32 typeContextCount, TypeHandle* methodContextArgs, INT32 methodContextCount, QCall::TypeHandle toType)
{
CONTRACTL {
FCALL_CHECK;
CONTRACTL
{
QCALL_CHECK;
PRECONDITION(CheckPointer(typeContextArgs, NULL_OK));
PRECONDITION(CheckPointer(methodContextArgs, NULL_OK));
}
CONTRACTL_END;

REFLECTCLASSBASEREF refParamType = (REFLECTCLASSBASEREF)ObjectToOBJECTREF(pParamTypeUNSAFE);
REFLECTCLASSBASEREF refArgumentType = (REFLECTCLASSBASEREF)ObjectToOBJECTREF(pArgumentTypeUNSAFE);

TypeHandle thGenericParameter = refParamType->GetType();
TypeHandle thGenericArgument = refArgumentType->GetType();
BOOL bResult = FALSE;
SigTypeContext typeContext;

Instantiation classInst;
Instantiation methodInst;
BEGIN_QCALL;

if (typeContextArgs != NULL)
{
classInst = Instantiation(typeContextArgs, typeContextCount);
}

if (methodContextArgs != NULL)
{
methodInst = Instantiation(methodContextArgs, methodContextCount);
}
Instantiation classInst = typeContextArgs != NULL
? Instantiation(typeContextArgs, typeContextCount)
: Instantiation{};
Instantiation methodInst = methodContextArgs != NULL
? Instantiation(methodContextArgs, methodContextCount)
: Instantiation{};

SigTypeContext typeContext;
SigTypeContext::InitTypeContext(classInst, methodInst, &typeContext);

HELPER_METHOD_FRAME_BEGIN_RET_2(refParamType, refArgumentType);
{
bResult = thGenericParameter.AsGenericVariable()->SatisfiesConstraints(&typeContext, thGenericArgument);
}
HELPER_METHOD_FRAME_END();
TypeHandle thGenericParameter = paramType.AsTypeHandle();
TypeHandle thGenericArgument = toType.AsTypeHandle();
bResult = thGenericParameter.AsGenericVariable()->SatisfiesConstraints(&typeContext, thGenericArgument);

END_QCALL;

FC_RETURN_BOOL(bResult);
return bResult;
}
FCIMPLEND

extern "C" void QCALLTYPE RuntimeTypeHandle_GetInstantiation(QCall::TypeHandle pType, QCall::ObjectHandleOnStack retTypes, BOOL fAsRuntimeTypeArray)
{
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/vm/runtimehandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ class RuntimeTypeHandle

static FCDECL2(TypeHandle::CastResult, CanCastToInternal, ReflectClassBaseObject *pType, ReflectClassBaseObject *pTarget);

static FCDECL6(FC_BOOL_RET, SatisfiesConstraints, PTR_ReflectClassBaseObject pGenericParameter, TypeHandle *typeContextArgs, INT32 typeContextCount, TypeHandle *methodContextArgs, INT32 methodContextCount, PTR_ReflectClassBaseObject pGenericArgument);

static
FCDECL1(FC_BOOL_RET, IsGenericVariable, PTR_ReflectClassBaseObject pType);

Expand Down Expand Up @@ -178,6 +176,7 @@ extern "C" void QCALLTYPE RuntimeTypeHandle_ConstructName(QCall::TypeHandle pTyp
extern "C" void QCALLTYPE RuntimeTypeHandle_GetInterfaces(MethodTable* pMT, QCall::ObjectHandleOnStack result);
extern "C" BOOL QCALLTYPE RuntimeTypeHandle_IsVisible(QCall::TypeHandle pTypeHandle);
extern "C" BOOL QCALLTYPE RuntimeTypeHandle_CanCastToSlow(QCall::TypeHandle type, QCall::TypeHandle target);
extern "C" BOOL QCALLTYPE RuntimeTypeHandle_SatisfiesConstraints(QCall::TypeHandle paramType, TypeHandle* typeContextArgs, INT32 typeContextCount, TypeHandle* methodContextArgs, INT32 methodContextCount, QCall::TypeHandle toType);
extern "C" void QCALLTYPE RuntimeTypeHandle_GetInstantiation(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType, BOOL fAsRuntimeTypeArray);
extern "C" void QCALLTYPE RuntimeTypeHandle_Instantiate(QCall::TypeHandle pTypeHandle, TypeHandle * pInstArray, INT32 cInstArray, QCall::ObjectHandleOnStack retType);
extern "C" void QCALLTYPE RuntimeTypeHandle_GetGenericTypeDefinition(QCall::TypeHandle pTypeHandle, QCall::ObjectHandleOnStack retType);
Expand Down

0 comments on commit f9ff74a

Please sign in to comment.