Compute the "existential conforms to self" bit lazily.

Instead of relying on Sema to set the existential-conforms-to-self bit, compute it lazily in the AST. This is far cleaner and more dependable than the previous solution.

Swift SVN r26225
This commit is contained in:
Doug Gregor
2015-03-17 16:34:26 +00:00
parent 59c22383fb
commit a90c306d6c
7 changed files with 85 additions and 43 deletions

View File

@@ -878,23 +878,14 @@ LookupConformanceResult Module::lookupConformance(Type type,
if (type->isExistentialType()) {
// If the protocol doesn't conform to itself, there's no point in looking
// further.
auto known = protocol->existentialConformsToSelf();
if (!known && resolver) {
resolver->resolveExistentialConformsToItself(protocol);
known = protocol->existentialConformsToSelf();
}
// If we know that protocol doesn't conform to itself, we're done.
if (known && !*known)
if (!protocol->existentialConformsToSelf(resolver))
return { nullptr, ConformanceKind::DoesNotConform };
// Special-case AnyObject, which may not be in the list of conformances.
if (protocol->isSpecificProtocol(KnownProtocolKind::AnyObject)) {
if (type->isClassExistentialType()) {
return { nullptr, known ? ConformanceKind::Conforms
: ConformanceKind::UncheckedConforms };
}
return { nullptr, ConformanceKind::DoesNotConform };
return { nullptr, type->isClassExistentialType()
? ConformanceKind::Conforms
: ConformanceKind::DoesNotConform };
}
// Look for this protocol within the existential's list of conformances.
@@ -902,9 +893,7 @@ LookupConformanceResult Module::lookupConformance(Type type,
type->getAnyExistentialTypeProtocols(protocols);
for (auto ap : protocols) {
if (ap == protocol || ap->inheritsFrom(protocol)) {
return { nullptr,
known? ConformanceKind::Conforms
: ConformanceKind::UncheckedConforms };
return { nullptr, ConformanceKind::Conforms };
}
}