@@ -99,67 +99,6 @@ SubstitutionMap Solution::computeSubstitutions(
99
99
lookupConformanceFn);
100
100
}
101
101
102
- // / Find a particular named function witness for a type that conforms to
103
- // / the given protocol.
104
- // /
105
- // / \param tc The type check we're using.
106
- // /
107
- // / \param dc The context in which we need a witness.
108
- // /
109
- // / \param type The type whose witness to find.
110
- // /
111
- // / \param proto The protocol to which the type conforms.
112
- // /
113
- // / \param name The name of the requirement.
114
- // /
115
- // / \param diag The diagnostic to emit if the protocol definition doesn't
116
- // / have a requirement with the given name.
117
- // /
118
- // / \returns The named witness, or an empty ConcreteDeclRef if no witness
119
- // / could be found.
120
- ConcreteDeclRef findNamedWitnessImpl (
121
- TypeChecker &tc, DeclContext *dc, Type type,
122
- ProtocolDecl *proto, DeclName name,
123
- Diag<> diag,
124
- Optional<ProtocolConformanceRef> conformance = None) {
125
- // Find the named requirement.
126
- ValueDecl *requirement = nullptr ;
127
- for (auto member : proto->getMembers ()) {
128
- auto d = dyn_cast<ValueDecl>(member);
129
- if (!d || !d->hasName ())
130
- continue ;
131
-
132
- if (d->getFullName ().matchesRef (name)) {
133
- requirement = d;
134
- break ;
135
- }
136
- }
137
-
138
- if (!requirement || requirement->isInvalid ()) {
139
- tc.diagnose (proto->getLoc (), diag);
140
- return nullptr ;
141
- }
142
-
143
- // Find the member used to satisfy the named requirement.
144
- if (!conformance) {
145
- conformance = tc.conformsToProtocol (type, proto, dc,
146
- ConformanceCheckFlags::InExpression);
147
- if (!conformance)
148
- return nullptr ;
149
- }
150
-
151
- // For a type with dependent conformance, just return the requirement from
152
- // the protocol. There are no protocol conformance tables.
153
- if (!conformance->isConcrete ()) {
154
- auto subMap = SubstitutionMap::getProtocolSubstitutions (proto, type,
155
- *conformance);
156
- return ConcreteDeclRef (requirement, subMap);
157
- }
158
-
159
- auto concrete = conformance->getConcrete ();
160
- return concrete->getWitnessDeclRef (requirement, &tc);
161
- }
162
-
163
102
static bool shouldAccessStorageDirectly (Expr *base, VarDecl *member,
164
103
DeclContext *DC) {
165
104
// This only matters for stored properties.
@@ -2974,10 +2913,8 @@ namespace {
2974
2913
2975
2914
DeclName name (tc.Context , DeclBaseName::createConstructor (),
2976
2915
{ tc.Context .Id_arrayLiteral });
2977
-
2978
2916
ConcreteDeclRef witness =
2979
- findNamedWitnessImpl (tc, dc, arrayTy->getRValueType (), arrayProto,
2980
- name, diag::array_protocol_broken, conformance);
2917
+ conformance->getWitnessByName (arrayTy->getRValueType (), name);
2981
2918
if (!witness || !isa<AbstractFunctionDecl>(witness.getDecl ()))
2982
2919
return nullptr ;
2983
2920
expr->setInitializer (witness);
@@ -6854,10 +6791,8 @@ Expr *ExprRewriter::convertLiteralInPlace(Expr *literal,
6854
6791
6855
6792
// Find the witness that we'll use to initialize the type via a builtin
6856
6793
// literal.
6857
- auto witness = findNamedWitnessImpl (
6858
- tc, dc, type->getRValueType (), builtinProtocol,
6859
- builtinLiteralFuncName, brokenBuiltinProtocolDiag,
6860
- *builtinConformance);
6794
+ auto witness = builtinConformance->getWitnessByName (type->getRValueType (),
6795
+ builtinLiteralFuncName);
6861
6796
if (!witness || !isa<AbstractFunctionDecl>(witness.getDecl ()))
6862
6797
return nullptr ;
6863
6798
@@ -6905,10 +6840,8 @@ Expr *ExprRewriter::convertLiteralInPlace(Expr *literal,
6905
6840
}
6906
6841
6907
6842
// Find the witness that we'll use to initialize the literal value.
6908
- auto witness = findNamedWitnessImpl (
6909
- tc, dc, type->getRValueType (), protocol,
6910
- literalFuncName, brokenProtocolDiag,
6911
- conformance);
6843
+ auto witness = conformance->getWitnessByName (type->getRValueType (),
6844
+ literalFuncName);
6912
6845
if (!witness || !isa<AbstractFunctionDecl>(witness.getDecl ()))
6913
6846
return nullptr ;
6914
6847
@@ -7752,10 +7685,9 @@ Expr *TypeChecker::callWitness(Expr *base, DeclContext *dc,
7752
7685
7753
7686
if (auto metaType = type->getAs <AnyMetatypeType>())
7754
7687
type = metaType->getInstanceType ();
7755
-
7756
- auto witness = findNamedWitnessImpl (
7757
- *this , dc, type->getRValueType (), protocol,
7758
- name, brokenProtocolDiag);
7688
+
7689
+ // Find the member used to satisfy the named requirement.
7690
+ auto witness = conformance.getWitnessByName (type, name);
7759
7691
if (!witness || !isa<AbstractFunctionDecl>(witness.getDecl ()))
7760
7692
return nullptr ;
7761
7693
0 commit comments