Skip to content

Commit afb9f19

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

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

include/swift/Sema/Constraint.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,11 @@ 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+
/// Prints constraint placed on type and constraint properties
856+
///
857+
/// \c repeatedLocator checks if current locator is repeated in
858+
/// preceding constraint and prevents repetitive locator printing.
859+
void print(llvm::raw_ostream &Out, SourceManager *sm, bool repeatedLocator = false) const;
856860

857861
SWIFT_DEBUG_DUMPER(dump(SourceManager *SM));
858862

lib/Sema/Constraint.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,12 @@ 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 repeatedLocator) const {
326326
// Print all type variables as $T0 instead of _ here.
327327
PrintOptions PO;
328328
PO.PrintTypesForDebugging = true;
329329

330+
ConstraintLocator *firstLocator;
330331
if (Kind == ConstraintKind::Disjunction ||
331332
Kind == ConstraintKind::Conjunction) {
332333
Out << (Kind == ConstraintKind::Disjunction ? "disjunction"
@@ -337,6 +338,7 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
337338
if (isIsolated())
338339
Out << " (isolated)";
339340

341+
firstLocator = Locator;
340342
if (Locator) {
341343
Out << " [[";
342344
Locator->dump(sm, Out);
@@ -352,7 +354,11 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
352354
Out << "> [favored] ";
353355
else
354356
Out << "> ";
357+
if (constraint->getLocator() == firstLocator) {
358+
constraint->print(Out, sm, true);
359+
} else {
355360
constraint->print(Out, sm);
361+
}
356362
},
357363
[&] { Out << "\n"; });
358364
return;
@@ -522,7 +528,7 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
522528
fix->print(Out);
523529
}
524530

525-
if (Locator) {
531+
if (Locator && !repeatedLocator) {
526532
Out << " [[";
527533
Locator->dump(sm, Out);
528534
Out << "]];";

0 commit comments

Comments
 (0)