Skip to content

Commit

Permalink
[ConstraintSolver] NFC: Prettify output of bindings in `PotentialBi…
Browse files Browse the repository at this point in the history
…ndings`
  • Loading branch information
xedin committed Sep 28, 2017
1 parent 42541ee commit c08610b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
55 changes: 26 additions & 29 deletions lib/Sema/ConstraintSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2641,35 +2641,32 @@ class ConstraintSystem {
if (NumDefaultableBindings > 0)
out << "#defaultable_bindings=" << NumDefaultableBindings << " ";

out << "bindings=";
if (!Bindings.empty()) {
interleave(Bindings,
[&](const PotentialBinding &binding) {
auto type = binding.BindingType;
auto &ctx = type->getASTContext();
llvm::SaveAndRestore<bool> debugConstraints(
ctx.LangOpts.DebugConstraintSolver, true);
switch (binding.Kind) {
case AllowedBindingKind::Exact:
break;

case AllowedBindingKind::Subtypes:
out << "(subtypes of) ";
break;

case AllowedBindingKind::Supertypes:
out << "(supertypes of) ";
break;
}
if (binding.DefaultedProtocol)
out << "(default from "
<< (*binding.DefaultedProtocol)->getName() << ") ";
out << type.getString();
},
[&]() { out << " "; });
} else {
out << "{}";
}
out << "bindings={";
interleave(Bindings,
[&](const PotentialBinding &binding) {
auto type = binding.BindingType;
auto &ctx = type->getASTContext();
llvm::SaveAndRestore<bool> debugConstraints(
ctx.LangOpts.DebugConstraintSolver, true);
switch (binding.Kind) {
case AllowedBindingKind::Exact:
break;

case AllowedBindingKind::Subtypes:
out << "(subtypes of) ";
break;

case AllowedBindingKind::Supertypes:
out << "(supertypes of) ";
break;
}
if (binding.DefaultedProtocol)
out << "(default from "
<< (*binding.DefaultedProtocol)->getName() << ") ";
out << type.getString();
},
[&]() { out << "; "; });
out << "}";
}

void dump(ConstraintSystem *cs,
Expand Down
18 changes: 9 additions & 9 deletions test/Constraints/interpolation_segments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@
// CHECK-NEXT: 9:

// CHECK: (solving component #
// CHECK: literal=3 bindings=(subtypes of) (default from ExpressibleByStringLiteral) String)
// CHECK: literal=3 bindings={(subtypes of) (default from ExpressibleByStringLiteral) String})

// CHECK: (solving component #
// CHECK: literal=3 bindings=(subtypes of) (default from ExpressibleByIntegerLiteral) Int)
// CHECK: literal=3 bindings={(subtypes of) (default from ExpressibleByIntegerLiteral) Int})

// CHECK: (solving component #
// CHECK: literal=3 bindings=(subtypes of) (default from ExpressibleByStringLiteral) String)
// CHECK: literal=3 bindings={(subtypes of) (default from ExpressibleByStringLiteral) String})

// CHECK: (solving component #
// CHECK: literal=3 bindings=(subtypes of) (default from ExpressibleByIntegerLiteral) Int)
// CHECK: literal=3 bindings={(subtypes of) (default from ExpressibleByIntegerLiteral) Int})

// CHECK: (solving component #
// CHECK: literal=3 bindings=(subtypes of) (default from ExpressibleByStringLiteral) String)
// CHECK: literal=3 bindings={(subtypes of) (default from ExpressibleByStringLiteral) String})

// CHECK: (solving component #
// CHECK: literal=3 bindings=(subtypes of) (default from ExpressibleByIntegerLiteral) Int)
// CHECK: literal=3 bindings={(subtypes of) (default from ExpressibleByIntegerLiteral) Int})

// CHECK: (solving component #
// CHECK: literal=3 bindings=(subtypes of) (default from ExpressibleByStringLiteral) String)
// CHECK: literal=3 bindings={(subtypes of) (default from ExpressibleByStringLiteral) String})

// CHECK: (solving component #
// CHECK: literal=3 bindings=(subtypes of) (default from ExpressibleByIntegerLiteral) Int)
// CHECK: literal=3 bindings={(subtypes of) (default from ExpressibleByIntegerLiteral) Int})

// CHECK: (solving component #
// CHECK: literal=3 bindings=(subtypes of) (default from ExpressibleByStringLiteral) String)
// CHECK: literal=3 bindings={(subtypes of) (default from ExpressibleByStringLiteral) String})

_ = "\(1), \(2), \(3), \(4)"

0 comments on commit c08610b

Please sign in to comment.