AST: Add ExistentialLayout::getSuperclass(), rename superclass to explicitSuperclass

More groundwork for protocols with superclass constraints.
In several places we need to distinguish between existential
types that have a superclass term (MyClass & Proto) and
existential types containing a protocol with a superclass
constraint.

This is similar to how I can write 'AnyObject & Proto', or
write 'Proto1 & Proto2' where Proto1 has an ': AnyObject'
in its inheritance clause.

Note that some of the usages will be revisited later as
I do more refactoring and testing. This is just a first pass.
This commit is contained in:
Slava Pestov
2018-06-29 16:11:14 -07:00
parent a7efed19a0
commit 45fb11ce3c
27 changed files with 152 additions and 83 deletions

View File

@@ -1387,10 +1387,10 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
}
}
if (layout.superclass) {
if (layout.explicitSuperclass) {
auto subKind = std::min(ConstraintKind::Subtype, kind);
auto result = matchTypes(type1, layout.superclass, subKind, subflags,
locator);
auto result = matchTypes(type1, layout.explicitSuperclass, subKind,
subflags, locator);
if (result.isFailure())
return result;
}
@@ -1398,6 +1398,14 @@ ConstraintSystem::matchExistentialTypes(Type type1, Type type2,
for (auto *proto : layout.getProtocols()) {
auto *protoDecl = proto->getDecl();
if (auto superclass = protoDecl->getSuperclass()) {
auto subKind = std::min(ConstraintKind::Subtype, kind);
auto result = matchTypes(type1, superclass, subKind,
subflags, locator);
if (result.isFailure())
return result;
}
switch (simplifyConformsToConstraint(type1, protoDecl, kind, locator,
subflags)) {
case SolutionKind::Solved: