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

Last ILCompiler.TypeSystem <-> ILCompiler.TypeSystem.ReadyToRun diff #63281

Merged
merged 1 commit into from
Jan 3, 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
16 changes: 0 additions & 16 deletions src/coreclr/tools/Common/TypeSystem/Aot/TargetDetails.Aot.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,73 @@ private static void FromInstanceLayoutHelper(ref GCPointerMapBuilder builder, De
}
}
}

/// <summary>
/// Computes the GC pointer map of the GC static region of the type.
/// </summary>
public static GCPointerMap FromStaticLayout(DefType type)
{
GCPointerMapBuilder builder = new GCPointerMapBuilder(type.GCStaticFieldSize.AsInt, type.Context.Target.PointerSize);

foreach (FieldDesc field in type.GetFields())
{
if (!field.IsStatic || field.HasRva || field.IsLiteral
|| field.IsThreadStatic || !field.HasGCStaticBase)
continue;

TypeDesc fieldType = field.FieldType;
if (fieldType.IsGCPointer)
{
builder.MarkGCPointer(field.Offset.AsInt);
}
else
{
Debug.Assert(fieldType.IsValueType);
var fieldDefType = (DefType)fieldType;
if (fieldDefType.ContainsGCPointers)
{
GCPointerMapBuilder innerBuilder =
builder.GetInnerBuilder(field.Offset.AsInt, fieldDefType.InstanceByteCount.AsInt);
FromInstanceLayoutHelper(ref innerBuilder, fieldDefType);
}
}
}

Debug.Assert(builder.ToGCMap().Size * type.Context.Target.PointerSize >= type.GCStaticFieldSize.AsInt);
return builder.ToGCMap();
}

/// <summary>
/// Computes the GC pointer map of the thread static region of the type.
/// </summary>
public static GCPointerMap FromThreadStaticLayout(DefType type)
{
GCPointerMapBuilder builder = new GCPointerMapBuilder(type.ThreadGcStaticFieldSize.AsInt, type.Context.Target.PointerSize);

foreach (FieldDesc field in type.GetFields())
{
if (!field.IsStatic || field.HasRva || field.IsLiteral || !field.IsThreadStatic || !field.HasGCStaticBase)
continue;

TypeDesc fieldType = field.FieldType;
if (fieldType.IsGCPointer)
{
builder.MarkGCPointer(field.Offset.AsInt);
}
else if (fieldType.IsValueType)
{
var fieldDefType = (DefType)fieldType;
if (fieldDefType.ContainsGCPointers)
{
GCPointerMapBuilder innerBuilder =
builder.GetInnerBuilder(field.Offset.AsInt, fieldDefType.InstanceByteCount.AsInt);
FromInstanceLayoutHelper(ref innerBuilder, fieldDefType);
}
}
}

Debug.Assert(builder.ToGCMap().Size * type.Context.Target.PointerSize >= type.ThreadGcStaticFieldSize.AsInt);
return builder.ToGCMap();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,156 @@ public static string GetName(this MethodSignature signature)
return nameBuilder.ToString();
}
}

public class UniqueTypeNameFormatter : TypeNameFormatter
{
public static UniqueTypeNameFormatter Instance { get; } = new UniqueTypeNameFormatter();

public override void AppendName(StringBuilder sb, PointerType type)
{
AppendName(sb, type.ParameterType);
sb.Append('*');
}

public override void AppendName(StringBuilder sb, GenericParameterDesc type)
{
string prefix = type.Kind == GenericParameterKind.Type ? "!" : "!!";
sb.Append(prefix);
sb.Append(type.Name);
}

public override void AppendName(StringBuilder sb, SignatureTypeVariable type)
{
sb.Append("!");
sb.Append(type.Index.ToStringInvariant());
}

public override void AppendName(StringBuilder sb, SignatureMethodVariable type)
{
sb.Append("!!");
sb.Append(type.Index.ToStringInvariant());
}

public override void AppendName(StringBuilder sb, FunctionPointerType type)
{
MethodSignature signature = type.Signature;

AppendName(sb, signature.ReturnType);

sb.Append(" (");
for (int i = 0; i < signature.Length; i++)
{
if (i > 0)
sb.Append(", ");
AppendName(sb, signature[i]);
}

// TODO: Append '...' for vararg methods

sb.Append(')');
}

public override void AppendName(StringBuilder sb, ByRefType type)
{
AppendName(sb, type.ParameterType);
sb.Append(" ByRef");
}

public override void AppendName(StringBuilder sb, ArrayType type)
{
AppendName(sb, type.ElementType);
sb.Append('[');

if (type.Rank == 1 && type.IsMdArray)
sb.Append('*');
sb.Append(',', type.Rank - 1);

sb.Append(']');
}

protected override void AppendNameForInstantiatedType(StringBuilder sb, DefType type)
{
AppendName(sb, type.GetTypeDefinition());
sb.Append('<');

for (int i = 0; i < type.Instantiation.Length; i++)
{
if (i > 0)
sb.Append(", ");
AppendName(sb, type.Instantiation[i]);
}

sb.Append('>');
}

protected override void AppendNameForNamespaceType(StringBuilder sb, DefType type)
{
string ns = GetTypeNamespace(type);
if (ns.Length > 0)
{
AppendEscapedIdentifier(sb, ns);
sb.Append('.');
}
AppendEscapedIdentifier(sb, GetTypeName(type));

if (type is MetadataType)
{
IAssemblyDesc homeAssembly = ((MetadataType)type).Module as IAssemblyDesc;
AppendAssemblyName(sb, homeAssembly);
}
}

private void AppendAssemblyName(StringBuilder sb, IAssemblyDesc assembly)
{
if (assembly == null)
return;

sb.Append(',');
AppendEscapedIdentifier(sb, assembly.GetName().Name);
}

protected override void AppendNameForNestedType(StringBuilder sb, DefType nestedType, DefType containingType)
{
AppendName(sb, containingType);

sb.Append('+');

string ns = GetTypeNamespace(nestedType);
if (ns.Length > 0)
{
AppendEscapedIdentifier(sb, ns);
sb.Append('.');
}
AppendEscapedIdentifier(sb, GetTypeName(nestedType));
}

private string GetTypeName(DefType type)
{
return type.Name;
}

private string GetTypeNamespace(DefType type)
{
return type.Namespace;
}

private static char[] s_escapedChars = new char[] { ',', '=', '"', ']', '[', '*', '&', '+', '\\' };
private void AppendEscapedIdentifier(StringBuilder sb, string identifier)
{
if (identifier.IndexOfAny(s_escapedChars) < 0)
{
string escapedIdentifier = identifier;
foreach (char escapedChar in s_escapedChars)
{
string escapedCharString = new string(escapedChar, 1);
escapedIdentifier = escapedIdentifier.Replace(escapedCharString, "\\" + escapedCharString);
}
sb.Append(escapedIdentifier);
}
else
{
sb.Append(identifier);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
}

int ISymbolDefinitionNode.Offset => 0;
int ISymbolNode.Offset => Method.Context.Target.FatFunctionPointerOffset;
int ISymbolNode.Offset => Method.Context.Target.Architecture == TargetArchitecture.Wasm32 ? 1 << 31 : 2;

public override bool IsShareable => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@
<Compile Include="..\..\Common\TypeSystem\Canon\TypeSystemContext.Canon.cs">
<Link>TypeSystem\Canon\TypeSystemContext.Canon.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Aot\TargetDetails.Aot.cs">
<Link>TypeSystem\Aot\TargetDetails.Aot.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\CodeGen\FieldDesc.CodeGen.cs">
<Link>TypeSystem\CodeGen\FieldDesc.CodeGen.cs</Link>
</Compile>
Expand Down Expand Up @@ -181,9 +178,6 @@
<Compile Include="..\..\Common\TypeSystem\Common\Utilities\GCPointerMap.Algorithm.cs">
<Link>Utilities\GCPointerMap.Algorithm.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Common\Utilities\GCPointerMap.Aot.cs">
<Link>Utilities\GCPointerMap.Aot.cs</Link>
</Compile>
<Compile Include="..\..\Common\TypeSystem\Common\Utilities\GCPointerMap.cs">
<Link>Utilities\GCPointerMap.cs</Link>
</Compile>
Expand Down Expand Up @@ -808,6 +802,5 @@
<Compile Include="..\..\Common\TypeSystem\Sorting\TypeSystemComparer.cs">
<Link>TypeSystem\Sorting\TypeSystemComparer.cs</Link>
</Compile>
<Compile Include="Utilities\UniqueTypeNameFormatter.cs" />
</ItemGroup>
</Project>
Loading