Skip to content

Commit 9086b2b

Browse files
committed
[Constraint solver] Flatten the disjunction created by call favoring.
The call-favoring code was creating a two-level disjunction, when would then immediately get flattened into a single level. Instead, create a single-level disjunction directly.
1 parent ae4949d commit 9086b2b

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

lib/Sema/CSGen.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,10 @@ namespace {
640640
return;
641641
auto decl = oldConstraint->getOverloadChoice().getDecl();
642642
if (!decl->getAttrs().isUnavailable(CS.getASTContext()) &&
643-
isFavored(decl))
643+
isFavored(decl)) {
644644
favoredConstraints.push_back(oldConstraint);
645-
else
645+
oldConstraint->setFavored();
646+
} else
646647
fallbackConstraints.push_back(oldConstraint);
647648
}
648649

@@ -660,23 +661,13 @@ namespace {
660661
// list and add the new one.
661662
CS.removeInactiveConstraint(disjunction);
662663

663-
// Create the disjunction of favored constraints.
664-
auto favoredConstraintsDisjunction =
665-
Constraint::createDisjunction(CS, favoredConstraints, csLoc);
666-
favoredConstraintsDisjunction->setFavored();
667-
668664
llvm::SmallVector<Constraint *, 2> aggregateConstraints;
669-
aggregateConstraints.push_back(favoredConstraintsDisjunction);
670-
671-
if (!fallbackConstraints.empty()) {
672-
// Find the disjunction of fallback constraints. If any
673-
// constraints were added here, create a new disjunction.
674-
Constraint *fallbackConstraintsDisjunction =
675-
Constraint::createDisjunction(CS, fallbackConstraints, csLoc);
676-
677-
aggregateConstraints.push_back(fallbackConstraintsDisjunction);
678-
}
679-
665+
aggregateConstraints.insert(aggregateConstraints.end(),
666+
favoredConstraints.begin(),
667+
favoredConstraints.end());
668+
aggregateConstraints.insert(aggregateConstraints.end(),
669+
fallbackConstraints.begin(),
670+
fallbackConstraints.end());
680671
CS.addDisjunctionConstraint(aggregateConstraints, csLoc);
681672
}
682673

0 commit comments

Comments
 (0)