@@ -353,17 +353,21 @@ bool ConstraintSystem::simplify() {
353
353
auto *constraint = &ActiveConstraints.front ();
354
354
deactivateConstraint (constraint);
355
355
356
+ auto isSimplifiable =
357
+ constraint->getKind () != ConstraintKind::Disjunction &&
358
+ constraint->getKind () != ConstraintKind::Conjunction;
359
+
356
360
if (isDebugMode ()) {
357
361
auto &log = llvm::errs ();
358
362
log.indent (solverState->getCurrentIndent ());
359
363
log << " (considering -> " ;
360
- constraint->print (log, &getASTContext ().SourceMgr );
364
+ constraint->print (log, &getASTContext ().SourceMgr ,
365
+ solverState->getCurrentIndent ());
361
366
log << " \n " ;
362
367
363
368
// {Dis, Con}junction are returned unsolved in \c simplifyConstraint() and
364
369
// handled separately by solver steps.
365
- if (constraint->getKind () != ConstraintKind::Disjunction &&
366
- constraint->getKind () != ConstraintKind::Conjunction) {
370
+ if (isSimplifiable) {
367
371
log.indent (solverState->getCurrentIndent () + 2 )
368
372
<< " (simplification result:\n " ;
369
373
}
@@ -375,7 +379,9 @@ bool ConstraintSystem::simplify() {
375
379
retireFailedConstraint (constraint);
376
380
if (isDebugMode ()) {
377
381
auto &log = llvm::errs ();
378
- log.indent (solverState->getCurrentIndent () + 2 ) << " )\n " ;
382
+ if (isSimplifiable) {
383
+ log.indent (solverState->getCurrentIndent () + 2 ) << " )\n " ;
384
+ }
379
385
log.indent (solverState->getCurrentIndent () + 2 ) << " (outcome: error)\n " ;
380
386
}
381
387
break ;
@@ -386,7 +392,9 @@ bool ConstraintSystem::simplify() {
386
392
retireConstraint (constraint);
387
393
if (isDebugMode ()) {
388
394
auto &log = llvm::errs ();
389
- log.indent (solverState->getCurrentIndent () + 2 ) << " )\n " ;
395
+ if (isSimplifiable) {
396
+ log.indent (solverState->getCurrentIndent () + 2 ) << " )\n " ;
397
+ }
390
398
log.indent (solverState->getCurrentIndent () + 2 )
391
399
<< " (outcome: simplified)\n " ;
392
400
}
@@ -397,7 +405,9 @@ bool ConstraintSystem::simplify() {
397
405
++solverState->NumUnsimplifiedConstraints ;
398
406
if (isDebugMode ()) {
399
407
auto &log = llvm::errs ();
400
- log.indent (solverState->getCurrentIndent () + 2 ) << " )\n " ;
408
+ if (isSimplifiable) {
409
+ log.indent (solverState->getCurrentIndent () + 2 ) << " )\n " ;
410
+ }
401
411
log.indent (solverState->getCurrentIndent () + 2 )
402
412
<< " (outcome: unsolved)\n " ;
403
413
}
@@ -489,7 +499,8 @@ ConstraintSystem::SolverState::SolverState(
489
499
if (tyOpts.DebugConstraintSolverAttempt &&
490
500
tyOpts.DebugConstraintSolverAttempt == SolutionAttempt) {
491
501
CS.Options |= ConstraintSystemFlags::DebugConstraints;
492
- llvm::errs () << " ---Constraint system #" << SolutionAttempt << " ---\n " ;
502
+ llvm::errs ().indent (CS.solverState ->getCurrentIndent ())
503
+ << " ---Constraint system #" << SolutionAttempt << " ---\n " ;
493
504
CS.print (llvm::errs ());
494
505
}
495
506
}
@@ -793,7 +804,8 @@ bool ConstraintSystem::Candidate::solve(
793
804
auto &ctx = cs.getASTContext ();
794
805
if (cs.isDebugMode ()) {
795
806
auto &log = llvm::errs ();
796
- log << " --- Solving candidate for shrinking at " ;
807
+ auto indent = cs.solverState ? cs.solverState ->getCurrentIndent () : 0 ;
808
+ log.indent (indent) << " --- Solving candidate for shrinking at " ;
797
809
auto R = E->getSourceRange ();
798
810
if (R.isValid ()) {
799
811
R.print (log, ctx.SourceMgr , /* PrintText=*/ false );
@@ -802,7 +814,7 @@ bool ConstraintSystem::Candidate::solve(
802
814
}
803
815
log << " ---\n " ;
804
816
805
- E->dump (log);
817
+ E->dump (log, indent );
806
818
log << ' \n ' ;
807
819
cs.print (log);
808
820
}
@@ -830,14 +842,18 @@ bool ConstraintSystem::Candidate::solve(
830
842
831
843
if (cs.isDebugMode ()) {
832
844
auto &log = llvm::errs ();
845
+ auto indent = cs.solverState ? cs.solverState ->getCurrentIndent () : 0 ;
833
846
if (solutions.empty ()) {
834
- log << " --- No Solutions ---\n " ;
847
+ log << " \n " ;
848
+ log.indent (indent) << " --- No Solutions ---\n " ;
835
849
} else {
836
- log << " --- Solutions ---\n " ;
850
+ log << " \n " ;
851
+ log.indent (indent) << " --- Solutions ---\n " ;
837
852
for (unsigned i = 0 , n = solutions.size (); i != n; ++i) {
838
853
auto &solution = solutions[i];
839
- log << " \n --- Solution #" << i << " ---\n " ;
840
- solution.dump (log);
854
+ log << " \n " ;
855
+ log.indent (indent) << " --- Solution #" << i << " ---\n " ;
856
+ solution.dump (log, indent);
841
857
}
842
858
}
843
859
}
@@ -1320,14 +1336,18 @@ Optional<std::vector<Solution>> ConstraintSystem::solve(
1320
1336
auto dumpSolutions = [&](const SolutionResult &result) {
1321
1337
// Debug-print the set of solutions.
1322
1338
if (isDebugMode ()) {
1339
+ auto &log = llvm::errs ();
1340
+ auto indent = solverState ? solverState->getCurrentIndent () : 0 ;
1323
1341
if (result.getKind () == SolutionResult::Success) {
1324
- llvm::errs () << " \n ---Solution---\n " ;
1325
- result.getSolution ().dump (llvm::errs ());
1342
+ log << " \n " ;
1343
+ log.indent (indent) << " ---Solution---\n " ;
1344
+ result.getSolution ().dump (llvm::errs (), indent);
1326
1345
} else if (result.getKind () == SolutionResult::Ambiguous) {
1327
1346
auto solutions = result.getAmbiguousSolutions ();
1328
1347
for (unsigned i : indices (solutions)) {
1329
- llvm::errs () << " \n --- Solution #" << i << " ---\n " ;
1330
- solutions[i].dump (llvm::errs ());
1348
+ log << " \n " ;
1349
+ log.indent (indent) << " --- Solution #" << i << " ---\n " ;
1350
+ solutions[i].dump (llvm::errs (), indent);
1331
1351
}
1332
1352
}
1333
1353
}
@@ -1596,10 +1616,12 @@ void ConstraintSystem::solveForCodeCompletion(
1596
1616
1597
1617
if (isDebugMode ()) {
1598
1618
auto &log = llvm::errs ();
1599
- log << " --- Discovered " << solutions.size () << " solutions ---\n " ;
1619
+ auto indent = solverState ? solverState->getCurrentIndent () : 0 ;
1620
+ log.indent (indent) << " --- Discovered " << solutions.size ()
1621
+ << " solutions ---\n " ;
1600
1622
for (const auto &solution : solutions) {
1601
- log << " --- Solution ---\n " ;
1602
- solution.dump (log);
1623
+ log. indent (indent) << " --- Solution ---\n " ;
1624
+ solution.dump (log, indent );
1603
1625
}
1604
1626
}
1605
1627
@@ -1621,7 +1643,8 @@ bool ConstraintSystem::solveForCodeCompletion(
1621
1643
1622
1644
if (isDebugMode ()) {
1623
1645
auto &log = llvm::errs ();
1624
- log << " --- Code Completion ---\n " ;
1646
+ log.indent (solverState ? solverState->getCurrentIndent () : 0 )
1647
+ << " --- Code Completion ---\n " ;
1625
1648
}
1626
1649
1627
1650
if (generateConstraints (target, FreeTypeVariableBinding::Disallow))
@@ -1665,10 +1688,10 @@ ConstraintSystem::filterDisjunction(
1665
1688
}
1666
1689
1667
1690
if (isDebugMode ()) {
1668
- llvm::errs (). indent (solverState ? solverState->getCurrentIndent () : 0 )
1669
- << " (disabled disjunction term " ;
1670
- constraint->print (llvm::errs (), &ctx.SourceMgr );
1671
- llvm::errs () << " )\n " ;
1691
+ auto indent = (solverState ? solverState->getCurrentIndent () : 0 ) + 4 ;
1692
+ llvm::errs (). indent (indent) << " (disabled disjunction term " ;
1693
+ constraint->print (llvm::errs (), &ctx.SourceMgr , indent );
1694
+ llvm::errs (). indent (indent) << " )\n " ;
1672
1695
}
1673
1696
1674
1697
if (restoreOnFail)
@@ -1724,10 +1747,11 @@ ConstraintSystem::filterDisjunction(
1724
1747
}
1725
1748
1726
1749
if (isDebugMode ()) {
1727
- llvm::errs ().indent (solverState ? solverState->getCurrentIndent (): 0 )
1728
- << " (introducing single enabled disjunction term " ;
1729
- choice->print (llvm::errs (), &ctx.SourceMgr );
1730
- llvm::errs () << " )\n " ;
1750
+ auto indent = (solverState ? solverState->getCurrentIndent () : 0 ) + 4 ;
1751
+ llvm::errs ().indent (indent)
1752
+ << " (introducing single enabled disjunction term " ;
1753
+ choice->print (llvm::errs (), &ctx.SourceMgr , indent);
1754
+ llvm::errs ().indent (indent) << " )\n " ;
1731
1755
}
1732
1756
1733
1757
simplifyDisjunctionChoice (choice);
0 commit comments