@@ -154,14 +154,14 @@ using namespace rewriting;
154
154
// / Strip associated types from types used as keys to erase differences between
155
155
// / resolved types coming from the parent generic signature and unresolved types
156
156
// / coming from user-written requirements.
157
- static CanType stripBoundDependentMemberTypes (Type t) {
157
+ static Type stripBoundDependentMemberTypes (Type t) {
158
158
if (auto *depMemTy = t->getAs <DependentMemberType>()) {
159
- return CanType ( DependentMemberType::get (
159
+ return DependentMemberType::get (
160
160
stripBoundDependentMemberTypes (depMemTy->getBase ()),
161
- depMemTy->getName ())) ;
161
+ depMemTy->getName ());
162
162
}
163
163
164
- return t-> getCanonicalType () ;
164
+ return t;
165
165
}
166
166
167
167
namespace {
@@ -232,17 +232,18 @@ Optional<Type> ConcreteContraction::substTypeParameterRec(
232
232
// losing the requirement.
233
233
if (position == Position::BaseType ||
234
234
position == Position::ConformanceRequirement) {
235
+ auto key = stripBoundDependentMemberTypes (type)->getCanonicalType ();
235
236
236
237
Type concreteType;
237
238
{
238
- auto found = ConcreteTypes.find (stripBoundDependentMemberTypes (type) );
239
+ auto found = ConcreteTypes.find (key );
239
240
if (found != ConcreteTypes.end () && found->second .size () == 1 )
240
241
concreteType = *found->second .begin ();
241
242
}
242
243
243
244
Type superclass;
244
245
{
245
- auto found = Superclasses.find (stripBoundDependentMemberTypes (type) );
246
+ auto found = Superclasses.find (key );
246
247
if (found != Superclasses.end () && found->second .size () == 1 )
247
248
superclass = *found->second .begin ();
248
249
}
@@ -392,7 +393,8 @@ ConcreteContraction::substRequirement(const Requirement &req) const {
392
393
// 'T : Sendable' would be incorrect; we want to ensure that we only admit
393
394
// subclasses of 'C' which are 'Sendable'.
394
395
bool allowMissing = false ;
395
- if (ConcreteTypes.count (stripBoundDependentMemberTypes (firstType)) > 0 )
396
+ auto key = stripBoundDependentMemberTypes (firstType)->getCanonicalType ();
397
+ if (ConcreteTypes.count (key) > 0 )
396
398
allowMissing = true ;
397
399
398
400
if (!substFirstType->isTypeParameter ()) {
@@ -449,17 +451,18 @@ hasResolvedMemberTypeOfInterestingParameter(Type type) const {
449
451
if (memberTy->getAssocType () == nullptr )
450
452
return false ;
451
453
452
- auto baseTy = memberTy->getBase ();
454
+ auto key = stripBoundDependentMemberTypes (memberTy->getBase ())
455
+ ->getCanonicalType ();
453
456
Type concreteType;
454
457
{
455
- auto found = ConcreteTypes.find (stripBoundDependentMemberTypes (baseTy) );
458
+ auto found = ConcreteTypes.find (key );
456
459
if (found != ConcreteTypes.end () && found->second .size () == 1 )
457
460
return true ;
458
461
}
459
462
460
463
Type superclass;
461
464
{
462
- auto found = Superclasses.find (stripBoundDependentMemberTypes (baseTy) );
465
+ auto found = Superclasses.find (key );
463
466
if (found != Superclasses.end () && found->second .size () == 1 )
464
467
return true ;
465
468
}
@@ -496,14 +499,14 @@ bool ConcreteContraction::preserveSameTypeRequirement(
496
499
497
500
// One of the parent types of this type parameter should be subject
498
501
// to a superclass requirement.
499
- auto type = req.getFirstType ();
502
+ auto type = stripBoundDependentMemberTypes (req.getFirstType ())
503
+ ->getCanonicalType ();
500
504
while (true ) {
501
- if (Superclasses.find (stripBoundDependentMemberTypes (type))
502
- != Superclasses.end ())
505
+ if (Superclasses.find (type) != Superclasses.end ())
503
506
break ;
504
507
505
- if (auto * memberType = type-> getAs <DependentMemberType>()) {
506
- type = memberType-> getBase ();
508
+ if (auto memberType = dyn_cast <DependentMemberType>(type )) {
509
+ type = memberType. getBase ();
507
510
continue ;
508
511
}
509
512
@@ -546,23 +549,23 @@ bool ConcreteContraction::performConcreteContraction(
546
549
if (constraintType->isTypeParameter ())
547
550
break ;
548
551
549
- ConcreteTypes[ stripBoundDependentMemberTypes (subjectType)]
550
- .insert (constraintType);
552
+ subjectType = stripBoundDependentMemberTypes (subjectType);
553
+ ConcreteTypes[subjectType-> getCanonicalType ()] .insert (constraintType);
551
554
break ;
552
555
}
553
556
case RequirementKind::Superclass: {
554
557
auto constraintType = req.req .getSecondType ();
555
558
assert (!constraintType->isTypeParameter () &&
556
559
" You forgot to call desugarRequirement()" );
557
560
558
- Superclasses[ stripBoundDependentMemberTypes (subjectType)]
559
- .insert (constraintType);
561
+ subjectType = stripBoundDependentMemberTypes (subjectType);
562
+ Superclasses[subjectType-> getCanonicalType ()] .insert (constraintType);
560
563
break ;
561
564
}
562
565
case RequirementKind::Conformance: {
563
566
auto *protoDecl = req.req .getProtocolDecl ();
564
- Conformances[ stripBoundDependentMemberTypes (subjectType)]
565
- .push_back (protoDecl);
567
+ subjectType = stripBoundDependentMemberTypes (subjectType);
568
+ Conformances[subjectType-> getCanonicalType ()] .push_back (protoDecl);
566
569
567
570
break ;
568
571
}
@@ -588,7 +591,7 @@ bool ConcreteContraction::performConcreteContraction(
588
591
if (auto otherSuperclassTy = proto->getSuperclass ()) {
589
592
if (Debug) {
590
593
llvm::dbgs () << " @ Subject type of superclass requirement "
591
- << " τ_ " << subjectType << " : " << superclassTy
594
+ << subjectType << " : " << superclassTy
592
595
<< " conforms to " << proto->getName ()
593
596
<< " which has a superclass bound "
594
597
<< otherSuperclassTy << " \n " ;
0 commit comments