Skip to content

Commit 0029ba2

Browse files
authored
Merge pull request swiftlang#5785 from rudkx/minor-cleanup
2 parents 85f7ddd + 8b2bfcb commit 0029ba2

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2247,32 +2247,32 @@ static bool shortCircuitDisjunctionAt(Constraint *constraint,
22472247
return false;
22482248
}
22492249

2250-
bool ConstraintSystem::solveSimplified(
2251-
SmallVectorImpl<Solution> &solutions,
2252-
FreeTypeVariableBinding allowFreeTypeVariables) {
2253-
// Collect disjunctions.
2254-
SmallVector<Constraint *, 4> disjunctions;
2250+
void ConstraintSystem::collectDisjunctions(
2251+
SmallVectorImpl<Constraint *> &disjunctions) {
22552252
for (auto &constraint : InactiveConstraints) {
22562253
if (constraint.getKind() == ConstraintKind::Disjunction)
22572254
disjunctions.push_back(&constraint);
22582255
}
2256+
}
22592257

2258+
std::pair<PotentialBindings, TypeVariableType *>
2259+
determineBestBindings(ConstraintSystem &CS) {
22602260
// Look for potential type variable bindings.
22612261
TypeVariableType *bestTypeVar = nullptr;
22622262
PotentialBindings bestBindings;
2263-
for (auto typeVar : TypeVariables) {
2263+
for (auto typeVar : CS.getTypeVariables()) {
22642264
// Skip any type variables that are bound.
22652265
if (typeVar->getImpl().hasRepresentativeOrFixed())
22662266
continue;
22672267

22682268
// Get potential bindings.
2269-
auto bindings = getPotentialBindings(*this, typeVar);
2269+
auto bindings = getPotentialBindings(CS, typeVar);
22702270
if (!bindings)
22712271
continue;
22722272

2273-
if (TC.getLangOpts().DebugConstraintSolver) {
2274-
auto &log = getASTContext().TypeCheckerDebug->getStream();
2275-
bindings.dump(typeVar, log, solverState->depth * 2);
2273+
if (CS.TC.getLangOpts().DebugConstraintSolver) {
2274+
auto &log = CS.getASTContext().TypeCheckerDebug->getStream();
2275+
bindings.dump(typeVar, log, CS.solverState->depth * 2);
22762276
}
22772277

22782278
// If these are the first bindings, or they are better than what
@@ -2283,6 +2283,20 @@ bool ConstraintSystem::solveSimplified(
22832283
}
22842284
}
22852285

2286+
return std::make_pair(bestBindings, bestTypeVar);
2287+
}
2288+
2289+
bool ConstraintSystem::solveSimplified(
2290+
SmallVectorImpl<Solution> &solutions,
2291+
FreeTypeVariableBinding allowFreeTypeVariables) {
2292+
2293+
SmallVector<Constraint *, 4> disjunctions;
2294+
collectDisjunctions(disjunctions);
2295+
2296+
TypeVariableType *bestTypeVar = nullptr;
2297+
PotentialBindings bestBindings;
2298+
std::tie(bestBindings, bestTypeVar) = determineBestBindings(*this);
2299+
22862300
// If we have a binding that does not involve type variables, or we have
22872301
// no other option, go ahead and try the bindings for this type variable.
22882302
if (bestBindings &&

lib/Sema/ConstraintSystem.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,9 @@ class ConstraintSystem {
20312031
ConstraintLocatorBuilder locator,
20322032
bool isFavored);
20332033

2034+
/// \brief Collect the current inactive disjunciton constraints.
2035+
void collectDisjunctions(SmallVectorImpl<Constraint *> &disjunctions);
2036+
20342037
/// \brief Solve the system of constraints after it has already been
20352038
/// simplified.
20362039
///

0 commit comments

Comments
 (0)