Skip to content

Commit ae5091b

Browse files
committed
[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).
1 parent dbc0422 commit ae5091b

File tree

4 files changed

+15
-25
lines changed

4 files changed

+15
-25
lines changed

lib/AST/Decl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,8 +3292,7 @@ void ProtocolDecl::computeRequirementSignature() {
32923292
LookUpConformanceInModule(module));
32933293
builder.addGenericParameter(selfType);
32943294
auto selfPA =
3295-
builder.resolveArchetype(selfType,
3296-
ArchetypeResolutionKind::CompleteWellFormed);
3295+
builder.resolveArchetype(selfType, ArchetypeResolutionKind::WellFormed);
32973296

32983297
builder.addRequirement(
32993298
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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,14 +1960,10 @@ PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
19601960
}
19611961

19621962
case ArchetypeResolutionKind::AlreadyKnown:
1963-
break;
1963+
return nullptr;
19641964
}
19651965
}
19661966

1967-
// If we still don't have a result potential archetype, we're done.
1968-
if (!resultPA)
1969-
return nullptr;
1970-
19711967
// If we have a potential archetype that requires more processing, do so now.
19721968
if (shouldUpdatePA) {
19731969
// 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)