@@ -2448,30 +2448,39 @@ ASTContext::getSpecializedConformance(Type type,
2448
2448
return result;
2449
2449
}
2450
2450
2451
- InheritedProtocolConformance *
2451
+ ProtocolConformance *
2452
2452
ASTContext::getInheritedConformance (Type type, ProtocolConformance *inherited) {
2453
2453
// Collapse multiple levels of inherited conformance.
2454
- while (auto *otherInherited = dyn_cast<InheritedProtocolConformance>(inherited))
2454
+ if (auto *otherInherited = dyn_cast<InheritedProtocolConformance>(inherited))
2455
2455
inherited = otherInherited->getInheritedConformance ();
2456
2456
2457
2457
assert (isa<SpecializedProtocolConformance>(inherited) ||
2458
2458
isa<NormalProtocolConformance>(inherited) ||
2459
2459
isa<BuiltinProtocolConformance>(inherited));
2460
2460
2461
+ // Collapse useless inherited conformances. Conformance lookup with aa
2462
+ // archetype T that has a superclass bound C will return a concrete
2463
+ // conformance if C conforms to the protocol P. This is wrapped in an
2464
+ // inherited conformance with the archetype type T. If you then substitute
2465
+ // T := C, you don't want to form an inherited conformance with a type of
2466
+ // C, because the underlying conformance already has a type of C.
2467
+ if (inherited->getType ()->isEqual (type))
2468
+ return inherited;
2469
+
2461
2470
llvm::FoldingSetNodeID id;
2462
2471
InheritedProtocolConformance::Profile (id, type, inherited);
2463
2472
2464
2473
// Figure out which arena this conformance should go into.
2465
2474
AllocationArena arena = getArena (type->getRecursiveProperties ());
2466
2475
2467
- // Did we already record the normal protocol conformance?
2476
+ // Did we already record the inherited protocol conformance?
2468
2477
void *insertPos;
2469
2478
auto &inheritedConformances = getImpl ().getArena (arena).InheritedConformances ;
2470
2479
if (auto result
2471
2480
= inheritedConformances.FindNodeOrInsertPos (id, insertPos))
2472
2481
return result;
2473
2482
2474
- // Build a new normal protocol conformance.
2483
+ // Build a new inherited protocol conformance.
2475
2484
auto result = new (*this , arena) InheritedProtocolConformance (type, inherited);
2476
2485
inheritedConformances.InsertNode (result, insertPos);
2477
2486
return result;
0 commit comments