Skip to content

Commit 8853d39

Browse files
authored
Merge pull request swiftlang#78961 from tbkka/tbkka-rdar143402921
Fix field count in emitted reflection data
2 parents 7c821ed + 10f554f commit 8853d39

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
@@ -944,18 +944,35 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
944944
B.addInt16(uint16_t(kind));
945945
B.addInt16(FieldRecordSize);
946946

947-
B.addInt32(getNumFields(NTD));
947+
// Filter to select which fields we'll export FieldDescriptors for.
948+
auto exportable_field =
949+
[](Field field) {
950+
// Don't export private C++ fields that were imported as private Swift fields.
951+
// The type of a private field might not have all the type witness
952+
// operations that Swift requires, for instance,
953+
// `std::unique_ptr<IncompleteType>` would not have a destructor.
954+
if (field.getKind() == Field::Kind::Var &&
955+
field.getVarDecl()->getClangDecl() &&
956+
field.getVarDecl()->getFormalAccess() == AccessLevel::Private)
957+
return false;
958+
// All other fields are exportable
959+
return true;
960+
};
961+
962+
// Count exportable fields
963+
int exportableFieldCount = 0;
948964
forEachField(IGM, NTD, [&](Field field) {
949-
// Skip private C++ fields that were imported as private Swift fields.
950-
// The type of a private field might not have all the type witness
951-
// operations that Swift requires, for instance,
952-
// `std::unique_ptr<IncompleteType>` would not have a destructor.
953-
if (field.getKind() == Field::Kind::Var &&
954-
field.getVarDecl()->getClangDecl() &&
955-
field.getVarDecl()->getFormalAccess() == AccessLevel::Private)
956-
return;
965+
if (exportable_field(field)) {
966+
++exportableFieldCount;
967+
}
968+
});
957969

958-
addField(field);
970+
// Emit exportable fields, prefixed with a count
971+
B.addInt32(exportableFieldCount);
972+
forEachField(IGM, NTD, [&](Field field) {
973+
if (exportable_field(field)) {
974+
addField(field);
975+
}
959976
});
960977
}
961978

0 commit comments

Comments
 (0)