Skip to content

Commit 75db43b

Browse files
committed
AST: Replace ProtocolType::compareProtocols() with TypeDecl::compare()
1 parent 3415a7e commit 75db43b

File tree

9 files changed

+16
-21
lines changed

9 files changed

+16
-21
lines changed

include/swift/AST/Decl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,14 @@ class TypeDecl : public ValueDecl {
25102510

25112511
/// Compute an ordering between two type declarations that is ABI-stable.
25122512
static int compare(const TypeDecl *type1, const TypeDecl *type2);
2513+
2514+
/// Compute an ordering between two type declarations that is ABI-stable.
2515+
/// This version takes a pointer-to-a-pointer for use with
2516+
/// llvm::array_pod_sort() and similar.
2517+
template<typename T>
2518+
static int compare(T * const* type1, T * const* type2) {
2519+
return compare(*type1, *type2);
2520+
}
25132521
};
25142522

25152523
/// A type declaration that can have generic parameters attached to it. Because

include/swift/AST/Types.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,11 +4288,6 @@ class ProtocolType : public NominalType, public llvm::FoldingSetNode {
42884288
static bool visitAllProtocols(ArrayRef<ProtocolDecl *> protocols,
42894289
llvm::function_ref<bool(ProtocolDecl *)> fn);
42904290

4291-
/// Compare two protocols to provide them with a stable ordering for
4292-
/// use in sorting.
4293-
static int compareProtocols(ProtocolDecl * const* PP1,
4294-
ProtocolDecl * const* PP2);
4295-
42964291
void Profile(llvm::FoldingSetNodeID &ID) {
42974292
Profile(ID, getDecl(), getParent());
42984293
}

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ static int compareSimilarAssociatedTypes(AssociatedTypeDecl *const *lhs,
16131613
AssociatedTypeDecl *const *rhs) {
16141614
auto lhsProto = (*lhs)->getProtocol();
16151615
auto rhsProto = (*rhs)->getProtocol();
1616-
return ProtocolType::compareProtocols(&lhsProto, &rhsProto);
1616+
return TypeDecl::compare(lhsProto, rhsProto);
16171617
}
16181618

16191619
ArrayRef<AssociatedTypeDecl *> AssociatedTypeDecl::getOverriddenDecls() const {

lib/AST/ConformanceLookupTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ int ConformanceLookupTable::compareProtocolConformances(
11101110
// Otherwise, sort by protocol.
11111111
ProtocolDecl *lhsProto = lhs->getProtocol();
11121112
ProtocolDecl *rhsProto = rhs->getProtocol();
1113-
return ProtocolType::compareProtocols(&lhsProto, &rhsProto);
1113+
return TypeDecl::compare(lhsProto, rhsProto);
11141114
}
11151115

11161116
void ConformanceLookupTable::getAllConformances(

lib/AST/GenericSignature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ GenericSignature::getCanonical(TypeArrayView<GenericTypeParamType> params,
271271
auto prevProto =
272272
prevReqt.getSecondType()->castTo<ProtocolType>()->getDecl();
273273
auto proto = reqt.getSecondType()->castTo<ProtocolType>()->getDecl();
274-
assert(ProtocolType::compareProtocols(&prevProto, &proto) < 0 &&
274+
assert(TypeDecl::compare(prevProto, proto) < 0 &&
275275
"Out-of-order conformance requirements");
276276
}
277277
#endif

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,7 @@ static int compareAssociatedTypes(AssociatedTypeDecl *assocType1,
20732073
// - by protocol, so t_n_m.`P.T` < t_n_m.`Q.T` (given P < Q)
20742074
auto proto1 = assocType1->getProtocol();
20752075
auto proto2 = assocType2->getProtocol();
2076-
if (int compareProtocols = ProtocolType::compareProtocols(&proto1, &proto2))
2076+
if (int compareProtocols = TypeDecl::compare(proto1, proto2))
20772077
return compareProtocols;
20782078

20792079
// Error case: if we have two associated types with the same name in the
@@ -7286,7 +7286,7 @@ void GenericSignatureBuilder::enumerateRequirements(
72867286

72877287
// Sort the protocols in canonical order.
72887288
llvm::array_pod_sort(protocols.begin(), protocols.end(),
7289-
ProtocolType::compareProtocols);
7289+
TypeDecl::compare);
72907290

72917291
// Enumerate the conformance requirements.
72927292
for (auto proto : protocols) {

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,8 +1188,7 @@ DeclContext::getLocalProtocols(
11881188

11891189
// Sort if required.
11901190
if (sorted) {
1191-
llvm::array_pod_sort(result.begin(), result.end(),
1192-
&ProtocolType::compareProtocols);
1191+
llvm::array_pod_sort(result.begin(), result.end(), TypeDecl::compare);
11931192
}
11941193

11951194
return result;

lib/AST/Type.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -971,12 +971,6 @@ static void addMinimumProtocols(Type T,
971971
}
972972
}
973973

974-
/// \brief Compare two protocols to establish an ordering between them.
975-
int ProtocolType::compareProtocols(ProtocolDecl * const* PP1,
976-
ProtocolDecl * const* PP2) {
977-
return TypeDecl::compare(*PP1, *PP2);
978-
}
979-
980974
bool ProtocolType::visitAllProtocols(
981975
ArrayRef<ProtocolDecl *> protocols,
982976
llvm::function_ref<bool(ProtocolDecl *)> fn) {
@@ -1052,7 +1046,7 @@ void ProtocolType::canonicalizeProtocols(
10521046

10531047
// Sort the set of protocols by module + name, to give a stable
10541048
// ordering.
1055-
llvm::array_pod_sort(protocols.begin(), protocols.end(), compareProtocols);
1049+
llvm::array_pod_sort(protocols.begin(), protocols.end(), TypeDecl::compare);
10561050
}
10571051

10581052
static Type

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4890,8 +4890,7 @@ TypeChecker::findWitnessedObjCRequirements(const ValueDecl *witness,
48904890
= cast<ProtocolDecl>(lhs->getDeclContext());
48914891
ProtocolDecl *rhsProto
48924892
= cast<ProtocolDecl>(rhs->getDeclContext());
4893-
return ProtocolType::compareProtocols(&lhsProto,
4894-
&rhsProto) < 0;
4893+
return TypeDecl::compare(lhsProto, rhsProto) < 0;
48954894
});
48964895
}
48974896
return result;

0 commit comments

Comments
 (0)