Skip to content

Commit 139c1e5

Browse files
authored
Merge pull request #19254 from jckarter/reflection-extra-inhabitants
Reflection: Update extra inhabitants logic for structs.
2 parents 9cda374 + d249725 commit 139c1e5

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

stdlib/public/Reflection/TypeLowering.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,33 @@ unsigned RecordTypeInfoBuilder::addField(unsigned fieldSize,
433433
// Update the aggregate alignment
434434
Alignment = std::max(Alignment, fieldAlignment);
435435

436-
// The extra inhabitants of a record are the same as the extra
437-
// inhabitants of the first field of the record.
438-
if (Empty) {
439-
NumExtraInhabitants = numExtraInhabitants;
440-
Empty = false;
436+
switch (Kind) {
437+
// The extra inhabitants of a struct are the same as the extra
438+
// inhabitants of the field that has the most.
439+
case RecordKind::Struct:
440+
NumExtraInhabitants = std::max(NumExtraInhabitants, numExtraInhabitants);
441+
break;
442+
443+
// For other kinds of records, we only use the extra inhabitants of the
444+
// first field.
445+
case RecordKind::ClassExistential:
446+
case RecordKind::ClassInstance:
447+
case RecordKind::ClosureContext:
448+
case RecordKind::ErrorExistential:
449+
case RecordKind::ExistentialMetatype:
450+
case RecordKind::Invalid:
451+
case RecordKind::MultiPayloadEnum:
452+
case RecordKind::NoPayloadEnum:
453+
case RecordKind::OpaqueExistential:
454+
case RecordKind::SinglePayloadEnum:
455+
case RecordKind::ThickFunction:
456+
case RecordKind::Tuple:
457+
if (Empty) {
458+
NumExtraInhabitants = numExtraInhabitants;
459+
}
460+
break;
441461
}
462+
Empty = false;
442463

443464
return offset;
444465
}

test/Reflection/typeref_lowering.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@
514514

515515
12TypeLowering17ExistentialStructV
516516
// CHECK-64: (struct TypeLowering.ExistentialStruct)
517-
// CHECK-64-NEXT: (struct size=464 alignment=8 stride=464 num_extra_inhabitants=0
517+
// CHECK-64-NEXT: (struct size=464 alignment=8 stride=464 num_extra_inhabitants=[[PTR_XI]]
518518
// CHECK-64-NEXT: (field name=any offset=0
519519
// CHECK-64-NEXT: (opaque_existential size=32 alignment=8 stride=32 num_extra_inhabitants=0
520520
// CHECK-64-NEXT: (field name=metadata offset=24
@@ -645,7 +645,7 @@
645645
// CHECK-64-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=1)))))
646646

647647
// CHECK-32: (struct TypeLowering.ExistentialStruct)
648-
// CHECK-32-NEXT: (struct size=232 alignment=4 stride=232 num_extra_inhabitants=0
648+
// CHECK-32-NEXT: (struct size=232 alignment=4 stride=232 num_extra_inhabitants=4096
649649
// CHECK-32-NEXT: (field name=any offset=0
650650
// CHECK-32-NEXT: (opaque_existential size=16 alignment=4 stride=16 num_extra_inhabitants=0
651651
// CHECK-32-NEXT: (field name=metadata offset=12
@@ -924,7 +924,7 @@
924924

925925
12TypeLowering10EnumStructV
926926
// CHECK-64: (struct TypeLowering.EnumStruct)
927-
// CHECK-64-NEXT: (struct size=81 alignment=8 stride=88 num_extra_inhabitants=0
927+
// CHECK-64-NEXT: (struct size=81 alignment=8 stride=88 num_extra_inhabitants=[[PTR_XI]]
928928
// CHECK-64-NEXT: (field name=empty offset=0
929929
// CHECK-64-NEXT: (no_payload_enum size=0 alignment=1 stride=1 num_extra_inhabitants=0))
930930
// CHECK-64-NEXT: (field name=noPayload offset=0

test/Reflection/typeref_lowering_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// CHECK-NEXT: (reference kind=strong refcounting=unknown)
2121

2222
12TypeLowering11HasObjCEnumV
23-
// CHECK: (struct size=24 alignment=8 stride=24 num_extra_inhabitants=0
23+
// CHECK: (struct size=24 alignment=8 stride=24 num_extra_inhabitants=2147483647
2424
// CHECK-NEXT: (field name=optionalEnum offset=0
2525
// CHECK-NEXT: (single_payload_enum size=9 alignment=8 stride=16 num_extra_inhabitants=0
2626
// CHECK-NEXT: (field name=some offset=0

0 commit comments

Comments
 (0)