@@ -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 << " \n Type 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 << " \n Overload 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 << " \n Constraint 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 << " \n Trailing 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 << " \n Disjunction 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 << " \n Disjunction 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 << " \n Contextual 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 << " \n Type 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 << " \n Active 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 << " \n Active 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 << " \n Inactive 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 << " \n Inactive 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 << " \n Resolved 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 << " \n Defaulted constraints: " ;
1577+ out << " \n Defaulted constraints:\n " ;
15661578 interleave (DefaultedConstraints, [&](ConstraintLocator *locator) {
15671579 locator->dump (&getASTContext ().SourceMgr , out);
15681580 }, [&] {
0 commit comments