Skip to content

Commit 6e3609d

Browse files
committed
AST: ProtocolConformanceRef::getTypeWitnessByName() should be an instance method
1 parent d93695f commit 6e3609d

File tree

7 files changed

+29
-37
lines changed

7 files changed

+29
-37
lines changed

include/swift/AST/ProtocolConformanceRef.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,7 @@ class ProtocolConformanceRef {
135135
return llvm::hash_value(conformance.Union.getOpaqueValue());
136136
}
137137

138-
static Type
139-
getTypeWitnessByName(Type type,
140-
ProtocolConformanceRef conformance,
141-
Identifier name);
138+
Type getTypeWitnessByName(Type type, Identifier name) const;
142139

143140
/// Determine whether this conformance is canonical.
144141
bool isCanonical() const;

lib/AST/ASTContext.cpp

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

42274227
// Find the Objective-C class type we bridge to.
4228-
return ProtocolConformanceRef::getTypeWitnessByName(
4229-
type, *conformance, Id_ObjectiveCType);
4228+
return conformance->getTypeWitnessByName(type, Id_ObjectiveCType);
42304229
}
42314230

42324231
// Do we conform to Error?

lib/AST/ProtocolConformance.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,14 @@ ProtocolConformanceRef::subst(Type origType,
142142
}
143143

144144
Type
145-
ProtocolConformanceRef::getTypeWitnessByName(Type type,
146-
ProtocolConformanceRef conformance,
147-
Identifier name) {
148-
assert(!conformance.isInvalid());
145+
ProtocolConformanceRef::getTypeWitnessByName(Type type, Identifier name) const {
146+
assert(!isInvalid());
149147

150148
// Find the named requirement.
151-
ProtocolDecl *proto = conformance.getRequirement();
149+
ProtocolDecl *proto = getRequirement();
152150
AssociatedTypeDecl *assocType = nullptr;
153-
auto members = proto->lookupDirect(name);
151+
auto members = proto->lookupDirect(name,
152+
NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions);
154153
for (auto member : members) {
155154
assocType = dyn_cast<AssociatedTypeDecl>(member);
156155
if (assocType)
@@ -162,7 +161,7 @@ ProtocolConformanceRef::getTypeWitnessByName(Type type,
162161
return nullptr;
163162

164163
return assocType->getDeclaredInterfaceType().subst(
165-
SubstitutionMap::getProtocolSubstitutions(proto, type, conformance));
164+
SubstitutionMap::getProtocolSubstitutions(proto, type, *this));
166165
}
167166

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

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,10 +1377,9 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
13771377

13781378
// Dig out the Objective-C type.
13791379
auto conformance = conformances.front();
1380-
Type objcType = ProtocolConformanceRef::getTypeWitnessByName(
1381-
nominal->getDeclaredType(),
1382-
ProtocolConformanceRef(conformance),
1383-
ctx.Id_ObjectiveCType);
1380+
Type objcType = ProtocolConformanceRef(conformance).getTypeWitnessByName(
1381+
nominal->getDeclaredType(),
1382+
ctx.Id_ObjectiveCType);
13841383
if (!objcType) return nullptr;
13851384

13861385
// Dig out the Objective-C class.

lib/SIL/Bridging.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ Type TypeConverter::getLoweredCBridgedType(AbstractionPattern pattern,
223223
auto conformance = foreignRepresentation.second;
224224
assert(conformance && "Missing conformance?");
225225
Type bridgedTy =
226-
ProtocolConformanceRef::getTypeWitnessByName(
227-
t, ProtocolConformanceRef(conformance),
228-
M.getASTContext().Id_ObjectiveCType);
226+
ProtocolConformanceRef(conformance).getTypeWitnessByName(
227+
t, M.getASTContext().Id_ObjectiveCType);
229228
assert(bridgedTy && "Missing _ObjectiveCType witness?");
230229
if (purpose == BridgedTypePurpose::ForResult && clangTy)
231230
bridgedTy = OptionalType::get(bridgedTy);

lib/Sema/CSDiag.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,8 +1740,8 @@ static Type isRawRepresentable(Type fromType, const ConstraintSystem &CS) {
17401740
if (!conformance)
17411741
return Type();
17421742

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

@@ -2119,9 +2119,9 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
21192119
ConformanceCheckFlags::InExpression)) {
21202120
Type errorCodeType = CS.getType(expr);
21212121
Type errorType =
2122-
ProtocolConformanceRef::getTypeWitnessByName(errorCodeType, *conformance,
2123-
TC.Context.Id_ErrorType)
2124-
->getCanonicalType();
2122+
conformance->getTypeWitnessByName(errorCodeType,
2123+
TC.Context.Id_ErrorType)
2124+
->getCanonicalType();
21252125
if (errorType) {
21262126
auto diag = diagnose(expr->getLoc(), diag::cannot_throw_error_code,
21272127
errorCodeType, errorType);
@@ -6253,9 +6253,8 @@ bool FailureDiagnosis::visitArrayExpr(ArrayExpr *E) {
62536253
= CS.TC.conformsToProtocol(contextualType, ALC, CS.DC,
62546254
ConformanceCheckFlags::InExpression)) {
62556255
Type contextualElementType =
6256-
ProtocolConformanceRef::getTypeWitnessByName(
6257-
contextualType, *Conformance,
6258-
CS.getASTContext().Id_ArrayLiteralElement)
6256+
Conformance->getTypeWitnessByName(
6257+
contextualType, CS.getASTContext().Id_ArrayLiteralElement)
62596258
->getDesugaredType();
62606259

62616260
// Type check each of the subexpressions in place, passing down the contextual
@@ -6343,13 +6342,13 @@ bool FailureDiagnosis::visitDictionaryExpr(DictionaryExpr *E) {
63436342
}
63446343

63456344
contextualKeyType =
6346-
ProtocolConformanceRef::getTypeWitnessByName(
6347-
contextualType, *Conformance, CS.getASTContext().Id_Key)
6345+
Conformance->getTypeWitnessByName(
6346+
contextualType, CS.getASTContext().Id_Key)
63486347
->getDesugaredType();
63496348

63506349
contextualValueType =
6351-
ProtocolConformanceRef::getTypeWitnessByName(
6352-
contextualType, *Conformance, CS.getASTContext().Id_Value)
6350+
Conformance->getTypeWitnessByName(
6351+
contextualType, CS.getASTContext().Id_Value)
63536352
->getDesugaredType();
63546353

63556354
assert(contextualKeyType && contextualValueType &&

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,8 +4325,8 @@ void TypeChecker::useBridgedNSErrorConformances(DeclContext *dc, Type type) {
43254325
// Hack: If we've used a conformance to the _BridgedStoredNSError
43264326
// protocol, also use the RawRepresentable and _ErrorCodeProtocol
43274327
// conformances on the Code associated type witness.
4328-
if (auto codeType = ProtocolConformanceRef::getTypeWitnessByName(
4329-
type, *conformance, Context.Id_Code)) {
4328+
if (auto codeType = conformance->getTypeWitnessByName(
4329+
type, Context.Id_Code)) {
43304330
(void)conformsToProtocol(codeType, errorCodeProto, dc,
43314331
ConformanceCheckFlags::Used);
43324332
(void)conformsToProtocol(codeType, rawProto, dc,
@@ -4340,8 +4340,8 @@ void TypeChecker::useBridgedNSErrorConformances(DeclContext *dc, Type type) {
43404340
(ConformanceCheckFlags::SuppressDependencyTracking|
43414341
ConformanceCheckFlags::Used));
43424342
if (conformance && conformance->isConcrete()) {
4343-
if (Type errorType = ProtocolConformanceRef::getTypeWitnessByName(
4344-
type, *conformance, Context.Id_ErrorType)) {
4343+
if (Type errorType = conformance->getTypeWitnessByName(
4344+
type, Context.Id_ErrorType)) {
43454345
(void)conformsToProtocol(errorType, bridgedStoredNSError, dc,
43464346
ConformanceCheckFlags::Used);
43474347
}
@@ -5663,7 +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, name);
5666+
Type ty = conformance.getTypeWitnessByName(type, name);
56675667
if (!ty &&
56685668
!(conformance.isConcrete() && conformance.getConcrete()->isInvalid()))
56695669
diagnose(protocol->getLoc(), brokenProtocolDiag);

0 commit comments

Comments
 (0)