Skip to content

Commit 2786f24

Browse files
author
Amritpan Kaur
committed
[TypeCheckConstraints.cpp] Remove printing of any empty constraint choice headings and fix minor spacing issues.
1 parent 538ee30 commit 2786f24

File tree

5 files changed

+104
-92
lines changed

5 files changed

+104
-92
lines changed

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9149,9 +9149,9 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
91499149

91509150
auto &log = llvm::errs();
91519151
if (isPartial) {
9152-
log << "---Partially type-checked expression---\n";
9152+
log << "\n---Partially type-checked expression---\n";
91539153
} else {
9154-
log << "---Type-checked expression---\n";
9154+
log << "\n---Type-checked expression---\n";
91559155
}
91569156
resultExpr->dump(log);
91579157
log << "\n";
@@ -9229,7 +9229,7 @@ Optional<SolutionApplicationTarget> ConstraintSystem::applySolution(
92299229
auto node = target.getAsASTNode();
92309230
if (node && needsPostProcessing) {
92319231
auto &log = llvm::errs();
9232-
log << "---Fully type-checked target---\n";
9232+
log << "\n---Fully type-checked target---\n";
92339233
node.dump(log);
92349234
log << "\n";
92359235
}

lib/Sema/CSRanking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ ConstraintSystem::findBestSolution(SmallVectorImpl<Solution> &viable,
14201420

14211421
for (unsigned i = 0, n = viable.size(); i != n; ++i) {
14221422
llvm::errs().indent(solverState->depth * 2)
1423-
<< "--- Solution #" << i << " ---\n";
1423+
<< "\n--- Solution #" << i << " ---\n";
14241424
viable[i].dump(llvm::errs().indent(solverState->depth * 2));
14251425
}
14261426
}

lib/Sema/CSSolver.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ bool ConstraintSystem::Candidate::solve(
790790
log << "--- Solutions ---\n";
791791
for (unsigned i = 0, n = solutions.size(); i != n; ++i) {
792792
auto &solution = solutions[i];
793-
log << "--- Solution #" << i << " ---\n";
793+
log << "\n--- Solution #" << i << " ---\n";
794794
solution.dump(log);
795795
}
796796
}
@@ -1275,12 +1275,12 @@ Optional<std::vector<Solution>> ConstraintSystem::solve(
12751275
// Debug-print the set of solutions.
12761276
if (isDebugMode()) {
12771277
if (result.getKind() == SolutionResult::Success) {
1278-
llvm::errs() << "---Solution---\n";
1278+
llvm::errs() << "\n---Solution---\n";
12791279
result.getSolution().dump(llvm::errs());
12801280
} else if (result.getKind() == SolutionResult::Ambiguous) {
12811281
auto solutions = result.getAmbiguousSolutions();
12821282
for (unsigned i : indices(solutions)) {
1283-
llvm::errs() << "--- Solution #" << i << " ---\n";
1283+
llvm::errs() << "\n--- Solution #" << i << " ---\n";
12841284
solutions[i].dump(llvm::errs());
12851285
}
12861286
}
@@ -1418,7 +1418,7 @@ bool ConstraintSystem::solve(SmallVectorImpl<Solution> &solutions,
14181418

14191419
if (isDebugMode()) {
14201420
auto &log = llvm::errs();
1421-
log << "---Solver statistics---\n";
1421+
log << "\n---Solver statistics---\n";
14221422
log << "Total number of scopes explored: " << solverState->NumStatesExplored << "\n";
14231423
log << "Maximum depth reached while exploring solutions: " << solverState->maxDepth << "\n";
14241424
if (Timer) {

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4612,7 +4612,7 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
46124612
<< " solutions with fixes ---\n";
46134613
int i = 0;
46144614
for (auto &solution : solutions) {
4615-
log << "--- Solution #" << i++ << "---\n";
4615+
log << "\n--- Solution #" << i++ << "---\n";
46164616
solution.dump(log);
46174617
log << "\n";
46184618
}

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 95 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,9 +1238,9 @@ void Solution::dump(raw_ostream &out) const {
12381238

12391239
SourceManager *sm = &getConstraintSystem().getASTContext().SourceMgr;
12401240

1241-
out << "Fixed score: " << FixedScore << "\n";
1241+
out << "Fixed score: " << FixedScore;
12421242

1243-
out << "Type variables:\n";
1243+
out << "\nType variables:\n";
12441244
std::vector<std::pair<TypeVariableType *, Type>> bindings(
12451245
typeBindings.begin(), typeBindings.end());
12461246
llvm::sort(bindings, [](const std::pair<TypeVariableType *, Type> &lhs,
@@ -1260,77 +1260,85 @@ void Solution::dump(raw_ostream &out) const {
12601260
out << "\n";
12611261
}
12621262

1263-
out << "\n";
1264-
out << "Overload choices:\n";
1265-
for (auto ovl : overloadChoices) {
1266-
out.indent(2);
1267-
if (ovl.first)
1268-
ovl.first->dump(sm, out);
1269-
out << " with ";
1270-
1271-
auto choice = ovl.second.choice;
1272-
switch (choice.getKind()) {
1273-
case OverloadChoiceKind::Decl:
1274-
case OverloadChoiceKind::DeclViaDynamic:
1275-
case OverloadChoiceKind::DeclViaBridge:
1276-
case OverloadChoiceKind::DeclViaUnwrappedOptional:
1277-
choice.getDecl()->dumpRef(out);
1278-
out << " as ";
1279-
if (choice.getBaseType())
1280-
out << choice.getBaseType()->getString(PO) << ".";
1281-
1282-
out << choice.getDecl()->getBaseName() << ": "
1283-
<< ovl.second.adjustedOpenedType->getString(PO) << "\n";
1284-
break;
1263+
if (!overloadChoices.empty()) {
1264+
out << "\nOverload choices:";
1265+
for (auto ovl : overloadChoices) {
1266+
out.indent(2);
1267+
if (ovl.first) {
1268+
out << "\n";
1269+
ovl.first->dump(sm, out);
1270+
}
1271+
out << " with ";
12851272

1286-
case OverloadChoiceKind::KeyPathApplication:
1287-
out << "key path application root "
1288-
<< choice.getBaseType()->getString(PO) << "\n";
1289-
break;
1273+
auto choice = ovl.second.choice;
1274+
switch (choice.getKind()) {
1275+
case OverloadChoiceKind::Decl:
1276+
case OverloadChoiceKind::DeclViaDynamic:
1277+
case OverloadChoiceKind::DeclViaBridge:
1278+
case OverloadChoiceKind::DeclViaUnwrappedOptional:
1279+
choice.getDecl()->dumpRef(out);
1280+
out << " as ";
1281+
if (choice.getBaseType())
1282+
out << choice.getBaseType()->getString(PO) << ".";
12901283

1291-
case OverloadChoiceKind::DynamicMemberLookup:
1292-
case OverloadChoiceKind::KeyPathDynamicMemberLookup:
1293-
out << "dynamic member lookup root "
1294-
<< choice.getBaseType()->getString(PO)
1295-
<< " name='" << choice.getName() << "'\n";
1296-
break;
1297-
1298-
case OverloadChoiceKind::TupleIndex:
1299-
out << "tuple " << choice.getBaseType()->getString(PO) << " index "
1300-
<< choice.getTupleIndex() << "\n";
1301-
break;
1284+
out << choice.getDecl()->getBaseName() << ": "
1285+
<< ovl.second.adjustedOpenedType->getString(PO);
1286+
break;
1287+
1288+
case OverloadChoiceKind::KeyPathApplication:
1289+
out << "key path application root "
1290+
<< choice.getBaseType()->getString(PO);
1291+
break;
1292+
1293+
case OverloadChoiceKind::DynamicMemberLookup:
1294+
case OverloadChoiceKind::KeyPathDynamicMemberLookup:
1295+
out << "dynamic member lookup root "
1296+
<< choice.getBaseType()->getString(PO)
1297+
<< " name='" << choice.getName();
1298+
break;
1299+
1300+
case OverloadChoiceKind::TupleIndex:
1301+
out << "tuple " << choice.getBaseType()->getString(PO) << " index "
1302+
<< choice.getTupleIndex();
1303+
break;
1304+
}
13021305
}
13031306
out << "\n";
13041307
}
13051308

1306-
out << "\n";
1307-
out << "Constraint restrictions:\n";
1308-
for (auto &restriction : ConstraintRestrictions) {
1309-
out.indent(2) << restriction.first.first
1310-
<< " to " << restriction.first.second
1311-
<< " is " << getName(restriction.second) << "\n";
1309+
1310+
if (!ConstraintRestrictions.empty()) {
1311+
out << "\nConstraint restrictions:\n";
1312+
for (auto &restriction : ConstraintRestrictions) {
1313+
out.indent(2) << restriction.first.first
1314+
<< " to " << restriction.first.second
1315+
<< " is " << getName(restriction.second) << "\n";
1316+
}
13121317
}
13131318

1314-
out << "\n";
1315-
out << "Trailing closure matching:\n";
1316-
for (auto &argumentMatching : argumentMatchingChoices) {
1317-
out.indent(2);
1318-
argumentMatching.first->dump(sm, out);
1319-
switch (argumentMatching.second.trailingClosureMatching) {
1320-
case TrailingClosureMatching::Forward:
1321-
out << ": forward\n";
1322-
break;
1323-
case TrailingClosureMatching::Backward:
1324-
out << ": backward\n";
1325-
break;
1319+
if (!argumentMatchingChoices.empty()) {
1320+
out << "\nTrailing closure matching:\n";
1321+
for (auto &argumentMatching : argumentMatchingChoices) {
1322+
out.indent(2);
1323+
argumentMatching.first->dump(sm, out);
1324+
switch (argumentMatching.second.trailingClosureMatching) {
1325+
case TrailingClosureMatching::Forward:
1326+
out << ": forward\n";
1327+
break;
1328+
case TrailingClosureMatching::Backward:
1329+
out << ": backward\n";
1330+
break;
1331+
}
13261332
}
13271333
}
13281334

1329-
out << "\nDisjunction choices:\n";
1330-
for (auto &choice : DisjunctionChoices) {
1331-
out.indent(2);
1332-
choice.first->dump(sm, out);
1333-
out << " is #" << choice.second << "\n";
1335+
if (!DisjunctionChoices.empty()) {
1336+
out << "\nDisjunction choices:\n";
1337+
for (auto &choice : DisjunctionChoices) {
1338+
out.indent(2);
1339+
choice.first->dump(sm, out);
1340+
out << " is #" << choice.second << "\n";
1341+
}
13341342
}
13351343

13361344
if (!OpenedTypes.empty()) {
@@ -1413,20 +1421,21 @@ void ConstraintSystem::print(raw_ostream &out) const {
14131421
// Print all type variables as $T0 instead of _ here.
14141422
PrintOptions PO;
14151423
PO.PrintTypesForDebugging = true;
1416-
1417-
out << "Score: " << CurrentScore << "\n";
1424+
1425+
out << "Score: " << CurrentScore;
14181426

14191427
for (const auto &contextualTypeEntry : contextualTypes) {
14201428
auto info = contextualTypeEntry.second.first;
1421-
out << "Contextual Type: " << info.getType().getString(PO);
1422-
if (TypeRepr *TR = info.typeLoc.getTypeRepr()) {
1423-
out << " at ";
1424-
TR->getSourceRange().print(out, getASTContext().SourceMgr, /*text*/false);
1429+
if (!info.getType().isNull()) {
1430+
out << "\nContextual Type: " << info.getType().getString(PO);
1431+
if (TypeRepr *TR = info.typeLoc.getTypeRepr()) {
1432+
out << " at ";
1433+
TR->getSourceRange().print(out, getASTContext().SourceMgr, /*text*/false);
1434+
}
14251435
}
1426-
out << "\n";
14271436
}
14281437

1429-
out << "Type Variables:\n";
1438+
out << "\nType Variables:\n";
14301439
std::vector<TypeVariableType *> typeVariables(getTypeVariables().begin(),
14311440
getTypeVariables().end());
14321441
llvm::sort(typeVariables,
@@ -1457,18 +1466,22 @@ void ConstraintSystem::print(raw_ostream &out) const {
14571466
out << "\n";
14581467
}
14591468

1460-
out << "\nActive Constraints:\n";
1461-
for (auto &constraint : ActiveConstraints) {
1462-
out.indent(2);
1463-
constraint.print(out, &getASTContext().SourceMgr);
1464-
out << "\n";
1469+
if (!ActiveConstraints.empty()) {
1470+
out << "\nActive Constraints:\n";
1471+
for (auto &constraint : ActiveConstraints) {
1472+
out.indent(2);
1473+
constraint.print(out, &getASTContext().SourceMgr);
1474+
out << "\n";
1475+
}
14651476
}
14661477

1467-
out << "\nInactive Constraints:\n";
1468-
for (auto &constraint : InactiveConstraints) {
1469-
out.indent(2);
1470-
constraint.print(out, &getASTContext().SourceMgr);
1471-
out << "\n";
1478+
if (!InactiveConstraints.empty()) {
1479+
out << "\nInactive Constraints:\n";
1480+
for (auto &constraint : InactiveConstraints) {
1481+
out.indent(2);
1482+
constraint.print(out, &getASTContext().SourceMgr);
1483+
out << "\n";
1484+
}
14721485
}
14731486

14741487
if (solverState && solverState->hasRetiredConstraints()) {
@@ -1481,7 +1494,7 @@ void ConstraintSystem::print(raw_ostream &out) const {
14811494
}
14821495

14831496
if (!ResolvedOverloads.empty()) {
1484-
out << "Resolved overloads:\n";
1497+
out << "\nResolved overloads:\n";
14851498

14861499
// Otherwise, report the resolved overloads.
14871500
for (auto elt : ResolvedOverloads) {
@@ -1521,7 +1534,6 @@ void ConstraintSystem::print(raw_ostream &out) const {
15211534
elt.first->dump(&getASTContext().SourceMgr, out);
15221535
out << "\n";
15231536
}
1524-
out << "\n";
15251537
}
15261538

15271539
if (!DisjunctionChoices.empty()) {
@@ -1562,7 +1574,7 @@ void ConstraintSystem::print(raw_ostream &out) const {
15621574
}
15631575

15641576
if (!DefaultedConstraints.empty()) {
1565-
out << "\nDefaulted constraints: ";
1577+
out << "\nDefaulted constraints:\n";
15661578
interleave(DefaultedConstraints, [&](ConstraintLocator *locator) {
15671579
locator->dump(&getASTContext().SourceMgr, out);
15681580
}, [&] {

0 commit comments

Comments
 (0)