Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete .NET Native leftovers from type loader (part 3 of X) #79133

Merged
merged 1 commit into from
Dec 2, 2022
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 @@ -1453,22 +1453,6 @@ public bool[] ReturnTypeAndParametersByRefFlags
}
}

public bool RequiresCallingConventionConverter(out bool[] forcedByRefParams)
{
Handle[] handles = null;
Type[] types = null;
GetReturnTypeAndParameterTypesAndMDHandles(ref handles, ref types);

// Compute whether any of the parameters have generic vars in their signatures ...
bool requiresCallingConventionConverter = false;
forcedByRefParams = new bool[handles.Length];
for (int i = 0; i < handles.Length; i++)
if ((forcedByRefParams[i] = TypeSignatureHasVarsNeedingCallingConventionConverter(handles[i], types[i], isTopLevelParameterType:true)))
requiresCallingConventionConverter = true;

return requiresCallingConventionConverter;
}

private void GetReturnTypeAndParameterTypesAndMDHandles(ref Handle[] handles, ref Type[] types)
{
if (_returnTypeAndParametersTypesCache == null)
Expand Down Expand Up @@ -1499,84 +1483,6 @@ private void GetReturnTypeAndParameterTypesAndMDHandles(ref Handle[] handles, re
types = _returnTypeAndParametersTypesCache;
Debug.Assert(handles != null && types != null);
}

// IF THESE SEMANTICS EVER CHANGE UPDATE THE LOGIC WHICH DEFINES THIS BEHAVIOR IN
// THE DYNAMIC TYPE LOADER AS WELL AS THE COMPILER.
//
// Parameter's are considered to have type layout dependent on their generic instantiation
// if the type of the parameter in its signature is a type variable, or if the type is a generic
// structure which meets 2 characteristics:
// 1. Structure size/layout is affected by the size/layout of one or more of its generic parameters
// 2. One or more of the generic parameters is a type variable, or a generic structure which also recursively
// would satisfy constraint 2. (Note, that in the recursion case, whether or not the structure is affected
// by the size/layout of its generic parameters is not investigated.)
//
// Examples parameter types, and behavior.
//
// T -> true
// List<T> -> false
// StructNotDependentOnArgsForSize<T> -> false
// GenStructDependencyOnArgsForSize<T> -> true
// StructNotDependentOnArgsForSize<GenStructDependencyOnArgsForSize<T>> -> true
// StructNotDependentOnArgsForSize<GenStructDependencyOnArgsForSize<List<T>>>> -> false
//
// Example non-parameter type behavior
// T -> true
// List<T> -> false
// StructNotDependentOnArgsForSize<T> -> *true*
// GenStructDependencyOnArgsForSize<T> -> true
// StructNotDependentOnArgsForSize<GenStructDependencyOnArgsForSize<T>> -> true
// StructNotDependentOnArgsForSize<GenStructDependencyOnArgsForSize<List<T>>>> -> false
//
private bool TypeSignatureHasVarsNeedingCallingConventionConverter(Handle typeHandle, Type type, bool isTopLevelParameterType)
{
if (typeHandle.HandleType == HandleType.TypeSpecification)
{
TypeSpecification typeSpec = typeHandle.ToTypeSpecificationHandle(_metadataReader).GetTypeSpecification(_metadataReader);
Handle sigHandle = typeSpec.Signature;
HandleType sigHandleType = sigHandle.HandleType;
switch (sigHandleType)
{
case HandleType.TypeVariableSignature:
case HandleType.MethodTypeVariableSignature:
return true;

case HandleType.TypeInstantiationSignature:
{
Debug.Assert(type.IsConstructedGenericType);
TypeInstantiationSignature sig = sigHandle.ToTypeInstantiationSignatureHandle(_metadataReader).GetTypeInstantiationSignature(_metadataReader);

if (RuntimeAugments.IsValueType(type.TypeHandle))
{
// This generic type is a struct (its base type is System.ValueType)
int genArgIndex = 0;
bool needsCallingConventionConverter = false;
foreach (Handle genericTypeArgumentHandle in sig.GenericTypeArguments)
{
if (TypeSignatureHasVarsNeedingCallingConventionConverter(genericTypeArgumentHandle, type.GenericTypeArguments[genArgIndex++], isTopLevelParameterType:false))
{
needsCallingConventionConverter = true;
break;
}
}

if (needsCallingConventionConverter)
{
if (!isTopLevelParameterType)
return true;

if (!TypeLoaderEnvironment.Instance.TryComputeHasInstantiationDeterminedSize(type.TypeHandle, out needsCallingConventionConverter))
RuntimeExceptionHelpers.FailFast("Unable to setup calling convention converter correctly");
return needsCallingConventionConverter;
}
}
}
return false;
}
}

return false;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,62 +49,6 @@ public TypeDesc TryGetNonUniversalTypeTemplate(TypeDesc concreteType, ref Native
}
#endif

/// <summary>
/// Get the NativeLayout for a type from a ReadyToRun image.
/// </summary>
public static bool TryGetMetadataNativeLayout(TypeDesc concreteType, out NativeFormatModuleInfo nativeLayoutInfoModule, out uint nativeLayoutInfoToken)
{
nativeLayoutInfoModule = null;
nativeLayoutInfoToken = 0;
#if SUPPORTS_NATIVE_METADATA_TYPE_LOADING
var nativeMetadataType = concreteType.GetTypeDefinition() as TypeSystem.NativeFormat.NativeFormatType;
if (nativeMetadataType == null)
return false;

var canonForm = concreteType.ConvertToCanonForm(CanonicalFormKind.Specific);
var hashCode = canonForm.GetHashCode();

#if SUPPORTS_R2R_LOADING
foreach (var moduleInfo in ModuleList.EnumerateModules())
{
if (moduleInfo.MetadataReader == null)
continue;

ExternalReferencesTable externalFixupsTable;
NativeHashtable typeTemplatesHashtable = LoadHashtable(moduleInfo.Handle, ReflectionMapBlob.MetadataBasedTypeTemplateMap, out externalFixupsTable);

if (typeTemplatesHashtable.IsNull)
continue;

var enumerator = typeTemplatesHashtable.Lookup(hashCode);
var nativeMetadataUnit = nativeMetadataType.Context.ResolveMetadataUnit(moduleInfo);

NativeParser entryParser;
while (!(entryParser = enumerator.GetNext()).IsNull)
{
var entryTypeHandle = entryParser.GetUnsigned().AsHandle();
TypeDesc typeDesc = nativeMetadataUnit.GetType(entryTypeHandle);
Debug.Assert(typeDesc != null);
if (typeDesc == canonForm)
{
TypeLoaderLogger.WriteLine("Found metadata template for type " + concreteType.ToString() + ": " + typeDesc.ToString());
nativeLayoutInfoToken = entryParser.GetUnsigned();
if (nativeLayoutInfoToken == BadTokenFixupValue)
{
throw new BadImageFormatException();
}

nativeLayoutInfoModule = moduleHandle;
return true;
}
}
}
#endif
#endif

return false;
}

/// <summary>
/// Get the NativeLayout for a method from a ReadyToRun image.
/// </summary>
Expand Down
Loading