diff --git a/include/swift/Sema/Constraint.h b/include/swift/Sema/Constraint.h index 5b1f53ee6923e..b0b166e2d105f 100644 --- a/include/swift/Sema/Constraint.h +++ b/include/swift/Sema/Constraint.h @@ -852,7 +852,10 @@ class Constraint final : public llvm::ilist_node, /// Clone the given constraint. Constraint *clone(ConstraintSystem &cs) const; - void print(llvm::raw_ostream &Out, SourceManager *sm) const; + /// Print constraint placed on type and constraint properties. + /// + /// \c skipLocator skips printing of locators. + void print(llvm::raw_ostream &Out, SourceManager *sm, bool skipLocator = false) const; SWIFT_DEBUG_DUMPER(dump(SourceManager *SM)); diff --git a/lib/Sema/Constraint.cpp b/lib/Sema/Constraint.cpp index 0bcc6842449f2..dd911b64fcb4e 100644 --- a/lib/Sema/Constraint.cpp +++ b/lib/Sema/Constraint.cpp @@ -322,7 +322,7 @@ Constraint *Constraint::clone(ConstraintSystem &cs) const { llvm_unreachable("Unhandled ConstraintKind in switch."); } -void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const { +void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm, bool skipLocator) const { // Print all type variables as $T0 instead of _ here. PrintOptions PO; PO.PrintTypesForDebugging = true; @@ -343,8 +343,21 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const { Out << "]]"; } Out << ":\n"; - - interleave(getNestedConstraints(), + + // Sort constraints by favored, unmarked, disabled + // for printing only. + std::vector sortedConstraints(getNestedConstraints().begin(), + getNestedConstraints().end()); + llvm::sort(sortedConstraints, + [](const Constraint *lhs, const Constraint *rhs) { + if (lhs->isFavored() != rhs->isFavored()) + return lhs->isFavored(); + if (lhs->isDisabled() != rhs->isDisabled()) + return rhs->isDisabled(); + return false; + }); + + interleave(sortedConstraints, [&](Constraint *constraint) { if (constraint->isDisabled()) Out << "> [disabled] "; @@ -352,7 +365,8 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const { Out << "> [favored] "; else Out << "> "; - constraint->print(Out, sm); + constraint->print(Out, sm, + /*skipLocator=*/constraint->getLocator() == Locator); }, [&] { Out << "\n"; }); return; @@ -522,7 +536,7 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const { fix->print(Out); } - if (Locator) { + if (Locator && !skipLocator) { Out << " [["; Locator->dump(sm, Out); Out << "]];"; diff --git a/test/Constraints/overload_filtering_objc.swift b/test/Constraints/overload_filtering_objc.swift index 386b3579bc728..7940c8d262225 100644 --- a/test/Constraints/overload_filtering_objc.swift +++ b/test/Constraints/overload_filtering_objc.swift @@ -25,10 +25,10 @@ func testOptional(obj: P) { func test_double_cgfloat_conversion_filtering(d: Double, cgf: CGFloat) { - // CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).CGFloat.init(_:)@{{.*}} : (CGFloat.Type) -> (Double) -> CGFloat {{.*}} -> implicit conversion [Double-to-CGFloat] -> apply function -> constructor member + // CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).CGFloat.init(_:)@{{.*}} : (CGFloat.Type) -> (Double) -> CGFloat let _: CGFloat = d - // CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).Double extension.init(_:)@{{.*}} : (Double.Type) -> (CGFloat) -> Double {{.*}} -> implicit conversion [CGFloat-to-Double] -> apply function -> constructor member + // CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).Double extension.init(_:)@{{.*}} : (Double.Type) -> (CGFloat) -> Double let _: Double = cgf func test_optional_cgf(_: CGFloat??) { @@ -37,9 +37,9 @@ func test_double_cgfloat_conversion_filtering(d: Double, cgf: CGFloat) { func test_optional_double(_: Double??) { } - // CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).CGFloat.init(_:)@{{.*}} : (CGFloat.Type) -> (Double) -> CGFloat {{.*}} -> implicit conversion [Double-to-CGFloat] -> apply function -> constructor member + // CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).CGFloat.init(_:)@{{.*}} : (CGFloat.Type) -> (Double) -> CGFloat test_optional_cgf(d) - // CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).Double extension.init(_:)@{{.*}} : (Double.Type) -> (CGFloat) -> Double {{.*}} -> implicit conversion [CGFloat-to-Double] -> apply function -> constructor member + // CHECK: [favored] $T{{.*}} bound to decl CoreGraphics.(file).Double extension.init(_:)@{{.*}} : (Double.Type) -> (CGFloat) -> Double test_optional_double(cgf) }