Skip to content

Commit f0aedd0

Browse files
committed
AST: Minor optimization for minimal composition computation
Trust the `GenericSignature` class with upholding its invariants and assert that a superclass bound is in the right place instead of prepending it.
1 parent 5358eb6 commit f0aedd0

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

lib/AST/Type.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4115,7 +4115,6 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
41154115
return Reqs.front().getSecondType()->getCanonicalType();
41164116
}
41174117

4118-
Type superclass;
41194118
llvm::SmallVector<Type, 2> MinimalMembers;
41204119
bool MinimalHasExplicitAnyObject = false;
41214120
auto ifaceTy = Sig.getGenericParams().back();
@@ -4126,10 +4125,6 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
41264125

41274126
switch (Req.getKind()) {
41284127
case RequirementKind::Superclass:
4129-
assert((!superclass || superclass->isEqual(Req.getSecondType()))
4130-
&& "Multiple distinct superclass constraints!");
4131-
superclass = Req.getSecondType();
4132-
break;
41334128
case RequirementKind::Conformance:
41344129
MinimalMembers.push_back(Req.getSecondType());
41354130
break;
@@ -4141,10 +4136,10 @@ CanType ProtocolCompositionType::getMinimalCanonicalType(
41414136
}
41424137
}
41434138

4144-
// Ensure superclass bounds appear first regardless of their order among
4145-
// the signature's requirements.
4146-
if (superclass)
4147-
MinimalMembers.insert(MinimalMembers.begin(), superclass->getCanonicalType());
4139+
// A superclass constraint is always retained and must appear first in the
4140+
// members list.
4141+
assert(Composition->getMembers().front()->getClassOrBoundGenericClass() ==
4142+
MinimalMembers.front()->getClassOrBoundGenericClass());
41484143

41494144
// If we are left with a single member and no layout constraint, the member
41504145
// is the minimal type. Also, note that a protocol composition cannot be

0 commit comments

Comments
 (0)