Skip to content

Commit d5a55d9

Browse files
committed
[GSB] Eliminate "allow unresolved" from PotentialArchetype::getDependentType().
We don't need this now that there are no more unresolved types.
1 parent 84e3efa commit d5a55d9

File tree

3 files changed

+43
-81
lines changed

3 files changed

+43
-81
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,12 +1581,7 @@ class GenericSignatureBuilder::PotentialArchetype {
15811581
///
15821582
/// \param genericParams The set of generic parameters to use in the resulting
15831583
/// dependent type.
1584-
///
1585-
/// \param allowUnresolved If true, allow the result to contain
1586-
/// \c DependentMemberType types with a name but no specific associated
1587-
/// type.
1588-
Type getDependentType(ArrayRef<GenericTypeParamType *> genericParams,
1589-
bool allowUnresolved);
1584+
Type getDependentType(ArrayRef<GenericTypeParamType *> genericParams);
15901585

15911586
/// True if the potential archetype has been bound by a concrete type
15921587
/// constraint.

lib/AST/GenericSignature.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ CanType GenericSignature::getCanonicalTypeInContext(Type type,
709709
return getCanonicalTypeInContext(rep->getConcreteType(), builder);
710710
}
711711

712-
return rep->getDependentType(getGenericParams(), /*allowUnresolved*/ false);
712+
return rep->getDependentType(getGenericParams());
713713
});
714714

715715
auto result = type->getCanonicalType();
@@ -894,8 +894,7 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
894894
auto conformsSource = getBestRequirementSource(conforms->second);
895895
assert(conformsSource != source || !requirementSignatureProto);
896896
Type localRootType = conformsSource->getRootPotentialArchetype()
897-
->getDependentType(inProtoSig->getGenericParams(),
898-
/*allowUnresolved*/true);
897+
->getDependentType(inProtoSig->getGenericParams());
899898
localRootType = inProtoSig->getCanonicalTypeInContext(
900899
localRootType,
901900
*inProtocol->getModuleContext());
@@ -937,8 +936,7 @@ ConformanceAccessPath GenericSignature::getConformanceAccessPath(
937936
auto source = getBestRequirementSource(conforms->second);
938937
auto subjectPA = source->getRootPotentialArchetype();
939938
subjectPA = subjectPA->getArchetypeAnchor(*subjectPA->getBuilder());
940-
Type rootType = subjectPA->getDependentType(getGenericParams(),
941-
/*allowUnresolved=*/false);
939+
Type rootType = subjectPA->getDependentType(getGenericParams());
942940

943941
// Build the path.
944942
buildPath(getRequirements(), source, protocol, rootType, nullptr);

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 39 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,8 +1300,7 @@ GenericSignatureBuilder::resolveConcreteConformance(PotentialArchetype *pa,
13001300

13011301
// Lookup the conformance of the concrete type to this protocol.
13021302
auto conformance =
1303-
getLookupConformanceFn()(pa->getDependentType({ }, /*allowUnresolved=*/true)
1304-
->getCanonicalType(),
1303+
getLookupConformanceFn()(pa->getDependentType({ })->getCanonicalType(),
13051304
concrete,
13061305
proto->getDeclaredInterfaceType()
13071306
->castTo<ProtocolType>());
@@ -1331,8 +1330,7 @@ const RequirementSource *GenericSignatureBuilder::resolveSuperConformance(
13311330

13321331
// Lookup the conformance of the superclass to this protocol.
13331332
auto conformance =
1334-
getLookupConformanceFn()(pa->getDependentType({ }, /*allowUnresolved=*/true)
1335-
->getCanonicalType(),
1333+
getLookupConformanceFn()(pa->getDependentType({ })->getCanonicalType(),
13361334
superclass,
13371335
proto->getDeclaredInterfaceType()
13381336
->castTo<ProtocolType>());
@@ -1992,8 +1990,7 @@ PotentialArchetype *PotentialArchetype::updateNestedTypeForConformance(
19921990
// Substitute in the type of the current PotentialArchetype in
19931991
// place of 'Self' here.
19941992
auto subMap = SubstitutionMap::getProtocolSubstitutions(
1995-
proto, getDependentType(/*genericParams=*/{},
1996-
/*allowUnresolved=*/true),
1993+
proto, getDependentType(/*genericParams=*/{}),
19971994
ProtocolConformanceRef(proto));
19981995
type = type.subst(subMap, SubstFlags::UseErrorType);
19991996
} else {
@@ -2058,8 +2055,7 @@ Type GenericSignatureBuilder::PotentialArchetype::getTypeInContext(
20582055
// If this has a recursive type, return an error type.
20592056
auto equivClass = representative->getEquivalenceClassIfPresent();
20602057
if (equivClass->recursiveConcreteType) {
2061-
return ErrorType::get(getDependentType(genericParams,
2062-
/*allowUnresolved=*/true));
2058+
return ErrorType::get(getDependentType(genericParams));
20632059
}
20642060

20652061
return genericEnv->mapTypeIntoContext(concreteType,
@@ -2086,8 +2082,7 @@ Type GenericSignatureBuilder::PotentialArchetype::getTypeInContext(
20862082
// proper nested type.
20872083
auto parentTy = parent->getTypeInContext(builder, genericEnv);
20882084
if (!parentTy)
2089-
return ErrorType::get(getDependentType(genericParams,
2090-
/*allowUnresolved=*/true));
2085+
return ErrorType::get(getDependentType(genericParams));
20912086

20922087
ParentArchetype = parentTy->getAs<ArchetypeType>();
20932088
if (!ParentArchetype) {
@@ -2096,7 +2091,7 @@ Type GenericSignatureBuilder::PotentialArchetype::getTypeInContext(
20962091
(void) resolver;
20972092

20982093
// Resolve the member type.
2099-
auto type = getDependentType(genericParams, /*allowUnresolved=*/false);
2094+
auto type = getDependentType(genericParams);
21002095
if (type->hasError())
21012096
return type;
21022097

@@ -2175,8 +2170,7 @@ Type GenericSignatureBuilder::PotentialArchetype::getTypeInContext(
21752170
// If we were unable to resolve this as an associated type, produce an
21762171
// error type.
21772172
if (!assocType) {
2178-
return ErrorType::get(getDependentType(genericParams,
2179-
/*allowUnresolved=*/true));
2173+
return ErrorType::get(getDependentType(genericParams));
21802174
}
21812175

21822176
// Create a nested archetype.
@@ -2221,23 +2215,16 @@ void ArchetypeType::resolveNestedType(
22212215
}
22222216

22232217
Type GenericSignatureBuilder::PotentialArchetype::getDependentType(
2224-
ArrayRef<GenericTypeParamType *> genericParams,
2225-
bool allowUnresolved) {
2218+
ArrayRef<GenericTypeParamType *> genericParams){
22262219
if (auto parent = getParent()) {
2227-
Type parentType = parent->getDependentType(genericParams,
2228-
allowUnresolved);
2220+
Type parentType = parent->getDependentType(genericParams);
22292221
if (parentType->hasError())
22302222
return parentType;
22312223

22322224
// If we've resolved to an associated type, use it.
22332225
if (auto assocType = getResolvedAssociatedType())
22342226
return DependentMemberType::get(parentType, assocType);
22352227

2236-
// If we don't allow unresolved dependent member types, fail.
2237-
if (!allowUnresolved)
2238-
return ErrorType::get(getDependentType(genericParams,
2239-
/*allowUnresolved=*/true));
2240-
22412228
return DependentMemberType::get(parentType, getNestedName());
22422229
}
22432230

@@ -2525,7 +2512,7 @@ ConstraintResult GenericSignatureBuilder::addConformanceRequirement(
25252512
if (!PAT->addConformance(Proto, Source, *this))
25262513
return ConstraintResult::Resolved;
25272514

2528-
auto concreteSelf = PAT->getDependentType({}, /*allowUnresolved=*/true);
2515+
auto concreteSelf = PAT->getDependentType({});
25292516
auto protocolSubMap = SubstitutionMap::getProtocolSubstitutions(
25302517
Proto, concreteSelf, ProtocolConformanceRef(Proto));
25312518

@@ -2974,9 +2961,7 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
29742961
if (auto constraintPA = resolvedConstraint->getPotentialArchetype()) {
29752962
// The constraint type isn't a statically-known constraint.
29762963
if (source.getLoc().isValid()) {
2977-
auto constraintType =
2978-
constraintPA->getDependentType(Impl->GenericParams,
2979-
/*allowUnresolved=*/true);
2964+
auto constraintType = constraintPA->getDependentType(Impl->GenericParams);
29802965
Diags.diagnose(source.getLoc(), diag::requires_not_suitable_archetype,
29812966
1, TypeLoc::withoutLoc(constraintType), 0);
29822967
}
@@ -2993,8 +2978,7 @@ ConstraintResult GenericSignatureBuilder::addTypeRequirement(
29932978
auto subjectType = subject.dyn_cast<Type>();
29942979
if (!subjectType)
29952980
subjectType = subject.get<PotentialArchetype *>()
2996-
->getDependentType(Impl->GenericParams,
2997-
/*allowUnresolved=*/true);
2981+
->getDependentType(Impl->GenericParams);
29982982

29992983
Diags.diagnose(source.getLoc(), diag::requires_conformance_nonprotocol,
30002984
TypeLoc::withoutLoc(subjectType),
@@ -3193,7 +3177,7 @@ GenericSignatureBuilder::addSameTypeRequirementBetweenArchetypes(
31933177
}
31943178

31953179
// Recursively merge the associated types of T2 into T1.
3196-
auto dependentT1 = T1->getDependentType({ }, /*allowUnresolved=*/true);
3180+
auto dependentT1 = T1->getDependentType({ });
31973181
for (auto equivT2 : equivClass2Members) {
31983182
for (auto T2Nested : equivT2->NestedTypes) {
31993183
// If T1 is concrete but T2 is not, concretize the nested types of T2.
@@ -3912,8 +3896,7 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
39123896
equivClass->findAnyConcreteConstraintAsWritten()) {
39133897
Diags.diagnose(constraint->source->getLoc(),
39143898
diag::recursive_same_type_constraint,
3915-
archetype->getDependentType(genericParams,
3916-
/*allowUnresolved=*/true),
3899+
archetype->getDependentType(genericParams),
39173900
constraint->value);
39183901
}
39193902

@@ -3929,9 +3912,7 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
39293912
if (auto source = equivClass->findAnySuperclassConstraintAsWritten()) {
39303913
Diags.diagnose(source->source->getLoc(),
39313914
diag::recursive_superclass_constraint,
3932-
source->archetype->getDependentType(
3933-
genericParams,
3934-
/*allowUnresolved=*/true),
3915+
source->archetype->getDependentType(genericParams),
39353916
equivClass->superclass);
39363917
}
39373918

@@ -3971,8 +3952,7 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
39713952
if (auto constraint = equivClass->findAnyConcreteConstraintAsWritten())
39723953
Diags.diagnose(constraint->source->getLoc(),
39733954
diag::requires_generic_param_made_equal_to_concrete,
3974-
rep->getDependentType(genericParams,
3975-
/*allowUnresolved=*/true));
3955+
rep->getDependentType(genericParams));
39763956
continue;
39773957
}
39783958

@@ -4004,8 +3984,8 @@ GenericSignatureBuilder::finalize(SourceLoc loc,
40043984
if (repConstraint && repConstraint->source->getLoc().isValid()) {
40053985
Diags.diagnose(repConstraint->source->getLoc(),
40063986
diag::requires_generic_params_made_equal,
4007-
pa->getDependentType(genericParams, true),
4008-
other->getDependentType(genericParams, true));
3987+
pa->getDependentType(genericParams),
3988+
other->getDependentType(genericParams));
40093989
}
40103990
break;
40113991
}
@@ -4173,7 +4153,7 @@ Constraint<T> GenericSignatureBuilder::checkConstraintList(
41734153
otherNoteDiag,
41744154
representativeConstraint->source->classifyDiagKind(),
41754155
representativeConstraint->archetype->
4176-
getDependentType(genericParams, /*allowUnresolved=*/true),
4156+
getDependentType(genericParams),
41774157
diagValue(representativeConstraint->value));
41784158
};
41794159

@@ -4192,7 +4172,7 @@ Constraint<T> GenericSignatureBuilder::checkConstraintList(
41924172
// diagnostic.
41934173
auto getSubjectType =
41944174
[&](PotentialArchetype *pa) -> std::pair<unsigned, Type> {
4195-
auto subjectType = pa->getDependentType(genericParams, true);
4175+
auto subjectType = pa->getDependentType(genericParams);
41964176
unsigned kind;
41974177
if (auto gp = subjectType->getAs<GenericTypeParamType>()) {
41984178
if (gp->getDecl() &&
@@ -4250,8 +4230,7 @@ Constraint<T> GenericSignatureBuilder::checkConstraintList(
42504230
constraint.source->getLoc().isValid()) {
42514231
Diags.diagnose(constraint.source->getLoc(),
42524232
redundancyDiag,
4253-
constraint.archetype->getDependentType(
4254-
genericParams, /*allowUnresolved=*/true),
4233+
constraint.archetype->getDependentType(genericParams),
42554234
diagValue(constraint.value));
42564235

42574236
noteRepresentativeConstraint();
@@ -4556,10 +4535,8 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
45564535
constraint.source->getLoc().isValid()) {
45574536
Diags.diagnose(constraint.source->getLoc(),
45584537
diag::redundant_same_type_constraint,
4559-
constraint.archetype->getDependentType(
4560-
genericParams, true),
4561-
constraint.value->getDependentType(
4562-
genericParams, true));
4538+
constraint.archetype->getDependentType(genericParams),
4539+
constraint.value->getDependentType(genericParams));
45634540
}
45644541

45654542
continue;
@@ -4626,7 +4603,7 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
46264603
diag::redundant_same_type_constraint,
46274604
diag::previous_same_type_constraint,
46284605
[&](PotentialArchetype *pa) {
4629-
return pa->getDependentType(genericParams, true);
4606+
return pa->getDependentType(genericParams);
46304607
},
46314608
/*removeSelfDerived=*/false);
46324609
}
@@ -4661,16 +4638,14 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
46614638
Diags.diagnose(lhs.constraint.source->getLoc(),
46624639
diag::redundant_same_type_constraint,
46634640
lhs.constraint.archetype->getDependentType(
4664-
genericParams, true),
4665-
lhs.constraint.value->getDependentType(
4666-
genericParams, true));
4641+
genericParams),
4642+
lhs.constraint.value->getDependentType(genericParams));
46674643
Diags.diagnose(rhs.constraint.source->getLoc(),
46684644
diag::previous_same_type_constraint,
46694645
rhs.constraint.source->classifyDiagKind(),
46704646
rhs.constraint.archetype->getDependentType(
4671-
genericParams, true),
4672-
rhs.constraint.value->getDependentType(
4673-
genericParams, true));
4647+
genericParams),
4648+
rhs.constraint.value->getDependentType(genericParams));
46744649
return true;
46754650
}),
46764651
intercomponentEdges.end());
@@ -4693,17 +4668,17 @@ void GenericSignatureBuilder::checkSameTypeConstraints(
46934668
Diags.diagnose(edge.constraint.source->getLoc(),
46944669
diag::redundant_same_type_constraint,
46954670
edge.constraint.archetype->getDependentType(
4696-
genericParams, true),
4671+
genericParams),
46974672
edge.constraint.value->getDependentType(
4698-
genericParams, true));
4673+
genericParams));
46994674

47004675
Diags.diagnose(firstEdge.constraint.source->getLoc(),
47014676
diag::previous_same_type_constraint,
47024677
firstEdge.constraint.source->classifyDiagKind(),
47034678
firstEdge.constraint.archetype->getDependentType(
4704-
genericParams, true),
4679+
genericParams),
47054680
firstEdge.constraint.value->getDependentType(
4706-
genericParams, true));
4681+
genericParams));
47074682
}
47084683

47094684
continue;
@@ -4730,7 +4705,7 @@ static Type resolveDependentMemberTypes(GenericSignatureBuilder &builder,
47304705
if (!pa)
47314706
return ErrorType::get(depTy);
47324707

4733-
return pa->getDependentType({ }, /*allowUnresolved=*/false);
4708+
return pa->getDependentType({ });
47344709
}
47354710

47364711
return None;
@@ -4820,36 +4795,31 @@ void GenericSignatureBuilder::checkSuperclassConstraints(
48204795
representativeConstraint.archetype)) {
48214796
Diags.diagnose(existing->source->getLoc(), diag::type_does_not_inherit,
48224797
existing->archetype->getDependentType(
4823-
genericParams,
4824-
/*allowUnresolved=*/true),
4798+
genericParams),
48254799
existing->value, equivClass->superclass);
48264800

48274801
// FIXME: Note the representative constraint.
48284802
} else if (representativeConstraint.source->getLoc().isValid()) {
48294803
Diags.diagnose(representativeConstraint.source->getLoc(),
48304804
diag::type_does_not_inherit,
48314805
representativeConstraint.archetype->getDependentType(
4832-
genericParams,
4833-
/*allowUnresolved=*/true),
4806+
genericParams),
48344807
equivClass->concreteType, equivClass->superclass);
48354808
}
48364809
} else if (representativeConstraint.source->getLoc().isValid()) {
48374810
// It does fulfill the requirement; diagnose the redundancy.
48384811
Diags.diagnose(representativeConstraint.source->getLoc(),
48394812
diag::redundant_superclass_constraint,
48404813
representativeConstraint.archetype->getDependentType(
4841-
genericParams,
4842-
/*allowUnresolved=*/true),
4814+
genericParams),
48434815
representativeConstraint.value);
48444816

48454817
if (auto existing = equivClass->findAnyConcreteConstraintAsWritten(
48464818
representativeConstraint.archetype)) {
48474819
Diags.diagnose(existing->source->getLoc(),
48484820
diag::same_type_redundancy_here,
48494821
existing->source->classifyDiagKind(),
4850-
existing->archetype->getDependentType(
4851-
genericParams,
4852-
/*allowUnresolved=*/true),
4822+
existing->archetype->getDependentType(genericParams),
48534823
existing->value);
48544824
}
48554825
}
@@ -5180,8 +5150,7 @@ static void collectRequirements(GenericSignatureBuilder &builder,
51805150
type.is<Type>()))
51815151
return;
51825152

5183-
auto depTy = archetype->getDependentType(params,
5184-
/*allowUnresolved=*/false);
5153+
auto depTy = archetype->getDependentType(params);
51855154

51865155
if (depTy->hasError())
51875156
return;
@@ -5201,7 +5170,7 @@ static void collectRequirements(GenericSignatureBuilder &builder,
52015170
} else {
52025171
// ...or to a dependent type.
52035172
repTy = type.get<GenericSignatureBuilder::PotentialArchetype *>()
5204-
->getDependentType(params, /*allowUnresolved=*/false);
5173+
->getDependentType(params);
52055174
}
52065175

52075176
if (repTy->hasError())

0 commit comments

Comments
 (0)