Skip to content

Commit dbf6257

Browse files
committed
NFC: Consolidate logic for serializing conformances.
This is motivated by needing to typecheck conformances before serializing them when lazy typechecking is enabled. It will also provide a centralized funnel point for filtering out conformances we don't want to serialize.
1 parent 52c732f commit dbf6257

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

lib/Serialization/Serialization.cpp

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,6 +3258,18 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
32583258
}
32593259
}
32603260

3261+
size_t addConformances(const IterableDeclContext *declContext,
3262+
ConformanceLookupKind lookupKind,
3263+
SmallVectorImpl<TypeID> &data) {
3264+
size_t count = 0;
3265+
for (auto conformance : declContext->getLocalConformances(lookupKind)) {
3266+
data.push_back(S.addConformanceRef(conformance));
3267+
count++;
3268+
}
3269+
3270+
return count;
3271+
}
3272+
32613273
public:
32623274
/// Determine if \p decl is safe to deserialize when it's public
32633275
/// or otherwise needed by the client in normal builds, this should usually
@@ -3787,8 +3799,8 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
37873799
/// Add all of the inherited entries to the result vector.
37883800
///
37893801
/// \returns the number of entries added.
3790-
unsigned addInherited(ArrayRef<InheritedEntry> inheritedEntries,
3791-
SmallVectorImpl<TypeID> &result) {
3802+
size_t addInherited(ArrayRef<InheritedEntry> inheritedEntries,
3803+
SmallVectorImpl<TypeID> &result) {
37923804
for (const auto &inherited : inheritedEntries) {
37933805
assert(!inherited.getType() || !inherited.getType()->hasArchetype());
37943806
TypeID typeRef = S.addTypeRef(inherited.getType());
@@ -3821,13 +3833,9 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
38213833
// simpler user model to just always desugar extension types.
38223834
extendedType = extendedType->getCanonicalType();
38233835

3824-
auto conformances = extension->getLocalConformances(
3825-
ConformanceLookupKind::All);
3826-
38273836
SmallVector<TypeID, 8> data;
3828-
for (auto conformance : conformances)
3829-
data.push_back(S.addConformanceRef(conformance));
3830-
3837+
size_t numConformances =
3838+
addConformances(extension, ConformanceLookupKind::All, data);
38313839
size_t numInherited = addInherited(
38323840
extension->getInherited(), data);
38333841

@@ -3850,7 +3858,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
38503858
extension->isImplicit(),
38513859
S.addGenericSignatureRef(
38523860
extension->getGenericSignature()),
3853-
conformances.size(),
3861+
numConformances,
38543862
numInherited,
38553863
data);
38563864

@@ -4054,14 +4062,10 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
40544062

40554063
auto contextID = S.addDeclContextRef(theStruct->getDeclContext());
40564064

4057-
auto conformances = theStruct->getLocalConformances(
4058-
ConformanceLookupKind::All);
4059-
40604065
SmallVector<TypeID, 4> data;
4061-
for (auto conformance : conformances)
4062-
data.push_back(S.addConformanceRef(conformance));
4063-
4064-
unsigned numInherited = addInherited(theStruct->getInherited(), data);
4066+
size_t numConformances =
4067+
addConformances(theStruct, ConformanceLookupKind::All, data);
4068+
size_t numInherited = addInherited(theStruct->getInherited(), data);
40654069

40664070
llvm::SmallSetVector<Type, 4> dependencyTypes;
40674071
for (Requirement req : theStruct->getGenericRequirements()) {
@@ -4083,7 +4087,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
40834087
S.addGenericSignatureRef(
40844088
theStruct->getGenericSignature()),
40854089
rawAccessLevel,
4086-
conformances.size(),
4090+
numConformances,
40874091
numInherited,
40884092
data);
40894093

@@ -4098,14 +4102,10 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
40984102

40994103
auto contextID = S.addDeclContextRef(theEnum->getDeclContext());
41004104

4101-
auto conformances = theEnum->getLocalConformances(
4102-
ConformanceLookupKind::All);
4103-
41044105
SmallVector<TypeID, 4> data;
4105-
for (auto conformance : conformances)
4106-
data.push_back(S.addConformanceRef(conformance));
4107-
4108-
unsigned numInherited = addInherited(theEnum->getInherited(), data);
4106+
size_t numConformances =
4107+
addConformances(theEnum, ConformanceLookupKind::All, data);
4108+
size_t numInherited = addInherited(theEnum->getInherited(), data);
41094109

41104110
llvm::SmallSetVector<Type, 4> dependencyTypes;
41114111
for (const EnumElementDecl *nextElt : theEnum->getAllElements()) {
@@ -4140,7 +4140,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
41404140
theEnum->getGenericSignature()),
41414141
S.addTypeRef(theEnum->getRawType()),
41424142
rawAccessLevel,
4143-
conformances.size(),
4143+
numConformances,
41444144
numInherited,
41454145
data);
41464146

@@ -4155,14 +4155,10 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
41554155

41564156
auto contextID = S.addDeclContextRef(theClass->getDeclContext());
41574157

4158-
auto conformances = theClass->getLocalConformances(
4159-
ConformanceLookupKind::NonInherited);
4160-
41614158
SmallVector<TypeID, 4> data;
4162-
for (auto conformance : conformances)
4163-
data.push_back(S.addConformanceRef(conformance));
4164-
4165-
unsigned numInherited = addInherited(theClass->getInherited(), data);
4159+
size_t numConformances =
4160+
addConformances(theClass, ConformanceLookupKind::NonInherited, data);
4161+
size_t numInherited = addInherited(theClass->getInherited(), data);
41664162

41674163
llvm::SmallSetVector<Type, 4> dependencyTypes;
41684164
if (theClass->hasSuperclass()) {
@@ -4199,7 +4195,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
41994195
theClass->getGenericSignature()),
42004196
S.addTypeRef(theClass->getSuperclass()),
42014197
rawAccessLevel,
4202-
conformances.size(),
4198+
numConformances,
42034199
numInherited,
42044200
data);
42054201

0 commit comments

Comments
 (0)