Skip to content

Commit 3bb865d

Browse files
committed
[CSSolver] Don't re-run solver to diagnose ambiguities
If ambiguity has been detected during normal solving, let's diagnose that right away instead of re-running the solver in diagnostic mode because it would produce exactly the same set of solutions (all solutions with fixes added in diagnostic mode would be filtered out because they'd have worse scores).
1 parent f53a9e4 commit 3bb865d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/Sema/CSSolver.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,23 @@ ConstraintSystem::solve(SyntacticElementTarget &target,
14751475
return std::move(result);
14761476
}
14771477

1478+
auto solutionsRef = std::move(solution).takeAmbiguousSolutions();
1479+
SmallVector<Solution, 4> ambiguity(
1480+
std::make_move_iterator(solutionsRef.begin()),
1481+
std::make_move_iterator(solutionsRef.end()));
1482+
1483+
{
1484+
SolverState state(*this, FreeTypeVariableBinding::Disallow);
1485+
1486+
// Constraint generator is allowed to introduce fixes to the
1487+
// contraint system.
1488+
if (diagnoseAmbiguityWithFixes(ambiguity) ||
1489+
diagnoseAmbiguity(ambiguity)) {
1490+
solution.markAsDiagnosed();
1491+
return None;
1492+
}
1493+
}
1494+
14781495
LLVM_FALLTHROUGH;
14791496
}
14801497

@@ -1569,7 +1586,7 @@ bool ConstraintSystem::solve(SmallVectorImpl<Solution> &solutions,
15691586
// Filter deduced solutions, try to figure out if there is
15701587
// a single best solution to use, if not explicitly disabled
15711588
// by constraint system options.
1572-
filterSolutions(solutions);
1589+
filterSolutions(solutions, /*minimize=*/true);
15731590

15741591
// We fail if there is no solution or the expression was too complex.
15751592
return solutions.empty() || isTooComplex(solutions);

0 commit comments

Comments
 (0)