Skip to content

Reflection: Update extra inhabitants logic for structs. #19254

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

Merged
merged 1 commit into from
Sep 12, 2018
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
31 changes: 26 additions & 5 deletions stdlib/public/Reflection/TypeLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,33 @@ unsigned RecordTypeInfoBuilder::addField(unsigned fieldSize,
// Update the aggregate alignment
Alignment = std::max(Alignment, fieldAlignment);

// The extra inhabitants of a record are the same as the extra
// inhabitants of the first field of the record.
if (Empty) {
NumExtraInhabitants = numExtraInhabitants;
Empty = false;
switch (Kind) {
// The extra inhabitants of a struct are the same as the extra
// inhabitants of the field that has the most.
case RecordKind::Struct:
NumExtraInhabitants = std::max(NumExtraInhabitants, numExtraInhabitants);
break;

// For other kinds of records, we only use the extra inhabitants of the
// first field.
case RecordKind::ClassExistential:
case RecordKind::ClassInstance:
case RecordKind::ClosureContext:
case RecordKind::ErrorExistential:
case RecordKind::ExistentialMetatype:
case RecordKind::Invalid:
case RecordKind::MultiPayloadEnum:
case RecordKind::NoPayloadEnum:
case RecordKind::OpaqueExistential:
case RecordKind::SinglePayloadEnum:
case RecordKind::ThickFunction:
case RecordKind::Tuple:
if (Empty) {
NumExtraInhabitants = numExtraInhabitants;
}
break;
}
Empty = false;

return offset;
}
Expand Down
6 changes: 3 additions & 3 deletions test/Reflection/typeref_lowering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@

12TypeLowering17ExistentialStructV
// CHECK-64: (struct TypeLowering.ExistentialStruct)
// CHECK-64-NEXT: (struct size=464 alignment=8 stride=464 num_extra_inhabitants=0
// CHECK-64-NEXT: (struct size=464 alignment=8 stride=464 num_extra_inhabitants=[[PTR_XI]]
// CHECK-64-NEXT: (field name=any offset=0
// CHECK-64-NEXT: (opaque_existential size=32 alignment=8 stride=32 num_extra_inhabitants=0
// CHECK-64-NEXT: (field name=metadata offset=24
Expand Down Expand Up @@ -645,7 +645,7 @@
// CHECK-64-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=1)))))

// CHECK-32: (struct TypeLowering.ExistentialStruct)
// CHECK-32-NEXT: (struct size=232 alignment=4 stride=232 num_extra_inhabitants=0
// CHECK-32-NEXT: (struct size=232 alignment=4 stride=232 num_extra_inhabitants=4096
// CHECK-32-NEXT: (field name=any offset=0
// CHECK-32-NEXT: (opaque_existential size=16 alignment=4 stride=16 num_extra_inhabitants=0
// CHECK-32-NEXT: (field name=metadata offset=12
Expand Down Expand Up @@ -924,7 +924,7 @@

12TypeLowering10EnumStructV
// CHECK-64: (struct TypeLowering.EnumStruct)
// CHECK-64-NEXT: (struct size=81 alignment=8 stride=88 num_extra_inhabitants=0
// CHECK-64-NEXT: (struct size=81 alignment=8 stride=88 num_extra_inhabitants=[[PTR_XI]]
// CHECK-64-NEXT: (field name=empty offset=0
// CHECK-64-NEXT: (no_payload_enum size=0 alignment=1 stride=1 num_extra_inhabitants=0))
// CHECK-64-NEXT: (field name=noPayload offset=0
Expand Down
2 changes: 1 addition & 1 deletion test/Reflection/typeref_lowering_objc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// CHECK-NEXT: (reference kind=strong refcounting=unknown)

12TypeLowering11HasObjCEnumV
// CHECK: (struct size=24 alignment=8 stride=24 num_extra_inhabitants=0
// CHECK: (struct size=24 alignment=8 stride=24 num_extra_inhabitants=2147483647
// CHECK-NEXT: (field name=optionalEnum offset=0
// CHECK-NEXT: (single_payload_enum size=9 alignment=8 stride=16 num_extra_inhabitants=0
// CHECK-NEXT: (field name=some offset=0
Expand Down