Skip to content

Commit 60e880b

Browse files
Amritpan Kauramritpan
authored andcommitted
[ConstraintSystem] Remove parens in simplification printing.
1 parent 2a84d6d commit 60e880b

File tree

8 files changed

+49
-74
lines changed

8 files changed

+49
-74
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4431,9 +4431,9 @@ class ConstraintSystem {
44314431
if (isDebugMode()) {
44324432
auto &log = llvm::errs();
44334433
log.indent(solverState ? solverState->getCurrentIndent() + 4 : 0)
4434-
<< "(failed constraint ";
4434+
<< "Failed constraint ";
44354435
constraint->print(log, &getASTContext().SourceMgr);
4436-
log << ")\n";
4436+
log << "\n";
44374437
}
44384438
}
44394439

@@ -4455,7 +4455,7 @@ 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() + 4) << "Added constraint: ";
44594459
constraint->print(log, &getASTContext().SourceMgr,
44604460
solverState->getCurrentIndent() + 4);
44614461
log << ")\n";
@@ -4474,10 +4474,10 @@ class ConstraintSystem {
44744474
if (isDebugMode() && getPhase() == ConstraintSystemPhase::Solving) {
44754475
auto &log = llvm::errs();
44764476
log.indent(solverState->getCurrentIndent() + 4)
4477-
<< "(removed constraint: ";
4477+
<< "Removed constraint: ";
44784478
constraint->print(log, &getASTContext().SourceMgr,
44794479
solverState->getCurrentIndent() + 4);
4480-
log << ")\n";
4480+
log << "\n";
44814481
}
44824482

44834483
if (solverState)

lib/Sema/CSRanking.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
5555
if (isDebugMode() && value > 0) {
5656
if (solverState)
5757
llvm::errs().indent(solverState->getCurrentIndent());
58-
llvm::errs() << "(increasing '" << Score::getNameFor(kind) << "' score by " << value
59-
<< ")\n";
58+
llvm::errs() << "Increasing '" << Score::getNameFor(kind) << "' score by " << value
59+
<< "\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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11860,9 +11860,8 @@ bool ConstraintSystem::simplifyAppliedOverloadsImpl(
1186011860
PrintOptions PO;
1186111861
PO.PrintTypesForDebugging = true;
1186211862
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 0)
11863-
<< "(common result type for $T" << fnTypeVar->getID() << " is "
11864-
<< commonResultType.getString(PO)
11865-
<< ")\n";
11863+
<< "Common result type for $T" << fnTypeVar->getID() << " is "
11864+
<< commonResultType.getString(PO) << "\n";
1186611865
}
1186711866

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

lib/Sema/CSSolver.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ bool ConstraintSystem::simplify() {
348348
if (isDebugMode()) {
349349
auto &log = llvm::errs();
350350
log.indent(solverState->getCurrentIndent());
351-
log << "(considering -> ";
351+
log << "Considering -> ";
352352
constraint->print(log, &getASTContext().SourceMgr);
353353
log << "\n";
354354

@@ -357,7 +357,7 @@ bool ConstraintSystem::simplify() {
357357
if (constraint->getKind() != ConstraintKind::Disjunction &&
358358
constraint->getKind() != ConstraintKind::Conjunction) {
359359
log.indent(solverState->getCurrentIndent() + 2)
360-
<< "(simplification result:\n";
360+
<< "Simplification result:\n";
361361
}
362362
}
363363

@@ -367,8 +367,7 @@ bool ConstraintSystem::simplify() {
367367
retireFailedConstraint(constraint);
368368
if (isDebugMode()) {
369369
auto &log = llvm::errs();
370-
log.indent(solverState->getCurrentIndent() + 2) << ")\n";
371-
log.indent(solverState->getCurrentIndent() + 2) << "(outcome: error)\n";
370+
log.indent(solverState->getCurrentIndent() + 2) << "Outcome: error\n";
372371
}
373372
break;
374373

@@ -378,9 +377,8 @@ bool ConstraintSystem::simplify() {
378377
retireConstraint(constraint);
379378
if (isDebugMode()) {
380379
auto &log = llvm::errs();
381-
log.indent(solverState->getCurrentIndent() + 2) << ")\n";
382380
log.indent(solverState->getCurrentIndent() + 2)
383-
<< "(outcome: simplified)\n";
381+
<< "Outcome: simplified\n";
384382
}
385383
break;
386384

@@ -389,18 +387,12 @@ bool ConstraintSystem::simplify() {
389387
++solverState->NumUnsimplifiedConstraints;
390388
if (isDebugMode()) {
391389
auto &log = llvm::errs();
392-
log.indent(solverState->getCurrentIndent() + 2) << ")\n";
393390
log.indent(solverState->getCurrentIndent() + 2)
394-
<< "(outcome: unsolved)\n";
391+
<< "Outcome: unsolved\n";
395392
}
396393
break;
397394
}
398395

399-
if (isDebugMode()) {
400-
auto &log = llvm::errs();
401-
log.indent(solverState->getCurrentIndent()) << ")\n";
402-
}
403-
404396
// Check whether a constraint failed. If so, we're done.
405397
if (failedConstraint) {
406398
return true;
@@ -1658,9 +1650,9 @@ ConstraintSystem::filterDisjunction(
16581650

16591651
if (isDebugMode()) {
16601652
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 0)
1661-
<< "(disabled disjunction term ";
1653+
<< "Disabled disjunction term ";
16621654
constraint->print(llvm::errs(), &ctx.SourceMgr);
1663-
llvm::errs() << ")\n";
1655+
llvm::errs() << "\n";
16641656
}
16651657

16661658
if (restoreOnFail)
@@ -1717,9 +1709,8 @@ ConstraintSystem::filterDisjunction(
17171709

17181710
if (isDebugMode()) {
17191711
llvm::errs().indent(solverState ? solverState->getCurrentIndent(): 0)
1720-
<< "(introducing single enabled disjunction term ";
1712+
<< "Introducing single enabled disjunction term ";
17211713
choice->print(llvm::errs(), &ctx.SourceMgr);
1722-
llvm::errs() << ")\n";
17231714
}
17241715

17251716
simplifyDisjunctionChoice(choice);

lib/Sema/CSStep.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,9 @@ bool SplitterStep::mergePartialSolutions() const {
243243
solutionMemory += solution.getTotalMemory();
244244
if (CS.isDebugMode()) {
245245
auto &log = getDebugLogger();
246-
log << "(composed solution:";
246+
log << "<! Composed solution:";
247247
CS.CurrentScore.print(log);
248-
log << ")\n";
248+
log << ">\n";
249249
}
250250

251251
// Save this solution.
@@ -352,9 +352,8 @@ StepResult ComponentStep::take(bool prevFailed) {
352352
auto bestBindings = CS.determineBestBindings([&](const BindingSet &bindings) {
353353
if (CS.isDebugMode() && bindings.hasViableBindings()) {
354354
bos.indent(CS.solverState->getCurrentIndent() + 2);
355-
bos << "(";
356355
bindings.dump(bos, CS.solverState->getCurrentIndent() + 2);
357-
bos << ")\n";
356+
bos << "\n";
358357
}
359358
});
360359

@@ -363,7 +362,7 @@ StepResult ComponentStep::take(bool prevFailed) {
363362
if (CS.isDebugMode()) {
364363
if (!potentialBindings.empty()) {
365364
auto &log = getDebugLogger();
366-
log << "(Potential Binding(s): " << '\n';
365+
log << "Potential Binding(s): " << '\n';
367366
log << potentialBindings;
368367
}
369368

@@ -385,11 +384,6 @@ StepResult ComponentStep::take(bool prevFailed) {
385384
log << "Disjunction(s) = [";
386385
interleave(overloadDisjunctions, log, ", ");
387386
log << "]\n";
388-
389-
if (!potentialBindings.empty() || !overloadDisjunctions.empty()) {
390-
auto &log = getDebugLogger();
391-
log << ")\n";
392-
}
393387
}
394388
}
395389

@@ -479,9 +473,9 @@ StepResult ComponentStep::take(bool prevFailed) {
479473
auto solution = CS.finalize();
480474
if (CS.isDebugMode()) {
481475
auto &log = getDebugLogger();
482-
log << "(found solution:";
476+
log << "Found solution:";
483477
getCurrentScore().print(log);
484-
log << ")\n";
478+
log << "\n";
485479
}
486480

487481
Solutions.push_back(std::move(solution));
@@ -500,8 +494,8 @@ StepResult ComponentStep::finalize(bool isSuccess) {
500494

501495
if (CS.isDebugMode()) {
502496
auto &log = getDebugLogger();
503-
log << (isSuccess ? "finished" : "failed") << " component #" << Index
504-
<< ")\n";
497+
log << (isSuccess ? "Finished" : "Failed") << " component #" << Index
498+
<< "}\n";
505499
}
506500

507501
// If we came either back to this step and previous
@@ -554,7 +548,7 @@ StepResult TypeVariableStep::resume(bool prevFailed) {
554548
ActiveChoice.reset();
555549

556550
if (CS.isDebugMode())
557-
getDebugLogger() << ")\n";
551+
getDebugLogger() << "}\n";
558552

559553
// Let's check if we should stop right before
560554
// attempting any new bindings.
@@ -600,7 +594,7 @@ StepResult DisjunctionStep::resume(bool prevFailed) {
600594
ActiveChoice.reset();
601595

602596
if (CS.isDebugMode())
603-
getDebugLogger() << ")\n";
597+
getDebugLogger() << "}\n";
604598

605599
// Attempt next disjunction choice (if any left).
606600
return take(prevFailed);
@@ -880,7 +874,7 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
880874
if (Snapshot && Snapshot->isScoped()) {
881875
Snapshot.reset();
882876
if (CS.isDebugMode())
883-
getDebugLogger() << ")\n";
877+
getDebugLogger() << "}\n";
884878

885879
return done(/*isSuccess=*/!prevFailed);
886880
}
@@ -893,7 +887,7 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
893887
ActiveChoice.reset();
894888

895889
if (CS.isDebugMode())
896-
getDebugLogger() << ")\n";
890+
getDebugLogger() << "}\n";
897891

898892
// Check whether it makes sense to continue solving
899893
// this conjunction. Note that for conjunction constraint
@@ -961,7 +955,7 @@ StepResult ConjunctionStep::resume(bool prevFailed) {
961955
if (Conjunction->isIsolated()) {
962956
if (CS.isDebugMode()) {
963957
auto &log = getDebugLogger();
964-
log << "(applying conjunction result to outer context\n";
958+
log << "{Applying conjunction result to outer context\n";
965959
}
966960

967961
assert(

lib/Sema/CSStep.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ class ComponentStep final : public SolverStep {
469469

470470
if (CS.isDebugMode()) {
471471
auto &log = getDebugLogger();
472-
log << "(solving component #" << Index << '\n';
472+
log << "{Solving component #" << Index << '\n';
473473
}
474474

475475
ComponentScope = std::make_unique<Scope>(*this);
@@ -536,7 +536,9 @@ template <typename P> class BindingStep : public SolverStep {
536536

537537
if (CS.isDebugMode()) {
538538
auto &log = getDebugLogger();
539-
log << "(attempting ";
539+
log << "{\n";
540+
log.indent(CS.solverState->getCurrentIndent());
541+
log << "Attempting ";
540542
choice->print(log, &CS.getASTContext().SourceMgr, CS.solverState->getCurrentIndent() + 2);
541543
log << '\n';
542544
}
@@ -557,7 +559,7 @@ template <typename P> class BindingStep : public SolverStep {
557559
}
558560

559561
if (CS.isDebugMode())
560-
getDebugLogger() << ")\n";
562+
getDebugLogger() << "}\n";
561563

562564
// If this binding didn't match, let's check if we've attempted
563565
// enough bindings to stop, because some producers might need

lib/Sema/ConstraintGraph.cpp

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,75 +1604,64 @@ void ConstraintGraph::dumpActiveScopeChanges(llvm::raw_ostream &out,
16041604
PrintOptions PO;
16051605
PO.PrintTypesForDebugging = true;
16061606
out.indent(indent);
1607-
out << "(Changes:\n";
1607+
out << "Changes:\n";
16081608
if (!tvWithboundTypes.empty()) {
16091609
out.indent(indent + 2);
1610-
out << "(Newly Bound: \n";
1610+
out << "Newly Bound: \n";
16111611
for (const auto &tvWithType : tvWithboundTypes) {
16121612
out.indent(indent + 4);
16131613
out << "> $T" << tvWithType.first->getImpl().getID() << " := ";
16141614
tvWithType.second->print(out, PO);
16151615
out << '\n';
16161616
}
1617-
out.indent(indent + 2);
1618-
out << ")\n";
16191617
}
16201618
if (!addedTypeVars.empty()) {
16211619
out.indent(indent + 2);
1622-
auto heading = (addedTypeVars.size() > 1) ? "(New Type Variables: \n"
1623-
: "(New Type Variable: \n";
1620+
auto heading = (addedTypeVars.size() > 1) ? "New Type Variables: \n"
1621+
: "New Type Variable: \n";
16241622
out << heading;
16251623
for (const auto &typeVar : addedTypeVars) {
16261624
out.indent(indent + 4);
16271625
out << "> $T" << typeVar->getImpl().getID();
16281626
out << '\n';
16291627
}
1630-
out.indent(indent + 2);
1631-
out << ")\n";
16321628
}
16331629
if (!equivTypeVars.empty()) {
16341630
out.indent(indent + 2);
1635-
auto heading = (equivTypeVars.size() > 1) ? "(New Equivalences: \n"
1636-
: "(New Equivalence: \n";
1631+
auto heading = (equivTypeVars.size() > 1) ? "New Equivalences: \n"
1632+
: "New Equivalence: \n";
16371633
out << heading;
16381634
for (const auto &typeVar : equivTypeVars) {
16391635
out.indent(indent + 4);
16401636
out << "> $T" << typeVar->getImpl().getID();
16411637
out << '\n';
16421638
}
1643-
out.indent(indent + 2);
1644-
out << ")\n";
16451639
}
16461640
if (!addedConstraints.empty()) {
16471641
out.indent(indent + 2);
1648-
auto heading = (addedConstraints.size() > 1) ? "(Added Constraints: \n"
1649-
: "(Added Constraint: \n";
1642+
auto heading = (addedConstraints.size() > 1) ? "Added Constraints: \n"
1643+
: "Added Constraint: \n";
16501644
out << heading;
16511645
for (const auto &constraint : addedConstraints) {
16521646
out.indent(indent + 4);
16531647
out << "> ";
16541648
constraint->print(out, &CS.getASTContext().SourceMgr, indent + 6);
16551649
out << '\n';
16561650
}
1657-
out.indent(indent + 2);
1658-
out << ")\n";
16591651
}
16601652
if (!removedConstraints.empty()) {
16611653
out.indent(indent + 2);
1662-
auto heading = (removedConstraints.size() > 1) ? "(Removed Constraints: \n"
1663-
: "(Removed Constraint: \n";
1654+
auto heading = (removedConstraints.size() > 1) ? "Removed Constraints: \n"
1655+
: "Removed Constraint: \n";
16641656
out << heading;
16651657
for (const auto &constraint : removedConstraints) {
16661658
out.indent(indent + 4);
16671659
out << "> ";
16681660
constraint->print(out, &CS.getASTContext().SourceMgr, indent + 6);
16691661
out << '\n';
16701662
}
1671-
out.indent(indent + 2);
1672-
out << ")\n";
16731663
}
1674-
out.indent(indent);
1675-
out << ")\n";
1664+
out << '\n';
16761665
}
16771666

16781667
void ConstraintGraph::printConnectedComponents(

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3576,7 +3576,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
35763576

35773577
auto &log = llvm::errs();
35783578
log.indent(solverState ? solverState->getCurrentIndent() : 2);
3579-
log << "(overload set choice binding ";
3579+
log << "Overload set choice binding ";
35803580
boundType->print(log, PO);
35813581
log << " := ";
35823582
adjustedRefType->print(log, PO);
@@ -3594,7 +3594,7 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
35943594
[&]() { log << ", "; });
35953595
log << "]";
35963596
}
3597-
log << ")\n";
3597+
log << "\n";
35983598
}
35993599

36003600
if (auto *decl = choice.getDeclOrNull()) {

0 commit comments

Comments
 (0)