@@ -8031,6 +8031,45 @@ static Optional<Requirement> createRequirement(RequirementKind kind,
8031
8031
}
8032
8032
}
8033
8033
8034
+ // / Determine the canonical ordering of requirements.
8035
+ static unsigned getRequirementKindOrder (RequirementKind kind) {
8036
+ switch (kind) {
8037
+ case RequirementKind::Conformance: return 2 ;
8038
+ case RequirementKind::Superclass: return 0 ;
8039
+ case RequirementKind::SameType: return 3 ;
8040
+ case RequirementKind::Layout: return 1 ;
8041
+ }
8042
+ llvm_unreachable (" unhandled kind" );
8043
+ }
8044
+
8045
+ static int compareRequirements (const Requirement *lhsPtr,
8046
+ const Requirement *rhsPtr) {
8047
+ auto &lhs = *lhsPtr;
8048
+ auto &rhs = *rhsPtr;
8049
+
8050
+ int compareLHS =
8051
+ compareDependentTypes (lhs.getFirstType (), rhs.getFirstType ());
8052
+
8053
+ if (compareLHS != 0 )
8054
+ return compareLHS;
8055
+
8056
+ int compareKind = (getRequirementKindOrder (lhs.getKind ()) -
8057
+ getRequirementKindOrder (rhs.getKind ()));
8058
+
8059
+ if (compareKind != 0 )
8060
+ return compareKind;
8061
+
8062
+ // We should only have multiple conformance requirements.
8063
+ assert (lhs.getKind () == RequirementKind::Conformance);
8064
+
8065
+ int compareProtos =
8066
+ TypeDecl::compare (lhs.getProtocolDecl (), rhs.getProtocolDecl ());
8067
+
8068
+ assert (compareProtos != 0 && " Duplicate conformance requirement" );
8069
+
8070
+ return compareProtos;
8071
+ }
8072
+
8034
8073
void GenericSignatureBuilder::enumerateRequirements (
8035
8074
TypeArrayView<GenericTypeParamType> genericParams,
8036
8075
SmallVectorImpl<Requirement> &requirements) {
@@ -8195,17 +8234,6 @@ void GenericSignatureBuilder::addGenericSignature(GenericSignature sig) {
8195
8234
8196
8235
#ifndef NDEBUG
8197
8236
8198
- // / Determine the canonical ordering of requirements.
8199
- static unsigned getRequirementKindOrder (RequirementKind kind) {
8200
- switch (kind) {
8201
- case RequirementKind::Conformance: return 2 ;
8202
- case RequirementKind::Superclass: return 0 ;
8203
- case RequirementKind::SameType: return 3 ;
8204
- case RequirementKind::Layout: return 1 ;
8205
- }
8206
- llvm_unreachable (" unhandled kind" );
8207
- }
8208
-
8209
8237
static void checkGenericSignature (CanGenericSignature canSig,
8210
8238
GenericSignatureBuilder &builder) {
8211
8239
PrettyStackTraceGenericSignature debugStack (" checking" , canSig);
@@ -8293,25 +8321,8 @@ static void checkGenericSignature(CanGenericSignature canSig,
8293
8321
}
8294
8322
}
8295
8323
8296
- // From here on, we only care about cases where the previous and current
8297
- // requirements have the same left-hand side.
8298
- if (compareLHS != 0 ) continue ;
8299
-
8300
- // Check ordering of requirement kinds.
8301
- assert ((getRequirementKindOrder (prevReqt.getKind ()) <=
8302
- getRequirementKindOrder (reqt.getKind ())) &&
8303
- " Requirements for a given kind are out-of-order" );
8304
-
8305
- // From here on, we only care about the same requirement kind.
8306
- if (prevReqt.getKind () != reqt.getKind ()) continue ;
8307
-
8308
- assert (reqt.getKind () == RequirementKind::Conformance &&
8309
- " Only conformance requirements can have multiples" );
8310
-
8311
- auto prevProto = prevReqt.getProtocolDecl ();
8312
- auto proto = reqt.getProtocolDecl ();
8313
- assert (TypeDecl::compare (prevProto, proto) < 0 &&
8314
- " Out-of-order conformance requirements" );
8324
+ assert (compareRequirements (&prevReqt, &reqt) < 0 &&
8325
+ " Out-of-order requirements" );
8315
8326
}
8316
8327
}
8317
8328
#endif
0 commit comments