Skip to content

Commit 7ea641b

Browse files
author
Amritpan Kaur
committed
[Constraint] Eliminate repetitive locators to make useful information easier to read.
1 parent ed88700 commit 7ea641b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

include/swift/Sema/Constraint.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,10 @@ class Constraint final : public llvm::ilist_node<Constraint>,
852852
/// Clone the given constraint.
853853
Constraint *clone(ConstraintSystem &cs) const;
854854

855-
void print(llvm::raw_ostream &Out, SourceManager *sm) const;
855+
/// Print constraint placed on type and constraint properties.
856+
///
857+
/// \c skipLocator skips printing of locators.
858+
void print(llvm::raw_ostream &Out, SourceManager *sm, bool skipLocator = false) const;
856859

857860
SWIFT_DEBUG_DUMPER(dump(SourceManager *SM));
858861

lib/Sema/Constraint.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ Constraint *Constraint::clone(ConstraintSystem &cs) const {
322322
llvm_unreachable("Unhandled ConstraintKind in switch.");
323323
}
324324

325-
void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
325+
void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm, bool skipLocator) const {
326326
// Print all type variables as $T0 instead of _ here.
327327
PrintOptions PO;
328328
PO.PrintTypesForDebugging = true;
@@ -337,7 +337,8 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
337337
if (isIsolated())
338338
Out << " (isolated)";
339339

340-
if (Locator) {
340+
auto firstLocator = Locator;
341+
if (firstLocator) {
341342
Out << " [[";
342343
Locator->dump(sm, Out);
343344
Out << "]]";
@@ -352,7 +353,8 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
352353
Out << "> [favored] ";
353354
else
354355
Out << "> ";
355-
constraint->print(Out, sm);
356+
constraint->print(Out, sm,
357+
/*skipLocator=*/constraint->getLocator() == firstLocator);
356358
},
357359
[&] { Out << "\n"; });
358360
return;
@@ -522,7 +524,7 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
522524
fix->print(Out);
523525
}
524526

525-
if (Locator) {
527+
if (Locator && !skipLocator) {
526528
Out << " [[";
527529
Locator->dump(sm, Out);
528530
Out << "]];";

0 commit comments

Comments
 (0)