@@ -2247,32 +2247,32 @@ static bool shortCircuitDisjunctionAt(Constraint *constraint,
2247
2247
return false ;
2248
2248
}
2249
2249
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) {
2255
2252
for (auto &constraint : InactiveConstraints) {
2256
2253
if (constraint.getKind () == ConstraintKind::Disjunction)
2257
2254
disjunctions.push_back (&constraint);
2258
2255
}
2256
+ }
2259
2257
2258
+ std::pair<PotentialBindings, TypeVariableType *>
2259
+ determineBestBindings (ConstraintSystem &CS) {
2260
2260
// Look for potential type variable bindings.
2261
2261
TypeVariableType *bestTypeVar = nullptr ;
2262
2262
PotentialBindings bestBindings;
2263
- for (auto typeVar : TypeVariables ) {
2263
+ for (auto typeVar : CS. getTypeVariables () ) {
2264
2264
// Skip any type variables that are bound.
2265
2265
if (typeVar->getImpl ().hasRepresentativeOrFixed ())
2266
2266
continue ;
2267
2267
2268
2268
// Get potential bindings.
2269
- auto bindings = getPotentialBindings (* this , typeVar);
2269
+ auto bindings = getPotentialBindings (CS , typeVar);
2270
2270
if (!bindings)
2271
2271
continue ;
2272
2272
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 );
2276
2276
}
2277
2277
2278
2278
// If these are the first bindings, or they are better than what
@@ -2283,6 +2283,20 @@ bool ConstraintSystem::solveSimplified(
2283
2283
}
2284
2284
}
2285
2285
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
+
2286
2300
// If we have a binding that does not involve type variables, or we have
2287
2301
// no other option, go ahead and try the bindings for this type variable.
2288
2302
if (bestBindings &&
0 commit comments