Skip to content

Commit b55692c

Browse files
Do not request type layout for RuntimeDetermined types (#75746)
#74123 broke compiling TechEmpower benchmarks with NativeAOT. We now crash with: ``` > ILCompiler.TypeSystem.dll!Internal.TypeSystem.RuntimeDeterminedFieldLayoutAlgorithm.ComputeInstanceLayout(Internal.TypeSystem.DefType defType, Internal.TypeSystem.InstanceLayoutKind layoutKind) Line 19 C# ILCompiler.TypeSystem.dll!Internal.TypeSystem.DefType.ComputeInstanceLayout(Internal.TypeSystem.InstanceLayoutKind layoutKind) Line 436 C# ILCompiler.TypeSystem.dll!Internal.TypeSystem.DefType.IsInt128OrHasInt128Fields.get() Line 150 C# ILCompiler.TypeSystem.dll!Internal.TypeSystem.MetadataFieldLayoutAlgorithm.ComputeAutoFieldLayout(Internal.TypeSystem.MetadataType type, int numInstanceFields) Line 483 C# ILCompiler.Compiler.dll!ILCompiler.CompilerMetadataFieldLayoutAlgorithm.ComputeInstanceFieldLayout(Internal.TypeSystem.MetadataType type, int numInstanceFields) Line 56 C# ILCompiler.TypeSystem.dll!Internal.TypeSystem.MetadataFieldLayoutAlgorithm.ComputeInstanceLayout(Internal.TypeSystem.DefType defType, Internal.TypeSystem.InstanceLayoutKind layoutKind) Line 164 C# ILCompiler.TypeSystem.dll!Internal.TypeSystem.DefType.ComputeInstanceLayout(Internal.TypeSystem.InstanceLayoutKind layoutKind) Line 436 C# ILCompiler.TypeSystem.dll!Internal.TypeSystem.DefType.InstanceFieldSize.get() Line 165 C# ILCompiler.TypeSystem.dll!Internal.TypeSystem.MetadataFieldLayoutAlgorithm.ComputeFieldSizeAndAlignment(Internal.TypeSystem.TypeDesc fieldType, bool hasLayout, int packingSize, out bool layoutAbiStable, out bool fieldTypeHasAutoLayout, out bool fieldTypeHasInt128Field) Line 838 C# ILCompiler.TypeSystem.dll!Internal.TypeSystem.MetadataFieldLayoutAlgorithm.ComputeStaticFieldLayout(Internal.TypeSystem.DefType defType, Internal.TypeSystem.StaticLayoutKind layoutKind) Line 215 C# ILCompiler.TypeSystem.dll!Internal.TypeSystem.DefType.ComputeStaticFieldLayout(Internal.TypeSystem.StaticLayoutKind layoutKind) Line 473 C# ILCompiler.TypeSystem.dll!Internal.TypeSystem.DefType.GCStaticFieldSize.get() Line 302 C# ILCompiler.Compiler.dll!ILCompiler.DependencyAnalysis.NativeLayoutTemplateTypeLayoutVertexNode.GetStaticDependencies(ILCompiler.DependencyAnalysis.NodeFactory context) Line 997 C# ``` https://github.com/dotnet/runtime/blob/4cf1383c8458945b7eb27ae5f57338c10ed25d54/src/coreclr/tools/Common/TypeSystem/RuntimeDetermined/RuntimeDeterminedFieldLayoutAlgorithm.cs#L17-L19 I was not able to come up with a standalone repro case, but this fixes compiling the benchmark. I'm not clear why native layout operates on runtime determined forms, but what I'm doing here should have equivalent behaviors, except avoiding the problem that we can no longer compute layouts of runtime determined things in some obscure scenarios due to the new code.
1 parent 8617efd commit b55692c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NativeLayoutVertexNode.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -950,15 +950,17 @@ private static TypeDesc GetActualTemplateTypeForType(NodeFactory factory, TypeDe
950950

951951
private ISymbolNode GetStaticsNode(NodeFactory context, out BagElementKind staticsBagKind)
952952
{
953-
ISymbolNode symbol = context.GCStaticEEType(GCPointerMap.FromStaticLayout(_type.GetClosestDefType()));
953+
DefType closestCanonDefType = (DefType)_type.GetClosestDefType().ConvertToCanonForm(CanonicalFormKind.Specific);
954+
ISymbolNode symbol = context.GCStaticEEType(GCPointerMap.FromStaticLayout(closestCanonDefType));
954955
staticsBagKind = BagElementKind.GcStaticDesc;
955956

956957
return symbol;
957958
}
958959

959960
private ISymbolNode GetThreadStaticsNode(NodeFactory context, out BagElementKind staticsBagKind)
960961
{
961-
ISymbolNode symbol = context.GCStaticEEType(GCPointerMap.FromThreadStaticLayout(_type.GetClosestDefType()));
962+
DefType closestCanonDefType = (DefType)_type.GetClosestDefType().ConvertToCanonForm(CanonicalFormKind.Specific);
963+
ISymbolNode symbol = context.GCStaticEEType(GCPointerMap.FromThreadStaticLayout(closestCanonDefType));
962964
staticsBagKind = BagElementKind.ThreadStaticDesc;
963965

964966
return symbol;
@@ -994,13 +996,14 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
994996

995997
if (!_isUniversalCanon)
996998
{
997-
if (_type.GetClosestDefType().GCStaticFieldSize.AsInt > 0)
999+
DefType closestCanonDefType = (DefType)_type.GetClosestDefType().ConvertToCanonForm(CanonicalFormKind.Specific);
1000+
if (closestCanonDefType.GCStaticFieldSize.AsInt > 0)
9981001
{
9991002
BagElementKind ignored;
10001003
yield return new DependencyListEntry(GetStaticsNode(context, out ignored), "type gc static info");
10011004
}
10021005

1003-
if (_type.GetClosestDefType().ThreadGcStaticFieldSize.AsInt > 0)
1006+
if (closestCanonDefType.ThreadGcStaticFieldSize.AsInt > 0)
10041007
{
10051008
BagElementKind ignored;
10061009
yield return new DependencyListEntry(GetThreadStaticsNode(context, out ignored), "type thread static info");
@@ -1200,24 +1203,24 @@ public override Vertex WriteVertex(NodeFactory factory)
12001203

12011204
if (!_isUniversalCanon)
12021205
{
1203-
DefType closestDefType = _type.GetClosestDefType();
1204-
if (closestDefType.NonGCStaticFieldSize.AsInt != 0)
1206+
DefType closestCanonDefType = (DefType)_type.GetClosestDefType().ConvertToCanonForm(CanonicalFormKind.Specific);
1207+
if (closestCanonDefType.NonGCStaticFieldSize.AsInt != 0)
12051208
{
1206-
layoutInfo.AppendUnsigned(BagElementKind.NonGcStaticDataSize, checked((uint)closestDefType.NonGCStaticFieldSize.AsInt));
1209+
layoutInfo.AppendUnsigned(BagElementKind.NonGcStaticDataSize, checked((uint)closestCanonDefType.NonGCStaticFieldSize.AsInt));
12071210
}
12081211

1209-
if (closestDefType.GCStaticFieldSize.AsInt != 0)
1212+
if (closestCanonDefType.GCStaticFieldSize.AsInt != 0)
12101213
{
1211-
layoutInfo.AppendUnsigned(BagElementKind.GcStaticDataSize, checked((uint)closestDefType.GCStaticFieldSize.AsInt));
1214+
layoutInfo.AppendUnsigned(BagElementKind.GcStaticDataSize, checked((uint)closestCanonDefType.GCStaticFieldSize.AsInt));
12121215
BagElementKind staticDescBagType;
12131216
ISymbolNode staticsDescSymbol = GetStaticsNode(factory, out staticDescBagType);
12141217
uint gcStaticsSymbolIndex = factory.MetadataManager.NativeLayoutInfo.StaticsReferences.GetIndex(staticsDescSymbol);
12151218
layoutInfo.AppendUnsigned(staticDescBagType, gcStaticsSymbolIndex);
12161219
}
12171220

1218-
if (closestDefType.ThreadGcStaticFieldSize.AsInt != 0)
1221+
if (closestCanonDefType.ThreadGcStaticFieldSize.AsInt != 0)
12191222
{
1220-
layoutInfo.AppendUnsigned(BagElementKind.ThreadStaticDataSize, checked((uint)closestDefType.ThreadGcStaticFieldSize.AsInt));
1223+
layoutInfo.AppendUnsigned(BagElementKind.ThreadStaticDataSize, checked((uint)closestCanonDefType.ThreadGcStaticFieldSize.AsInt));
12211224
BagElementKind threadStaticDescBagType;
12221225
ISymbolNode threadStaticsDescSymbol = GetThreadStaticsNode(factory, out threadStaticDescBagType);
12231226
uint threadStaticsSymbolIndex = factory.MetadataManager.NativeLayoutInfo.StaticsReferences.GetIndex(threadStaticsDescSymbol);

0 commit comments

Comments
 (0)