Skip to content

Commit e3f7531

Browse files
committed
[TypeJoin] Use isExistentialType() and inheritsFrom() as appropriate.
1 parent 852ac4c commit e3f7531

File tree

1 file changed

+5
-32
lines changed

1 file changed

+5
-32
lines changed

lib/AST/TypeJoinMeet.cpp

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ CanType TypeJoin::visitProtocolCompositionType(CanType second) {
396396
assert(First != second);
397397

398398
// FIXME: Handle other types here.
399-
if (!First->is<ProtocolType>() &&
400-
!First->is<ProtocolCompositionType>())
399+
if (!First->isExistentialType())
401400
return TheAnyType;
402401

403402
SmallVector<Type, 1> protocolType;
@@ -413,32 +412,6 @@ CanType TypeJoin::visitProtocolCompositionType(CanType second) {
413412
return computeProtocolCompositionJoin(firstMembers, secondMembers);
414413
}
415414

416-
// Return true if the first ProtocolDecl is a supertype of the second.
417-
static bool isSupertypeOf(ProtocolDecl *super, ProtocolDecl *sub) {
418-
if (super == sub)
419-
return true;
420-
421-
SmallVector<ProtocolDecl *, 4> worklist;
422-
for (auto *decl : sub->getInheritedProtocols())
423-
worklist.push_back(decl);
424-
425-
llvm::SmallPtrSet<ProtocolDecl *, 4> visited;
426-
while (!worklist.empty()) {
427-
auto *entry = worklist.pop_back_val();
428-
if (visited.count(entry))
429-
continue;
430-
visited.insert(entry);
431-
432-
if (entry == super)
433-
return true;
434-
435-
for (auto *decl : entry->getInheritedProtocols())
436-
worklist.push_back(decl);
437-
}
438-
439-
return false;
440-
}
441-
442415
CanType TypeJoin::visitProtocolType(CanType second) {
443416
assert(First != second);
444417

@@ -459,12 +432,12 @@ CanType TypeJoin::visitProtocolType(CanType second) {
459432
secondDecl->getInheritedProtocols().empty())
460433
return TheAnyType;
461434

462-
if (isSupertypeOf(firstDecl, secondDecl))
463-
return First;
464-
465-
if (isSupertypeOf(secondDecl, firstDecl))
435+
if (firstDecl->inheritsFrom(secondDecl))
466436
return second;
467437

438+
if (secondDecl->inheritsFrom(firstDecl))
439+
return First;
440+
468441
// One isn't the supertype of the other, so instead, treat each as
469442
// if it's a protocol composition of its inherited members, and join
470443
// those.

0 commit comments

Comments
 (0)