@@ -1177,7 +1177,7 @@ void Serializer::writeGenericRequirements(ArrayRef<Requirement> requirements,
1177
1177
}
1178
1178
}
1179
1179
1180
- void Serializer::writeGenericSignature (const GenericSignature *sig) {
1180
+ void Serializer::writeASTBlockEntity (const GenericSignature *sig) {
1181
1181
using namespace decls_block ;
1182
1182
1183
1183
assert (sig != nullptr );
@@ -1257,7 +1257,7 @@ void Serializer::writeGenericEnvironment(const GenericEnvironment *env) {
1257
1257
DeclTypeAbbrCodes);
1258
1258
}
1259
1259
1260
- void Serializer::writeSubstitutionMap (const SubstitutionMap substitutions) {
1260
+ void Serializer::writeASTBlockEntity (const SubstitutionMap substitutions) {
1261
1261
using namespace decls_block ;
1262
1262
assert (substitutions);
1263
1263
assert (SubstitutionMapsToSerialize.hasRef (substitutions));
@@ -1277,7 +1277,7 @@ void Serializer::writeSubstitutionMap(const SubstitutionMap substitutions) {
1277
1277
writeConformances (substitutions.getConformances (), DeclTypeAbbrCodes);
1278
1278
}
1279
1279
1280
- void Serializer::writeSILLayout (const SILLayout *layout) {
1280
+ void Serializer::writeASTBlockEntity (const SILLayout *layout) {
1281
1281
using namespace decls_block ;
1282
1282
assert (SILLayoutsToSerialize.hasRef (layout));
1283
1283
@@ -1301,7 +1301,7 @@ void Serializer::writeSILLayout(const SILLayout *layout) {
1301
1301
data);
1302
1302
}
1303
1303
1304
- void Serializer::writeNormalConformance (
1304
+ void Serializer::writeASTBlockEntity (
1305
1305
const NormalProtocolConformance *conformance) {
1306
1306
using namespace decls_block ;
1307
1307
@@ -1925,11 +1925,11 @@ void Serializer::writeAbstractClosureExpr(const DeclContext *parentContext,
1925
1925
parentID.getOpaqueValue ());
1926
1926
}
1927
1927
1928
- void Serializer::writeLocalDeclContext (const DeclContext *DC) {
1928
+ void Serializer::writeASTBlockEntity (const DeclContext *DC) {
1929
1929
using namespace decls_block ;
1930
1930
1931
1931
assert (shouldSerializeAsLocalContext (DC) &&
1932
- " Can't serialize as local context " );
1932
+ " should be serialized as a Decl instead " );
1933
1933
assert (LocalDeclContextsToSerialize.hasRef (DC));
1934
1934
1935
1935
switch (DC->getContextKind ()) {
@@ -3577,7 +3577,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
3577
3577
}
3578
3578
};
3579
3579
3580
- void Serializer::writeDecl (const Decl *D) {
3580
+ void Serializer::writeASTBlockEntity (const Decl *D) {
3581
3581
using namespace decls_block ;
3582
3582
3583
3583
PrettyStackTraceDecl trace (" serializing" , D);
@@ -4103,7 +4103,7 @@ class Serializer::TypeSerializer : public TypeVisitor<TypeSerializer> {
4103
4103
}
4104
4104
};
4105
4105
4106
- void Serializer::writeType (Type ty) {
4106
+ void Serializer::writeASTBlockEntity (Type ty) {
4107
4107
using namespace decls_block ;
4108
4108
PrettyStackTraceType traceRAII (ty->getASTContext (), " serializing" , ty);
4109
4109
assert (TypesToSerialize.hasRef (ty));
@@ -4120,6 +4120,16 @@ void Serializer::writeType(Type ty) {
4120
4120
TypeSerializer (*this ).visit (ty);
4121
4121
}
4122
4122
4123
+ template <typename SpecificASTBlockRecordKeeper>
4124
+ bool Serializer::writeASTBlockEntitiesIfNeeded (
4125
+ SpecificASTBlockRecordKeeper &entities) {
4126
+ if (!entities.hasMoreToSerialize ())
4127
+ return false ;
4128
+ while (auto next = entities.popNext (Out.GetCurrentBitNo ()))
4129
+ writeASTBlockEntity (next.getValue ());
4130
+ return true ;
4131
+ }
4132
+
4123
4133
void Serializer::writeAllDeclsAndTypes () {
4124
4134
BCBlockRAII restoreBlock (Out, DECLS_AND_TYPES_BLOCK_ID, 8 );
4125
4135
using namespace decls_block ;
@@ -4234,50 +4244,25 @@ void Serializer::writeAllDeclsAndTypes() {
4234
4244
// until /all/ of the pending lists are empty.
4235
4245
wroteSomething = false ;
4236
4246
4237
- while (auto next = DeclsToSerialize.popNext (Out.GetCurrentBitNo ())) {
4238
- writeDecl (next.getValue ());
4239
- wroteSomething = true ;
4240
- }
4241
-
4242
- while (auto next = TypesToSerialize.popNext (Out.GetCurrentBitNo ())) {
4243
- writeType (next.getValue ());
4244
- wroteSomething = true ;
4245
- }
4246
-
4247
- while (auto next =
4248
- LocalDeclContextsToSerialize.popNext (Out.GetCurrentBitNo ())) {
4249
- writeLocalDeclContext (next.getValue ());
4250
- wroteSomething = true ;
4251
- }
4252
-
4253
- while (auto next =
4254
- GenericSignaturesToSerialize.popNext (Out.GetCurrentBitNo ())) {
4255
- writeGenericSignature (next.getValue ());
4256
- wroteSomething = true ;
4257
- }
4258
-
4247
+ wroteSomething |= writeASTBlockEntitiesIfNeeded (DeclsToSerialize);
4248
+ wroteSomething |= writeASTBlockEntitiesIfNeeded (TypesToSerialize);
4249
+ wroteSomething |=
4250
+ writeASTBlockEntitiesIfNeeded (LocalDeclContextsToSerialize);
4251
+ wroteSomething |=
4252
+ writeASTBlockEntitiesIfNeeded (GenericSignaturesToSerialize);
4253
+ wroteSomething |=
4254
+ writeASTBlockEntitiesIfNeeded (SubstitutionMapsToSerialize);
4255
+ wroteSomething |=
4256
+ writeASTBlockEntitiesIfNeeded (NormalConformancesToSerialize);
4257
+ wroteSomething |= writeASTBlockEntitiesIfNeeded (SILLayoutsToSerialize);
4258
+
4259
+ // Generic environments are recorded in a funny way; see
4260
+ // writeNextGenericEnvironment() for why they can't just use the same logic
4261
+ // as everything else.
4259
4262
while (GenericEnvironmentsToSerialize.hasMoreToSerialize ()) {
4260
4263
writeNextGenericEnvironment ();
4261
4264
wroteSomething = true ;
4262
4265
}
4263
-
4264
- while (auto next =
4265
- SubstitutionMapsToSerialize.popNext (Out.GetCurrentBitNo ())) {
4266
- writeSubstitutionMap (next.getValue ());
4267
- wroteSomething = true ;
4268
- }
4269
-
4270
- while (auto next =
4271
- NormalConformancesToSerialize.popNext (Out.GetCurrentBitNo ())) {
4272
- writeNormalConformance (next.getValue ());
4273
- wroteSomething = true ;
4274
- }
4275
-
4276
- while (auto next = SILLayoutsToSerialize.popNext (Out.GetCurrentBitNo ())) {
4277
- writeSILLayout (next.getValue ());
4278
- wroteSomething = true ;
4279
- }
4280
-
4281
4266
} while (wroteSomething);
4282
4267
}
4283
4268
0 commit comments