@@ -2253,32 +2253,32 @@ static bool shortCircuitDisjunctionAt(Constraint *constraint,
2253
2253
return false ;
2254
2254
}
2255
2255
2256
- bool ConstraintSystem::solveSimplified (
2257
- SmallVectorImpl<Solution> &solutions,
2258
- FreeTypeVariableBinding allowFreeTypeVariables) {
2259
- // Collect disjunctions.
2260
- SmallVector<Constraint *, 4 > disjunctions;
2256
+ void ConstraintSystem::collectDisjunctions (
2257
+ SmallVectorImpl<Constraint *> &disjunctions) {
2261
2258
for (auto &constraint : InactiveConstraints) {
2262
2259
if (constraint.getKind () == ConstraintKind::Disjunction)
2263
2260
disjunctions.push_back (&constraint);
2264
2261
}
2262
+ }
2265
2263
2264
+ std::pair<PotentialBindings, TypeVariableType *>
2265
+ determineBestBindings (ConstraintSystem &CS) {
2266
2266
// Look for potential type variable bindings.
2267
2267
TypeVariableType *bestTypeVar = nullptr ;
2268
2268
PotentialBindings bestBindings;
2269
- for (auto typeVar : TypeVariables ) {
2269
+ for (auto typeVar : CS. getTypeVariables () ) {
2270
2270
// Skip any type variables that are bound.
2271
2271
if (typeVar->getImpl ().hasRepresentativeOrFixed ())
2272
2272
continue ;
2273
2273
2274
2274
// Get potential bindings.
2275
- auto bindings = getPotentialBindings (* this , typeVar);
2275
+ auto bindings = getPotentialBindings (CS , typeVar);
2276
2276
if (!bindings)
2277
2277
continue ;
2278
2278
2279
- if (TC.getLangOpts ().DebugConstraintSolver ) {
2280
- auto &log = getASTContext ().TypeCheckerDebug ->getStream ();
2281
- bindings.dump (typeVar, log, solverState->depth * 2 );
2279
+ if (CS. TC .getLangOpts ().DebugConstraintSolver ) {
2280
+ auto &log = CS. getASTContext ().TypeCheckerDebug ->getStream ();
2281
+ bindings.dump (typeVar, log, CS. solverState ->depth * 2 );
2282
2282
}
2283
2283
2284
2284
// If these are the first bindings, or they are better than what
@@ -2289,6 +2289,20 @@ bool ConstraintSystem::solveSimplified(
2289
2289
}
2290
2290
}
2291
2291
2292
+ return std::make_pair (bestBindings, bestTypeVar);
2293
+ }
2294
+
2295
+ bool ConstraintSystem::solveSimplified (
2296
+ SmallVectorImpl<Solution> &solutions,
2297
+ FreeTypeVariableBinding allowFreeTypeVariables) {
2298
+
2299
+ SmallVector<Constraint *, 4 > disjunctions;
2300
+ collectDisjunctions (disjunctions);
2301
+
2302
+ TypeVariableType *bestTypeVar = nullptr ;
2303
+ PotentialBindings bestBindings;
2304
+ std::tie (bestBindings, bestTypeVar) = determineBestBindings (*this );
2305
+
2292
2306
// If we have a binding that does not involve type variables, or we have
2293
2307
// no other option, go ahead and try the bindings for this type variable.
2294
2308
if (bestBindings &&
0 commit comments