Skip to content

Commit 9ccd5cb

Browse files
author
Amritpan Kaur
committed
[ConstraintSystem] Refactor solver state depth to its own function for easier indent editing in future.
1 parent 2aa47b8 commit 9ccd5cb

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
@@ -2966,9 +2966,9 @@ class ConstraintSystem {
29662966
ConstraintSystem &CS;
29672967

29682968
FreeTypeVariableBinding AllowFreeTypeVariables;
2969-
2970-
/// Depth of the solution stack.
2971-
unsigned depth = 0;
2969+
2970+
/// Return current depth of solution stack for debug printing.
2971+
unsigned int getCurrentIndent() const { return depth * 2; }
29722972

29732973
/// Maximum depth reached so far in exploring solutions.
29742974
unsigned maxDepth = 0;
@@ -3151,6 +3151,9 @@ class ConstraintSystem {
31513151

31523152
SmallVector<Constraint *, 4> disabledConstraints;
31533153
SmallVector<Constraint *, 4> favoredConstraints;
3154+
3155+
/// Depth of the solution stack.
3156+
unsigned depth = 0;
31543157
};
31553158

31563159
class CacheExprTypes : public ASTWalker {
@@ -4254,7 +4257,7 @@ class ConstraintSystem {
42544257

42554258
if (isDebugMode()) {
42564259
auto &log = llvm::errs();
4257-
log.indent(solverState ? solverState->depth * 2 : 0)
4260+
log.indent(solverState ? solverState->getCurrentIndent() : 0)
42584261
<< "(failed constraint ";
42594262
constraint->print(log, &getASTContext().SourceMgr);
42604263
log << ")\n";

lib/Sema/BuilderTransform.cpp

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

25362536
if (isDebugMode()) {
25372537
auto &log = llvm::errs();
2538-
auto indent = solverState ? solverState->depth * 2 : 0;
2538+
auto indent = solverState ? solverState->getCurrentIndent() : 0;
25392539
log.indent(indent) << "------- Transfomed Body -------\n";
25402540
transformedBody->second->dump(log);
25412541
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
@@ -118,7 +118,7 @@ void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
118118

119119
if (isDebugMode() && value > 0) {
120120
if (solverState)
121-
llvm::errs().indent(solverState->depth * 2);
121+
llvm::errs().indent(solverState->getCurrentIndent());
122122
llvm::errs() << "(increasing score due to " << getScoreKindName(kind) << ")\n";
123123
}
124124

@@ -135,7 +135,7 @@ bool ConstraintSystem::worseThanBestSolution() const {
135135
return false;
136136

137137
if (isDebugMode()) {
138-
llvm::errs().indent(solverState->depth * 2)
138+
llvm::errs().indent(solverState->getCurrentIndent())
139139
<< "(solution is worse than the best solution)\n";
140140
}
141141

@@ -858,7 +858,7 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
858858
ConstraintSystem &cs, ArrayRef<Solution> solutions,
859859
const SolutionDiff &diff, unsigned idx1, unsigned idx2) {
860860
if (cs.isDebugMode()) {
861-
llvm::errs().indent(cs.solverState->depth * 2)
861+
llvm::errs().indent(cs.solverState->getCurrentIndent())
862862
<< "comparing solutions " << idx1 << " and " << idx2 <<"\n";
863863
}
864864

@@ -1415,13 +1415,13 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
14151415
return 0;
14161416

14171417
if (isDebugMode()) {
1418-
llvm::errs().indent(solverState->depth * 2)
1418+
llvm::errs().indent(solverState->getCurrentIndent())
14191419
<< "Comparing " << viable.size() << " viable solutions\n";
14201420

14211421
for (unsigned i = 0, n = viable.size(); i != n; ++i) {
1422-
llvm::errs().indent(solverState->depth * 2)
1422+
llvm::errs().indent(solverState->getCurrentIndent())
14231423
<< "--- Solution #" << i << " ---\n";
1424-
viable[i].dump(llvm::errs().indent(solverState->depth * 2));
1424+
viable[i].dump(llvm::errs().indent(solverState->getCurrentIndent()));
14251425
}
14261426
}
14271427

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11160,7 +11160,7 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1116011160
if (isDebugMode()) {
1116111161
PrintOptions PO;
1116211162
PO.PrintTypesForDebugging = true;
11163-
llvm::errs().indent(solverState ? solverState->depth * 2 : 0)
11163+
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 0)
1116411164
<< "(common result type for $T" << fnTypeVar->getID() << " is "
1116511165
<< commonResultType.getString(PO)
1116611166
<< ")\n";
@@ -12666,7 +12666,7 @@ static bool isAugmentingFix(ConstraintFix *fix) {
1266612666
bool ConstraintSystem::recordFix(ConstraintFix *fix, unsigned impact) {
1266712667
if (isDebugMode()) {
1266812668
auto &log = llvm::errs();
12669-
log.indent(solverState ? solverState->depth * 2 : 0)
12669+
log.indent(solverState ? solverState->getCurrentIndent() : 0)
1267012670
<< "(attempting fix ";
1267112671
fix->print(log);
1267212672
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)