-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Improve indentation in type checker debugging output #62053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xedin
merged 2 commits into
swiftlang:main
from
abdulowork:improve-type-checker-debugging-indentation
Nov 30, 2022
+193
−144
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,17 +353,21 @@ bool ConstraintSystem::simplify() { | |
auto *constraint = &ActiveConstraints.front(); | ||
deactivateConstraint(constraint); | ||
|
||
auto isSimplifiable = | ||
constraint->getKind() != ConstraintKind::Disjunction && | ||
constraint->getKind() != ConstraintKind::Conjunction; | ||
|
||
if (isDebugMode()) { | ||
auto &log = llvm::errs(); | ||
log.indent(solverState->getCurrentIndent()); | ||
log << "(considering -> "; | ||
constraint->print(log, &getASTContext().SourceMgr); | ||
constraint->print(log, &getASTContext().SourceMgr, | ||
solverState->getCurrentIndent()); | ||
log << "\n"; | ||
|
||
// {Dis, Con}junction are returned unsolved in \c simplifyConstraint() and | ||
// handled separately by solver steps. | ||
if (constraint->getKind() != ConstraintKind::Disjunction && | ||
constraint->getKind() != ConstraintKind::Conjunction) { | ||
if (isSimplifiable) { | ||
log.indent(solverState->getCurrentIndent() + 2) | ||
<< "(simplification result:\n"; | ||
} | ||
|
@@ -375,7 +379,9 @@ bool ConstraintSystem::simplify() { | |
retireFailedConstraint(constraint); | ||
if (isDebugMode()) { | ||
auto &log = llvm::errs(); | ||
log.indent(solverState->getCurrentIndent() + 2) << ")\n"; | ||
if (isSimplifiable) { | ||
log.indent(solverState->getCurrentIndent() + 2) << ")\n"; | ||
} | ||
log.indent(solverState->getCurrentIndent() + 2) << "(outcome: error)\n"; | ||
} | ||
break; | ||
|
@@ -386,7 +392,9 @@ bool ConstraintSystem::simplify() { | |
retireConstraint(constraint); | ||
if (isDebugMode()) { | ||
auto &log = llvm::errs(); | ||
log.indent(solverState->getCurrentIndent() + 2) << ")\n"; | ||
if (isSimplifiable) { | ||
log.indent(solverState->getCurrentIndent() + 2) << ")\n"; | ||
} | ||
log.indent(solverState->getCurrentIndent() + 2) | ||
<< "(outcome: simplified)\n"; | ||
} | ||
|
@@ -397,7 +405,9 @@ bool ConstraintSystem::simplify() { | |
++solverState->NumUnsimplifiedConstraints; | ||
if (isDebugMode()) { | ||
auto &log = llvm::errs(); | ||
log.indent(solverState->getCurrentIndent() + 2) << ")\n"; | ||
if (isSimplifiable) { | ||
log.indent(solverState->getCurrentIndent() + 2) << ")\n"; | ||
} | ||
log.indent(solverState->getCurrentIndent() + 2) | ||
<< "(outcome: unsolved)\n"; | ||
} | ||
|
@@ -489,7 +499,8 @@ ConstraintSystem::SolverState::SolverState( | |
if (tyOpts.DebugConstraintSolverAttempt && | ||
tyOpts.DebugConstraintSolverAttempt == SolutionAttempt) { | ||
CS.Options |= ConstraintSystemFlags::DebugConstraints; | ||
llvm::errs() << "---Constraint system #" << SolutionAttempt << "---\n"; | ||
llvm::errs().indent(CS.solverState->getCurrentIndent()) | ||
<< "---Constraint system #" << SolutionAttempt << "---\n"; | ||
CS.print(llvm::errs()); | ||
} | ||
} | ||
|
@@ -793,7 +804,8 @@ bool ConstraintSystem::Candidate::solve( | |
auto &ctx = cs.getASTContext(); | ||
if (cs.isDebugMode()) { | ||
auto &log = llvm::errs(); | ||
log << "--- Solving candidate for shrinking at "; | ||
auto indent = cs.solverState ? cs.solverState->getCurrentIndent() : 0; | ||
log.indent(indent) << "--- Solving candidate for shrinking at "; | ||
auto R = E->getSourceRange(); | ||
if (R.isValid()) { | ||
R.print(log, ctx.SourceMgr, /*PrintText=*/ false); | ||
|
@@ -802,7 +814,7 @@ bool ConstraintSystem::Candidate::solve( | |
} | ||
log << " ---\n"; | ||
|
||
E->dump(log); | ||
E->dump(log, indent); | ||
log << '\n'; | ||
cs.print(log); | ||
} | ||
|
@@ -830,14 +842,18 @@ bool ConstraintSystem::Candidate::solve( | |
|
||
if (cs.isDebugMode()) { | ||
auto &log = llvm::errs(); | ||
auto indent = cs.solverState ? cs.solverState->getCurrentIndent() : 0; | ||
if (solutions.empty()) { | ||
log << "--- No Solutions ---\n"; | ||
log << "\n"; | ||
log.indent(indent) << "--- No Solutions ---\n"; | ||
} else { | ||
log << "--- Solutions ---\n"; | ||
log << "\n"; | ||
log.indent(indent) << "--- Solutions ---\n"; | ||
for (unsigned i = 0, n = solutions.size(); i != n; ++i) { | ||
auto &solution = solutions[i]; | ||
log << "\n--- Solution #" << i << " ---\n"; | ||
solution.dump(log); | ||
log << "\n"; | ||
log.indent(indent) << "--- Solution #" << i << " ---\n"; | ||
solution.dump(log, indent); | ||
} | ||
} | ||
} | ||
|
@@ -1320,14 +1336,18 @@ Optional<std::vector<Solution>> ConstraintSystem::solve( | |
auto dumpSolutions = [&](const SolutionResult &result) { | ||
// Debug-print the set of solutions. | ||
if (isDebugMode()) { | ||
auto &log = llvm::errs(); | ||
auto indent = solverState ? solverState->getCurrentIndent() : 0; | ||
if (result.getKind() == SolutionResult::Success) { | ||
llvm::errs() << "\n---Solution---\n"; | ||
result.getSolution().dump(llvm::errs()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
log << "\n"; | ||
log.indent(indent) << "---Solution---\n"; | ||
result.getSolution().dump(llvm::errs(), indent); | ||
} else if (result.getKind() == SolutionResult::Ambiguous) { | ||
auto solutions = result.getAmbiguousSolutions(); | ||
for (unsigned i : indices(solutions)) { | ||
llvm::errs() << "\n--- Solution #" << i << " ---\n"; | ||
solutions[i].dump(llvm::errs()); | ||
log << "\n"; | ||
log.indent(indent) << "--- Solution #" << i << " ---\n"; | ||
solutions[i].dump(llvm::errs(), indent); | ||
} | ||
} | ||
} | ||
|
@@ -1596,10 +1616,12 @@ void ConstraintSystem::solveForCodeCompletion( | |
|
||
if (isDebugMode()) { | ||
auto &log = llvm::errs(); | ||
log << "--- Discovered " << solutions.size() << " solutions ---\n"; | ||
auto indent = solverState ? solverState->getCurrentIndent() : 0; | ||
log.indent(indent) << "--- Discovered " << solutions.size() | ||
<< " solutions ---\n"; | ||
for (const auto &solution : solutions) { | ||
log << "--- Solution ---\n"; | ||
solution.dump(log); | ||
log.indent(indent) << "--- Solution ---\n"; | ||
solution.dump(log, indent); | ||
} | ||
} | ||
|
||
|
@@ -1621,7 +1643,8 @@ bool ConstraintSystem::solveForCodeCompletion( | |
|
||
if (isDebugMode()) { | ||
auto &log = llvm::errs(); | ||
log << "--- Code Completion ---\n"; | ||
log.indent(solverState ? solverState->getCurrentIndent() : 0) | ||
<< "--- Code Completion ---\n"; | ||
} | ||
|
||
if (generateConstraints(target, FreeTypeVariableBinding::Disallow)) | ||
|
@@ -1665,10 +1688,10 @@ ConstraintSystem::filterDisjunction( | |
} | ||
|
||
if (isDebugMode()) { | ||
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 0) | ||
<< "(disabled disjunction term "; | ||
constraint->print(llvm::errs(), &ctx.SourceMgr); | ||
llvm::errs() << ")\n"; | ||
auto indent = (solverState ? solverState->getCurrentIndent() : 0) + 4; | ||
llvm::errs().indent(indent) << "(disabled disjunction term "; | ||
constraint->print(llvm::errs(), &ctx.SourceMgr, indent); | ||
llvm::errs().indent(indent) << ")\n"; | ||
} | ||
|
||
if (restoreOnFail) | ||
|
@@ -1724,10 +1747,11 @@ ConstraintSystem::filterDisjunction( | |
} | ||
|
||
if (isDebugMode()) { | ||
llvm::errs().indent(solverState ? solverState->getCurrentIndent(): 0) | ||
<< "(introducing single enabled disjunction term "; | ||
choice->print(llvm::errs(), &ctx.SourceMgr); | ||
llvm::errs() << ")\n"; | ||
auto indent = (solverState ? solverState->getCurrentIndent() : 0) + 4; | ||
llvm::errs().indent(indent) | ||
<< "(introducing single enabled disjunction term "; | ||
choice->print(llvm::errs(), &ctx.SourceMgr, indent); | ||
llvm::errs().indent(indent) << ")\n"; | ||
} | ||
|
||
simplifyDisjunctionChoice(choice); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,13 +105,14 @@ void SplitterStep::computeFollowupSteps( | |
|
||
if (CS.isDebugMode()) { | ||
auto &log = getDebugLogger(); | ||
auto indent = CS.solverState->getCurrentIndent(); | ||
// Verify that the constraint graph is valid. | ||
CG.verify(); | ||
|
||
log << "---Constraint graph---\n"; | ||
log.indent(indent) << "---Constraint graph---\n"; | ||
CG.print(CS.getTypeVariables(), log); | ||
|
||
log << "---Connected components---\n"; | ||
log.indent(indent) << "---Connected components---\n"; | ||
CG.printConnectedComponents(CS.getTypeVariables(), log); | ||
} | ||
|
||
|
@@ -361,12 +362,6 @@ StepResult ComponentStep::take(bool prevFailed) { | |
auto *disjunction = CS.selectDisjunction(); | ||
|
||
if (CS.isDebugMode()) { | ||
if (!potentialBindings.empty()) { | ||
auto &log = getDebugLogger(); | ||
log << "(Potential Binding(s): " << '\n'; | ||
log << potentialBindings; | ||
} | ||
|
||
SmallVector<Constraint *, 4> disjunctions; | ||
CS.collectDisjunctions(disjunctions); | ||
std::vector<std::string> overloadDisjunctions; | ||
|
@@ -379,17 +374,24 @@ StepResult ComponentStep::take(bool prevFailed) { | |
overloadDisjunctions.push_back( | ||
constraints[0]->getFirstType()->getString(PO)); | ||
} | ||
|
||
if (!potentialBindings.empty() || !overloadDisjunctions.empty()) { | ||
auto &log = getDebugLogger(); | ||
log << "(Potential Binding(s): " << '\n'; | ||
log << potentialBindings; | ||
} | ||
|
||
if (!overloadDisjunctions.empty()) { | ||
auto &log = getDebugLogger(); | ||
log.indent(2); | ||
log.indent(CS.solverState->getCurrentIndent() + 2); | ||
log << "Disjunction(s) = ["; | ||
interleave(overloadDisjunctions, log, ", "); | ||
log << "]\n"; | ||
} | ||
|
||
if (!potentialBindings.empty() || !overloadDisjunctions.empty()) { | ||
auto &log = getDebugLogger(); | ||
log << ")\n"; | ||
} | ||
if (!potentialBindings.empty() || !overloadDisjunctions.empty()) { | ||
auto &log = getDebugLogger(); | ||
log << ")\n"; | ||
} | ||
} | ||
|
||
|
@@ -428,7 +430,9 @@ StepResult ComponentStep::take(bool prevFailed) { | |
|
||
auto printConstraints = [&](const ConstraintList &constraints) { | ||
for (auto &constraint : constraints) | ||
constraint.print(getDebugLogger(), &CS.getASTContext().SourceMgr); | ||
constraint.print( | ||
getDebugLogger().indent(CS.solverState->getCurrentIndent()), | ||
&CS.getASTContext().SourceMgr, CS.solverState->getCurrentIndent()); | ||
}; | ||
|
||
// If we don't have any disjunction or type variable choices left, we're done | ||
|
@@ -670,8 +674,8 @@ bool DisjunctionStep::shouldSkip(const DisjunctionChoice &choice) const { | |
if (CS.isDebugMode()) { | ||
auto &log = getDebugLogger(); | ||
log << "(skipping " + reason + " "; | ||
choice.print(log, &ctx.SourceMgr); | ||
log << '\n'; | ||
choice.print(log, &ctx.SourceMgr, CS.solverState->getCurrentIndent()); | ||
log << ")\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This brace was unbalanced |
||
} | ||
|
||
return true; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would print an unbalanced brace if constrain was
ConstraintKind::Disjunction || ConstraintKind::Conjunction