[GSB] Clean up and audit uses of ArchetypeResolutionKind.

Use ArchetypeResolutionKind::CompleteWellFormed whenever we need to
ask questions about the potential archetype, and
ArchetypeResolutionKind::WellFormed when we need only evaluate whether
there is a legitimate type with that name (and possibly get a handle
to it).
This commit is contained in:
Doug Gregor
2017-06-30 09:47:05 -07:00
parent dbc042261f
commit ae5091b09a
4 changed files with 15 additions and 25 deletions

View File

@@ -3292,8 +3292,7 @@ void ProtocolDecl::computeRequirementSignature() {
LookUpConformanceInModule(module)); LookUpConformanceInModule(module));
builder.addGenericParameter(selfType); builder.addGenericParameter(selfType);
auto selfPA = auto selfPA =
builder.resolveArchetype(selfType, builder.resolveArchetype(selfType, ArchetypeResolutionKind::WellFormed);
ArchetypeResolutionKind::CompleteWellFormed);
builder.addRequirement( builder.addRequirement(
requirement, requirement,

View File

@@ -488,21 +488,25 @@ bool GenericSignature::requiresClass(Type type, ModuleDecl &mod) {
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed); builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return false; if (!pa) return false;
pa = pa->getRepresentative(); if (pa->isConcreteType()) return false;
// If this type was mapped to a concrete type, then there is no // If this type was mapped to a concrete type, then there is no
// requirement. // requirement.
pa = pa->getRepresentative();
if (pa->isConcreteType()) return false; if (pa->isConcreteType()) return false;
// If there is a layout constraint, it might be a class. // If there is a layout constraint, it might be a class.
if (auto layout = pa->getLayout()) if (auto layout = pa->getLayout()) {
if (layout->isClass()) if (layout->isClass()) return true;
return true; }
// If there is a superclass bound, then obviously it must be a class. // If there is a superclass bound, then obviously it must be a class.
// FIXME: We shouldn't need this?
if (pa->getSuperclass()) return true; if (pa->getSuperclass()) return true;
// If any of the protocols are class-bound, then it must be a class. // If any of the protocols are class-bound, then it must be a class.
// FIXME: We shouldn't need this?
for (auto proto : pa->getConformsTo()) { for (auto proto : pa->getConformsTo()) {
if (proto->requiresClass()) return true; if (proto->requiresClass()) return true;
} }
@@ -519,8 +523,6 @@ Type GenericSignature::getSuperclassBound(Type type, ModuleDecl &mod) {
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed); builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return nullptr; if (!pa) return nullptr;
pa = pa->getRepresentative();
// If this type was mapped to a concrete type, then there is no // If this type was mapped to a concrete type, then there is no
// requirement. // requirement.
if (pa->isConcreteType()) return nullptr; if (pa->isConcreteType()) return nullptr;
@@ -540,8 +542,6 @@ SmallVector<ProtocolDecl *, 2> GenericSignature::getConformsTo(Type type,
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed); builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return { }; if (!pa) return { };
pa = pa->getRepresentative();
// If this type was mapped to a concrete type, then there are no // If this type was mapped to a concrete type, then there are no
// requirements. // requirements.
if (pa->isConcreteType()) return { }; if (pa->isConcreteType()) return { };
@@ -567,8 +567,6 @@ bool GenericSignature::conformsToProtocol(Type type, ProtocolDecl *proto,
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed); builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return false; if (!pa) return false;
pa = pa->getRepresentative();
// FIXME: Deal with concrete conformances here? // FIXME: Deal with concrete conformances here?
if (pa->isConcreteType()) return false; if (pa->isConcreteType()) return false;
@@ -596,9 +594,6 @@ Type GenericSignature::getConcreteType(Type type, ModuleDecl &mod) {
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed); builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return Type(); if (!pa) return Type();
pa = pa->getRepresentative();
if (!pa->isConcreteType()) return Type();
return pa->getConcreteType(); return pa->getConcreteType();
} }
@@ -611,7 +606,6 @@ LayoutConstraint GenericSignature::getLayoutConstraint(Type type,
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed); builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return LayoutConstraint(); if (!pa) return LayoutConstraint();
pa = pa->getRepresentative();
return pa->getLayout(); return pa->getLayout();
} }
@@ -882,7 +876,7 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
auto pa = auto pa =
inProtoSigBuilder.resolveArchetype( inProtoSigBuilder.resolveArchetype(
storedType, storedType,
ArchetypeResolutionKind::WellFormed); ArchetypeResolutionKind::CompleteWellFormed);
auto equivClass = pa->getOrCreateEquivalenceClass(); auto equivClass = pa->getOrCreateEquivalenceClass();
// Find the conformance of this potential archetype to the protocol in // Find the conformance of this potential archetype to the protocol in

View File

@@ -1960,13 +1960,9 @@ PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
} }
case ArchetypeResolutionKind::AlreadyKnown: case ArchetypeResolutionKind::AlreadyKnown:
break;
}
}
// If we still don't have a result potential archetype, we're done.
if (!resultPA)
return nullptr; return nullptr;
}
}
// If we have a potential archetype that requires more processing, do so now. // If we have a potential archetype that requires more processing, do so now.
if (shouldUpdatePA) { if (shouldUpdatePA) {

View File

@@ -132,8 +132,9 @@ Type CompleteGenericTypeResolver::resolveDependentMemberType(
assert(basePA && "Missing potential archetype for base"); assert(basePA && "Missing potential archetype for base");
// Retrieve the potential archetype for the nested type. // Retrieve the potential archetype for the nested type.
auto nestedPA = basePA->getNestedType(ref->getIdentifier(), auto nestedPA =
ArchetypeResolutionKind::WellFormed, basePA->getNestedType(ref->getIdentifier(),
ArchetypeResolutionKind::CompleteWellFormed,
Builder); Builder);
// If there was no such nested type, produce an error. // If there was no such nested type, produce an error.