mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Improve indentation in debugging output
This commit is contained in:
@@ -1708,7 +1708,7 @@ public:
|
|||||||
SWIFT_DEBUG_DUMP;
|
SWIFT_DEBUG_DUMP;
|
||||||
|
|
||||||
/// Dump this solution.
|
/// Dump this solution.
|
||||||
void dump(raw_ostream &OS) const LLVM_ATTRIBUTE_USED;
|
void dump(raw_ostream &OS, unsigned indent) const LLVM_ATTRIBUTE_USED;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Describes the differences between several solutions to the same
|
/// Describes the differences between several solutions to the same
|
||||||
@@ -6433,9 +6433,10 @@ public:
|
|||||||
bool isSymmetricOperator() const;
|
bool isSymmetricOperator() const;
|
||||||
bool isUnaryOperator() const;
|
bool isUnaryOperator() const;
|
||||||
|
|
||||||
void print(llvm::raw_ostream &Out, SourceManager *SM, unsigned indent = 0) const {
|
void print(llvm::raw_ostream &Out, SourceManager *SM,
|
||||||
|
unsigned indent = 0) const {
|
||||||
Out << "disjunction choice ";
|
Out << "disjunction choice ";
|
||||||
Choice->print(Out, SM);
|
Choice->print(Out, SM, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator Constraint *() { return Choice; }
|
operator Constraint *() { return Choice; }
|
||||||
|
|||||||
@@ -2370,9 +2370,10 @@ Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cs.isDebugMode()) {
|
if (cs.isDebugMode()) {
|
||||||
auto &log = llvm::errs();
|
auto indent = cs.solverState ? cs.solverState->getCurrentIndent() : 0;
|
||||||
|
auto &log = llvm::errs().indent(indent);
|
||||||
log << "--- Applying Solution ---\n";
|
log << "--- Applying Solution ---\n";
|
||||||
solutions.front().dump(log);
|
solutions.front().dump(log, indent);
|
||||||
log << '\n';
|
log << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2387,7 +2388,8 @@ Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
|
|||||||
auto *body = result->getFunctionBody();
|
auto *body = result->getFunctionBody();
|
||||||
|
|
||||||
if (cs.isDebugMode()) {
|
if (cs.isDebugMode()) {
|
||||||
auto &log = llvm::errs();
|
auto indent = cs.solverState ? cs.solverState->getCurrentIndent() : 0;
|
||||||
|
auto &log = llvm::errs().indent(indent);
|
||||||
log << "--- Type-checked function body ---\n";
|
log << "--- Type-checked function body ---\n";
|
||||||
body->dump(log);
|
body->dump(log);
|
||||||
log << '\n';
|
log << '\n';
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ void ConstraintSystem::increaseScore(ScoreKind kind, unsigned value) {
|
|||||||
if (isDebugMode() && value > 0) {
|
if (isDebugMode() && value > 0) {
|
||||||
if (solverState)
|
if (solverState)
|
||||||
llvm::errs().indent(solverState->getCurrentIndent());
|
llvm::errs().indent(solverState->getCurrentIndent());
|
||||||
llvm::errs() << "(increasing '" << Score::getNameFor(kind) << "' score by " << value
|
llvm::errs() << "(increasing '" << Score::getNameFor(kind) << "' score by "
|
||||||
<< ")\n";
|
<< value << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned index = static_cast<unsigned>(kind);
|
unsigned index = static_cast<unsigned>(kind);
|
||||||
@@ -73,7 +73,7 @@ bool ConstraintSystem::worseThanBestSolution() const {
|
|||||||
|
|
||||||
if (isDebugMode()) {
|
if (isDebugMode()) {
|
||||||
llvm::errs().indent(solverState->getCurrentIndent())
|
llvm::errs().indent(solverState->getCurrentIndent())
|
||||||
<< "(solution is worse than the best solution)\n";
|
<< "(solution is worse than the best solution)\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -804,7 +804,7 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
|
|||||||
const SolutionDiff &diff, unsigned idx1, unsigned idx2) {
|
const SolutionDiff &diff, unsigned idx1, unsigned idx2) {
|
||||||
if (cs.isDebugMode()) {
|
if (cs.isDebugMode()) {
|
||||||
llvm::errs().indent(cs.solverState->getCurrentIndent())
|
llvm::errs().indent(cs.solverState->getCurrentIndent())
|
||||||
<< "comparing solutions " << idx1 << " and " << idx2 <<"\n";
|
<< "comparing solutions " << idx1 << " and " << idx2 << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whether the solutions are identical.
|
// Whether the solutions are identical.
|
||||||
@@ -1360,13 +1360,15 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (isDebugMode()) {
|
if (isDebugMode()) {
|
||||||
llvm::errs().indent(solverState->getCurrentIndent())
|
auto indent = solverState->getCurrentIndent();
|
||||||
<< "Comparing " << viable.size() << " viable solutions\n";
|
auto &log = llvm::errs();
|
||||||
|
|
||||||
|
log.indent(indent) << "Comparing " << viable.size()
|
||||||
|
<< " viable solutions\n";
|
||||||
for (unsigned i = 0, n = viable.size(); i != n; ++i) {
|
for (unsigned i = 0, n = viable.size(); i != n; ++i) {
|
||||||
llvm::errs().indent(solverState->getCurrentIndent())
|
log << "\n";
|
||||||
<< "\n--- Solution #" << i << " ---\n";
|
log.indent(indent) << "--- Solution #" << i << " ---\n";
|
||||||
viable[i].dump(llvm::errs().indent(solverState->getCurrentIndent()));
|
viable[i].dump(llvm::errs(), indent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -361,7 +361,8 @@ bool ConstraintSystem::simplify() {
|
|||||||
auto &log = llvm::errs();
|
auto &log = llvm::errs();
|
||||||
log.indent(solverState->getCurrentIndent());
|
log.indent(solverState->getCurrentIndent());
|
||||||
log << "(considering -> ";
|
log << "(considering -> ";
|
||||||
constraint->print(log, &getASTContext().SourceMgr);
|
constraint->print(log, &getASTContext().SourceMgr,
|
||||||
|
solverState->getCurrentIndent());
|
||||||
log << "\n";
|
log << "\n";
|
||||||
|
|
||||||
// {Dis, Con}junction are returned unsolved in \c simplifyConstraint() and
|
// {Dis, Con}junction are returned unsolved in \c simplifyConstraint() and
|
||||||
@@ -498,7 +499,8 @@ ConstraintSystem::SolverState::SolverState(
|
|||||||
if (tyOpts.DebugConstraintSolverAttempt &&
|
if (tyOpts.DebugConstraintSolverAttempt &&
|
||||||
tyOpts.DebugConstraintSolverAttempt == SolutionAttempt) {
|
tyOpts.DebugConstraintSolverAttempt == SolutionAttempt) {
|
||||||
CS.Options |= ConstraintSystemFlags::DebugConstraints;
|
CS.Options |= ConstraintSystemFlags::DebugConstraints;
|
||||||
llvm::errs() << "---Constraint system #" << SolutionAttempt << "---\n";
|
llvm::errs().indent(CS.solverState->getCurrentIndent())
|
||||||
|
<< "---Constraint system #" << SolutionAttempt << "---\n";
|
||||||
CS.print(llvm::errs());
|
CS.print(llvm::errs());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -802,7 +804,8 @@ bool ConstraintSystem::Candidate::solve(
|
|||||||
auto &ctx = cs.getASTContext();
|
auto &ctx = cs.getASTContext();
|
||||||
if (cs.isDebugMode()) {
|
if (cs.isDebugMode()) {
|
||||||
auto &log = llvm::errs();
|
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();
|
auto R = E->getSourceRange();
|
||||||
if (R.isValid()) {
|
if (R.isValid()) {
|
||||||
R.print(log, ctx.SourceMgr, /*PrintText=*/ false);
|
R.print(log, ctx.SourceMgr, /*PrintText=*/ false);
|
||||||
@@ -811,7 +814,7 @@ bool ConstraintSystem::Candidate::solve(
|
|||||||
}
|
}
|
||||||
log << " ---\n";
|
log << " ---\n";
|
||||||
|
|
||||||
E->dump(log);
|
E->dump(log, indent);
|
||||||
log << '\n';
|
log << '\n';
|
||||||
cs.print(log);
|
cs.print(log);
|
||||||
}
|
}
|
||||||
@@ -839,14 +842,18 @@ bool ConstraintSystem::Candidate::solve(
|
|||||||
|
|
||||||
if (cs.isDebugMode()) {
|
if (cs.isDebugMode()) {
|
||||||
auto &log = llvm::errs();
|
auto &log = llvm::errs();
|
||||||
|
auto indent = cs.solverState ? cs.solverState->getCurrentIndent() : 0;
|
||||||
if (solutions.empty()) {
|
if (solutions.empty()) {
|
||||||
log << "--- No Solutions ---\n";
|
log << "\n";
|
||||||
|
log.indent(indent) << "--- No Solutions ---\n";
|
||||||
} else {
|
} else {
|
||||||
log << "--- Solutions ---\n";
|
log << "\n";
|
||||||
|
log.indent(indent) << "--- Solutions ---\n";
|
||||||
for (unsigned i = 0, n = solutions.size(); i != n; ++i) {
|
for (unsigned i = 0, n = solutions.size(); i != n; ++i) {
|
||||||
auto &solution = solutions[i];
|
auto &solution = solutions[i];
|
||||||
log << "\n--- Solution #" << i << " ---\n";
|
log << "\n";
|
||||||
solution.dump(log);
|
log.indent(indent) << "--- Solution #" << i << " ---\n";
|
||||||
|
solution.dump(log, indent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1329,14 +1336,18 @@ Optional<std::vector<Solution>> ConstraintSystem::solve(
|
|||||||
auto dumpSolutions = [&](const SolutionResult &result) {
|
auto dumpSolutions = [&](const SolutionResult &result) {
|
||||||
// Debug-print the set of solutions.
|
// Debug-print the set of solutions.
|
||||||
if (isDebugMode()) {
|
if (isDebugMode()) {
|
||||||
|
auto &log = llvm::errs();
|
||||||
|
auto indent = solverState ? solverState->getCurrentIndent() : 0;
|
||||||
if (result.getKind() == SolutionResult::Success) {
|
if (result.getKind() == SolutionResult::Success) {
|
||||||
llvm::errs() << "\n---Solution---\n";
|
log << "\n";
|
||||||
result.getSolution().dump(llvm::errs());
|
log.indent(indent) << "---Solution---\n";
|
||||||
|
result.getSolution().dump(llvm::errs(), indent);
|
||||||
} else if (result.getKind() == SolutionResult::Ambiguous) {
|
} else if (result.getKind() == SolutionResult::Ambiguous) {
|
||||||
auto solutions = result.getAmbiguousSolutions();
|
auto solutions = result.getAmbiguousSolutions();
|
||||||
for (unsigned i : indices(solutions)) {
|
for (unsigned i : indices(solutions)) {
|
||||||
llvm::errs() << "\n--- Solution #" << i << " ---\n";
|
log << "\n";
|
||||||
solutions[i].dump(llvm::errs());
|
log.indent(indent) << "--- Solution #" << i << " ---\n";
|
||||||
|
solutions[i].dump(llvm::errs(), indent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1605,10 +1616,12 @@ void ConstraintSystem::solveForCodeCompletion(
|
|||||||
|
|
||||||
if (isDebugMode()) {
|
if (isDebugMode()) {
|
||||||
auto &log = llvm::errs();
|
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) {
|
for (const auto &solution : solutions) {
|
||||||
log << "--- Solution ---\n";
|
log.indent(indent) << "--- Solution ---\n";
|
||||||
solution.dump(log);
|
solution.dump(log, indent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1630,7 +1643,8 @@ bool ConstraintSystem::solveForCodeCompletion(
|
|||||||
|
|
||||||
if (isDebugMode()) {
|
if (isDebugMode()) {
|
||||||
auto &log = llvm::errs();
|
auto &log = llvm::errs();
|
||||||
log << "--- Code Completion ---\n";
|
log.indent(solverState ? solverState->getCurrentIndent() : 0)
|
||||||
|
<< "--- Code Completion ---\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generateConstraints(target, FreeTypeVariableBinding::Disallow))
|
if (generateConstraints(target, FreeTypeVariableBinding::Disallow))
|
||||||
@@ -1674,10 +1688,10 @@ ConstraintSystem::filterDisjunction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isDebugMode()) {
|
if (isDebugMode()) {
|
||||||
llvm::errs().indent(solverState ? solverState->getCurrentIndent() : 0)
|
auto indent = (solverState ? solverState->getCurrentIndent() : 0) + 4;
|
||||||
<< "(disabled disjunction term ";
|
llvm::errs().indent(indent) << "(disabled disjunction term ";
|
||||||
constraint->print(llvm::errs(), &ctx.SourceMgr);
|
constraint->print(llvm::errs(), &ctx.SourceMgr, indent);
|
||||||
llvm::errs() << ")\n";
|
llvm::errs().indent(indent) << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restoreOnFail)
|
if (restoreOnFail)
|
||||||
@@ -1733,10 +1747,11 @@ ConstraintSystem::filterDisjunction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isDebugMode()) {
|
if (isDebugMode()) {
|
||||||
llvm::errs().indent(solverState ? solverState->getCurrentIndent(): 0)
|
auto indent = (solverState ? solverState->getCurrentIndent() : 0) + 4;
|
||||||
<< "(introducing single enabled disjunction term ";
|
llvm::errs().indent(indent)
|
||||||
choice->print(llvm::errs(), &ctx.SourceMgr);
|
<< "(introducing single enabled disjunction term ";
|
||||||
llvm::errs() << ")\n";
|
choice->print(llvm::errs(), &ctx.SourceMgr, indent);
|
||||||
|
llvm::errs().indent(indent) << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
simplifyDisjunctionChoice(choice);
|
simplifyDisjunctionChoice(choice);
|
||||||
|
|||||||
@@ -105,13 +105,14 @@ void SplitterStep::computeFollowupSteps(
|
|||||||
|
|
||||||
if (CS.isDebugMode()) {
|
if (CS.isDebugMode()) {
|
||||||
auto &log = getDebugLogger();
|
auto &log = getDebugLogger();
|
||||||
|
auto indent = CS.solverState->getCurrentIndent();
|
||||||
// Verify that the constraint graph is valid.
|
// Verify that the constraint graph is valid.
|
||||||
CG.verify();
|
CG.verify();
|
||||||
|
|
||||||
log << "---Constraint graph---\n";
|
log.indent(indent) << "---Constraint graph---\n";
|
||||||
CG.print(CS.getTypeVariables(), log);
|
CG.print(CS.getTypeVariables(), log);
|
||||||
|
|
||||||
log << "---Connected components---\n";
|
log.indent(indent) << "---Connected components---\n";
|
||||||
CG.printConnectedComponents(CS.getTypeVariables(), log);
|
CG.printConnectedComponents(CS.getTypeVariables(), log);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,7 +383,7 @@ StepResult ComponentStep::take(bool prevFailed) {
|
|||||||
|
|
||||||
if (!overloadDisjunctions.empty()) {
|
if (!overloadDisjunctions.empty()) {
|
||||||
auto &log = getDebugLogger();
|
auto &log = getDebugLogger();
|
||||||
log.indent(2);
|
log.indent(CS.solverState->getCurrentIndent() + 2);
|
||||||
log << "Disjunction(s) = [";
|
log << "Disjunction(s) = [";
|
||||||
interleave(overloadDisjunctions, log, ", ");
|
interleave(overloadDisjunctions, log, ", ");
|
||||||
log << "]\n";
|
log << "]\n";
|
||||||
@@ -429,7 +430,9 @@ StepResult ComponentStep::take(bool prevFailed) {
|
|||||||
|
|
||||||
auto printConstraints = [&](const ConstraintList &constraints) {
|
auto printConstraints = [&](const ConstraintList &constraints) {
|
||||||
for (auto &constraint : 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
|
// If we don't have any disjunction or type variable choices left, we're done
|
||||||
@@ -671,7 +674,7 @@ bool DisjunctionStep::shouldSkip(const DisjunctionChoice &choice) const {
|
|||||||
if (CS.isDebugMode()) {
|
if (CS.isDebugMode()) {
|
||||||
auto &log = getDebugLogger();
|
auto &log = getDebugLogger();
|
||||||
log << "(skipping " + reason + " ";
|
log << "(skipping " + reason + " ";
|
||||||
choice.print(log, &ctx.SourceMgr);
|
choice.print(log, &ctx.SourceMgr, CS.solverState->getCurrentIndent());
|
||||||
log << ")\n";
|
log << ")\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -707,7 +707,8 @@ public:
|
|||||||
|
|
||||||
void print(llvm::raw_ostream &Out) override {
|
void print(llvm::raw_ostream &Out) override {
|
||||||
Out << "DisjunctionStep for ";
|
Out << "DisjunctionStep for ";
|
||||||
Disjunction->print(Out, &CS.getASTContext().SourceMgr);
|
Disjunction->print(Out, &CS.getASTContext().SourceMgr,
|
||||||
|
CS.solverState->getCurrentIndent());
|
||||||
Out << '\n';
|
Out << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1013,7 +1014,8 @@ public:
|
|||||||
|
|
||||||
void print(llvm::raw_ostream &Out) override {
|
void print(llvm::raw_ostream &Out) override {
|
||||||
Out << "ConjunctionStep for ";
|
Out << "ConjunctionStep for ";
|
||||||
Conjunction->print(Out, &CS.getASTContext().SourceMgr);
|
Conjunction->print(Out, &CS.getASTContext().SourceMgr,
|
||||||
|
CS.solverState->getCurrentIndent());
|
||||||
Out << '\n';
|
Out << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -360,7 +360,8 @@ Constraint *Constraint::clone(ConstraintSystem &cs) const {
|
|||||||
llvm_unreachable("Unhandled ConstraintKind in switch.");
|
llvm_unreachable("Unhandled ConstraintKind in switch.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm, unsigned indent, bool skipLocator) const {
|
void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm,
|
||||||
|
unsigned indent, bool skipLocator) const {
|
||||||
// Print all type variables as $T0 instead of _ here.
|
// Print all type variables as $T0 instead of _ here.
|
||||||
PrintOptions PO;
|
PrintOptions PO;
|
||||||
PO.PrintTypesForDebugging = true;
|
PO.PrintTypesForDebugging = true;
|
||||||
@@ -395,19 +396,21 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm, unsigned inden
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
interleave(sortedConstraints,
|
interleave(
|
||||||
[&](Constraint *constraint) {
|
sortedConstraints,
|
||||||
Out.indent(indent);
|
[&](Constraint *constraint) {
|
||||||
if (constraint->isDisabled())
|
Out.indent(indent + 2);
|
||||||
Out << "> [disabled] ";
|
if (constraint->isDisabled())
|
||||||
else if (constraint->isFavored())
|
Out << "> [disabled] ";
|
||||||
Out << "> [favored] ";
|
else if (constraint->isFavored())
|
||||||
else
|
Out << "> [favored] ";
|
||||||
Out << "> ";
|
else
|
||||||
constraint->print(Out, sm, indent,
|
Out << "> ";
|
||||||
/*skipLocator=*/constraint->getLocator() == Locator);
|
constraint->print(Out, sm, indent,
|
||||||
},
|
/*skipLocator=*/constraint->getLocator() ==
|
||||||
[&] { Out << "\n"; });
|
Locator);
|
||||||
|
},
|
||||||
|
[&] { Out << "\n"; });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1438,12 +1438,12 @@ bool ConstraintGraph::contractEdges() {
|
|||||||
auto rep2 = CS.getRepresentative(tyvar2);
|
auto rep2 = CS.getRepresentative(tyvar2);
|
||||||
|
|
||||||
if (CS.isDebugMode()) {
|
if (CS.isDebugMode()) {
|
||||||
auto &log = llvm::errs();
|
auto indent = CS.solverState ? CS.solverState->getCurrentIndent() : 0;
|
||||||
if (CS.solverState)
|
auto &log = llvm::errs().indent(indent);
|
||||||
log.indent(CS.solverState->getCurrentIndent());
|
|
||||||
|
|
||||||
log << "Contracting constraint ";
|
log << "Contracting constraint ";
|
||||||
constraint->print(log, &CS.getASTContext().SourceMgr);
|
constraint->print(log.indent(indent), &CS.getASTContext().SourceMgr,
|
||||||
|
indent);
|
||||||
log << "\n";
|
log << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1488,7 +1488,7 @@ void ConstraintGraphNode::print(llvm::raw_ostream &out, unsigned indent,
|
|||||||
|
|
||||||
for (auto constraint : sortedConstraints) {
|
for (auto constraint : sortedConstraints) {
|
||||||
out.indent(indent + 4);
|
out.indent(indent + 4);
|
||||||
constraint->print(out, &TypeVar->getASTContext().SourceMgr);
|
constraint->print(out, &TypeVar->getASTContext().SourceMgr, indent + 4);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1545,7 +1545,8 @@ void ConstraintGraph::print(ArrayRef<TypeVariableType *> typeVars,
|
|||||||
PO.PrintTypesForDebugging = true;
|
PO.PrintTypesForDebugging = true;
|
||||||
|
|
||||||
for (auto typeVar : typeVars) {
|
for (auto typeVar : typeVars) {
|
||||||
(*this)[typeVar].print(out, 2, PO);
|
(*this)[typeVar].print(
|
||||||
|
out, (CS.solverState ? CS.solverState->getCurrentIndent() : 0) + 2, PO);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1682,7 +1683,7 @@ void ConstraintGraph::printConnectedComponents(
|
|||||||
PrintOptions PO;
|
PrintOptions PO;
|
||||||
PO.PrintTypesForDebugging = true;
|
PO.PrintTypesForDebugging = true;
|
||||||
for (const auto& component : components) {
|
for (const auto& component : components) {
|
||||||
out.indent(2);
|
out.indent((CS.solverState ? CS.solverState->getCurrentIndent() : 0) + 2);
|
||||||
out << component.solutionIndex << ": ";
|
out << component.solutionIndex << ": ";
|
||||||
SWIFT_DEFER {
|
SWIFT_DEFER {
|
||||||
out << '\n';
|
out << '\n';
|
||||||
|
|||||||
@@ -3958,7 +3958,7 @@ SolutionResult ConstraintSystem::salvage() {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto &solution : viable) {
|
for (auto &solution : viable) {
|
||||||
log << "---Ambiguous solution #" << i++ << "---\n";
|
log << "---Ambiguous solution #" << i++ << "---\n";
|
||||||
solution.dump(log);
|
solution.dump(log, solverState->getCurrentIndent());
|
||||||
log << "\n";
|
log << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4692,13 +4692,15 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (isDebugMode()) {
|
if (isDebugMode()) {
|
||||||
auto &log = llvm::errs();
|
auto indent = solverState->getCurrentIndent();
|
||||||
|
auto &log = llvm::errs().indent(indent);
|
||||||
log << "--- Ambiguity: Considering #" << solutions.size()
|
log << "--- Ambiguity: Considering #" << solutions.size()
|
||||||
<< " solutions with fixes ---\n";
|
<< " solutions with fixes ---\n";
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (auto &solution : solutions) {
|
for (auto &solution : solutions) {
|
||||||
log << "\n--- Solution #" << i++ << "---\n";
|
log << "\n";
|
||||||
solution.dump(log);
|
log.indent(indent) << "--- Solution #" << i++ << "---\n";
|
||||||
|
solution.dump(log, indent);
|
||||||
log << "\n";
|
log << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -410,8 +410,10 @@ getTypeOfCompletionOperatorImpl(DeclContext *DC, Expr *expr,
|
|||||||
|
|
||||||
if (CS.isDebugMode()) {
|
if (CS.isDebugMode()) {
|
||||||
auto &log = llvm::errs();
|
auto &log = llvm::errs();
|
||||||
log << "---Initial constraints for the given expression---\n";
|
auto indent = CS.solverState ? CS.solverState->getCurrentIndent() : 0;
|
||||||
expr->dump(log);
|
log.indent(indent)
|
||||||
|
<< "---Initial constraints for the given expression---\n";
|
||||||
|
expr->dump(log, indent);
|
||||||
log << "\n";
|
log << "\n";
|
||||||
CS.print(log);
|
CS.print(log);
|
||||||
}
|
}
|
||||||
@@ -424,8 +426,9 @@ getTypeOfCompletionOperatorImpl(DeclContext *DC, Expr *expr,
|
|||||||
auto &solution = viable[0];
|
auto &solution = viable[0];
|
||||||
if (CS.isDebugMode()) {
|
if (CS.isDebugMode()) {
|
||||||
auto &log = llvm::errs();
|
auto &log = llvm::errs();
|
||||||
log << "---Solution---\n";
|
auto indent = CS.solverState ? CS.solverState->getCurrentIndent() : 0;
|
||||||
solution.dump(log);
|
log.indent(indent) << "---Solution---\n";
|
||||||
|
solution.dump(log, indent);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill the results.
|
// Fill the results.
|
||||||
|
|||||||
@@ -1006,7 +1006,7 @@ static Type replaceArchetypesWithTypeVariables(ConstraintSystem &cs,
|
|||||||
// for nested types applies.
|
// for nested types applies.
|
||||||
if (root != archetypeType)
|
if (root != archetypeType)
|
||||||
return Type();
|
return Type();
|
||||||
|
|
||||||
auto locator = cs.getConstraintLocator({});
|
auto locator = cs.getConstraintLocator({});
|
||||||
auto replacement = cs.createTypeVariable(locator,
|
auto replacement = cs.createTypeVariable(locator,
|
||||||
TVO_CanBindToNoEscape);
|
TVO_CanBindToNoEscape);
|
||||||
@@ -1273,20 +1273,19 @@ void OverloadChoice::dump(Type adjustedOpenedType, SourceManager *sm,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Solution::dump() const {
|
void Solution::dump() const { dump(llvm::errs(), 0); }
|
||||||
dump(llvm::errs());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Solution::dump(raw_ostream &out) const {
|
void Solution::dump(raw_ostream &out, unsigned indent) const {
|
||||||
PrintOptions PO;
|
PrintOptions PO;
|
||||||
PO.PrintTypesForDebugging = true;
|
PO.PrintTypesForDebugging = true;
|
||||||
|
|
||||||
SourceManager *sm = &getConstraintSystem().getASTContext().SourceMgr;
|
SourceManager *sm = &getConstraintSystem().getASTContext().SourceMgr;
|
||||||
|
|
||||||
out << "Fixed score:";
|
out.indent(indent) << "Fixed score:";
|
||||||
FixedScore.print(out);
|
FixedScore.print(out);
|
||||||
|
|
||||||
out << "\nType variables:\n";
|
out << "\n";
|
||||||
|
out.indent(indent) << "Type variables:\n";
|
||||||
std::vector<std::pair<TypeVariableType *, Type>> bindings(
|
std::vector<std::pair<TypeVariableType *, Type>> bindings(
|
||||||
typeBindings.begin(), typeBindings.end());
|
typeBindings.begin(), typeBindings.end());
|
||||||
llvm::sort(bindings, [](const std::pair<TypeVariableType *, Type> &lhs,
|
llvm::sort(bindings, [](const std::pair<TypeVariableType *, Type> &lhs,
|
||||||
@@ -1295,7 +1294,7 @@ void Solution::dump(raw_ostream &out) const {
|
|||||||
});
|
});
|
||||||
for (auto binding : bindings) {
|
for (auto binding : bindings) {
|
||||||
auto &typeVar = binding.first;
|
auto &typeVar = binding.first;
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
Type(typeVar).print(out, PO);
|
Type(typeVar).print(out, PO);
|
||||||
out << " as ";
|
out << " as ";
|
||||||
binding.second.print(out, PO);
|
binding.second.print(out, PO);
|
||||||
@@ -1307,11 +1306,12 @@ void Solution::dump(raw_ostream &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!overloadChoices.empty()) {
|
if (!overloadChoices.empty()) {
|
||||||
out << "\nOverload choices:";
|
out << "\n";
|
||||||
|
out.indent(indent) << "Overload choices:";
|
||||||
for (auto ovl : overloadChoices) {
|
for (auto ovl : overloadChoices) {
|
||||||
if (ovl.first) {
|
if (ovl.first) {
|
||||||
out << "\n";
|
out << "\n";
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
ovl.first->dump(sm, out);
|
ovl.first->dump(sm, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1323,18 +1323,18 @@ void Solution::dump(raw_ostream &out) const {
|
|||||||
|
|
||||||
|
|
||||||
if (!ConstraintRestrictions.empty()) {
|
if (!ConstraintRestrictions.empty()) {
|
||||||
out << "\nConstraint restrictions:\n";
|
out.indent(indent) << "Constraint restrictions:\n";
|
||||||
for (auto &restriction : ConstraintRestrictions) {
|
for (auto &restriction : ConstraintRestrictions) {
|
||||||
out.indent(2) << restriction.first.first
|
out.indent(indent + 2)
|
||||||
<< " to " << restriction.first.second
|
<< restriction.first.first << " to " << restriction.first.second
|
||||||
<< " is " << getName(restriction.second) << "\n";
|
<< " is " << getName(restriction.second) << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!argumentMatchingChoices.empty()) {
|
if (!argumentMatchingChoices.empty()) {
|
||||||
out << "\nTrailing closure matching:\n";
|
out.indent(indent) << "Trailing closure matching:\n";
|
||||||
for (auto &argumentMatching : argumentMatchingChoices) {
|
for (auto &argumentMatching : argumentMatchingChoices) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
argumentMatching.first->dump(sm, out);
|
argumentMatching.first->dump(sm, out);
|
||||||
switch (argumentMatching.second.trailingClosureMatching) {
|
switch (argumentMatching.second.trailingClosureMatching) {
|
||||||
case TrailingClosureMatching::Forward:
|
case TrailingClosureMatching::Forward:
|
||||||
@@ -1348,18 +1348,18 @@ void Solution::dump(raw_ostream &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!DisjunctionChoices.empty()) {
|
if (!DisjunctionChoices.empty()) {
|
||||||
out << "\nDisjunction choices:\n";
|
out.indent(indent) << "Disjunction choices:\n";
|
||||||
for (auto &choice : DisjunctionChoices) {
|
for (auto &choice : DisjunctionChoices) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
choice.first->dump(sm, out);
|
choice.first->dump(sm, out);
|
||||||
out << " is #" << choice.second << "\n";
|
out << " is #" << choice.second << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!OpenedTypes.empty()) {
|
if (!OpenedTypes.empty()) {
|
||||||
out << "\nOpened types:\n";
|
out.indent(indent) << "Opened types:\n";
|
||||||
for (const auto &opened : OpenedTypes) {
|
for (const auto &opened : OpenedTypes) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
opened.first->dump(sm, out);
|
opened.first->dump(sm, out);
|
||||||
out << " opens ";
|
out << " opens ";
|
||||||
llvm::interleave(
|
llvm::interleave(
|
||||||
@@ -1391,9 +1391,9 @@ void Solution::dump(raw_ostream &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!OpenedExistentialTypes.empty()) {
|
if (!OpenedExistentialTypes.empty()) {
|
||||||
out << "\nOpened existential types:\n";
|
out.indent(indent) << "Opened existential types:\n";
|
||||||
for (const auto &openedExistential : OpenedExistentialTypes) {
|
for (const auto &openedExistential : OpenedExistentialTypes) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
openedExistential.first->dump(sm, out);
|
openedExistential.first->dump(sm, out);
|
||||||
out << " opens to " << openedExistential.second->getString(PO);
|
out << " opens to " << openedExistential.second->getString(PO);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
@@ -1401,18 +1401,19 @@ void Solution::dump(raw_ostream &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!DefaultedConstraints.empty()) {
|
if (!DefaultedConstraints.empty()) {
|
||||||
out << "\nDefaulted constraints: ";
|
out.indent(indent) << "Defaulted constraints: ";
|
||||||
interleave(DefaultedConstraints, [&](ConstraintLocator *locator) {
|
interleave(DefaultedConstraints, [&](ConstraintLocator *locator) {
|
||||||
locator->dump(sm, out);
|
locator->dump(sm, out);
|
||||||
}, [&] {
|
}, [&] {
|
||||||
out << ", ";
|
out << ", ";
|
||||||
});
|
});
|
||||||
|
out << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Fixes.empty()) {
|
if (!Fixes.empty()) {
|
||||||
out << "\nFixes:\n";
|
out.indent(indent) << "Fixes:\n";
|
||||||
for (auto *fix : Fixes) {
|
for (auto *fix : Fixes) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
fix->print(out);
|
fix->print(out);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
@@ -1444,7 +1445,8 @@ void ConstraintSystem::print(raw_ostream &out, Expr *E) const {
|
|||||||
return Type();
|
return Type();
|
||||||
};
|
};
|
||||||
|
|
||||||
E->dump(out, getTypeOfExpr, getTypeOfTypeRepr, getTypeOfKeyPathComponent);
|
E->dump(out, getTypeOfExpr, getTypeOfTypeRepr, getTypeOfKeyPathComponent,
|
||||||
|
solverState ? solverState->getCurrentIndent() : 0);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1453,13 +1455,15 @@ void ConstraintSystem::print(raw_ostream &out) const {
|
|||||||
PrintOptions PO;
|
PrintOptions PO;
|
||||||
PO.PrintTypesForDebugging = true;
|
PO.PrintTypesForDebugging = true;
|
||||||
|
|
||||||
out << "Score:";
|
auto indent = solverState ? solverState->getCurrentIndent() : 0;
|
||||||
|
out.indent(indent) << "Score:";
|
||||||
CurrentScore.print(out);
|
CurrentScore.print(out);
|
||||||
|
|
||||||
for (const auto &contextualTypeEntry : contextualTypes) {
|
for (const auto &contextualTypeEntry : contextualTypes) {
|
||||||
auto info = contextualTypeEntry.second.first;
|
auto info = contextualTypeEntry.second.first;
|
||||||
if (!info.getType().isNull()) {
|
if (!info.getType().isNull()) {
|
||||||
out << "\nContextual Type: " << info.getType().getString(PO);
|
out << "\n";
|
||||||
|
out.indent(indent) << "Contextual Type: " << info.getType().getString(PO);
|
||||||
if (TypeRepr *TR = info.typeLoc.getTypeRepr()) {
|
if (TypeRepr *TR = info.typeLoc.getTypeRepr()) {
|
||||||
out << " at ";
|
out << " at ";
|
||||||
TR->getSourceRange().print(out, getASTContext().SourceMgr, /*text*/false);
|
TR->getSourceRange().print(out, getASTContext().SourceMgr, /*text*/false);
|
||||||
@@ -1467,7 +1471,8 @@ void ConstraintSystem::print(raw_ostream &out) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "\nType Variables:\n";
|
out << "\n";
|
||||||
|
out.indent(indent) << "Type Variables:\n";
|
||||||
std::vector<TypeVariableType *> typeVariables(getTypeVariables().begin(),
|
std::vector<TypeVariableType *> typeVariables(getTypeVariables().begin(),
|
||||||
getTypeVariables().end());
|
getTypeVariables().end());
|
||||||
llvm::sort(typeVariables,
|
llvm::sort(typeVariables,
|
||||||
@@ -1475,7 +1480,7 @@ void ConstraintSystem::print(raw_ostream &out) const {
|
|||||||
return lhs->getID() < rhs->getID();
|
return lhs->getID() < rhs->getID();
|
||||||
});
|
});
|
||||||
for (auto tv : typeVariables) {
|
for (auto tv : typeVariables) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
auto rep = getRepresentative(tv);
|
auto rep = getRepresentative(tv);
|
||||||
if (rep == tv) {
|
if (rep == tv) {
|
||||||
if (auto fixed = getFixedType(tv)) {
|
if (auto fixed = getFixedType(tv)) {
|
||||||
@@ -1500,34 +1505,34 @@ void ConstraintSystem::print(raw_ostream &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!ActiveConstraints.empty()) {
|
if (!ActiveConstraints.empty()) {
|
||||||
out << "\nActive Constraints:\n";
|
out.indent(indent) << "Active Constraints:\n";
|
||||||
for (auto &constraint : ActiveConstraints) {
|
for (auto &constraint : ActiveConstraints) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
constraint.print(out, &getASTContext().SourceMgr);
|
constraint.print(out, &getASTContext().SourceMgr);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!InactiveConstraints.empty()) {
|
if (!InactiveConstraints.empty()) {
|
||||||
out << "\nInactive Constraints:\n";
|
out.indent(indent) << "Inactive Constraints:\n";
|
||||||
for (auto &constraint : InactiveConstraints) {
|
for (auto &constraint : InactiveConstraints) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
constraint.print(out, &getASTContext().SourceMgr);
|
constraint.print(out, &getASTContext().SourceMgr);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (solverState && solverState->hasRetiredConstraints()) {
|
if (solverState && solverState->hasRetiredConstraints()) {
|
||||||
out << "\nRetired Constraints:\n";
|
out.indent(indent) << "Retired Constraints:\n";
|
||||||
solverState->forEachRetired([&](Constraint &constraint) {
|
solverState->forEachRetired([&](Constraint &constraint) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
constraint.print(out, &getASTContext().SourceMgr);
|
constraint.print(out, &getASTContext().SourceMgr);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ResolvedOverloads.empty()) {
|
if (!ResolvedOverloads.empty()) {
|
||||||
out << "\nResolved overloads:\n";
|
out.indent(indent) << "Resolved overloads:\n";
|
||||||
|
|
||||||
// Otherwise, report the resolved overloads.
|
// Otherwise, report the resolved overloads.
|
||||||
for (auto elt : ResolvedOverloads) {
|
for (auto elt : ResolvedOverloads) {
|
||||||
@@ -1570,18 +1575,18 @@ void ConstraintSystem::print(raw_ostream &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!DisjunctionChoices.empty()) {
|
if (!DisjunctionChoices.empty()) {
|
||||||
out << "\nDisjunction choices:\n";
|
out.indent(indent) << "Disjunction choices:\n";
|
||||||
for (auto &choice : DisjunctionChoices) {
|
for (auto &choice : DisjunctionChoices) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
choice.first->dump(&getASTContext().SourceMgr, out);
|
choice.first->dump(&getASTContext().SourceMgr, out);
|
||||||
out << " is #" << choice.second << "\n";
|
out << " is #" << choice.second << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!OpenedTypes.empty()) {
|
if (!OpenedTypes.empty()) {
|
||||||
out << "\nOpened types:\n";
|
out.indent(indent) << "Opened types:\n";
|
||||||
for (const auto &opened : OpenedTypes) {
|
for (const auto &opened : OpenedTypes) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
opened.first->dump(&getASTContext().SourceMgr, out);
|
opened.first->dump(&getASTContext().SourceMgr, out);
|
||||||
out << " opens ";
|
out << " opens ";
|
||||||
llvm::interleave(
|
llvm::interleave(
|
||||||
@@ -1601,9 +1606,9 @@ void ConstraintSystem::print(raw_ostream &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!OpenedExistentialTypes.empty()) {
|
if (!OpenedExistentialTypes.empty()) {
|
||||||
out << "\nOpened existential types:\n";
|
out.indent(indent) << "Opened existential types:\n";
|
||||||
for (const auto &openedExistential : OpenedExistentialTypes) {
|
for (const auto &openedExistential : OpenedExistentialTypes) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
openedExistential.first->dump(&getASTContext().SourceMgr, out);
|
openedExistential.first->dump(&getASTContext().SourceMgr, out);
|
||||||
out << " opens to " << openedExistential.second->getString(PO);
|
out << " opens to " << openedExistential.second->getString(PO);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
@@ -1611,7 +1616,7 @@ void ConstraintSystem::print(raw_ostream &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!DefaultedConstraints.empty()) {
|
if (!DefaultedConstraints.empty()) {
|
||||||
out << "\nDefaulted constraints:\n";
|
out.indent(indent) << "Defaulted constraints:\n";
|
||||||
interleave(DefaultedConstraints, [&](ConstraintLocator *locator) {
|
interleave(DefaultedConstraints, [&](ConstraintLocator *locator) {
|
||||||
locator->dump(&getASTContext().SourceMgr, out);
|
locator->dump(&getASTContext().SourceMgr, out);
|
||||||
}, [&] {
|
}, [&] {
|
||||||
@@ -1621,16 +1626,16 @@ void ConstraintSystem::print(raw_ostream &out) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (failedConstraint) {
|
if (failedConstraint) {
|
||||||
out << "\nFailed constraint:\n";
|
out.indent(indent) << "Failed constraint:\n";
|
||||||
out.indent(2);
|
failedConstraint->print(out.indent(indent + 2), &getASTContext().SourceMgr,
|
||||||
failedConstraint->print(out, &getASTContext().SourceMgr);
|
indent + 2);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Fixes.empty()) {
|
if (!Fixes.empty()) {
|
||||||
out << "\nFixes:\n";
|
out.indent(indent) << "Fixes:\n";
|
||||||
for (auto *fix : Fixes) {
|
for (auto *fix : Fixes) {
|
||||||
out.indent(2);
|
out.indent(indent + 2);
|
||||||
fix->print(out);
|
fix->print(out);
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user