Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky committed Jul 18, 2024
1 parent 2b3088b commit ba3d31d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1252,9 +1252,20 @@ protected void OutputGenericInstantiationDetails(NodeFactory factory, ref Object
else
objData.EmitPointerReloc(typeDefNode);

ISymbolNode compositionNode = _type.Instantiation.Length > 1
? factory.GenericComposition(_type.Instantiation)
: factory.NecessaryTypeSymbol(_type.Instantiation[0]);
ISymbolNode compositionNode;

if (this == factory.MaximallyConstructableType(_type))
{
compositionNode = _type.Instantiation.Length > 1
? factory.ConstructedGenericComposition(_type.Instantiation)
: factory.MaximallyConstructableType(_type.Instantiation[0]);
}
else
{
compositionNode = _type.Instantiation.Length > 1
? factory.GenericComposition(_type.Instantiation)
: factory.NecessaryTypeSymbol(_type.Instantiation[0]);
}

if (factory.Target.SupportsRelativePointers)
objData.EmitReloc(compositionNode, RelocType.IMAGE_REL_BASED_RELPTR32);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ namespace ILCompiler.DependencyAnalysis
/// </summary>
public class GenericCompositionNode : ObjectNode, ISymbolDefinitionNode
{
private Instantiation _details;
private readonly Instantiation _details;
private readonly bool _constructed;

internal GenericCompositionNode(Instantiation details)
internal GenericCompositionNode(Instantiation details, bool constructed)
{
_details = details;
_constructed = constructed;
}

public override bool ShouldSkipEmittingObjectNode(NodeFactory factory) => !_constructed && factory.ConstructedGenericComposition(_details).Marked;

public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
{
sb.Append("__GenericInstance"u8);
Expand Down Expand Up @@ -62,10 +66,12 @@ public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false)

foreach (var typeArg in _details)
{
IEETypeNode node = _constructed ? factory.MaximallyConstructableType(typeArg) : factory.NecessaryTypeSymbol(typeArg);

if (useRelativePointers)
builder.EmitReloc(factory.NecessaryTypeSymbol(typeArg), RelocType.IMAGE_REL_BASED_RELPTR32);
builder.EmitReloc(node, RelocType.IMAGE_REL_BASED_RELPTR32);
else
builder.EmitPointerReloc(factory.NecessaryTypeSymbol(typeArg));
builder.EmitPointerReloc(node);
}

return builder.ToObjectData();
Expand All @@ -81,6 +87,10 @@ public override int CompareToImpl(ISortableNode other, CompilerComparer comparer
if (compare != 0)
return compare;

compare = _constructed.CompareTo(otherComposition._constructed);
if (compare != 0)
return compare;

for (int i = 0; i < _details.Length; i++)
{
compare = comparer.Compare(_details[i], otherComposition._details[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,12 @@ private void CreateNodeCaches()

_genericCompositions = new NodeCache<Instantiation, GenericCompositionNode>((Instantiation details) =>
{
return new GenericCompositionNode(details);
return new GenericCompositionNode(details, constructed: false);
});

_constructedGenericCompositions = new NodeCache<Instantiation, GenericCompositionNode>((Instantiation details) =>
{
return new GenericCompositionNode(details, constructed: true);
});

_genericVariances = new NodeCache<GenericVarianceDetails, GenericVarianceNode>((GenericVarianceDetails details) =>
Expand Down Expand Up @@ -842,6 +847,13 @@ internal ISymbolNode GenericComposition(Instantiation details)
return _genericCompositions.GetOrAdd(details);
}

private NodeCache<Instantiation, GenericCompositionNode> _constructedGenericCompositions;

internal ISymbolNode ConstructedGenericComposition(Instantiation details)
{
return _constructedGenericCompositions.GetOrAdd(details);
}

private NodeCache<GenericVarianceDetails, GenericVarianceNode> _genericVariances;

internal ISymbolNode GenericVariance(GenericVarianceDetails details)
Expand Down

0 comments on commit ba3d31d

Please sign in to comment.