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

Don't report dependency on canonical forms just because there's GVMs #103331

Closed
wants to merge 3 commits into from
Closed
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 @@ -234,8 +234,7 @@ public static int GetMinimumObjectSize(TypeSystemContext typeSystemContext)

protected virtual bool EmitVirtualSlots => false;

public override bool InterestingForDynamicDependencyAnalysis
=> (_virtualMethodAnalysisFlags & VirtualMethodAnalysisFlags.InterestingForDynamicDependencies) != 0;
public override bool InterestingForDynamicDependencyAnalysis => false;

internal bool HasOptionalFields
{
Expand Down Expand Up @@ -624,10 +623,11 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact
dependencies.Add(new DependencyListEntry(factory.TypeGVMEntries(_type.GetTypeDefinition()), "Type with generic virtual methods"));

AddDependenciesForUniversalGVMSupport(factory, _type, ref dependencies);
}

TypeDesc canonicalType = _type.ConvertToCanonForm(CanonicalFormKind.Specific);
if (canonicalType != _type)
dependencies.Add(factory.ConstructedTypeSymbol(canonicalType), "Type with generic virtual methods");
if ((_virtualMethodAnalysisFlags & VirtualMethodAnalysisFlags.InterestingForDynamicDependencies) != 0)
{
dependencies.Add(factory.TypeWithGenericVirtualMethods(_type), "Type with generic virtual methods");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,10 @@ public override IEnumerable<CombinedDependencyListEntry> SearchDynamicDependenci
for (int i = firstNode; i < markedNodes.Count; i++)
{
DependencyNodeCore<NodeFactory> entry = markedNodes[i];
EETypeNode entryAsEETypeNode;

// This method is often called with a long list of ScannedMethodNode
// or MethodCodeNode nodes. We are not interested in those. In order
// to make the type check as cheap as possible we check for specific
// *sealed* types instead of doing `entry is EETypeNode` which has
// to walk the whole class hierarchy for the non matching nodes.
if (entry is ConstructedEETypeNode constructedEETypeNode)
entryAsEETypeNode = constructedEETypeNode;
else if (entry is CanonicalEETypeNode canonicalEETypeNode)
entryAsEETypeNode = canonicalEETypeNode;
else
if (entry is not TypeWithGenericVirtualMethodsNode gvmType)
continue;

TypeDesc potentialOverrideType = entryAsEETypeNode.Type;
TypeDesc potentialOverrideType = gvmType.Type;
if (!potentialOverrideType.IsDefType || potentialOverrideType.IsInterface)
continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ private void CreateNodeCaches()
return new GenericMethodsHashtableEntryNode(method);
});

_typesWithGvms = new NodeCache<TypeDesc, TypeWithGenericVirtualMethodsNode>(type =>
{
return new TypeWithGenericVirtualMethodsNode(type);
});

_gvmTableEntries = new NodeCache<TypeDesc, TypeGVMEntriesNode>(type =>
{
return new TypeGVMEntriesNode(type);
Expand Down Expand Up @@ -1007,6 +1012,12 @@ public GenericMethodsHashtableEntryNode GenericMethodsHashtableEntry(MethodDesc
return _genericMethodEntries.GetOrAdd(method);
}

private NodeCache<TypeDesc, TypeWithGenericVirtualMethodsNode> _typesWithGvms;
internal TypeWithGenericVirtualMethodsNode TypeWithGenericVirtualMethods(TypeDesc type)
{
return _typesWithGvms.GetOrAdd(type);
}

private NodeCache<TypeDesc, TypeGVMEntriesNode> _gvmTableEntries;
internal TypeGVMEntriesNode TypeGVMEntries(TypeDesc type)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;

using Internal.TypeSystem;

using ILCompiler.DependencyAnalysisFramework;

namespace ILCompiler.DependencyAnalysis
{
internal sealed class TypeWithGenericVirtualMethodsNode : DependencyNodeCore<NodeFactory>
{
private readonly TypeDesc _type;

public TypeWithGenericVirtualMethodsNode(TypeDesc type)
{
_type = type;
}

public TypeDesc Type => _type;

public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory factory)
{
TypeDesc canonType = _type.ConvertToCanonForm(CanonicalFormKind.Specific);
if (_type != canonType)
return [new DependencyListEntry(factory.TypeWithGenericVirtualMethods(canonType), "Canonical form")];
return null;
}

public override bool HasConditionalStaticDependencies => false;
public override bool HasDynamicDependencies => false;
public override bool InterestingForDynamicDependencyAnalysis => true;
public override bool StaticDependenciesAreComputed => true;
protected override string GetName(NodeFactory factory) => $"Generic virtual method analysis for {_type}";
public override IEnumerable<CombinedDependencyListEntry> GetConditionalStaticDependencies(NodeFactory context) => null;
public override IEnumerable<CombinedDependencyListEntry> SearchDynamicDependencies(List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory context) => null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
<Compile Include="Compiler\DependencyAnalysis\TentativeInstanceMethodNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\TentativeMethodNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\TrimmingDescriptorNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\TypeWithGenericVirtualMethodsNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\VariantInterfaceMethodUseNode.cs" />
<Compile Include="Compiler\DependencyAnalysis\CustomAttributeBasedDependencyAlgorithm.cs" />
<Compile Include="Compiler\DependencyAnalysis\FieldMetadataNode.cs" />
Expand Down
Loading