Skip to content

Commit 644b6ad

Browse files
committed
AST: Simplify ProtocolConformanceRef::getTypeWitnessByName()
1 parent 4643cbd commit 644b6ad

File tree

7 files changed

+19
-41
lines changed

7 files changed

+19
-41
lines changed

include/swift/AST/ProtocolConformanceRef.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ class ProtocolConformanceRef {
138138
static Type
139139
getTypeWitnessByName(Type type,
140140
ProtocolConformanceRef conformance,
141-
Identifier name,
142-
LazyResolver *resolver);
141+
Identifier name);
143142

144143
/// Determine whether this conformance is canonical.
145144
bool isCanonical() const;

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4225,13 +4225,8 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
42254225
*bridgedValueType = type;
42264226

42274227
// Find the Objective-C class type we bridge to.
4228-
if (conformance->isConcrete()) {
4229-
return ProtocolConformanceRef::getTypeWitnessByName(
4230-
type, *conformance, Id_ObjectiveCType,
4231-
getLazyResolver());
4232-
} else {
4233-
return type->castTo<ArchetypeType>()->getNestedType(Id_ObjectiveCType);
4234-
}
4228+
return ProtocolConformanceRef::getTypeWitnessByName(
4229+
type, *conformance, Id_ObjectiveCType);
42354230
}
42364231

42374232
// Do we conform to Error?

lib/AST/ProtocolConformance.cpp

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ ProtocolConformanceRef::subst(Type origType,
144144
Type
145145
ProtocolConformanceRef::getTypeWitnessByName(Type type,
146146
ProtocolConformanceRef conformance,
147-
Identifier name,
148-
LazyResolver *resolver) {
147+
Identifier name) {
149148
assert(!conformance.isInvalid());
150149

151150
// Find the named requirement.
151+
ProtocolDecl *proto = conformance.getRequirement();
152152
AssociatedTypeDecl *assocType = nullptr;
153-
auto members = conformance.getRequirement()->lookupDirect(name);
153+
auto members = proto->lookupDirect(name);
154154
for (auto member : members) {
155155
assocType = dyn_cast<AssociatedTypeDecl>(member);
156156
if (assocType)
@@ -161,21 +161,8 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type,
161161
if (!assocType)
162162
return nullptr;
163163

164-
if (conformance.isAbstract()) {
165-
// For an archetype, retrieve the nested type with the appropriate
166-
// name. There are no conformance tables.
167-
if (auto archetype = type->getAs<ArchetypeType>()) {
168-
return archetype->getNestedType(name);
169-
}
170-
171-
return DependentMemberType::get(type, assocType);
172-
}
173-
174-
auto concrete = conformance.getConcrete();
175-
if (!concrete->hasTypeWitness(assocType, resolver)) {
176-
return nullptr;
177-
}
178-
return concrete->getTypeWitness(assocType, resolver);
164+
return assocType->getDeclaredInterfaceType().subst(
165+
SubstitutionMap::getProtocolSubstitutions(proto, type, conformance));
179166
}
180167

181168
void *ProtocolConformance::operator new(size_t bytes, ASTContext &context,

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,8 +1380,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
13801380
Type objcType = ProtocolConformanceRef::getTypeWitnessByName(
13811381
nominal->getDeclaredType(),
13821382
ProtocolConformanceRef(conformance),
1383-
ctx.Id_ObjectiveCType,
1384-
nullptr);
1383+
ctx.Id_ObjectiveCType);
13851384
if (!objcType) return nullptr;
13861385

13871386
// Dig out the Objective-C class.

lib/SIL/Bridging.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ Type TypeConverter::getLoweredCBridgedType(AbstractionPattern pattern,
225225
Type bridgedTy =
226226
ProtocolConformanceRef::getTypeWitnessByName(
227227
t, ProtocolConformanceRef(conformance),
228-
M.getASTContext().Id_ObjectiveCType,
229-
M.getASTContext().getLazyResolver());
228+
M.getASTContext().Id_ObjectiveCType);
230229
assert(bridgedTy && "Missing _ObjectiveCType witness?");
231230
if (purpose == BridgedTypePurpose::ForResult && clangTy)
232231
bridgedTy = OptionalType::get(bridgedTy);

lib/Sema/CSDiag.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ static Type isRawRepresentable(Type fromType, const ConstraintSystem &CS) {
17411741
return Type();
17421742

17431743
Type rawTy = ProtocolConformanceRef::getTypeWitnessByName(
1744-
fromType, *conformance, CS.getASTContext().Id_RawValue, &CS.TC);
1744+
fromType, *conformance, CS.getASTContext().Id_RawValue);
17451745
return rawTy;
17461746
}
17471747

@@ -2120,8 +2120,8 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
21202120
Type errorCodeType = CS.getType(expr);
21212121
Type errorType =
21222122
ProtocolConformanceRef::getTypeWitnessByName(errorCodeType, *conformance,
2123-
TC.Context.Id_ErrorType,
2124-
&TC)->getCanonicalType();
2123+
TC.Context.Id_ErrorType)
2124+
->getCanonicalType();
21252125
if (errorType) {
21262126
auto diag = diagnose(expr->getLoc(), diag::cannot_throw_error_code,
21272127
errorCodeType, errorType);
@@ -6255,7 +6255,7 @@ bool FailureDiagnosis::visitArrayExpr(ArrayExpr *E) {
62556255
Type contextualElementType =
62566256
ProtocolConformanceRef::getTypeWitnessByName(
62576257
contextualType, *Conformance,
6258-
CS.getASTContext().Id_ArrayLiteralElement, &CS.TC)
6258+
CS.getASTContext().Id_ArrayLiteralElement)
62596259
->getDesugaredType();
62606260

62616261
// Type check each of the subexpressions in place, passing down the contextual
@@ -6344,12 +6344,12 @@ bool FailureDiagnosis::visitDictionaryExpr(DictionaryExpr *E) {
63446344

63456345
contextualKeyType =
63466346
ProtocolConformanceRef::getTypeWitnessByName(
6347-
contextualType, *Conformance, CS.getASTContext().Id_Key, &CS.TC)
6347+
contextualType, *Conformance, CS.getASTContext().Id_Key)
63486348
->getDesugaredType();
63496349

63506350
contextualValueType =
63516351
ProtocolConformanceRef::getTypeWitnessByName(
6352-
contextualType, *Conformance, CS.getASTContext().Id_Value, &CS.TC)
6352+
contextualType, *Conformance, CS.getASTContext().Id_Value)
63536353
->getDesugaredType();
63546354

63556355
assert(contextualKeyType && contextualValueType &&

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4326,7 +4326,7 @@ void TypeChecker::useBridgedNSErrorConformances(DeclContext *dc, Type type) {
43264326
// protocol, also use the RawRepresentable and _ErrorCodeProtocol
43274327
// conformances on the Code associated type witness.
43284328
if (auto codeType = ProtocolConformanceRef::getTypeWitnessByName(
4329-
type, *conformance, Context.Id_Code, this)) {
4329+
type, *conformance, Context.Id_Code)) {
43304330
(void)conformsToProtocol(codeType, errorCodeProto, dc,
43314331
ConformanceCheckFlags::Used);
43324332
(void)conformsToProtocol(codeType, rawProto, dc,
@@ -4341,7 +4341,7 @@ void TypeChecker::useBridgedNSErrorConformances(DeclContext *dc, Type type) {
43414341
ConformanceCheckFlags::Used));
43424342
if (conformance && conformance->isConcrete()) {
43434343
if (Type errorType = ProtocolConformanceRef::getTypeWitnessByName(
4344-
type, *conformance, Context.Id_ErrorType, this)) {
4344+
type, *conformance, Context.Id_ErrorType)) {
43454345
(void)conformsToProtocol(errorType, bridgedStoredNSError, dc,
43464346
ConformanceCheckFlags::Used);
43474347
}
@@ -5663,8 +5663,7 @@ Type TypeChecker::getWitnessType(Type type, ProtocolDecl *protocol,
56635663
ProtocolConformanceRef conformance,
56645664
Identifier name,
56655665
Diag<> brokenProtocolDiag) {
5666-
Type ty = ProtocolConformanceRef::getTypeWitnessByName(type, conformance,
5667-
name, this);
5666+
Type ty = ProtocolConformanceRef::getTypeWitnessByName(type, conformance, name);
56685667
if (!ty &&
56695668
!(conformance.isConcrete() && conformance.getConcrete()->isInvalid()))
56705669
diagnose(protocol->getLoc(), brokenProtocolDiag);

0 commit comments

Comments
 (0)