Skip to content

Commit

Permalink
Do not run validation on runtime determined types (dotnet#1357)
Browse files Browse the repository at this point in the history
It doesn't seem like we validate anything for those and `IsRuntimeDeterminedSubtype` check is rather expensive.
  • Loading branch information
MichalStrehovsky authored Jan 22, 2020
1 parent 9b4eece commit 8c1512c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,11 @@ private static TypeDesc EnsureLoadableTypeUncached(TypeDesc type)
ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, type);
}

if (!parameterType.IsRuntimeDeterminedSubtype)
LayoutInt elementSize = parameterType.GetElementSize();
if (!elementSize.IsIndeterminate && elementSize.AsInt >= ushort.MaxValue)
{
LayoutInt elementSize = parameterType.GetElementSize();
if (!elementSize.IsIndeterminate && elementSize.AsInt >= ushort.MaxValue)
{
// Element size over 64k can't be encoded in the GCDesc
ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadValueClassTooLarge, parameterType);
}
// Element size over 64k can't be encoded in the GCDesc
ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadValueClassTooLarge, parameterType);
}

if (((ArrayType)parameterizedType).Rank > 32)
Expand All @@ -105,17 +102,19 @@ private static TypeDesc EnsureLoadableTypeUncached(TypeDesc type)
{
ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, type);
}
#if READYTORUN
else if (type.IsGenericParameter)
{
return type;
}
#endif
else
{
// Validate classes, structs, enums, interfaces, and delegates
Debug.Assert(type.IsDefType);

// Don't validate generic definitons or runtime determined subtypes
if (type.IsGenericDefinition || type.IsRuntimeDeterminedSubtype)
// Don't validate generic definitons
if (type.IsGenericDefinition)
{
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@ public GenericLookupSignature(
_fieldArgument = fieldArgument;
_methodContext = methodContext;
_signatureContext = signatureContext;

// Ensure types in signature are loadable and resolvable, otherwise we'll fail later while emitting the signature
if (typeArgument != null)
{
signatureContext.Resolver.CompilerContext.EnsureLoadableType(typeArgument);
}
if (fieldArgument != null)
{
signatureContext.Resolver.CompilerContext.EnsureLoadableType(fieldArgument.OwningType);
}
if (methodArgument != null)
{
signatureContext.Resolver.CompilerContext.EnsureLoadableMethod(methodArgument.Method);
if (methodArgument.ConstrainedType != null)
signatureContext.Resolver.CompilerContext.EnsureLoadableType(methodArgument.ConstrainedType);
}
}

public override int ClassCode => 258608008;
Expand Down

0 comments on commit 8c1512c

Please sign in to comment.