Skip to content

Commit baceb68

Browse files
committed
[ConstraintSystem] Rename solveIteratively to solve and start using it
Remove solution filtering from new iterative `solve` method, and replace all usages of `solveRec` with it.
1 parent 4f50710 commit baceb68

File tree

4 files changed

+17
-24
lines changed

4 files changed

+17
-24
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,9 @@ bool ConstraintSystem::Candidate::solve(
686686
{
687687
SolverState state(E, cs, FreeTypeVariableBinding::Allow);
688688

689-
// Use solveRec() instead of solve() in here, because solve()
690-
// would try to deduce the best solution, which we don't
691-
// really want. Instead, we want the reduced set of domain choices.
692-
cs.solveRec(solutions);
689+
// Use solve which doesn't try to filter solution list.
690+
// Because we want the whole set of possible domain choices.
691+
cs.solve(solutions);
693692
}
694693

695694
if (TC.getLangOpts().DebugConstraintSolver) {
@@ -1276,7 +1275,7 @@ bool ConstraintSystem::solve(Expr *const expr,
12761275
SolverState state(expr, *this, allowFreeTypeVariables);
12771276

12781277
// Solve the system.
1279-
solveRec(solutions);
1278+
solve(solutions);
12801279

12811280
if (TC.getLangOpts().DebugConstraintSolver) {
12821281
auto &log = getASTContext().TypeCheckerDebug->getStream();
@@ -1557,10 +1556,8 @@ bool ConstraintSystem::solveRec(SmallVectorImpl<Solution> &solutions) {
15571556
return !anySolutions;
15581557
}
15591558

1560-
bool ConstraintSystem::solveIteratively(
1561-
Expr *expr, SmallVectorImpl<Solution> &solutions,
1562-
FreeTypeVariableBinding allowFreeTypeVariables) {
1563-
SolverState state(expr, *this, allowFreeTypeVariables);
1559+
void ConstraintSystem::solve(SmallVectorImpl<Solution> &solutions) {
1560+
assert(solverState);
15641561

15651562
SmallVector<SolverStep *, 16> workList;
15661563
// First step is always wraps whole constraint system.
@@ -1640,15 +1637,6 @@ bool ConstraintSystem::solveIteratively(
16401637
result.transfer(workList);
16411638
}
16421639
}
1643-
1644-
// Filter deduced solutions, try to figure out if there is
1645-
// a single best solution to use, if not explicitly disabled
1646-
// by constraint system options.
1647-
if (!retainAllSolutions())
1648-
filterSolutions(solutions, state.ExprWeights);
1649-
1650-
// We fail if there is no solution or the expression was too complex.
1651-
return solutions.empty() || getExpressionTooComplex(solutions);
16521640
}
16531641

16541642
/// Whether we should short-circuit a disjunction that already has a

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@ bool ConstraintSystem::salvage(SmallVectorImpl<Solution> &viable, Expr *expr) {
20722072
state.recordFixes = true;
20732073

20742074
// Solve the system.
2075-
solveRec(viable);
2075+
solve(viable);
20762076

20772077
// Check whether we have a best solution; this can happen if we found
20782078
// a series of fixes that worked.

lib/Sema/ConstraintSystem.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,9 +3100,6 @@ class ConstraintSystem {
31003100
/// \returns true if there are no solutions
31013101
bool solveRec(SmallVectorImpl<Solution> &solutions);
31023102

3103-
bool solveIteratively(Expr *expr, SmallVectorImpl<Solution> &solutions,
3104-
FreeTypeVariableBinding allowFreeTypeVariables);
3105-
31063103
/// \brief Solve the system of constraints.
31073104
///
31083105
/// \param allowFreeTypeVariables How to bind free type variables in
@@ -3114,6 +3111,14 @@ class ConstraintSystem {
31143111
= FreeTypeVariableBinding::Disallow);
31153112

31163113
private:
3114+
/// \brief Solve the system of constraints.
3115+
///
3116+
/// This method responsible for running search/solver algorithm.
3117+
/// It doesn't filter solutions, that's the job of top-level `solve` methods.
3118+
///
3119+
/// \param solutions The set of solutions to this system of constraints.
3120+
void solve(SmallVectorImpl<Solution> &solutions);
3121+
31173122
/// \brief Compare two solutions to the same set of constraints.
31183123
///
31193124
/// \param cs The constraint system.

test/Constraints/closures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,8 @@ sr3520_1 { $0 = 1 } // expected-error {{cannot convert value of type '()' to clo
497497
struct S_3520 {
498498
var number1: Int
499499
}
500-
func sr3520_set_via_closure<S, T>(_ closure: (inout S, T) -> ()) {}
501-
sr3520_set_via_closure({ $0.number1 = $1 }) // expected-error {{type of expression is ambiguous without more context}}
500+
func sr3520_set_via_closure<S, T>(_ closure: (inout S, T) -> ()) {} // expected-note {{in call to function 'sr3520_set_via_closure'}}
501+
sr3520_set_via_closure({ $0.number1 = $1 }) // expected-error {{generic parameter 'S' could not be inferred}}
502502

503503
// SR-3073: UnresolvedDotExpr in single expression closure
504504

0 commit comments

Comments
 (0)