@@ -87,11 +87,9 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
8787 assert (!First.isNull ());
8888 assert (!Second.isNull ());
8989 break ;
90- case ConstraintKind::ApplicableFunction:
9190 case ConstraintKind::DynamicCallableApplicableFunction:
9291 assert (First->is <FunctionType>()
9392 && " The left-hand side type should be a function type" );
94- trailingClosureMatching = 0 ;
9593 break ;
9694
9795 case ConstraintKind::ValueMember:
@@ -120,6 +118,10 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
120118
121119 case ConstraintKind::SyntacticElement:
122120 llvm_unreachable (" Syntactic element constraint should use create()" );
121+
122+ case ConstraintKind::ApplicableFunction:
123+ llvm_unreachable (
124+ " Application constraint should use create()" );
123125 }
124126
125127 std::uninitialized_copy (typeVars.begin (), typeVars.end (),
@@ -287,6 +289,27 @@ Constraint::Constraint(ASTNode node, ContextualTypeInfo context,
287289 std::copy (typeVars.begin (), typeVars.end (), getTypeVariablesBuffer ().begin ());
288290}
289291
292+ Constraint::Constraint (FunctionType *appliedFn, Type calleeType,
293+ unsigned trailingClosureMatching, DeclContext *useDC,
294+ ConstraintLocator *locator,
295+ SmallPtrSetImpl<TypeVariableType *> &typeVars)
296+ : Kind(ConstraintKind::ApplicableFunction), HasFix(false ),
297+ HasRestriction(false ), IsActive(false ), IsDisabled(false ),
298+ IsDisabledForPerformance(false ), RememberChoice(false ), IsFavored(false ),
299+ IsIsolated(false ), NumTypeVariables(typeVars.size()), Locator(locator) {
300+ assert (appliedFn);
301+ assert (calleeType);
302+ assert (trailingClosureMatching >= 0 && trailingClosureMatching <= 2 );
303+ assert (useDC);
304+
305+ Apply.AppliedFn = appliedFn;
306+ Apply.Callee = calleeType;
307+ Apply.TrailingClosureMatching = trailingClosureMatching;
308+ Apply.UseDC = useDC;
309+
310+ std::copy (typeVars.begin (), typeVars.end (), getTypeVariablesBuffer ().begin ());
311+ }
312+
290313ProtocolDecl *Constraint::getProtocol () const {
291314 assert ((Kind == ConstraintKind::ConformsTo ||
292315 Kind == ConstraintKind::LiteralConformsTo ||
@@ -986,7 +1009,7 @@ Constraint *Constraint::createConjunction(
9861009}
9871010
9881011Constraint *Constraint::createApplicableFunction (
989- ConstraintSystem &cs, Type argumentFnType, Type calleeType,
1012+ ConstraintSystem &cs, FunctionType * argumentFnType, Type calleeType,
9901013 std::optional<TrailingClosureMatching> trailingClosureMatching,
9911014 DeclContext *useDC, ConstraintLocator *locator) {
9921015 // Collect type variables.
@@ -996,30 +1019,29 @@ Constraint *Constraint::createApplicableFunction(
9961019 if (calleeType->hasTypeVariable ())
9971020 calleeType->getTypeVariables (typeVars);
9981021
999- // Create the constraint.
1000- auto size =
1001- totalSizeToAlloc<TypeVariableType *, ConstraintFix *, OverloadChoice>(
1002- typeVars.size (), /* hasFix=*/ 0 , /* hasOverloadChoice=*/ 0 );
1003- void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
1004- auto constraint = new (mem) Constraint (
1005- ConstraintKind::ApplicableFunction, argumentFnType, calleeType, locator,
1006- typeVars);
1007-
10081022 // Encode the trailing closure matching.
1023+ unsigned rawTrailingClosureMatching = 0 ;
10091024 if (trailingClosureMatching) {
10101025 switch (*trailingClosureMatching) {
10111026 case TrailingClosureMatching::Forward:
1012- constraint-> trailingClosureMatching = 1 ;
1027+ rawTrailingClosureMatching = 1 ;
10131028 break ;
10141029
10151030 case TrailingClosureMatching::Backward:
1016- constraint-> trailingClosureMatching = 2 ;
1031+ rawTrailingClosureMatching = 2 ;
10171032 break ;
10181033 }
1019- } else {
1020- constraint->trailingClosureMatching = 0 ;
10211034 }
10221035
1036+ // Create the constraint.
1037+ auto size =
1038+ totalSizeToAlloc<TypeVariableType *, ConstraintFix *, OverloadChoice>(
1039+ typeVars.size (), /* hasFix=*/ 0 , /* hasOverloadChoice=*/ 0 );
1040+ void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
1041+ auto constraint = new (mem)
1042+ Constraint (argumentFnType, calleeType, rawTrailingClosureMatching, useDC,
1043+ locator, typeVars);
1044+
10231045 return constraint;
10241046}
10251047
@@ -1051,7 +1073,7 @@ Constraint *Constraint::createSyntacticElement(ConstraintSystem &cs,
10511073std::optional<TrailingClosureMatching>
10521074Constraint::getTrailingClosureMatching () const {
10531075 assert (Kind == ConstraintKind::ApplicableFunction);
1054- switch (trailingClosureMatching ) {
1076+ switch (Apply. TrailingClosureMatching ) {
10551077 case 0 :
10561078 return std::nullopt ;
10571079 case 1 : return TrailingClosureMatching::Forward;
0 commit comments