Skip to content

Commit cb38983

Browse files
authored
Merge pull request #10742 from DougGregor/gsb-no-longer-gross
2 parents e1a4bf3 + ea34392 commit cb38983

File tree

4 files changed

+15
-56
lines changed

4 files changed

+15
-56
lines changed

lib/AST/Decl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3294,8 +3294,7 @@ void ProtocolDecl::computeRequirementSignature() {
32943294
LookUpConformanceInModule(module));
32953295
builder.addGenericParameter(selfType);
32963296
auto selfPA =
3297-
builder.resolveArchetype(selfType,
3298-
ArchetypeResolutionKind::CompleteWellFormed);
3297+
builder.resolveArchetype(selfType, ArchetypeResolutionKind::WellFormed);
32993298

33003299
builder.addRequirement(
33013300
requirement,

lib/AST/GenericSignature.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -488,21 +488,25 @@ bool GenericSignature::requiresClass(Type type, ModuleDecl &mod) {
488488
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
489489
if (!pa) return false;
490490

491-
pa = pa->getRepresentative();
491+
if (pa->isConcreteType()) return false;
492492

493493
// If this type was mapped to a concrete type, then there is no
494494
// requirement.
495+
pa = pa->getRepresentative();
496+
495497
if (pa->isConcreteType()) return false;
496498

497499
// If there is a layout constraint, it might be a class.
498-
if (auto layout = pa->getLayout())
499-
if (layout->isClass())
500-
return true;
500+
if (auto layout = pa->getLayout()) {
501+
if (layout->isClass()) return true;
502+
}
501503

502504
// If there is a superclass bound, then obviously it must be a class.
505+
// FIXME: We shouldn't need this?
503506
if (pa->getSuperclass()) return true;
504507

505508
// If any of the protocols are class-bound, then it must be a class.
509+
// FIXME: We shouldn't need this?
506510
for (auto proto : pa->getConformsTo()) {
507511
if (proto->requiresClass()) return true;
508512
}
@@ -519,8 +523,6 @@ Type GenericSignature::getSuperclassBound(Type type, ModuleDecl &mod) {
519523
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
520524
if (!pa) return nullptr;
521525

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

543-
pa = pa->getRepresentative();
544-
545545
// If this type was mapped to a concrete type, then there are no
546546
// requirements.
547547
if (pa->isConcreteType()) return { };
@@ -567,8 +567,6 @@ bool GenericSignature::conformsToProtocol(Type type, ProtocolDecl *proto,
567567
builder.resolveArchetype(type, ArchetypeResolutionKind::CompleteWellFormed);
568568
if (!pa) return false;
569569

570-
pa = pa->getRepresentative();
571-
572570
// FIXME: Deal with concrete conformances here?
573571
if (pa->isConcreteType()) return false;
574572

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

599-
pa = pa->getRepresentative();
600-
if (!pa->isConcreteType()) return Type();
601-
602597
return pa->getConcreteType();
603598
}
604599

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

614-
pa = pa->getRepresentative();
615609
return pa->getLayout();
616610
}
617611

@@ -882,7 +876,7 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
882876
auto pa =
883877
inProtoSigBuilder.resolveArchetype(
884878
storedType,
885-
ArchetypeResolutionKind::WellFormed);
879+
ArchetypeResolutionKind::CompleteWellFormed);
886880
auto equivClass = pa->getOrCreateEquivalenceClass();
887881

888882
// Find the conformance of this potential archetype to the protocol in

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,37 +1063,6 @@ bool FloatingRequirementSource::isRecursive(
10631063
return true;
10641064
}
10651065

1066-
// For a nested type match, look for another type with that name.
1067-
// FIXME: Actually, look for 5 of them. This is totally bogus.
1068-
if (kind == NestedTypeNameMatch) {
1069-
unsigned grossCount = 0;
1070-
auto pa = storage.dyn_cast<const RequirementSource *>()
1071-
->getAffectedPotentialArchetype();
1072-
while (auto parent = pa->getParent()) {
1073-
if (pa->getNestedName() == nestedName) {
1074-
if (++grossCount > 4) {
1075-
++NumRecursive;
1076-
return true;
1077-
}
1078-
}
1079-
1080-
pa = parent;
1081-
}
1082-
1083-
// Also check the root type.
1084-
grossCount = 0;
1085-
for (Type type = rootType;
1086-
auto depTy = type->getAs<DependentMemberType>();
1087-
type = depTy->getBase()) {
1088-
if (depTy->getName() == nestedName) {
1089-
if (++grossCount > 4) {
1090-
++NumRecursive;
1091-
return true;
1092-
}
1093-
}
1094-
}
1095-
}
1096-
10971066
return false;
10981067
}
10991068

@@ -1960,14 +1929,10 @@ PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
19601929
}
19611930

19621931
case ArchetypeResolutionKind::AlreadyKnown:
1963-
break;
1932+
return nullptr;
19641933
}
19651934
}
19661935

1967-
// If we still don't have a result potential archetype, we're done.
1968-
if (!resultPA)
1969-
return nullptr;
1970-
19711936
// If we have a potential archetype that requires more processing, do so now.
19721937
if (shouldUpdatePA) {
19731938
// For concrete types, introduce a same-type requirement to the aliased

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@ Type CompleteGenericTypeResolver::resolveDependentMemberType(
132132
assert(basePA && "Missing potential archetype for base");
133133

134134
// Retrieve the potential archetype for the nested type.
135-
auto nestedPA = basePA->getNestedType(ref->getIdentifier(),
136-
ArchetypeResolutionKind::WellFormed,
137-
Builder);
135+
auto nestedPA =
136+
basePA->getNestedType(ref->getIdentifier(),
137+
ArchetypeResolutionKind::CompleteWellFormed,
138+
Builder);
138139

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

0 commit comments

Comments
 (0)