@@ -176,23 +176,9 @@ bool GenericSignatureImpl::isCanonical() const {
176
176
return getCanonicalSignature ().getPointer () == this ;
177
177
}
178
178
179
- #ifndef NDEBUG
180
- // / Determine the canonical ordering of requirements.
181
- static unsigned getRequirementKindOrder (RequirementKind kind) {
182
- switch (kind) {
183
- case RequirementKind::Conformance: return 2 ;
184
- case RequirementKind::Superclass: return 0 ;
185
- case RequirementKind::SameType: return 3 ;
186
- case RequirementKind::Layout: return 1 ;
187
- }
188
- llvm_unreachable (" unhandled kind" );
189
- }
190
- #endif
191
-
192
179
CanGenericSignature
193
180
CanGenericSignature::getCanonical (TypeArrayView<GenericTypeParamType> params,
194
- ArrayRef<Requirement> requirements,
195
- bool skipValidation) {
181
+ ArrayRef<Requirement> requirements) {
196
182
// Canonicalize the parameters and requirements.
197
183
SmallVector<GenericTypeParamType*, 8 > canonicalParams;
198
184
canonicalParams.reserve (params.size ());
@@ -205,116 +191,9 @@ CanGenericSignature::getCanonical(TypeArrayView<GenericTypeParamType> params,
205
191
for (auto &reqt : requirements)
206
192
canonicalRequirements.push_back (reqt.getCanonical ());
207
193
208
- (void )skipValidation;
209
194
auto canSig = get (canonicalParams, canonicalRequirements,
210
195
/* isKnownCanonical=*/ true );
211
196
212
- #ifndef NDEBUG
213
- if (skipValidation)
214
- return CanGenericSignature (canSig);
215
-
216
- PrettyStackTraceGenericSignature debugStack (" canonicalizing" , canSig);
217
-
218
- // Check that the signature is canonical.
219
- for (unsigned idx : indices (canonicalRequirements)) {
220
- debugStack.setRequirement (idx);
221
-
222
- const auto &reqt = canonicalRequirements[idx];
223
-
224
- // Left-hand side must be canonical in its context.
225
- // Check canonicalization of requirement itself.
226
- switch (reqt.getKind ()) {
227
- case RequirementKind::Superclass:
228
- assert (canSig->isCanonicalTypeInContext (reqt.getFirstType ()) &&
229
- " Left-hand side is not canonical" );
230
- assert (canSig->isCanonicalTypeInContext (reqt.getSecondType ()) &&
231
- " Superclass type isn't canonical in its own context" );
232
- break ;
233
-
234
- case RequirementKind::Layout:
235
- assert (canSig->isCanonicalTypeInContext (reqt.getFirstType ()) &&
236
- " Left-hand side is not canonical" );
237
- break ;
238
-
239
- case RequirementKind::SameType: {
240
- auto isCanonicalAnchor = [&](Type type) {
241
- if (auto *dmt = type->getAs <DependentMemberType>())
242
- return canSig->isCanonicalTypeInContext (dmt->getBase ());
243
- return type->is <GenericTypeParamType>();
244
- };
245
-
246
- auto firstType = reqt.getFirstType ();
247
- auto secondType = reqt.getSecondType ();
248
- assert (isCanonicalAnchor (firstType));
249
-
250
- if (reqt.getSecondType ()->isTypeParameter ()) {
251
- assert (isCanonicalAnchor (secondType));
252
- assert (compareDependentTypes (firstType, secondType) < 0 &&
253
- " Out-of-order type parameters in same-type constraint" );
254
- } else {
255
- assert (canSig->isCanonicalTypeInContext (secondType) &&
256
- " Concrete same-type isn't canonical in its own context" );
257
- }
258
- break ;
259
- }
260
-
261
- case RequirementKind::Conformance:
262
- assert (reqt.getFirstType ()->isTypeParameter () &&
263
- " Left-hand side must be a type parameter" );
264
- assert (isa<ProtocolType>(reqt.getSecondType ().getPointer ()) &&
265
- " Right-hand side of conformance isn't a protocol type" );
266
- break ;
267
- }
268
-
269
- // From here on, we're only interested in requirements beyond the first.
270
- if (idx == 0 ) continue ;
271
-
272
- // Make sure that the left-hand sides are in nondecreasing order.
273
- const auto &prevReqt = canonicalRequirements[idx-1 ];
274
- int compareLHS =
275
- compareDependentTypes (prevReqt.getFirstType (), reqt.getFirstType ());
276
- assert (compareLHS <= 0 && " Out-of-order left-hand sides" );
277
-
278
- // If we have two same-type requirements where the left-hand sides differ
279
- // but fall into the same equivalence class, we can check the form.
280
- if (compareLHS < 0 && reqt.getKind () == RequirementKind::SameType &&
281
- prevReqt.getKind () == RequirementKind::SameType &&
282
- canSig->areSameTypeParameterInContext (prevReqt.getFirstType (),
283
- reqt.getFirstType ())) {
284
- // If it's a it's a type parameter, make sure the equivalence class is
285
- // wired together sanely.
286
- if (prevReqt.getSecondType ()->isTypeParameter ()) {
287
- assert (prevReqt.getSecondType ()->isEqual (reqt.getFirstType ()) &&
288
- " same-type constraints within an equiv. class are out-of-order" );
289
- } else {
290
- // Otherwise, the concrete types must match up.
291
- assert (prevReqt.getSecondType ()->isEqual (reqt.getSecondType ()) &&
292
- " inconsistent concrete same-type constraints in equiv. class" );
293
- }
294
- }
295
-
296
- // From here on, we only care about cases where the previous and current
297
- // requirements have the same left-hand side.
298
- if (compareLHS != 0 ) continue ;
299
-
300
- // Check ordering of requirement kinds.
301
- assert ((getRequirementKindOrder (prevReqt.getKind ()) <=
302
- getRequirementKindOrder (reqt.getKind ())) &&
303
- " Requirements for a given kind are out-of-order" );
304
-
305
- // From here on, we only care about the same requirement kind.
306
- if (prevReqt.getKind () != reqt.getKind ()) continue ;
307
-
308
- assert (reqt.getKind () == RequirementKind::Conformance &&
309
- " Only conformance requirements can have multiples" );
310
-
311
- auto prevProto = prevReqt.getProtocolDecl ();
312
- auto proto = reqt.getProtocolDecl ();
313
- assert (TypeDecl::compare (prevProto, proto) < 0 &&
314
- " Out-of-order conformance requirements" );
315
- }
316
- #endif
317
-
318
197
return CanGenericSignature (canSig);
319
198
}
320
199
@@ -519,7 +398,19 @@ bool GenericSignatureImpl::areSameTypeParameterInContext(Type type1,
519
398
if (type1.getPointer () == type2.getPointer ())
520
399
return true ;
521
400
522
- auto &builder = *getGenericSignatureBuilder ();
401
+ return areSameTypeParameterInContext (type1, type2,
402
+ *getGenericSignatureBuilder ());
403
+ }
404
+
405
+ bool GenericSignatureImpl::areSameTypeParameterInContext (Type type1,
406
+ Type type2,
407
+ GenericSignatureBuilder &builder) const {
408
+ assert (type1->isTypeParameter ());
409
+ assert (type2->isTypeParameter ());
410
+
411
+ if (type1.getPointer () == type2.getPointer ())
412
+ return true ;
413
+
523
414
auto equivClass1 =
524
415
builder.resolveEquivalenceClass (
525
416
type1,
0 commit comments