Skip to content

[GSB] Eliminate the ridiculous ad hoc recursion-breaking code. #10742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3292,8 +3292,7 @@ void ProtocolDecl::computeRequirementSignature() {
LookUpConformanceInModule(module));
builder.addGenericParameter(selfType);
auto selfPA =
builder.resolveArchetype(selfType,
ArchetypeResolutionKind::CompleteWellFormed);
builder.resolveArchetype(selfType, ArchetypeResolutionKind::WellFormed);

builder.addRequirement(
requirement,
Expand Down
24 changes: 9 additions & 15 deletions lib/AST/GenericSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,21 +488,25 @@ bool GenericSignature::requiresClass(Type type, ModuleDecl &mod) {
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
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
// requirement.
pa = pa->getRepresentative();

if (pa->isConcreteType()) return false;

// If there is a layout constraint, it might be a class.
if (auto layout = pa->getLayout())
if (layout->isClass())
return true;
if (auto layout = pa->getLayout()) {
if (layout->isClass()) return true;
}

// 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 any of the protocols are class-bound, then it must be a class.
// FIXME: We shouldn't need this?
for (auto proto : pa->getConformsTo()) {
if (proto->requiresClass()) return true;
}
Expand All @@ -519,8 +523,6 @@ Type GenericSignature::getSuperclassBound(Type type, ModuleDecl &mod) {
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return nullptr;

pa = pa->getRepresentative();

// If this type was mapped to a concrete type, then there is no
// requirement.
if (pa->isConcreteType()) return nullptr;
Expand All @@ -540,8 +542,6 @@ SmallVector<ProtocolDecl *, 2> GenericSignature::getConformsTo(Type type,
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return { };

pa = pa->getRepresentative();

// If this type was mapped to a concrete type, then there are no
// requirements.
if (pa->isConcreteType()) return { };
Expand All @@ -567,8 +567,6 @@ bool GenericSignature::conformsToProtocol(Type type, ProtocolDecl *proto,
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return false;

pa = pa->getRepresentative();

// FIXME: Deal with concrete conformances here?
if (pa->isConcreteType()) return false;

Expand Down Expand Up @@ -596,9 +594,6 @@ Type GenericSignature::getConcreteType(Type type, ModuleDecl &mod) {
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return Type();

pa = pa->getRepresentative();
if (!pa->isConcreteType()) return Type();

return pa->getConcreteType();
}

Expand All @@ -611,7 +606,6 @@ LayoutConstraint GenericSignature::getLayoutConstraint(Type type,
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
if (!pa) return LayoutConstraint();

pa = pa->getRepresentative();
return pa->getLayout();
}

Expand Down Expand Up @@ -882,7 +876,7 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
auto pa =
inProtoSigBuilder.resolveArchetype(
storedType,
ArchetypeResolutionKind::WellFormed);
ArchetypeResolutionKind::CompleteWellFormed);
auto equivClass = pa->getOrCreateEquivalenceClass();

// Find the conformance of this potential archetype to the protocol in
Expand Down
37 changes: 1 addition & 36 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,37 +1063,6 @@ bool FloatingRequirementSource::isRecursive(
return true;
}

// For a nested type match, look for another type with that name.
// FIXME: Actually, look for 5 of them. This is totally bogus.
if (kind == NestedTypeNameMatch) {
unsigned grossCount = 0;
auto pa = storage.dyn_cast<const RequirementSource *>()
->getAffectedPotentialArchetype();
while (auto parent = pa->getParent()) {
if (pa->getNestedName() == nestedName) {
if (++grossCount > 4) {
++NumRecursive;
return true;
}
}

pa = parent;
}

// Also check the root type.
grossCount = 0;
for (Type type = rootType;
auto depTy = type->getAs<DependentMemberType>();
type = depTy->getBase()) {
if (depTy->getName() == nestedName) {
if (++grossCount > 4) {
++NumRecursive;
return true;
}
}
}
}

return false;
}

Expand Down Expand Up @@ -1960,14 +1929,10 @@ PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
}

case ArchetypeResolutionKind::AlreadyKnown:
break;
return nullptr;
}
}

// If we still don't have a result potential archetype, we're done.
if (!resultPA)
return nullptr;

// If we have a potential archetype that requires more processing, do so now.
if (shouldUpdatePA) {
// For concrete types, introduce a same-type requirement to the aliased
Expand Down
7 changes: 4 additions & 3 deletions lib/Sema/TypeCheckGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ Type CompleteGenericTypeResolver::resolveDependentMemberType(
assert(basePA && "Missing potential archetype for base");

// Retrieve the potential archetype for the nested type.
auto nestedPA = basePA->getNestedType(ref->getIdentifier(),
ArchetypeResolutionKind::WellFormed,
Builder);
auto nestedPA =
basePA->getNestedType(ref->getIdentifier(),
ArchetypeResolutionKind::CompleteWellFormed,
Builder);

// If there was no such nested type, produce an error.
if (!nestedPA) {
Expand Down