Skip to content

Commit 1278d5b

Browse files
Amritpan Kauramritpan
authored andcommitted
[ConstraintSystem] Connect output with |.
1 parent 60e880b commit 1278d5b

File tree

8 files changed

+90
-72
lines changed

8 files changed

+90
-72
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,8 +4430,8 @@ class ConstraintSystem {
44304430

44314431
if (isDebugMode()) {
44324432
auto &log = llvm::errs();
4433-
log.indent(solverState ? solverState->getCurrentIndent() + 4 : 0)
4434-
<< "Failed constraint ";
4433+
log.indent(solverState ? solverState->getCurrentIndent() : 2) << "|";
4434+
log.indent(2) << "`- Failed constraint ";
44354435
constraint->print(log, &getASTContext().SourceMgr);
44364436
log << "\n";
44374437
}
@@ -4455,7 +4455,8 @@ class ConstraintSystem {
44554455

44564456
if (isDebugMode() && getPhase() == ConstraintSystemPhase::Solving) {
44574457
auto &log = llvm::errs();
4458-
log.indent(solverState->getCurrentIndent() + 4) << "Added constraint: ";
4458+
log.indent(solverState->getCurrentIndent()) << "|";
4459+
log.indent(4) << "`- Added constraint: ";
44594460
constraint->print(log, &getASTContext().SourceMgr,
44604461
solverState->getCurrentIndent() + 4);
44614462
log << ")\n";
@@ -4473,8 +4474,8 @@ class ConstraintSystem {
44734474

44744475
if (isDebugMode() && getPhase() == ConstraintSystemPhase::Solving) {
44754476
auto &log = llvm::errs();
4476-
log.indent(solverState->getCurrentIndent() + 4)
4477-
<< "Removed constraint: ";
4477+
log.indent(solverState->getCurrentIndent()) << "|";
4478+
log.indent(4) << "`- Removed constraint: ";
44784479
constraint->print(log, &getASTContext().SourceMgr,
44794480
solverState->getCurrentIndent() + 4);
44804481
log << "\n";
@@ -6467,7 +6468,7 @@ class ConjunctionElement {
64676468

64686469
void print(llvm::raw_ostream &Out, SourceManager *SM, unsigned indent) const {
64696470
Out << "conjunction element ";
6470-
Element->print(Out, SM, indent);
6471+
Element->print(Out, SM, indent + 2);
64716472
}
64726473

64736474
private:

lib/Sema/CSRanking.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
5353
}
5454

5555
if (isDebugMode() && value > 0) {
56-
if (solverState)
57-
llvm::errs().indent(solverState->getCurrentIndent());
58-
llvm::errs() << "Increasing '" << Score::getNameFor(kind) << "' score by " << value
59-
<< "\n";
56+
auto &log = llvm::errs();
57+
log.indent(solverState ? solverState->getCurrentIndent() : 2) << "|";
58+
log.indent(2) << "`- Increasing '" << Score::getNameFor(kind)
59+
<< "' score by " << value << "\n";
6060
}
6161

6262
unsigned index = static_cast<unsigned>(kind);
@@ -73,7 +73,7 @@ bool ConstraintSystem::worseThanBestSolution() const {
7373

7474
if (isDebugMode()) {
7575
llvm::errs().indent(solverState->getCurrentIndent())
76-
<< "Solution is worse than the best solution\n";
76+
<< "| Solution is worse than the best solution\n";
7777
}
7878

7979
return true;

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11859,9 +11859,10 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1185911859
if (isDebugMode()) {
1186011860
PrintOptions PO;
1186111861
PO.PrintTypesForDebugging = true;
11862-
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 0)
11863-
<< "Common result type for $T" << fnTypeVar->getID() << " is "
11864-
<< commonResultType.getString(PO) << "\n";
11862+
auto &log = llvm::errs();
11863+
log.indent(solverState ? solverState->getCurrentIndent() : 0) << "|";
11864+
log.indent(2) << "Common result type for $T" << fnTypeVar->getID()
11865+
<< " is " << commonResultType.getString(PO) << "\n";
1186511866
}
1186611867

1186711868
// Introduction of a `Bind` constraint here could result in the disconnect

lib/Sema/CSSolver.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,19 @@ bool ConstraintSystem::simplify() {
347347

348348
if (isDebugMode()) {
349349
auto &log = llvm::errs();
350-
log.indent(solverState->getCurrentIndent());
351-
log << "Considering -> ";
352-
constraint->print(log, &getASTContext().SourceMgr);
350+
log.indent(solverState->getCurrentIndent()) << "|"
351+
<< "\n";
352+
log.indent(solverState->getCurrentIndent()) << "`-> Considering -> ";
353+
constraint->print(log, &getASTContext().SourceMgr,
354+
solverState->getCurrentIndent() + 2);
353355
log << "\n";
354356

355357
// {Dis, Con}junction are returned unsolved in \c simplifyConstraint() and
356358
// handled separately by solver steps.
357359
if (constraint->getKind() != ConstraintKind::Disjunction &&
358360
constraint->getKind() != ConstraintKind::Conjunction) {
359-
log.indent(solverState->getCurrentIndent() + 2)
360-
<< "Simplification result:\n";
361+
log.indent(solverState->getCurrentIndent()) << "|";
362+
log.indent(2) << "`- Simplification result:\n";
361363
}
362364
}
363365

@@ -367,7 +369,8 @@ bool ConstraintSystem::simplify() {
367369
retireFailedConstraint(constraint);
368370
if (isDebugMode()) {
369371
auto &log = llvm::errs();
370-
log.indent(solverState->getCurrentIndent() + 2) << "Outcome: error\n";
372+
log.indent(solverState->getCurrentIndent()) << "|";
373+
log.indent(2) << "`-- Outcome: error\n";
371374
}
372375
break;
373376

@@ -377,8 +380,8 @@ bool ConstraintSystem::simplify() {
377380
retireConstraint(constraint);
378381
if (isDebugMode()) {
379382
auto &log = llvm::errs();
380-
log.indent(solverState->getCurrentIndent() + 2)
381-
<< "Outcome: simplified\n";
383+
log.indent(solverState->getCurrentIndent()) << "|";
384+
log.indent(2) << "`-- Outcome: simplified\n";
382385
}
383386
break;
384387

@@ -387,8 +390,8 @@ bool ConstraintSystem::simplify() {
387390
++solverState->NumUnsimplifiedConstraints;
388391
if (isDebugMode()) {
389392
auto &log = llvm::errs();
390-
log.indent(solverState->getCurrentIndent() + 2)
391-
<< "Outcome: unsolved\n";
393+
log.indent(solverState->getCurrentIndent()) << "|";
394+
log.indent(2) << "`-- Outcome: unsolved\n";
392395
}
393396
break;
394397
}
@@ -1649,10 +1652,11 @@ ConstraintSystem::filterDisjunction(
16491652
}
16501653

16511654
if (isDebugMode()) {
1652-
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 0)
1653-
<< "Disabled disjunction term ";
1655+
auto &log = llvm::errs();
1656+
log.indent(solverState ? solverState->getCurrentIndent() : 0) << "|";
1657+
log.indent(2) << "Disabled disjunction term ";
16541658
constraint->print(llvm::errs(), &ctx.SourceMgr);
1655-
llvm::errs() << "\n";
1659+
log << "\n";
16561660
}
16571661

16581662
if (restoreOnFail)
@@ -1708,8 +1712,9 @@ ConstraintSystem::filterDisjunction(
17081712
}
17091713

17101714
if (isDebugMode()) {
1711-
llvm::errs().indent(solverState ? solverState->getCurrentIndent(): 0)
1712-
<< "Introducing single enabled disjunction term ";
1715+
auto &log = llvm::errs();
1716+
log.indent(solverState ? solverState->getCurrentIndent() : 2) << "|";
1717+
log.indent(2) << "Introducing single enabled disjunction term ";
17131718
choice->print(llvm::errs(), &ctx.SourceMgr);
17141719
}
17151720

lib/Sema/CSStep.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ StepResult ComponentStep::take(bool prevFailed) {
351351

352352
auto bestBindings = CS.determineBestBindings([&](const BindingSet &bindings) {
353353
if (CS.isDebugMode() && bindings.hasViableBindings()) {
354-
bos.indent(CS.solverState->getCurrentIndent() + 2);
354+
bos.indent(CS.solverState->getCurrentIndent());
355+
bos << "`- ";
355356
bindings.dump(bos, CS.solverState->getCurrentIndent() + 2);
356357
bos << "\n";
357358
}
@@ -362,7 +363,7 @@ StepResult ComponentStep::take(bool prevFailed) {
362363
if (CS.isDebugMode()) {
363364
if (!potentialBindings.empty()) {
364365
auto &log = getDebugLogger();
365-
log << "Potential Binding(s): " << '\n';
366+
log << "| Potential Binding(s): " << '\n';
366367
log << potentialBindings;
367368
}
368369

@@ -380,8 +381,8 @@ StepResult ComponentStep::take(bool prevFailed) {
380381
}
381382
if (!overloadDisjunctions.empty()) {
382383
auto &log = getDebugLogger();
383-
log.indent(2);
384-
log << "Disjunction(s) = [";
384+
// log.indent(2);
385+
log << "`- Disjunction(s) = [";
385386
interleave(overloadDisjunctions, log, ", ");
386387
log << "]\n";
387388
}
@@ -473,9 +474,9 @@ StepResult ComponentStep::take(bool prevFailed) {
473474
auto solution = CS.finalize();
474475
if (CS.isDebugMode()) {
475476
auto &log = getDebugLogger();
476-
log << "Found solution:";
477+
log << "<! Found solution:";
477478
getCurrentScore().print(log);
478-
log << "\n";
479+
log << ">\n";
479480
}
480481

481482
Solutions.push_back(std::move(solution));

lib/Sema/CSStep.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ class ComponentStep final : public SolverStep {
476476

477477
if (CS.isDebugMode()) {
478478
auto &log = getDebugLogger();
479-
log << "Type variables in scope = "
479+
// log.indent(CS.solverState->getCurrentIndent());
480+
log << "`- Type variables in scope = "
480481
<< "[";
481482
auto typeVars = CS.getTypeVariables();
482483
PrintOptions PO;
@@ -537,10 +538,10 @@ template <typename P> class BindingStep : public SolverStep {
537538
if (CS.isDebugMode()) {
538539
auto &log = getDebugLogger();
539540
log << "{\n";
540-
log.indent(CS.solverState->getCurrentIndent());
541-
log << "Attempting ";
541+
log.indent(CS.solverState->getCurrentIndent() + 2);
542+
log << "!> Attempting ";
542543
choice->print(log, &CS.getASTContext().SourceMgr, CS.solverState->getCurrentIndent() + 2);
543-
log << '\n';
544+
log << "\n";
544545
}
545546

546547
{

lib/Sema/ConstraintGraph.cpp

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,65 +1603,74 @@ void ConstraintGraph::dumpActiveScopeChanges(llvm::raw_ostream &out,
16031603
// Print out Changes.
16041604
PrintOptions PO;
16051605
PO.PrintTypesForDebugging = true;
1606-
out.indent(indent);
1607-
out << "Changes:\n";
1606+
out.indent(indent) << "|"
1607+
<< "\n";
1608+
;
1609+
out.indent(indent) << "| * Changes:\n";
1610+
// out.indent(2) << "* Changes:\n";
16081611
if (!tvWithboundTypes.empty()) {
1609-
out.indent(indent + 2);
1610-
out << "Newly Bound: \n";
1612+
out.indent(indent) << "|";
1613+
out.indent(2) << "| Newly Bound: \n";
16111614
for (const auto &tvWithType : tvWithboundTypes) {
1612-
out.indent(indent + 4);
1613-
out << "> $T" << tvWithType.first->getImpl().getID() << " := ";
1615+
out.indent(indent) << "|";
1616+
out.indent(2) << "|";
1617+
out.indent(2) << "> $T" << tvWithType.first->getImpl().getID() << " := ";
16141618
tvWithType.second->print(out, PO);
16151619
out << '\n';
16161620
}
16171621
}
16181622
if (!addedTypeVars.empty()) {
1619-
out.indent(indent + 2);
1620-
auto heading = (addedTypeVars.size() > 1) ? "New Type Variables: \n"
1621-
: "New Type Variable: \n";
1622-
out << heading;
1623+
out.indent(indent) << "|";
1624+
auto heading = (addedTypeVars.size() > 1) ? "| New Type Variables: \n"
1625+
: "| New Type Variable: \n";
1626+
out.indent(2) << heading;
16231627
for (const auto &typeVar : addedTypeVars) {
1624-
out.indent(indent + 4);
1625-
out << "> $T" << typeVar->getImpl().getID();
1628+
out.indent(indent) << "|";
1629+
out.indent(2) << "|";
1630+
out.indent(2) << "> $T" << typeVar->getImpl().getID();
16261631
out << '\n';
16271632
}
16281633
}
16291634
if (!equivTypeVars.empty()) {
1630-
out.indent(indent + 2);
1631-
auto heading = (equivTypeVars.size() > 1) ? "New Equivalences: \n"
1632-
: "New Equivalence: \n";
1633-
out << heading;
1635+
out.indent(indent) << "|";
1636+
auto heading = (equivTypeVars.size() > 1) ? "| New Equivalences: \n"
1637+
: "| New Equivalence: \n";
1638+
out.indent(2) << heading;
16341639
for (const auto &typeVar : equivTypeVars) {
1635-
out.indent(indent + 4);
1636-
out << "> $T" << typeVar->getImpl().getID();
1640+
out.indent(indent) << "|";
1641+
out.indent(2) << "|";
1642+
out.indent(2) << "> $T" << typeVar->getImpl().getID();
16371643
out << '\n';
16381644
}
16391645
}
16401646
if (!addedConstraints.empty()) {
1641-
out.indent(indent + 2);
1642-
auto heading = (addedConstraints.size() > 1) ? "Added Constraints: \n"
1643-
: "Added Constraint: \n";
1644-
out << heading;
1647+
out.indent(indent) << "|";
1648+
auto heading = (addedConstraints.size() > 1) ? "| Added Constraints: \n"
1649+
: "| Added Constraint: \n";
1650+
out.indent(2) << heading;
16451651
for (const auto &constraint : addedConstraints) {
1646-
out.indent(indent + 4);
1647-
out << "> ";
1652+
out.indent(indent) << "|";
1653+
out.indent(2) << "|";
1654+
out.indent(2) << "> ";
16481655
constraint->print(out, &CS.getASTContext().SourceMgr, indent + 6);
16491656
out << '\n';
16501657
}
16511658
}
16521659
if (!removedConstraints.empty()) {
1653-
out.indent(indent + 2);
1654-
auto heading = (removedConstraints.size() > 1) ? "Removed Constraints: \n"
1655-
: "Removed Constraint: \n";
1656-
out << heading;
1660+
out.indent(indent) << "|";
1661+
auto heading = (removedConstraints.size() > 1) ? "| Removed Constraints: \n"
1662+
: "| Removed Constraint: \n";
1663+
out.indent(2) << heading;
16571664
for (const auto &constraint : removedConstraints) {
1658-
out.indent(indent + 4);
1659-
out << "> ";
1665+
out.indent(indent) << "|";
1666+
out.indent(2) << "|";
1667+
out.indent(2) << "> ";
16601668
constraint->print(out, &CS.getASTContext().SourceMgr, indent + 6);
16611669
out << '\n';
16621670
}
16631671
}
1664-
out << '\n';
1672+
out.indent(indent) << "|"
1673+
<< "\n";
16651674
}
16661675

16671676
void ConstraintGraph::printConnectedComponents(

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,8 +3575,8 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
35753575
PO.PrintTypesForDebugging = true;
35763576

35773577
auto &log = llvm::errs();
3578-
log.indent(solverState ? solverState->getCurrentIndent() : 2);
3579-
log << "Overload set choice binding ";
3578+
log.indent(solverState ? solverState->getCurrentIndent() : 2) << "|";
3579+
log.indent(2) << "Overload set choice binding ";
35803580
boundType->print(log, PO);
35813581
log << " := ";
35823582
adjustedRefType->print(log, PO);

0 commit comments

Comments
 (0)