Skip to content

Commit 05270c9

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

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

include/swift/Sema/Constraint.h

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

855-
/// Prints constraint placed on type and constraint properties
855+
/// Print constraint placed on type and constraint properties.
856856
///
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;
857+
/// \c skipLocator skips printing of repetitive locators.
858+
void print(llvm::raw_ostream &Out, SourceManager *sm, bool skipLocator = false) const;
860859

861860
SWIFT_DEBUG_DUMPER(dump(SourceManager *SM));
862861

lib/Sema/Constraint.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,11 @@ 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, bool repeatedLocator) 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;
329329

330-
ConstraintLocator *firstLocator;
331330
if (Kind == ConstraintKind::Disjunction ||
332331
Kind == ConstraintKind::Conjunction) {
333332
Out << (Kind == ConstraintKind::Disjunction ? "disjunction"
@@ -338,8 +337,8 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm, bool repeatedL
338337
if (isIsolated())
339338
Out << " (isolated)";
340339

341-
firstLocator = Locator;
342-
if (Locator) {
340+
auto firstLocator = Locator;
341+
if (firstLocator) {
343342
Out << " [[";
344343
Locator->dump(sm, Out);
345344
Out << "]]";
@@ -354,11 +353,8 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm, bool repeatedL
354353
Out << "> [favored] ";
355354
else
356355
Out << "> ";
357-
if (constraint->getLocator() == firstLocator) {
358-
constraint->print(Out, sm, true);
359-
} else {
360-
constraint->print(Out, sm);
361-
}
356+
constraint->print(Out, sm,
357+
/*skipLocator=*/constraint->getLocator() == firstLocator);
362358
},
363359
[&] { Out << "\n"; });
364360
return;
@@ -528,7 +524,7 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm, bool repeatedL
528524
fix->print(Out);
529525
}
530526

531-
if (Locator && !repeatedLocator) {
527+
if (Locator && !skipLocator) {
532528
Out << " [[";
533529
Locator->dump(sm, Out);
534530
Out << "]];";

0 commit comments

Comments
 (0)