Skip to content

Commit

Permalink
Beef up WithoutFunctionPointerType
Browse files Browse the repository at this point in the history
We don't have a `MethodTable` shape for function pointer types because how they should look like hasn't been defined until .NET 8.

Beef up the CoreCLR compat shim. We'll not be 100% compatible with this because `typeof(Tuple<delegate*<void>[]>)` doesn't actually load as `typeof(Tuple<IntPtr[]>)`, but this'll do until dotnet#71883.
  • Loading branch information
MichalStrehovsky committed Jan 25, 2023
1 parent 8e72029 commit 0611a32
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,43 @@ public GenericDictionaryLookup ComputeGenericLookup(MethodDesc contextMethod, Re

// CoreCLR compat - referring to function pointer types handled as IntPtr. No MethodTable for function pointers for now.
private static TypeDesc WithoutFunctionPointerType(TypeDesc type)
=> type.IsFunctionPointer ? type.Context.GetWellKnownType(WellKnownType.IntPtr) : type;
{
switch (type.Category)
{
case TypeFlags.Array:
return WithoutFunctionPointerType(((ParameterizedType)type).ParameterType).MakeArrayType(((ArrayType)type).Rank);
case TypeFlags.SzArray:
return WithoutFunctionPointerType(((ParameterizedType)type).ParameterType).MakeArrayType();
case TypeFlags.Pointer:
return WithoutFunctionPointerType(((ParameterizedType)type).ParameterType).MakePointerType();
case TypeFlags.FunctionPointer:
return type.Context.GetWellKnownType(WellKnownType.IntPtr);
default:
TypeDesc typeDef = type.GetTypeDefinition();
if (type != typeDef)
{
TypeDesc[] newInst = null;
for (int i = 0; i < type.Instantiation.Length; i++)
{
TypeDesc arg = type.Instantiation[i];
TypeDesc newArg = WithoutFunctionPointerType(arg);
if (arg != newArg || newInst != null)
{
if (newInst == null)
{
newInst = new TypeDesc[type.Instantiation.Length];
for (int j = 0; j < i; i++)
newInst[j] = type.Instantiation[j];
}
newInst[i] = newArg;
}
}
if (newInst != null)
return ((MetadataType)typeDef).MakeInstantiatedType(newInst);
}
return type;
}
}

public bool IsFatPointerCandidate(MethodDesc containingMethod, MethodSignature signature)
{
Expand Down

0 comments on commit 0611a32

Please sign in to comment.