Skip to content

Commit 732f942

Browse files
committed
[ConstraintSystem] Additional debug logging for constraint system shrinking
Add logging before solving each of the candidates considered for shrinking with information about sub-expression and new constraint system. At the end of the candidate solving print each of the produced solutions.
1 parent 97a73c2 commit 732f942

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,22 @@ bool ConstraintSystem::Candidate::solve() {
15101510
return true;
15111511
}
15121512

1513+
if (TC.getLangOpts().DebugConstraintSolver) {
1514+
auto &log = cs.getASTContext().TypeCheckerDebug->getStream();
1515+
log << "--- Solving candidate for shrinking at ";
1516+
auto R = E->getSourceRange();
1517+
if (R.isValid()) {
1518+
R.print(log, TC.Context.SourceMgr, /*PrintText=*/ false);
1519+
} else {
1520+
log << "<invalid range>";
1521+
}
1522+
log << " ---\n";
1523+
1524+
E->print(log);
1525+
log << '\n';
1526+
cs.print(log);
1527+
}
1528+
15131529
// If there is contextual type present, add an explicit "conversion"
15141530
// constraint to the system.
15151531
if (!CT.isNull()) {
@@ -1532,6 +1548,20 @@ bool ConstraintSystem::Candidate::solve() {
15321548
cs.solveRec(solutions, FreeTypeVariableBinding::Allow);
15331549
}
15341550

1551+
if (TC.getLangOpts().DebugConstraintSolver) {
1552+
auto &log = cs.getASTContext().TypeCheckerDebug->getStream();
1553+
if (solutions.empty()) {
1554+
log << "--- No Solutions ---\n";
1555+
} else {
1556+
log << "--- Solutions ---\n";
1557+
for (unsigned i = 0, n = solutions.size(); i != n; ++i) {
1558+
auto &solution = solutions[i];
1559+
log << "--- Solution #" << i << " ---\n";
1560+
solution.dump(log);
1561+
}
1562+
}
1563+
}
1564+
15351565
// Record found solutions as suggestions.
15361566
this->applySolutions(solutions);
15371567

0 commit comments

Comments
 (0)