From f3dd7f68a8070f44b2509d7ad1cbaba9c174d5ea Mon Sep 17 00:00:00 2001 From: Amritpan Kaur Date: Thu, 30 Jun 2022 19:03:17 -0700 Subject: [PATCH 1/3] [Constraint] Eliminate repetitive locators to make useful information easier to read. --- include/swift/Sema/Constraint.h | 5 ++++- lib/Sema/Constraint.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) 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..0e8c41cddd7e0 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; @@ -352,7 +352,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 +523,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 << "]];"; From e07f49d0e81cdcb6bb8248bc4e5d2c3ffc2d109d Mon Sep 17 00:00:00 2001 From: Amritpan Kaur Date: Fri, 1 Jul 2022 15:23:49 -0700 Subject: [PATCH 2/3] [Constraint] Sort constraint printing by favored, unmarked, and disabled in that order for printing only. --- lib/Sema/Constraint.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/Sema/Constraint.cpp b/lib/Sema/Constraint.cpp index 0e8c41cddd7e0..dd911b64fcb4e 100644 --- a/lib/Sema/Constraint.cpp +++ b/lib/Sema/Constraint.cpp @@ -343,8 +343,21 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm, bool skipLocat 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] "; From e23576fad700346011bf5c0cd0f335f88e8965d4 Mon Sep 17 00:00:00 2001 From: Amritpan Kaur Date: Tue, 5 Jul 2022 16:07:13 -0700 Subject: [PATCH 3/3] [Test] Remove locator information that no longer exists in Checks. --- test/Constraints/overload_filtering_objc.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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) }