Skip to content

Commit a308a7e

Browse files
committed
[Constraint system] Sink down debug logging.
This way we’ll see constraints whenever they’re generated, and remove some of the expression-centric nature of the top-level solve() and solveImpl().
1 parent bddee5c commit a308a7e

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

lib/Sema/CSApply.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7441,6 +7441,13 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
74417441

74427442
solution.setExprTypes(resultExpr);
74437443
result.setExpr(resultExpr);
7444+
7445+
if (Context.TypeCheckerOpts.DebugConstraintSolver) {
7446+
auto &log = Context.TypeCheckerDebug->getStream();
7447+
log << "---Type-checked expression---\n";
7448+
resultExpr->dump(log);
7449+
log << "\n";
7450+
}
74447451
}
74457452

74467453
rewriter.finalize();

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3947,6 +3947,14 @@ bool ConstraintSystem::generateConstraints(
39473947
return true;
39483948
}
39493949

3950+
if (getASTContext().TypeCheckerOpts.DebugConstraintSolver) {
3951+
auto &log = getASTContext().TypeCheckerDebug->getStream();
3952+
log << "---Initial constraints for the given expression---\n";
3953+
print(log, expr);
3954+
log << "\n";
3955+
print(log);
3956+
}
3957+
39503958
return false;
39513959
}
39523960

lib/Sema/CSSolver.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,17 +1252,10 @@ ConstraintSystem::solveImpl(SolutionApplicationTarget &target,
12521252
return SolutionResult::forError();;
12531253

12541254
// Notify the listener that we've built the constraint system.
1255-
Expr *expr = target.getAsExpr();
1256-
if (listener && listener->builtConstraints(*this, expr)) {
1257-
return SolutionResult::forError();
1258-
}
1259-
1260-
if (getASTContext().TypeCheckerOpts.DebugConstraintSolver) {
1261-
auto &log = getASTContext().TypeCheckerDebug->getStream();
1262-
log << "---Initial constraints for the given expression---\n";
1263-
print(log, expr);
1264-
log << "\n";
1265-
print(log);
1255+
if (Expr *expr = target.getAsExpr()) {
1256+
if (listener && listener->builtConstraints(*this, expr)) {
1257+
return SolutionResult::forError();
1258+
}
12661259
}
12671260

12681261
// Try to solve the constraint system using computed suggestions.
@@ -1272,8 +1265,6 @@ ConstraintSystem::solveImpl(SolutionApplicationTarget &target,
12721265
if (getExpressionTooComplex(solutions))
12731266
return SolutionResult::forTooComplex();
12741267

1275-
target.setExpr(expr);
1276-
12771268
switch (solutions.size()) {
12781269
case 0:
12791270
return SolutionResult::forUndiagnosedError();

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,13 +2132,6 @@ TypeChecker::typeCheckExpression(
21322132
return None;
21332133
}
21342134

2135-
if (Context.TypeCheckerOpts.DebugConstraintSolver) {
2136-
auto &log = Context.TypeCheckerDebug->getStream();
2137-
log << "---Type-checked expression---\n";
2138-
result->dump(log);
2139-
log << "\n";
2140-
}
2141-
21422135
// Unless the client has disabled them, perform syntactic checks on the
21432136
// expression now.
21442137
if (!cs.shouldSuppressDiagnostics() &&

0 commit comments

Comments
 (0)