Skip to content

Commit 72810db

Browse files
authored
Merge pull request swiftlang#78981 from tbkka/tbkka-rdar143402921-6.1
Fix field count in emitted reflection data
2 parents 37cda5d + 2eb79a0 commit 72810db

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

lib/IRGen/GenReflection.cpp

+27-10
Original file line numberDiff line numberDiff line change
@@ -929,18 +929,35 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
929929
B.addInt16(uint16_t(kind));
930930
B.addInt16(FieldRecordSize);
931931

932-
B.addInt32(getNumFields(NTD));
932+
// Filter to select which fields we'll export FieldDescriptors for.
933+
auto exportable_field =
934+
[](Field field) {
935+
// Don't export private C++ fields that were imported as private Swift fields.
936+
// The type of a private field might not have all the type witness
937+
// operations that Swift requires, for instance,
938+
// `std::unique_ptr<IncompleteType>` would not have a destructor.
939+
if (field.getKind() == Field::Kind::Var &&
940+
field.getVarDecl()->getClangDecl() &&
941+
field.getVarDecl()->getFormalAccess() == AccessLevel::Private)
942+
return false;
943+
// All other fields are exportable
944+
return true;
945+
};
946+
947+
// Count exportable fields
948+
int exportableFieldCount = 0;
933949
forEachField(IGM, NTD, [&](Field field) {
934-
// Skip private C++ fields that were imported as private Swift fields.
935-
// The type of a private field might not have all the type witness
936-
// operations that Swift requires, for instance,
937-
// `std::unique_ptr<IncompleteType>` would not have a destructor.
938-
if (field.getKind() == Field::Kind::Var &&
939-
field.getVarDecl()->getClangDecl() &&
940-
field.getVarDecl()->getFormalAccess() == AccessLevel::Private)
941-
return;
950+
if (exportable_field(field)) {
951+
++exportableFieldCount;
952+
}
953+
});
942954

943-
addField(field);
955+
// Emit exportable fields, prefixed with a count
956+
B.addInt32(exportableFieldCount);
957+
forEachField(IGM, NTD, [&](Field field) {
958+
if (exportable_field(field)) {
959+
addField(field);
960+
}
944961
});
945962
}
946963

0 commit comments

Comments
 (0)