Skip to content

Commit 9cdb51f

Browse files
authored
Merge pull request #5793 from rudkx/clean-up
2 parents 6ccb662 + fbbd834 commit 9cdb51f

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,47 +2308,38 @@ bool ConstraintSystem::solveSimplified(
23082308
allowFreeTypeVariables);
23092309
}
23102310

2311-
// If there are no disjunctions, we can't solve this system.
2311+
// If there are no disjunctions we can't solve this system unless we have
2312+
// free type variables and are allowing them in the solution.
23122313
if (disjunctions.empty()) {
2313-
// If the only remaining constraints are conformance constraints
2314-
// or member equality constraints, and we're allowed to have free
2315-
// variables, we still have a solution. FIXME: It seems like this
2316-
// should be easier to detect. Aren't there other kinds of
2317-
// constraints that could show up here?
2318-
if (allowFreeTypeVariables != FreeTypeVariableBinding::Disallow &&
2319-
hasFreeTypeVariables()) {
2320-
2321-
// If this solution is worse than the best solution we've seen so far,
2322-
// skip it.
2323-
if (worseThanBestSolution())
2324-
return true;
2314+
if (allowFreeTypeVariables == FreeTypeVariableBinding::Disallow ||
2315+
!hasFreeTypeVariables())
2316+
return true;
23252317

2326-
bool anyNonConformanceConstraints = false;
2327-
for (auto &constraint : InactiveConstraints) {
2328-
switch (constraint.getClassification()) {
2329-
case ConstraintClassification::Relational:
2330-
case ConstraintClassification::Member:
2331-
continue;
2332-
default:
2333-
break;
2334-
}
2318+
// If this solution is worse than the best solution we've seen so far,
2319+
// skip it.
2320+
if (worseThanBestSolution())
2321+
return true;
23352322

2336-
anyNonConformanceConstraints = true;
2337-
break;
2323+
// If we only have relational or member constraints and are allowing
2324+
// free type variables, save the solution.
2325+
for (auto &constraint : InactiveConstraints) {
2326+
switch (constraint.getClassification()) {
2327+
case ConstraintClassification::Relational:
2328+
case ConstraintClassification::Member:
2329+
continue;
2330+
default:
2331+
return true;
23382332
}
2333+
}
23392334

2340-
if (!anyNonConformanceConstraints) {
2341-
auto solution = finalize(allowFreeTypeVariables);
2342-
if (TC.getLangOpts().DebugConstraintSolver) {
2343-
auto &log = getASTContext().TypeCheckerDebug->getStream();
2344-
log.indent(solverState->depth * 2) << "(found solution)\n";
2345-
}
2346-
2347-
solutions.push_back(std::move(solution));
2348-
return false;
2349-
}
2335+
auto solution = finalize(allowFreeTypeVariables);
2336+
if (TC.getLangOpts().DebugConstraintSolver) {
2337+
auto &log = getASTContext().TypeCheckerDebug->getStream();
2338+
log.indent(solverState->depth * 2) << "(found solution)\n";
23502339
}
2351-
return true;
2340+
2341+
solutions.push_back(std::move(solution));
2342+
return false;
23522343
}
23532344

23542345
// Pick the smallest disjunction.

0 commit comments

Comments
 (0)