@@ -8364,8 +8364,9 @@ ConstraintSystem::simplifyConstructionConstraint(
83648364 paramTypeVar, locator);
83658365 }
83668366
8367- addConstraint(ConstraintKind::ApplicableFunction, fnType, memberType,
8368- fnLocator);
8367+ addApplicationConstraint(fnType, memberType,
8368+ /*trailingClosureMatching=*/std::nullopt, useDC,
8369+ fnLocator);
83698370
83708371 return SolutionKind::Solved;
83718372}
@@ -13108,6 +13109,7 @@ createImplicitRootForCallAsFunction(ConstraintSystem &cs, Type refType,
1310813109ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
1310913110 Type type1, Type type2,
1311013111 std::optional<TrailingClosureMatching> trailingClosureMatching,
13112+ DeclContext *useDC,
1311113113 TypeMatchOptions flags, ConstraintLocatorBuilder locator) {
1311213114 auto &ctx = getASTContext();
1311313115
@@ -13171,7 +13173,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
1317113173 auto formUnsolved = [&](bool activate = false) {
1317213174 if (flags.contains(TMF_GenerateConstraints)) {
1317313175 auto *application = Constraint::createApplicableFunction(
13174- *this, type1, type2, trailingClosureMatching,
13176+ *this, type1, type2, trailingClosureMatching, useDC,
1317513177 getConstraintLocator(locator));
1317613178
1317713179 addUnsolvedConstraint(application);
@@ -13232,8 +13234,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
1323213234 /*outerAlternatives*/ {}, memberLoc);
1323313235 // Add new applicable function constraint based on the member type
1323413236 // variable.
13235- addConstraint(ConstraintKind::ApplicableFunction, func1, memberTy,
13236- locator);
13237+ addApplicationConstraint( func1, memberTy, trailingClosureMatching, useDC ,
13238+ locator);
1323713239 return SolutionKind::Solved;
1323813240 }
1323913241
@@ -13348,9 +13350,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
1334813350 // Form an unsolved constraint to apply trailing closures to a
1334913351 // callable type produced by `.init`. This constraint would become
1335013352 // active when `callableType` is bound.
13351- addUnsolvedConstraint(Constraint::create (
13352- *this, ConstraintKind::ApplicableFunction, callAsFunctionArguments ,
13353- callableType ,
13353+ addUnsolvedConstraint(Constraint::createApplicableFunction (
13354+ *this, callAsFunctionArguments, callableType ,
13355+ trailingClosureMatching, useDC ,
1335413356 getConstraintLocator(implicitRef,
1335513357 ConstraintLocator::ApplyFunction)));
1335613358 break;
@@ -13368,12 +13370,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
1336813370
1336913371 auto applyLocator = getConstraintLocator(locator);
1337013372 auto forwardConstraint = Constraint::createApplicableFunction(
13371- *this, type1, type2, TrailingClosureMatching::Forward, applyLocator);
13373+ *this, type1, type2, TrailingClosureMatching::Forward, useDC,
13374+ applyLocator);
1337213375 auto backwardConstraint = Constraint::createApplicableFunction(
13373- *this, type1, type2, TrailingClosureMatching::Backward,
13376+ *this, type1, type2, TrailingClosureMatching::Backward, useDC,
1337413377 applyLocator);
13375- addDisjunctionConstraint(
13376- { forwardConstraint, backwardConstraint}, applyLocator);
13378+ addDisjunctionConstraint({forwardConstraint, backwardConstraint},
13379+ applyLocator);
1337713380 break;
1337813381 }
1337913382
@@ -13450,7 +13453,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
1345013453 // Construct the instance from the input arguments.
1345113454 auto simplified = simplifyConstructionConstraint(
1345213455 instance2, func1, subflags,
13453- /*FIXME?*/ DC , FunctionRefInfo::singleBaseNameApply(),
13456+ useDC , FunctionRefInfo::singleBaseNameApply(),
1345413457 getConstraintLocator(outerLocator));
1345513458
1345613459 // Record any fixes we attempted to get to the correct solution.
@@ -15673,15 +15676,6 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
1567315676 case ConstraintKind::BridgingConversion:
1567415677 return simplifyBridgingConstraint(first, second, subflags, locator);
1567515678
15676- case ConstraintKind::ApplicableFunction: {
15677- // First try to simplify the overload set for the function being applied.
15678- if (simplifyAppliedOverloads(second, first->castTo<FunctionType>(),
15679- locator)) {
15680- return SolutionKind::Error;
15681- }
15682- return simplifyApplicableFnConstraint(first, second, std::nullopt, subflags,
15683- locator);
15684- }
1568515679 case ConstraintKind::DynamicCallableApplicableFunction:
1568615680 return simplifyDynamicCallableApplicableFnConstraint(first, second,
1568715681 subflags, locator);
@@ -15762,6 +15756,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
1576215756 case ConstraintKind::KeyPathApplication:
1576315757 case ConstraintKind::FallbackType:
1576415758 case ConstraintKind::SyntacticElement:
15759+ case ConstraintKind::ApplicableFunction:
1576515760 llvm_unreachable("Use the correct addConstraint()");
1576615761 }
1576715762
@@ -15990,6 +15985,41 @@ void ConstraintSystem::addConstraint(ConstraintKind kind, Type first,
1599015985 }
1599115986}
1599215987
15988+ void ConstraintSystem::addApplicationConstraint(
15989+ FunctionType *appliedFn, Type calleeType,
15990+ std::optional<TrailingClosureMatching> trailingClosureMatching,
15991+ DeclContext *useDC,
15992+ ConstraintLocatorBuilder locator) {
15993+ auto recordFailure = [&]() {
15994+ if (shouldRecordFailedConstraint()) {
15995+ auto *c = Constraint::createApplicableFunction(
15996+ *this, appliedFn, calleeType, trailingClosureMatching, useDC,
15997+ getConstraintLocator(locator));
15998+ recordFailedConstraint(c);
15999+ }
16000+ };
16001+
16002+ // First try to simplify the overload set for the function being applied.
16003+ if (simplifyAppliedOverloads(calleeType, appliedFn, locator)) {
16004+ recordFailure();
16005+ return;
16006+ }
16007+
16008+ switch (simplifyApplicableFnConstraint(appliedFn, calleeType,
16009+ trailingClosureMatching, useDC,
16010+ TMF_GenerateConstraints, locator)) {
16011+ case SolutionKind::Error:
16012+ recordFailure();
16013+ break;
16014+
16015+ case SolutionKind::Unsolved:
16016+ llvm_unreachable("should have generated constraints");
16017+
16018+ case SolutionKind::Solved:
16019+ return;
16020+ }
16021+ }
16022+
1599316023void ConstraintSystem::addContextualConversionConstraint(
1599416024 Expr *expr, Type conversionType, ContextualTypePurpose purpose,
1599516025 ConstraintLocator *locator) {
@@ -16175,7 +16205,8 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
1617516205 case ConstraintKind::ApplicableFunction:
1617616206 return simplifyApplicableFnConstraint(
1617716207 constraint.getFirstType(), constraint.getSecondType(),
16178- constraint.getTrailingClosureMatching(), std::nullopt,
16208+ constraint.getTrailingClosureMatching(),
16209+ /*FIXME*/DC, /*flags=*/std::nullopt,
1617916210 constraint.getLocator());
1618016211
1618116212 case ConstraintKind::DynamicCallableApplicableFunction:
0 commit comments