@@ -8364,8 +8364,9 @@ ConstraintSystem::simplifyConstructionConstraint(
8364
8364
paramTypeVar, locator);
8365
8365
}
8366
8366
8367
- addConstraint(ConstraintKind::ApplicableFunction, fnType, memberType,
8368
- fnLocator);
8367
+ addApplicationConstraint(fnType, memberType,
8368
+ /*trailingClosureMatching=*/std::nullopt, useDC,
8369
+ fnLocator);
8369
8370
8370
8371
return SolutionKind::Solved;
8371
8372
}
@@ -13108,6 +13109,7 @@ createImplicitRootForCallAsFunction(ConstraintSystem &cs, Type refType,
13108
13109
ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
13109
13110
Type type1, Type type2,
13110
13111
std::optional<TrailingClosureMatching> trailingClosureMatching,
13112
+ DeclContext *useDC,
13111
13113
TypeMatchOptions flags, ConstraintLocatorBuilder locator) {
13112
13114
auto &ctx = getASTContext();
13113
13115
@@ -13171,7 +13173,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
13171
13173
auto formUnsolved = [&](bool activate = false) {
13172
13174
if (flags.contains(TMF_GenerateConstraints)) {
13173
13175
auto *application = Constraint::createApplicableFunction(
13174
- *this, type1, type2, trailingClosureMatching,
13176
+ *this, type1, type2, trailingClosureMatching, useDC,
13175
13177
getConstraintLocator(locator));
13176
13178
13177
13179
addUnsolvedConstraint(application);
@@ -13232,8 +13234,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
13232
13234
/*outerAlternatives*/ {}, memberLoc);
13233
13235
// Add new applicable function constraint based on the member type
13234
13236
// variable.
13235
- addConstraint(ConstraintKind::ApplicableFunction, func1, memberTy,
13236
- locator);
13237
+ addApplicationConstraint( func1, memberTy, trailingClosureMatching, useDC ,
13238
+ locator);
13237
13239
return SolutionKind::Solved;
13238
13240
}
13239
13241
@@ -13348,9 +13350,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
13348
13350
// Form an unsolved constraint to apply trailing closures to a
13349
13351
// callable type produced by `.init`. This constraint would become
13350
13352
// 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 ,
13354
13356
getConstraintLocator(implicitRef,
13355
13357
ConstraintLocator::ApplyFunction)));
13356
13358
break;
@@ -13368,12 +13370,13 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
13368
13370
13369
13371
auto applyLocator = getConstraintLocator(locator);
13370
13372
auto forwardConstraint = Constraint::createApplicableFunction(
13371
- *this, type1, type2, TrailingClosureMatching::Forward, applyLocator);
13373
+ *this, type1, type2, TrailingClosureMatching::Forward, useDC,
13374
+ applyLocator);
13372
13375
auto backwardConstraint = Constraint::createApplicableFunction(
13373
- *this, type1, type2, TrailingClosureMatching::Backward,
13376
+ *this, type1, type2, TrailingClosureMatching::Backward, useDC,
13374
13377
applyLocator);
13375
- addDisjunctionConstraint(
13376
- { forwardConstraint, backwardConstraint}, applyLocator);
13378
+ addDisjunctionConstraint({forwardConstraint, backwardConstraint},
13379
+ applyLocator);
13377
13380
break;
13378
13381
}
13379
13382
@@ -13450,7 +13453,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyApplicableFnConstraint(
13450
13453
// Construct the instance from the input arguments.
13451
13454
auto simplified = simplifyConstructionConstraint(
13452
13455
instance2, func1, subflags,
13453
- /*FIXME?*/ DC , FunctionRefInfo::singleBaseNameApply(),
13456
+ useDC , FunctionRefInfo::singleBaseNameApply(),
13454
13457
getConstraintLocator(outerLocator));
13455
13458
13456
13459
// Record any fixes we attempted to get to the correct solution.
@@ -15673,15 +15676,6 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
15673
15676
case ConstraintKind::BridgingConversion:
15674
15677
return simplifyBridgingConstraint(first, second, subflags, locator);
15675
15678
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
- }
15685
15679
case ConstraintKind::DynamicCallableApplicableFunction:
15686
15680
return simplifyDynamicCallableApplicableFnConstraint(first, second,
15687
15681
subflags, locator);
@@ -15762,6 +15756,7 @@ ConstraintSystem::addConstraintImpl(ConstraintKind kind, Type first,
15762
15756
case ConstraintKind::KeyPathApplication:
15763
15757
case ConstraintKind::FallbackType:
15764
15758
case ConstraintKind::SyntacticElement:
15759
+ case ConstraintKind::ApplicableFunction:
15765
15760
llvm_unreachable("Use the correct addConstraint()");
15766
15761
}
15767
15762
@@ -15990,6 +15985,41 @@ void ConstraintSystem::addConstraint(ConstraintKind kind, Type first,
15990
15985
}
15991
15986
}
15992
15987
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
+
15993
16023
void ConstraintSystem::addContextualConversionConstraint(
15994
16024
Expr *expr, Type conversionType, ContextualTypePurpose purpose,
15995
16025
ConstraintLocator *locator) {
@@ -16175,7 +16205,8 @@ ConstraintSystem::simplifyConstraint(const Constraint &constraint) {
16175
16205
case ConstraintKind::ApplicableFunction:
16176
16206
return simplifyApplicableFnConstraint(
16177
16207
constraint.getFirstType(), constraint.getSecondType(),
16178
- constraint.getTrailingClosureMatching(), std::nullopt,
16208
+ constraint.getTrailingClosureMatching(),
16209
+ /*FIXME*/DC, /*flags=*/std::nullopt,
16179
16210
constraint.getLocator());
16180
16211
16181
16212
case ConstraintKind::DynamicCallableApplicableFunction:
0 commit comments