@@ -7644,6 +7644,38 @@ Type ConstraintSystem::simplifyAppliedOverloads(
7644
7644
getUnboundBindOverloadDisjunction (fnTypeVar, &numOptionalUnwraps);
7645
7645
if (!disjunction) return fnType;
7646
7646
7647
+ if (shouldAttemptFixes ()) {
7648
+ auto arguments = argFnType->getParams ();
7649
+ bool allHoles =
7650
+ arguments.size () > 0 &&
7651
+ llvm::all_of (arguments, [&](const AnyFunctionType::Param &arg) -> bool {
7652
+ auto argType = arg.getPlainType ();
7653
+ if (argType->isHole ())
7654
+ return true ;
7655
+
7656
+ if (auto *typeVar = argType->getAs <TypeVariableType>())
7657
+ return hasFixFor (typeVar->getImpl ().getLocator ());
7658
+
7659
+ return false ;
7660
+ });
7661
+
7662
+ // If all of the arguments are holes, let's disable all but one
7663
+ // overload to make sure holes don't cause performance problems
7664
+ // because hole could be bound to any type.
7665
+ if (allHoles) {
7666
+ auto choices = disjunction->getNestedConstraints ();
7667
+ for (auto *choice : choices.slice (1 ))
7668
+ choice->setDisabled ();
7669
+ }
7670
+
7671
+ // Don't attempt further optimization in "diagnostic mode" because
7672
+ // in such mode we'd like to attempt all of the available overloads
7673
+ // regardless of problems related to missing or extraneous labels
7674
+ // and/or arguments.
7675
+ if (solverState)
7676
+ return fnTypeVar;
7677
+ }
7678
+
7647
7679
// / The common result type amongst all function overloads.
7648
7680
Type commonResultType;
7649
7681
auto updateCommonResultType = [&](Type choiceType) {
@@ -7842,20 +7874,14 @@ ConstraintSystem::simplifyApplicableFnConstraint(
7842
7874
7843
7875
};
7844
7876
7845
- // Don't attempt this optimization in "diagnostic mode" because
7846
- // in such mode we'd like to attempt all of the available
7847
- // overloads regardless of problems related to missing or
7848
- // extraneous labels and/or arguments.
7849
- if (!(solverState && shouldAttemptFixes ())) {
7850
- // If the right-hand side is a type variable,
7851
- // try to simplify the overload set.
7852
- if (auto typeVar = desugar2->getAs <TypeVariableType>()) {
7853
- Type newType2 = simplifyAppliedOverloads (typeVar, func1, locator);
7854
- if (!newType2)
7855
- return SolutionKind::Error;
7877
+ // If the right-hand side is a type variable,
7878
+ // try to simplify the overload set.
7879
+ if (auto typeVar = desugar2->getAs <TypeVariableType>()) {
7880
+ Type newType2 = simplifyAppliedOverloads (typeVar, func1, locator);
7881
+ if (!newType2)
7882
+ return SolutionKind::Error;
7856
7883
7857
- desugar2 = newType2->getDesugaredType ();
7858
- }
7884
+ desugar2 = newType2->getDesugaredType ();
7859
7885
}
7860
7886
7861
7887
// If right-hand side is a type variable, the constraint is unsolved.
0 commit comments