Skip to content

Commit 93417d9

Browse files
authored
Merge pull request #60495 from amritpan/refactor-solver-state-indents
[ConstraintSystem] NFC: Refactor solver state depth to its own function fo…
2 parents b0fb7c5 + fd41a39 commit 93417d9

File tree

9 files changed

+24
-21
lines changed

9 files changed

+24
-21
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,9 +3053,9 @@ class ConstraintSystem {
30533053
ConstraintSystem &CS;
30543054

30553055
FreeTypeVariableBinding AllowFreeTypeVariables;
3056-
3057-
/// Depth of the solution stack.
3058-
unsigned depth = 0;
3056+
3057+
/// Return current depth of solution stack for debug printing.
3058+
unsigned int getCurrentIndent() const { return depth * 2; }
30593059

30603060
/// Maximum depth reached so far in exploring solutions.
30613061
unsigned maxDepth = 0;
@@ -3238,6 +3238,9 @@ class ConstraintSystem {
32383238

32393239
SmallVector<Constraint *, 4> disabledConstraints;
32403240
SmallVector<Constraint *, 4> favoredConstraints;
3241+
3242+
/// Depth of the solution stack.
3243+
unsigned depth = 0;
32413244
};
32423245

32433246
class CacheExprTypes : public ASTWalker {
@@ -4341,7 +4344,7 @@ class ConstraintSystem {
43414344

43424345
if (isDebugMode()) {
43434346
auto &log = llvm::errs();
4344-
log.indent(solverState ? solverState->depth * 2 : 0)
4347+
log.indent(solverState ? solverState->getCurrentIndent() : 0)
43454348
<< "(failed constraint ";
43464349
constraint->print(log, &getASTContext().SourceMgr);
43474350
log << ")\n";

lib/Sema/BuilderTransform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2528,7 +2528,7 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
25282528

25292529
if (isDebugMode()) {
25302530
auto &log = llvm::errs();
2531-
auto indent = solverState ? solverState->depth * 2 : 0;
2531+
auto indent = solverState ? solverState->getCurrentIndent() : 0;
25322532
log.indent(indent) << "------- Transfomed Body -------\n";
25332533
transformedBody->second->dump(log);
25342534
log << '\n';

lib/Sema/CSBindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ Optional<BindingSet> ConstraintSystem::determineBestBindings() {
808808
continue;
809809

810810
if (isDebugMode()) {
811-
bindings.dump(typeVar, llvm::errs(), solverState->depth * 2);
811+
bindings.dump(typeVar, llvm::errs(), solverState->getCurrentIndent());
812812
}
813813

814814
// If these are the first bindings, or they are better than what

lib/Sema/CSRanking.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
5454

5555
if (isDebugMode() && value > 0) {
5656
if (solverState)
57-
llvm::errs().indent(solverState->depth * 2);
57+
llvm::errs().indent(solverState->getCurrentIndent());
5858
llvm::errs() << "(increasing '" << Score::getNameFor(kind) << "' score by " << value
5959
<< ")\n";
6060
}
@@ -72,7 +72,7 @@ bool ConstraintSystem::worseThanBestSolution() const {
7272
return false;
7373

7474
if (isDebugMode()) {
75-
llvm::errs().indent(solverState->depth * 2)
75+
llvm::errs().indent(solverState->getCurrentIndent())
7676
<< "(solution is worse than the best solution)\n";
7777
}
7878

@@ -795,7 +795,7 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
795795
ConstraintSystem &cs, ArrayRef<Solution> solutions,
796796
const SolutionDiff &diff, unsigned idx1, unsigned idx2) {
797797
if (cs.isDebugMode()) {
798-
llvm::errs().indent(cs.solverState->depth * 2)
798+
llvm::errs().indent(cs.solverState->getCurrentIndent())
799799
<< "comparing solutions " << idx1 << " and " << idx2 <<"\n";
800800
}
801801

@@ -1352,13 +1352,13 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
13521352
return 0;
13531353

13541354
if (isDebugMode()) {
1355-
llvm::errs().indent(solverState->depth * 2)
1355+
llvm::errs().indent(solverState->getCurrentIndent())
13561356
<< "Comparing " << viable.size() << " viable solutions\n";
13571357

13581358
for (unsigned i = 0, n = viable.size(); i != n; ++i) {
1359-
llvm::errs().indent(solverState->depth * 2)
1359+
llvm::errs().indent(solverState->getCurrentIndent())
13601360
<< "\n--- Solution #" << i << " ---\n";
1361-
viable[i].dump(llvm::errs().indent(solverState->depth * 2));
1361+
viable[i].dump(llvm::errs().indent(solverState->getCurrentIndent()));
13621362
}
13631363
}
13641364

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11187,7 +11187,7 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1118711187
if (isDebugMode()) {
1118811188
PrintOptions PO;
1118911189
PO.PrintTypesForDebugging = true;
11190-
llvm::errs().indent(solverState ? solverState->depth * 2 : 0)
11190+
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 0)
1119111191
<< "(common result type for $T" << fnTypeVar->getID() << " is "
1119211192
<< commonResultType.getString(PO)
1119311193
<< ")\n";
@@ -12693,7 +12693,7 @@ static bool isAugmentingFix(ConstraintFix *fix) {
1269312693
bool ConstraintSystem::recordFix(ConstraintFix *fix, unsigned impact) {
1269412694
if (isDebugMode()) {
1269512695
auto &log = llvm::errs();
12696-
log.indent(solverState ? solverState->depth * 2 : 0)
12696+
log.indent(solverState ? solverState->getCurrentIndent() : 0)
1269712697
<< "(attempting fix ";
1269812698
fix->print(log);
1269912699
log << ")\n";

lib/Sema/CSSolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ ConstraintSystem::filterDisjunction(
16191619
}
16201620

16211621
if (isDebugMode()) {
1622-
llvm::errs().indent(solverState ? solverState->depth * 2 : 0)
1622+
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 0)
16231623
<< "(disabled disjunction term ";
16241624
constraint->print(llvm::errs(), &ctx.SourceMgr);
16251625
llvm::errs() << ")\n";
@@ -1678,7 +1678,7 @@ ConstraintSystem::filterDisjunction(
16781678
}
16791679

16801680
if (isDebugMode()) {
1681-
llvm::errs().indent(solverState ? solverState->depth * 2 : 0)
1681+
llvm::errs().indent(solverState ? solverState->getCurrentIndent(): 0)
16821682
<< "(introducing single enabled disjunction term ";
16831683
choice->print(llvm::errs(), &ctx.SourceMgr);
16841684
llvm::errs() << ")\n";

lib/Sema/CSStep.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class SolverStep {
229229

230230
llvm::raw_ostream &getDebugLogger(bool indent = true) const {
231231
auto &log = llvm::errs();
232-
return indent ? log.indent(CS.solverState->depth * 2) : log;
232+
return indent ? log.indent(CS.solverState->getCurrentIndent()) : log;
233233
}
234234
};
235235

@@ -519,7 +519,7 @@ template <typename P> class BindingStep : public SolverStep {
519519
if (CS.isDebugMode()) {
520520
auto &log = getDebugLogger();
521521
log << "(attempting ";
522-
choice->print(log, &CS.getASTContext().SourceMgr, CS.solverState->depth * 2 + 2);
522+
choice->print(log, &CS.getASTContext().SourceMgr, CS.solverState->getCurrentIndent() + 2);
523523
log << '\n';
524524
}
525525

lib/Sema/ConstraintGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ namespace {
11351135
if (cs.isDebugMode()) {
11361136
auto &log = llvm::errs();
11371137
if (cs.solverState)
1138-
log.indent(cs.solverState->depth * 2);
1138+
log.indent(cs.solverState->getCurrentIndent());
11391139

11401140
log << "Collapsing one-way components for $T"
11411141
<< edge.first->getID() << " and $T" << edge.second->getID()
@@ -1440,7 +1440,7 @@ bool ConstraintGraph::contractEdges() {
14401440
if (CS.isDebugMode()) {
14411441
auto &log = llvm::errs();
14421442
if (CS.solverState)
1443-
log.indent(CS.solverState->depth * 2);
1443+
log.indent(CS.solverState->getCurrentIndent());
14441444

14451445
log << "Contracting constraint ";
14461446
constraint->print(log, &CS.getASTContext().SourceMgr);

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3528,7 +3528,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
35283528
if (isDebugMode()) {
35293529
PrintOptions PO;
35303530
PO.PrintTypesForDebugging = true;
3531-
llvm::errs().indent(solverState ? solverState->depth * 2 : 2)
3531+
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 2)
35323532
<< "(overload set choice binding "
35333533
<< boundType->getString(PO) << " := "
35343534
<< adjustedRefType->getString(PO) << ")\n";

0 commit comments

Comments
 (0)