@@ -929,18 +929,35 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
929
929
B.addInt16 (uint16_t (kind));
930
930
B.addInt16 (FieldRecordSize);
931
931
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 ;
933
949
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
+ });
942
954
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
+ }
944
961
});
945
962
}
946
963
0 commit comments