Skip to content

Commit

Permalink
Generate fewer type loader templates (#72350)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky authored Jul 18, 2022
1 parent aafa910 commit f025132
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,7 @@ void ICompilationRootProvider.AddCompilationRoots(IRootingServiceProvider rootPr
if ((pair.Value & MetadataCategory.RuntimeMapping) != 0)
{
FieldDesc field = pair.Key;

// We only care about static fields at this point. Instance fields don't need
// runtime artifacts generated in the image.
if (field.IsStatic && !field.IsLiteral)
{
if (field.IsThreadStatic)
rootProvider.RootThreadStaticBaseForType(field.OwningType, reason);
else if (field.HasGCStaticBase)
rootProvider.RootGCStaticBaseForType(field.OwningType, reason);
else
rootProvider.RootNonGCStaticBaseForType(field.OwningType, reason);
}
rootProvider.AddReflectionRoot(field, reason);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -666,5 +666,11 @@ public int CompareTo(ConstrainedCallInfo other, TypeSystemComparer comparer)
result = comparer.Compare(Method, other.Method);
return result;
}
public override bool Equals(object obj) =>
obj is ConstrainedCallInfo other
&& ConstrainedType == other.ConstrainedType
&& Method == other.Method;

public override int GetHashCode() => HashCode.Combine(ConstrainedType, Method);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,7 @@ public NativeLayoutTemplateMethodLayoutVertexNode(NodeFactory factory, MethodDes
{
_method = method;
Debug.Assert(method.HasInstantiation);
Debug.Assert(!method.IsGenericMethodDefinition);
Debug.Assert(method.IsCanonicalMethod(CanonicalFormKind.Any));
Debug.Assert(method.GetCanonMethodTarget(CanonicalFormKind.Specific) == method, "Assert that the canonical method passed in is in standard canonical form");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,34 +218,5 @@ public sealed override MethodDesc GetCanonicalReflectionInvokeStub(MethodDesc me

return InstantiateCanonicalDynamicInvokeMethodForMethod(thunk, method);
}

protected override void GetDependenciesDueToEETypePresence(ref DependencyList dependencies, NodeFactory factory, TypeDesc type)
{
if (!ConstructedEETypeNode.CreationAllowed(type))
{
// Both EETypeNode and ConstructedEETypeNode call into this logic. EETypeNode will only call for unconstructable
// EETypes. We don't have templates for those.
return;
}

DefType closestDefType = type.GetClosestDefType();

// TODO-SIZE: this is overly generous in the templates we create
if (_blockingPolicy is FullyBlockedMetadataBlockingPolicy)
return;

if (closestDefType.HasInstantiation)
{
TypeDesc canonType = type.ConvertToCanonForm(CanonicalFormKind.Specific);
TypeDesc canonClosestDefType = closestDefType.ConvertToCanonForm(CanonicalFormKind.Specific);

// Add a dependency on the template for this type, if the canonical type should be generated into this binary.
// If the type is an array type, the check should be on its underlying Array<T> type. This is because a copy of
// an array type gets placed into each module but the Array<T> type only exists in the defining module and only
// one template is needed for the Array<T> type by the dynamic type loader.
if (canonType.IsCanonicalSubtype(CanonicalFormKind.Any) && !factory.NecessaryTypeSymbol(canonClosestDefType).RepresentsIndirectionCell)
dependencies.Add(factory.NativeLayout.TemplateTypeLayout(canonType), "Template Type Layout");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ public void GetDependenciesDueToReflectability(ref DependencyList dependencies,

ReflectionInvokeSupportDependencyAlgorithm.GetDependenciesFromParamsArray(ref dependencies, factory, method);
}

GenericMethodsTemplateMap.GetTemplateMethodDependencies(ref dependencies, factory, method);
GenericTypesTemplateMap.GetTemplateTypeDependencies(ref dependencies, factory, method.OwningType);
}
}

Expand All @@ -359,6 +362,12 @@ public void GetDependenciesDueToReflectability(ref DependencyList dependencies,
{
GetMetadataDependenciesDueToReflectability(ref dependencies, factory, field);
}

if ((category & MetadataCategory.RuntimeMapping) != 0)
{
TypeDesc owningCanonicalType = field.OwningType.ConvertToCanonForm(CanonicalFormKind.Specific);
GenericTypesTemplateMap.GetTemplateTypeDependencies(ref dependencies, factory, owningCanonicalType);
}
}

/// <summary>
Expand Down Expand Up @@ -393,8 +402,6 @@ public void GetDependenciesDueToReflectability(ref DependencyList dependencies,
{
GetMetadataDependenciesDueToReflectability(ref dependencies, factory, type);
}

GetDependenciesDueToEETypePresence(ref dependencies, factory, type);
}

protected virtual void GetMetadataDependenciesDueToReflectability(ref DependencyList dependencies, NodeFactory factory, TypeDesc type)
Expand All @@ -404,11 +411,6 @@ protected virtual void GetMetadataDependenciesDueToReflectability(ref Dependency
// and property setters)
}

protected virtual void GetDependenciesDueToEETypePresence(ref DependencyList dependencies, NodeFactory factory, TypeDesc type)
{
// MetadataManagers can override this to provide additional dependencies caused by the emission of an MethodTable.
}

public virtual void GetConditionalDependenciesDueToEETypePresence(ref CombinedDependencyList dependencies, NodeFactory factory, TypeDesc type)
{
// MetadataManagers can override this to provide additional dependencies caused by the presence of
Expand Down Expand Up @@ -464,7 +466,6 @@ public void GetDependenciesDueToMethodCodePresence(ref DependencyList dependenci
ExactMethodInstantiationsNode.GetExactMethodInstantiationDependenciesForMethod(ref dependencies, factory, method);
}

GetDependenciesDueToTemplateTypeLoader(ref dependencies, factory, method);
GetDependenciesDueToMethodCodePresenceInternal(ref dependencies, factory, method, methodIL);
}

Expand All @@ -480,28 +481,6 @@ public virtual void GetConditionalDependenciesDueToMethodCodePresence(ref Combin
// method code.
}

private void GetDependenciesDueToTemplateTypeLoader(ref DependencyList dependencies, NodeFactory factory, MethodDesc method)
{
// TODO-SIZE: this is overly generous in the templates we create
if (_blockingPolicy is FullyBlockedMetadataBlockingPolicy)
return;

if (method.HasInstantiation)
{
GenericMethodsTemplateMap.GetTemplateMethodDependencies(ref dependencies, factory, method);
}
else
{
TypeDesc owningTemplateType = method.OwningType;

// Unboxing and Instantiating stubs use a different type as their template
if (factory.TypeSystemContext.IsSpecialUnboxingThunk(method))
owningTemplateType = factory.TypeSystemContext.GetTargetOfSpecialUnboxingThunk(method).OwningType;

GenericTypesTemplateMap.GetTemplateTypeDependencies(ref dependencies, factory, owningTemplateType);
}
}

protected virtual void GetDependenciesDueToMethodCodePresenceInternal(ref DependencyList dependencies, NodeFactory factory, MethodDesc method, MethodIL methodIL)
{
// MetadataManagers can override this to provide additional dependencies caused by the presence of a
Expand Down

0 comments on commit f025132

Please sign in to comment.