Skip to content

Commit cb01397

Browse files
committed
AssociatedTypeInference: Rename 'completeSolution' to 'inferAbstractTypeWitnesses'
1 parent d7d3fe3 commit cb01397

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

lib/Sema/TypeCheckProtocol.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,14 +1040,12 @@ class AssociatedTypeInference {
10401040
/// requirements of the given constrained extension.
10411041
bool checkConstrainedExtension(ExtensionDecl *ext);
10421042

1043-
/// Validate the current tentative solution represented by \p typeWitnesses
1044-
/// and attempt to resolve abstract type witnesses for associated types that
1045-
/// could not be inferred otherwise.
1043+
/// Attempt to infer abstract type witnesses for the given set of associated
1044+
/// types.
10461045
///
10471046
/// \returns \c nullptr, or the associated type that failed.
1048-
AssociatedTypeDecl *
1049-
completeSolution(ArrayRef<AssociatedTypeDecl *> unresolvedAssocTypes,
1050-
unsigned reqDepth);
1047+
AssociatedTypeDecl *inferAbstractTypeWitnesses(
1048+
ArrayRef<AssociatedTypeDecl *> unresolvedAssocTypes, unsigned reqDepth);
10511049

10521050
/// Top-level operation to find solutions for the given unresolved
10531051
/// associated types.

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,22 +1165,16 @@ bool AssociatedTypeInference::checkConstrainedExtension(ExtensionDecl *ext) {
11651165
llvm_unreachable("unhandled result");
11661166
}
11671167

1168-
AssociatedTypeDecl *AssociatedTypeInference::completeSolution(
1168+
AssociatedTypeDecl *AssociatedTypeInference::inferAbstractTypeWitnesses(
11691169
ArrayRef<AssociatedTypeDecl *> unresolvedAssocTypes, unsigned reqDepth) {
1170+
if (unresolvedAssocTypes.empty()) {
1171+
return nullptr;
1172+
}
1173+
11701174
// Examine the solution for errors and attempt to compute abstract type
11711175
// witnesses for associated types that are still lacking an entry.
11721176
llvm::SmallVector<AbstractTypeWitness, 2> abstractTypeWitnesses;
11731177
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-
11841178
// Try to compute the type without the aid of a specific potential witness.
11851179
if (const auto &typeWitness = computeAbstractTypeWitness(assocType)) {
11861180
// Record the type witness immediately to make it available
@@ -1285,9 +1279,28 @@ void AssociatedTypeInference::findSolutionsRec(
12851279
// Introduce a hash table scope; we may add type witnesses here.
12861280
TypeWitnessesScope typeWitnessesScope(typeWitnesses);
12871281

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.
12891302
if (auto *const assocType =
1290-
completeSolution(unresolvedAssocTypes, reqDepth)) {
1303+
inferAbstractTypeWitnesses(stillUnresolved, reqDepth)) {
12911304
// The solution is decisively incomplete; record the associated type
12921305
// we failed on and bail out.
12931306
if (!missingTypeWitness)
@@ -1298,6 +1311,7 @@ void AssociatedTypeInference::findSolutionsRec(
12981311

12991312
++NumSolutionStates;
13001313

1314+
// Validate and complete the solution.
13011315
// Fold the dependent member types within this type.
13021316
for (auto assocType : proto->getAssociatedTypeMembers()) {
13031317
if (conformance->hasTypeWitness(assocType))

0 commit comments

Comments
 (0)