@@ -359,6 +359,7 @@ StepResult ComponentStep::take(bool prevFailed) {
359
359
});
360
360
361
361
auto *disjunction = CS.selectDisjunction ();
362
+ auto *conjunction = CS.selectConjunction ();
362
363
363
364
if (CS.isDebugMode ()) {
364
365
if (!potentialBindings.empty ()) {
@@ -393,33 +394,45 @@ StepResult ComponentStep::take(bool prevFailed) {
393
394
}
394
395
}
395
396
396
- if (CS.shouldAttemptFixes ()) {
397
- if ((bestBindings &&
398
- (bestBindings->forClosureResult () ||
399
- bestBindings->forGenericParameter ()) &&
400
- bestBindings->isHole ()) &&
401
- !disjunction) {
402
- if (auto *conjunction = CS.selectConjunction ()) {
403
- return suspend (
404
- std::make_unique<ConjunctionStep>(CS, conjunction, Solutions));
405
- }
397
+ enum class StepKind { Binding, Disjunction, Conjunction };
398
+
399
+ auto chooseStep = [&]() -> Optional<StepKind> {
400
+ // Bindings usually happen first, but sometimes we want to prioritize a
401
+ // disjunction or conjunction.
402
+ if (bestBindings) {
403
+ if (disjunction && !bestBindings->favoredOverDisjunction (disjunction))
404
+ return StepKind::Disjunction;
405
+
406
+ if (conjunction && !bestBindings->favoredOverConjunction (conjunction))
407
+ return StepKind::Conjunction;
408
+
409
+ return StepKind::Binding;
410
+ }
411
+ if (disjunction)
412
+ return StepKind::Disjunction;
413
+
414
+ if (conjunction)
415
+ return StepKind::Conjunction;
416
+
417
+ return None;
418
+ };
419
+
420
+ if (auto step = chooseStep ()) {
421
+ switch (*step) {
422
+ case StepKind::Binding:
423
+ return suspend (
424
+ std::make_unique<TypeVariableStep>(*bestBindings, Solutions));
425
+ case StepKind::Disjunction:
426
+ return suspend (
427
+ std::make_unique<DisjunctionStep>(CS, disjunction, Solutions));
428
+ case StepKind::Conjunction:
429
+ return suspend (
430
+ std::make_unique<ConjunctionStep>(CS, conjunction, Solutions));
406
431
}
432
+ llvm_unreachable (" Unhandled case in switch!" );
407
433
}
408
434
409
- if (bestBindings &&
410
- (!disjunction || bestBindings->favoredOverDisjunction (disjunction))) {
411
- // Produce a type variable step.
412
- return suspend (
413
- std::make_unique<TypeVariableStep>(*bestBindings, Solutions));
414
- } else if (disjunction) {
415
- // Produce a disjunction step.
416
- return suspend (
417
- std::make_unique<DisjunctionStep>(CS, disjunction, Solutions));
418
- } else if (auto *conjunction = CS.selectConjunction ()) {
419
- return suspend (
420
- std::make_unique<ConjunctionStep>(CS, conjunction, Solutions));
421
- } else if (!CS.solverState ->allowsFreeTypeVariables () &&
422
- CS.hasFreeTypeVariables ()) {
435
+ if (!CS.solverState ->allowsFreeTypeVariables () && CS.hasFreeTypeVariables ()) {
423
436
// If there are no disjunctions or type variables to bind
424
437
// we can't solve this system unless we have free type variables
425
438
// allowed in the solution.
0 commit comments