@@ -1165,22 +1165,16 @@ bool AssociatedTypeInference::checkConstrainedExtension(ExtensionDecl *ext) {
1165
1165
llvm_unreachable (" unhandled result" );
1166
1166
}
1167
1167
1168
- AssociatedTypeDecl *AssociatedTypeInference::completeSolution (
1168
+ AssociatedTypeDecl *AssociatedTypeInference::inferAbstractTypeWitnesses (
1169
1169
ArrayRef<AssociatedTypeDecl *> unresolvedAssocTypes, unsigned reqDepth) {
1170
+ if (unresolvedAssocTypes.empty ()) {
1171
+ return nullptr ;
1172
+ }
1173
+
1170
1174
// Examine the solution for errors and attempt to compute abstract type
1171
1175
// witnesses for associated types that are still lacking an entry.
1172
1176
llvm::SmallVector<AbstractTypeWitness, 2 > abstractTypeWitnesses;
1173
1177
for (auto *const assocType : unresolvedAssocTypes) {
1174
- const auto typeWitness = typeWitnesses.begin (assocType);
1175
- if (typeWitness != typeWitnesses.end ()) {
1176
- // The solution contains an error.
1177
- if (typeWitness->first ->hasError ()) {
1178
- return assocType;
1179
- }
1180
-
1181
- continue ;
1182
- }
1183
-
1184
1178
// Try to compute the type without the aid of a specific potential witness.
1185
1179
if (const auto &typeWitness = computeAbstractTypeWitness (assocType)) {
1186
1180
// Record the type witness immediately to make it available
@@ -1285,9 +1279,28 @@ void AssociatedTypeInference::findSolutionsRec(
1285
1279
// Introduce a hash table scope; we may add type witnesses here.
1286
1280
TypeWitnessesScope typeWitnessesScope (typeWitnesses);
1287
1281
1288
- // Validate and complete the solution.
1282
+ // Filter out the associated types that remain unresolved.
1283
+ SmallVector<AssociatedTypeDecl *, 4 > stillUnresolved;
1284
+ for (auto *const assocType : unresolvedAssocTypes) {
1285
+ const auto typeWitness = typeWitnesses.begin (assocType);
1286
+ if (typeWitness == typeWitnesses.end ()) {
1287
+ stillUnresolved.push_back (assocType);
1288
+ } else {
1289
+ // If an erroneous type witness has already been recorded for one of
1290
+ // the associated types, give up.
1291
+ if (typeWitness->first ->hasError ()) {
1292
+ if (!missingTypeWitness)
1293
+ missingTypeWitness = assocType;
1294
+
1295
+ return ;
1296
+ }
1297
+ }
1298
+ }
1299
+
1300
+ // Attempt to infer abstract type witnesses for associated types that
1301
+ // could not be resolved otherwise.
1289
1302
if (auto *const assocType =
1290
- completeSolution (unresolvedAssocTypes , reqDepth)) {
1303
+ inferAbstractTypeWitnesses (stillUnresolved , reqDepth)) {
1291
1304
// The solution is decisively incomplete; record the associated type
1292
1305
// we failed on and bail out.
1293
1306
if (!missingTypeWitness)
@@ -1298,6 +1311,7 @@ void AssociatedTypeInference::findSolutionsRec(
1298
1311
1299
1312
++NumSolutionStates;
1300
1313
1314
+ // Validate and complete the solution.
1301
1315
// Fold the dependent member types within this type.
1302
1316
for (auto assocType : proto->getAssociatedTypeMembers ()) {
1303
1317
if (conformance->hasTypeWitness (assocType))
0 commit comments