Skip to content

Commit 9150371

Browse files
committed
AST: Remove origType parameter from ProtocolConformanceRef::getTypeWitness()
1 parent 1828c7e commit 9150371

10 files changed

+28
-45
lines changed

include/swift/AST/ProtocolConformanceRef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class ProtocolConformanceRef {
205205

206206
/// Look up the type witness for an associated type declaration in this
207207
/// conformance.
208-
Type getTypeWitness(Type origType, AssociatedTypeDecl *assocType,
208+
Type getTypeWitness(AssociatedTypeDecl *assocType,
209209
SubstOptions options = std::nullopt) const;
210210

211211
/// Given a dependent type (expressed in terms of this conformance's

lib/AST/PackConformance.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,15 @@ PackType *PackConformance::getTypeWitness(
112112
// conformance.
113113
if (auto *packExpansion = packElement->getAs<PackExpansionType>()) {
114114
auto assocTypePattern =
115-
conformances[i].getTypeWitness(packExpansion->getPatternType(),
116-
assocType, options);
115+
conformances[i].getTypeWitness(assocType, options);
117116

118117
packElements.push_back(PackExpansionType::get(
119118
assocTypePattern, packExpansion->getCountType()));
120119

121120
// If the pack element is a scalar type, replace the scalar type with
122121
// the associated type witness from the pattern conformance.
123122
} else {
124-
auto assocTypeScalar =
125-
conformances[i].getTypeWitness(packElement, assocType, options);
123+
auto assocTypeScalar = conformances[i].getTypeWitness(assocType, options);
126124
packElements.push_back(assocTypeScalar);
127125
}
128126
}

lib/AST/ProtocolConformanceRef.cpp

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type, Identifier name) const {
160160
if (!assocType)
161161
return ErrorType::get(proto->getASTContext());
162162

163-
return getTypeWitness(type, assocType);
163+
return getTypeWitness(assocType);
164164
}
165165

166166
ConcreteDeclRef
@@ -190,43 +190,32 @@ ProtocolConformanceRef::getConditionalRequirements() const {
190190
return {};
191191
}
192192

193-
Type ProtocolConformanceRef::getTypeWitness(Type conformingType,
194-
AssociatedTypeDecl *assocType,
193+
Type ProtocolConformanceRef::getTypeWitness(AssociatedTypeDecl *assocType,
195194
SubstOptions options) const {
195+
if (isInvalid())
196+
return ErrorType::get(assocType->getASTContext());
197+
196198
if (isPack()) {
197199
auto *pack = getPack();
198-
ASSERT(conformingType->isEqual(pack->getType()));
199-
return pack->getTypeWitness(assocType);
200+
return pack->getTypeWitness(assocType, options);
200201
}
201202

202-
auto failed = [&]() {
203-
return DependentMemberType::get(ErrorType::get(conformingType),
204-
assocType);
205-
};
206-
207-
if (isInvalid())
208-
return failed();
209-
210-
auto proto = getProtocol();
211-
ASSERT(assocType->getProtocol() == proto);
212-
213203
if (isConcrete()) {
214-
auto witnessType = getConcrete()->getTypeWitness(assocType, options);
215-
if (!witnessType || witnessType->is<ErrorType>())
216-
return failed();
204+
auto *concrete = getConcrete();
205+
ASSERT(concrete->getProtocol() == assocType->getProtocol());
206+
207+
auto witnessType = concrete->getTypeWitness(assocType, options);
208+
if (!witnessType)
209+
return ErrorType::get(assocType->getASTContext());
217210
return witnessType;
218211
}
219212

220-
ASSERT(isAbstract());
213+
auto *abstract = getAbstract();
214+
auto conformingType = abstract->getType();
215+
ASSERT(abstract->getProtocol() == assocType->getProtocol());
221216

222-
if (auto *archetypeType = conformingType->getAs<ArchetypeType>()) {
217+
if (auto *archetypeType = conformingType->getAs<ArchetypeType>())
223218
return archetypeType->getNestedType(assocType);
224-
}
225-
226-
CONDITIONAL_ASSERT(conformingType->isTypeParameter() ||
227-
conformingType->isTypeVariableOrMember() ||
228-
conformingType->is<UnresolvedType>() ||
229-
conformingType->is<PlaceholderType>());
230219

231220
return DependentMemberType::get(conformingType, assocType);
232221
}

lib/AST/RequirementMachine/ConcreteContraction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ ConcreteContraction::substTypeParameterRec(Type type, Position position) const {
302302
return std::nullopt;
303303
}
304304

305-
return conformance.getTypeWitness(*substBaseType, assocType);
305+
return conformance.getTypeWitness(assocType);
306306
}
307307

308308
// An unresolved DependentMemberType stores an identifier. Handle this

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ static Type substPrefixType(Type type, unsigned suffixLength, Type prefixType,
346346
auto *assocDecl = memberType->getAssocType();
347347
auto *proto = assocDecl->getProtocol();
348348
auto conformance = lookupConformance(substBaseType, proto);
349-
return conformance.getTypeWitness(substBaseType, assocDecl);
349+
return conformance.getTypeWitness(assocDecl);
350350
}
351351

352352
Type RequirementMachine::getReducedTypeParameter(

lib/AST/RequirementMachine/RequirementLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ struct InferRequirementsWalker : public TypeWalker {
665665
auto addSameTypeConstraint = [&](Type firstType,
666666
AssociatedTypeDecl *assocType) {
667667
auto conformance = lookupConformance(firstType, differentiableProtocol);
668-
auto secondType = conformance.getTypeWitness(firstType, assocType);
668+
auto secondType = conformance.getTypeWitness(assocType);
669669
reqs.push_back({Requirement(RequirementKind::SameType,
670670
firstType, secondType),
671671
SourceLoc()});

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4569,7 +4569,7 @@ TypeBase::getAutoDiffTangentSpace(LookupConformanceFn lookupConformance) {
45694569
// Try to get the `TangentVector` associated type of `base`.
45704570
// Return the associated type if it is valid.
45714571
auto conformance = swift::lookupConformance(this, differentiableProtocol);
4572-
auto assocTy = conformance.getTypeWitness(this, assocDecl);
4572+
auto assocTy = conformance.getTypeWitness(assocDecl);
45734573
if (!assocTy->hasError())
45744574
return cache(TangentSpace::getTangentVector(assocTy));
45754575

lib/AST/TypeSubstitution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ Type TypeSubstituter::transformDependentMemberType(DependentMemberType *dependen
443443
IFS.lookupConformance(origBase->getCanonicalType(), substBase,
444444
proto, level);
445445

446-
auto result = conformance.getTypeWitness(substBase, assocType, IFS.getOptions());
446+
auto result = conformance.getTypeWitness(assocType, IFS.getOptions());
447447
if (result->is<ErrorType>())
448448
return DependentMemberType::get(ErrorType::get(substBase), assocType);
449449
return result;

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ struct TypeSimplifier {
17091709
return memberTy;
17101710
}
17111711

1712-
auto result = conformance.getTypeWitness(lookupBaseType, assocType);
1712+
auto result = conformance.getTypeWitness(assocType);
17131713
if (result && !result->hasError())
17141714
return result;
17151715
}

lib/Sema/TypeCheckEffects.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,7 @@ class ApplyClassifier {
13521352
}
13531353
}
13541354

1355-
Classification classifyConformance(Type type,
1356-
ProtocolConformanceRef conformanceRef,
1355+
Classification classifyConformance(ProtocolConformanceRef conformanceRef,
13571356
EffectKind kind) {
13581357
if (conformanceRef.isInvalid())
13591358
return Classification::forInvalidCode();
@@ -1374,8 +1373,7 @@ class ApplyClassifier {
13741373
conditional = ConditionalEffectKind::Always;
13751374

13761375
// Use the Failure type witness, when present.
1377-
Type thrownError = conformanceRef.getTypeWitness(
1378-
type, failureAssocType);
1376+
Type thrownError = conformanceRef.getTypeWitness(failureAssocType);
13791377
return Classification::forThrows(
13801378
thrownError, conditional,
13811379
/*FIXME*/PotentialEffectReason::forConformance());
@@ -1671,13 +1669,11 @@ class ApplyClassifier {
16711669
if (req.getKind() != RequirementKind::Conformance)
16721670
continue;
16731671

1674-
Type type = req.getFirstType().subst(substitutions);
1675-
16761672
auto conformanceRef = substitutions.lookupConformance(
16771673
req.getFirstType()->getCanonicalType(), req.getProtocolDecl());
16781674
assert(conformanceRef);
16791675

1680-
result.merge(classifyConformance(type, conformanceRef, kind));
1676+
result.merge(classifyConformance(conformanceRef, kind));
16811677
}
16821678

16831679
// 'ByConformance' is a superset of 'ByClosure', so check for

0 commit comments

Comments
 (0)