[CSStep] Don't favor choices until the disjunction is picked

This commit is contained in:
Pavel Yaskevich
2023-02-10 14:54:06 -08:00
parent a094c3ebb0
commit e404ed722a
4 changed files with 34 additions and 22 deletions

View File

@@ -468,15 +468,16 @@ selectBestBindingDisjunction(ConstraintSystem &cs,
return firstBindDisjunction;
}
Constraint *ConstraintSystem::selectDisjunction() {
Optional<std::pair<Constraint *, llvm::TinyPtrVector<Constraint *>>>
ConstraintSystem::selectDisjunction() {
SmallVector<Constraint *, 4> disjunctions;
collectDisjunctions(disjunctions);
if (disjunctions.empty())
return nullptr;
return None;
if (auto *disjunction = selectBestBindingDisjunction(*this, disjunctions))
return disjunction;
return std::make_pair(disjunction, llvm::TinyPtrVector<Constraint *>());
llvm::DenseMap<Constraint *, llvm::TinyPtrVector<Constraint *>> favorings;
determineBestChoicesInContext(*this, disjunctions, favorings);
@@ -508,14 +509,8 @@ Constraint *ConstraintSystem::selectDisjunction() {
return firstFavored < secondFavored;
});
if (bestDisjunction != disjunctions.end()) {
// If selected disjunction has any choices that should be favored
// let's record them now.
for (auto *choice : favorings[*bestDisjunction])
favorConstraint(choice);
if (bestDisjunction != disjunctions.end())
return std::make_pair(*bestDisjunction, favorings[*bestDisjunction]);
return *bestDisjunction;
}
return nullptr;
return None;
}