@@ -345,17 +345,30 @@ bool GenericSignature::enumeratePairedRequirements(
345
345
auto genericParams = getGenericParams ();
346
346
unsigned curGenericParamIdx = 0 , numGenericParams = genericParams.size ();
347
347
348
- // Figure out which generic parameters are complete.
349
- SmallVector<bool , 4 > genericParamsAreConcrete (genericParams.size (), false );
348
+ // Figure out which generic parameters are concrete or same-typed to another
349
+ // generic parameter.
350
+ auto genericParamsAreNonCanonical =
351
+ SmallVector<bool , 4 >(genericParams.size (), false );
350
352
for (auto req : reqs) {
351
353
if (req.getKind () != RequirementKind::SameType) continue ;
352
- if (req.getSecondType ()->isTypeParameter ()) continue ;
353
-
354
- auto gp = req.getFirstType ()->getAs <GenericTypeParamType>();
355
- if (!gp) continue ;
354
+
355
+ GenericTypeParamType *gp;
356
+ if (auto secondGP = req.getSecondType ()->getAs <GenericTypeParamType>()) {
357
+ // If two generic parameters are same-typed, then the left-hand one
358
+ // is canonical.
359
+ gp = secondGP;
360
+ } else {
361
+ // If an associated type is same-typed, it doesn't constrain the generic
362
+ // parameter itself.
363
+ if (req.getSecondType ()->isTypeParameter ()) continue ;
364
+
365
+ // Otherwise, the generic parameter is concrete.
366
+ gp = req.getFirstType ()->getAs <GenericTypeParamType>();
367
+ if (!gp) continue ;
368
+ }
356
369
357
370
unsigned index = GenericParamKey (gp).findIndexIn (genericParams);
358
- genericParamsAreConcrete [index] = true ;
371
+ genericParamsAreNonCanonical [index] = true ;
359
372
}
360
373
361
374
// / Local function to 'catch up' to the next dependent type we're going to
@@ -382,7 +395,7 @@ bool GenericSignature::enumeratePairedRequirements(
382
395
if (curGenericParam->getDepth () < stopDepth ||
383
396
(curGenericParam->getDepth () == stopDepth &&
384
397
curGenericParam->getIndex () < stopIndex)) {
385
- if (!genericParamsAreConcrete [curGenericParamIdx] &&
398
+ if (!genericParamsAreNonCanonical [curGenericParamIdx] &&
386
399
fn (curGenericParam, { }))
387
400
return true ;
388
401
@@ -441,7 +454,7 @@ bool GenericSignature::enumeratePairedRequirements(
441
454
// parameter we can't skip, invoke the callback.
442
455
if ((startIdx != endIdx ||
443
456
(isa<GenericTypeParamType>(depTy) &&
444
- !genericParamsAreConcrete [
457
+ !genericParamsAreNonCanonical [
445
458
GenericParamKey (cast<GenericTypeParamType>(depTy))
446
459
.findIndexIn (genericParams)])) &&
447
460
fn (depTy, reqs.slice (startIdx, endIdx-startIdx)))
@@ -807,7 +820,7 @@ bool GenericSignature::isCanonicalTypeInContext(Type type) {
807
820
}
808
821
809
822
bool GenericSignature::isCanonicalTypeInContext (Type type,
810
- GenericSignatureBuilder &builder) {
823
+ GenericSignatureBuilder &builder) {
811
824
// If the type isn't independently canonical, it's certainly not canonical
812
825
// in this context.
813
826
if (!type->isCanonical ())
@@ -835,7 +848,7 @@ bool GenericSignature::isCanonicalTypeInContext(Type type,
835
848
}
836
849
837
850
CanType GenericSignature::getCanonicalTypeInContext (Type type,
838
- GenericSignatureBuilder &builder) {
851
+ GenericSignatureBuilder &builder) {
839
852
type = type->getCanonicalType ();
840
853
841
854
// All the contextual canonicality rules apply to type parameters, so if the
0 commit comments