@@ -87,11 +87,9 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
87
87
assert (!First.isNull ());
88
88
assert (!Second.isNull ());
89
89
break ;
90
- case ConstraintKind::ApplicableFunction:
91
90
case ConstraintKind::DynamicCallableApplicableFunction:
92
91
assert (First->is <FunctionType>()
93
92
&& " The left-hand side type should be a function type" );
94
- trailingClosureMatching = 0 ;
95
93
break ;
96
94
97
95
case ConstraintKind::ValueMember:
@@ -120,6 +118,10 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
120
118
121
119
case ConstraintKind::SyntacticElement:
122
120
llvm_unreachable (" Syntactic element constraint should use create()" );
121
+
122
+ case ConstraintKind::ApplicableFunction:
123
+ llvm_unreachable (
124
+ " Application constraint should use create()" );
123
125
}
124
126
125
127
std::uninitialized_copy (typeVars.begin (), typeVars.end (),
@@ -287,6 +289,27 @@ Constraint::Constraint(ASTNode node, ContextualTypeInfo context,
287
289
std::copy (typeVars.begin (), typeVars.end (), getTypeVariablesBuffer ().begin ());
288
290
}
289
291
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
+
290
313
ProtocolDecl *Constraint::getProtocol () const {
291
314
assert ((Kind == ConstraintKind::ConformsTo ||
292
315
Kind == ConstraintKind::LiteralConformsTo ||
@@ -986,7 +1009,7 @@ Constraint *Constraint::createConjunction(
986
1009
}
987
1010
988
1011
Constraint *Constraint::createApplicableFunction (
989
- ConstraintSystem &cs, Type argumentFnType, Type calleeType,
1012
+ ConstraintSystem &cs, FunctionType * argumentFnType, Type calleeType,
990
1013
std::optional<TrailingClosureMatching> trailingClosureMatching,
991
1014
DeclContext *useDC, ConstraintLocator *locator) {
992
1015
// Collect type variables.
@@ -996,30 +1019,29 @@ Constraint *Constraint::createApplicableFunction(
996
1019
if (calleeType->hasTypeVariable ())
997
1020
calleeType->getTypeVariables (typeVars);
998
1021
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
-
1008
1022
// Encode the trailing closure matching.
1023
+ unsigned rawTrailingClosureMatching = 0 ;
1009
1024
if (trailingClosureMatching) {
1010
1025
switch (*trailingClosureMatching) {
1011
1026
case TrailingClosureMatching::Forward:
1012
- constraint-> trailingClosureMatching = 1 ;
1027
+ rawTrailingClosureMatching = 1 ;
1013
1028
break ;
1014
1029
1015
1030
case TrailingClosureMatching::Backward:
1016
- constraint-> trailingClosureMatching = 2 ;
1031
+ rawTrailingClosureMatching = 2 ;
1017
1032
break ;
1018
1033
}
1019
- } else {
1020
- constraint->trailingClosureMatching = 0 ;
1021
1034
}
1022
1035
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
+
1023
1045
return constraint;
1024
1046
}
1025
1047
@@ -1051,7 +1073,7 @@ Constraint *Constraint::createSyntacticElement(ConstraintSystem &cs,
1051
1073
std::optional<TrailingClosureMatching>
1052
1074
Constraint::getTrailingClosureMatching () const {
1053
1075
assert (Kind == ConstraintKind::ApplicableFunction);
1054
- switch (trailingClosureMatching ) {
1076
+ switch (Apply. TrailingClosureMatching ) {
1055
1077
case 0 :
1056
1078
return std::nullopt ;
1057
1079
case 1 : return TrailingClosureMatching::Forward;
0 commit comments