@@ -944,18 +944,35 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
944
944
B.addInt16 (uint16_t (kind));
945
945
B.addInt16 (FieldRecordSize);
946
946
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 ;
948
964
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
+ });
957
969
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
+ }
959
976
});
960
977
}
961
978
0 commit comments