Skip to content

Commit 27396a2

Browse files
Do not request type layout for RuntimeDetermined types (#75789)
#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. Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
1 parent b23dc07 commit 27396a2

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
@@ -953,15 +953,17 @@ private static TypeDesc GetActualTemplateTypeForType(NodeFactory factory, TypeDe
953953

954954
private ISymbolNode GetStaticsNode(NodeFactory context, out BagElementKind staticsBagKind)
955955
{
956-
ISymbolNode symbol = context.GCStaticEEType(GCPointerMap.FromStaticLayout(_type.GetClosestDefType()));
956+
DefType closestCanonDefType = (DefType)_type.GetClosestDefType().ConvertToCanonForm(CanonicalFormKind.Specific);
957+
ISymbolNode symbol = context.GCStaticEEType(GCPointerMap.FromStaticLayout(closestCanonDefType));
957958
staticsBagKind = BagElementKind.GcStaticDesc;
958959

959960
return symbol;
960961
}
961962

962963
private ISymbolNode GetThreadStaticsNode(NodeFactory context, out BagElementKind staticsBagKind)
963964
{
964-
ISymbolNode symbol = context.GCStaticEEType(GCPointerMap.FromThreadStaticLayout(_type.GetClosestDefType()));
965+
DefType closestCanonDefType = (DefType)_type.GetClosestDefType().ConvertToCanonForm(CanonicalFormKind.Specific);
966+
ISymbolNode symbol = context.GCStaticEEType(GCPointerMap.FromThreadStaticLayout(closestCanonDefType));
965967
staticsBagKind = BagElementKind.ThreadStaticDesc;
966968

967969
return symbol;
@@ -997,13 +999,14 @@ public override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFacto
997999

9981000
if (!_isUniversalCanon)
9991001
{
1000-
if (_type.GetClosestDefType().GCStaticFieldSize.AsInt > 0)
1002+
DefType closestCanonDefType = (DefType)_type.GetClosestDefType().ConvertToCanonForm(CanonicalFormKind.Specific);
1003+
if (closestCanonDefType.GCStaticFieldSize.AsInt > 0)
10011004
{
10021005
BagElementKind ignored;
10031006
yield return new DependencyListEntry(GetStaticsNode(context, out ignored), "type gc static info");
10041007
}
10051008

1006-
if (_type.GetClosestDefType().ThreadGcStaticFieldSize.AsInt > 0)
1009+
if (closestCanonDefType.ThreadGcStaticFieldSize.AsInt > 0)
10071010
{
10081011
BagElementKind ignored;
10091012
yield return new DependencyListEntry(GetThreadStaticsNode(context, out ignored), "type thread static info");
@@ -1207,24 +1210,24 @@ public override Vertex WriteVertex(NodeFactory factory)
12071210

12081211
if (!_isUniversalCanon)
12091212
{
1210-
DefType closestDefType = _type.GetClosestDefType();
1211-
if (closestDefType.NonGCStaticFieldSize.AsInt != 0)
1213+
DefType closestCanonDefType = (DefType)_type.GetClosestDefType().ConvertToCanonForm(CanonicalFormKind.Specific);
1214+
if (closestCanonDefType.NonGCStaticFieldSize.AsInt != 0)
12121215
{
1213-
layoutInfo.AppendUnsigned(BagElementKind.NonGcStaticDataSize, checked((uint)closestDefType.NonGCStaticFieldSize.AsInt));
1216+
layoutInfo.AppendUnsigned(BagElementKind.NonGcStaticDataSize, checked((uint)closestCanonDefType.NonGCStaticFieldSize.AsInt));
12141217
}
12151218

1216-
if (closestDefType.GCStaticFieldSize.AsInt != 0)
1219+
if (closestCanonDefType.GCStaticFieldSize.AsInt != 0)
12171220
{
1218-
layoutInfo.AppendUnsigned(BagElementKind.GcStaticDataSize, checked((uint)closestDefType.GCStaticFieldSize.AsInt));
1221+
layoutInfo.AppendUnsigned(BagElementKind.GcStaticDataSize, checked((uint)closestCanonDefType.GCStaticFieldSize.AsInt));
12191222
BagElementKind staticDescBagType;
12201223
ISymbolNode staticsDescSymbol = GetStaticsNode(factory, out staticDescBagType);
12211224
uint gcStaticsSymbolIndex = factory.MetadataManager.NativeLayoutInfo.StaticsReferences.GetIndex(staticsDescSymbol);
12221225
layoutInfo.AppendUnsigned(staticDescBagType, gcStaticsSymbolIndex);
12231226
}
12241227

1225-
if (closestDefType.ThreadGcStaticFieldSize.AsInt != 0)
1228+
if (closestCanonDefType.ThreadGcStaticFieldSize.AsInt != 0)
12261229
{
1227-
layoutInfo.AppendUnsigned(BagElementKind.ThreadStaticDataSize, checked((uint)closestDefType.ThreadGcStaticFieldSize.AsInt));
1230+
layoutInfo.AppendUnsigned(BagElementKind.ThreadStaticDataSize, checked((uint)closestCanonDefType.ThreadGcStaticFieldSize.AsInt));
12281231
BagElementKind threadStaticDescBagType;
12291232
ISymbolNode threadStaticsDescSymbol = GetThreadStaticsNode(factory, out threadStaticDescBagType);
12301233
uint threadStaticsSymbolIndex = factory.MetadataManager.NativeLayoutInfo.StaticsReferences.GetIndex(threadStaticsDescSymbol);

0 commit comments

Comments
 (0)