Skip to content

Commit d5c049e

Browse files
committed
Sema: Better debug output in compareSolutions()
1 parent f3e6b4c commit d5c049e

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

lib/Sema/CSRanking.cpp

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,8 +1085,14 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
10851085
// In this case solver would produce 2 solutions: one where `count`
10861086
// is a property reference on `[Int]` and another one is tuple access
10871087
// for a `count:` element.
1088-
if (choice1.isDecl() != choice2.isDecl())
1088+
if (choice1.isDecl() != choice2.isDecl()) {
1089+
if (cs.isDebugMode()) {
1090+
llvm::errs().indent(cs.solverState->getCurrentIndent())
1091+
<< "- incomparable\n";
1092+
}
1093+
10891094
return SolutionCompareResult::Incomparable;
1095+
}
10901096

10911097
auto decl1 = choice1.getDecl();
10921098
auto dc1 = decl1->getDeclContext();
@@ -1553,13 +1559,39 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
15531559

15541560
// If the scores are different, we have a winner.
15551561
if (score1 != score2) {
1556-
return score1 > score2? SolutionCompareResult::Better
1557-
: SolutionCompareResult::Worse;
1562+
if (score1 > score2) {
1563+
if (cs.isDebugMode()) {
1564+
llvm::errs().indent(cs.solverState->getCurrentIndent())
1565+
<< "- better\n";
1566+
}
1567+
1568+
return SolutionCompareResult::Better;
1569+
} else {
1570+
if (cs.isDebugMode()) {
1571+
llvm::errs().indent(cs.solverState->getCurrentIndent())
1572+
<< "- worse\n";
1573+
}
1574+
1575+
return SolutionCompareResult::Worse;
1576+
}
15581577
}
15591578

15601579
// Neither system wins; report whether they were identical or not.
1561-
return identical? SolutionCompareResult::Identical
1562-
: SolutionCompareResult::Incomparable;
1580+
if (identical) {
1581+
if (cs.isDebugMode()) {
1582+
llvm::errs().indent(cs.solverState->getCurrentIndent())
1583+
<< "- identical\n";
1584+
}
1585+
1586+
return SolutionCompareResult::Identical;
1587+
} else {
1588+
if (cs.isDebugMode()) {
1589+
llvm::errs().indent(cs.solverState->getCurrentIndent())
1590+
<< "- incomparable\n";
1591+
}
1592+
1593+
return SolutionCompareResult::Incomparable;
1594+
}
15631595
}
15641596

15651597
std::optional<unsigned>

0 commit comments

Comments
 (0)