@@ -30,9 +30,9 @@ using namespace constraints;
30
30
Constraint::Constraint (ConstraintKind kind, ArrayRef<Constraint *> constraints,
31
31
bool isIsolated, ConstraintLocator *locator,
32
32
SmallPtrSetImpl<TypeVariableType *> &typeVars)
33
- : Kind(kind), HasRestriction (false ), IsActive (false ), IsDisabled (false ),
34
- IsDisabledForPerformance (false ), RememberChoice (false ), IsFavored (false ),
35
- IsIsolated(isIsolated), NumTypeVariables(typeVars.size()),
33
+ : Kind(kind), HasFix (false ), HasRestriction (false ), IsActive (false ),
34
+ IsDisabled (false ), IsDisabledForPerformance (false ), RememberChoice (false ),
35
+ IsFavored( false ), IsIsolated(isIsolated), NumTypeVariables(typeVars.size()),
36
36
Nested(constraints), Locator(locator) {
37
37
assert (kind == ConstraintKind::Disjunction ||
38
38
kind == ConstraintKind::Conjunction);
@@ -50,9 +50,9 @@ Constraint::Constraint(ConstraintKind kind, ArrayRef<Constraint *> constraints,
50
50
Constraint::Constraint (ConstraintKind Kind, Type First, Type Second,
51
51
ConstraintLocator *locator,
52
52
SmallPtrSetImpl<TypeVariableType *> &typeVars)
53
- : Kind(Kind), HasRestriction (false ), IsActive (false ), IsDisabled (false ),
54
- IsDisabledForPerformance (false ), RememberChoice (false ), IsFavored (false ),
55
- IsIsolated(false ),
53
+ : Kind(Kind), HasFix (false ), HasRestriction (false ), IsActive (false ),
54
+ IsDisabled (false ), IsDisabledForPerformance (false ), RememberChoice (false ),
55
+ IsFavored( false ), IsIsolated(false ),
56
56
NumTypeVariables(typeVars.size()), Types{First, Second, Type ()},
57
57
Locator (locator) {
58
58
switch (Kind) {
@@ -131,9 +131,9 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
131
131
Constraint::Constraint (ConstraintKind Kind, Type First, Type Second, Type Third,
132
132
ConstraintLocator *locator,
133
133
SmallPtrSetImpl<TypeVariableType *> &typeVars)
134
- : Kind(Kind), HasRestriction (false ), IsActive (false ), IsDisabled (false ),
135
- IsDisabledForPerformance (false ), RememberChoice (false ), IsFavored (false ),
136
- IsIsolated(false ),
134
+ : Kind(Kind), HasFix (false ), HasRestriction (false ), IsActive (false ),
135
+ IsDisabled (false ), IsDisabledForPerformance (false ), RememberChoice (false ),
136
+ IsFavored( false ), IsIsolated(false ),
137
137
NumTypeVariables(typeVars.size()), Types{First, Second, Third},
138
138
Locator (locator) {
139
139
switch (Kind) {
@@ -197,9 +197,9 @@ Constraint::Constraint(ConstraintKind kind, Type first, Type second,
197
197
FunctionRefKind functionRefKind,
198
198
ConstraintLocator *locator,
199
199
SmallPtrSetImpl<TypeVariableType *> &typeVars)
200
- : Kind(kind), HasRestriction (false ), IsActive (false ), IsDisabled (false ),
201
- IsDisabledForPerformance (false ), RememberChoice (false ), IsFavored (false ),
202
- IsIsolated(false ),
200
+ : Kind(kind), HasFix (false ), HasRestriction (false ), IsActive (false ),
201
+ IsDisabled (false ), IsDisabledForPerformance (false ), RememberChoice (false ),
202
+ IsFavored( false ), IsIsolated(false ),
203
203
NumTypeVariables(typeVars.size()), Member{first, second, {member}, useDC},
204
204
Locator (locator) {
205
205
assert (kind == ConstraintKind::ValueMember ||
@@ -217,9 +217,10 @@ Constraint::Constraint(ConstraintKind kind, Type first, Type second,
217
217
FunctionRefKind functionRefKind,
218
218
ConstraintLocator *locator,
219
219
SmallPtrSetImpl<TypeVariableType *> &typeVars)
220
- : Kind(kind), HasRestriction(false ), IsActive(false ), IsDisabled(false ),
221
- IsDisabledForPerformance(false ), RememberChoice(false ), IsFavored(false ),
222
- IsIsolated(false ), NumTypeVariables(typeVars.size()), Locator(locator) {
220
+ : Kind(kind), HasFix(false ), HasRestriction(false ), IsActive(false ),
221
+ IsDisabled(false ), IsDisabledForPerformance(false ), RememberChoice(false ),
222
+ IsFavored(false ), IsIsolated(false ), NumTypeVariables(typeVars.size()),
223
+ Locator(locator) {
223
224
Member.First = first;
224
225
Member.Second = second;
225
226
Member.Member .Ref = requirement;
@@ -237,19 +238,21 @@ Constraint::Constraint(ConstraintKind kind, Type first, Type second,
237
238
Constraint::Constraint (Type type, OverloadChoice choice, DeclContext *useDC,
238
239
ConstraintFix *fix, ConstraintLocator *locator,
239
240
SmallPtrSetImpl<TypeVariableType *> &typeVars)
240
- : Kind(ConstraintKind::BindOverload), TheFix (fix), HasRestriction(false ),
241
+ : Kind(ConstraintKind::BindOverload), HasFix (fix != nullptr ), HasRestriction(false ),
241
242
IsActive(false ), IsDisabled(bool (fix)), IsDisabledForPerformance(false ),
242
243
RememberChoice(false ), IsFavored(false ), IsIsolated(false ),
243
244
NumTypeVariables(typeVars.size()), Overload{type, choice, useDC},
244
245
Locator (locator) {
245
246
std::copy (typeVars.begin (), typeVars.end (), getTypeVariablesBuffer ().begin ());
247
+ if (fix)
248
+ *getTrailingObjects<ConstraintFix *>() = fix;
246
249
}
247
250
248
251
Constraint::Constraint (ConstraintKind kind,
249
252
ConversionRestrictionKind restriction, Type first,
250
253
Type second, ConstraintLocator *locator,
251
254
SmallPtrSetImpl<TypeVariableType *> &typeVars)
252
- : Kind(kind), Restriction(restriction), HasRestriction(true ),
255
+ : Kind(kind), Restriction(restriction), HasFix( false ), HasRestriction(true ),
253
256
IsActive(false ), IsDisabled(false ), IsDisabledForPerformance(false ),
254
257
RememberChoice(false ), IsFavored(false ), IsIsolated(false ),
255
258
NumTypeVariables(typeVars.size()), Types{first, second, Type ()},
@@ -262,20 +265,22 @@ Constraint::Constraint(ConstraintKind kind,
262
265
Constraint::Constraint (ConstraintKind kind, ConstraintFix *fix, Type first,
263
266
Type second, ConstraintLocator *locator,
264
267
SmallPtrSetImpl<TypeVariableType *> &typeVars)
265
- : Kind(kind), TheFix (fix), HasRestriction(false ), IsActive(false ),
268
+ : Kind(kind), HasFix (fix != nullptr ), HasRestriction(false ), IsActive(false ),
266
269
IsDisabled(false ), IsDisabledForPerformance(false ), RememberChoice(false ),
267
270
IsFavored(false ), IsIsolated(false ),
268
271
NumTypeVariables(typeVars.size()), Types{first, second, Type ()},
269
272
Locator (locator) {
270
273
assert (!first.isNull ());
271
274
assert (!second.isNull ());
272
275
std::copy (typeVars.begin (), typeVars.end (), getTypeVariablesBuffer ().begin ());
276
+ if (fix)
277
+ *getTrailingObjects<ConstraintFix *>() = fix;
273
278
}
274
279
275
280
Constraint::Constraint (ASTNode node, ContextualTypeInfo context,
276
281
bool isDiscarded, ConstraintLocator *locator,
277
282
SmallPtrSetImpl<TypeVariableType *> &typeVars)
278
- : Kind(ConstraintKind::SyntacticElement), TheFix( nullptr ),
283
+ : Kind(ConstraintKind::SyntacticElement), HasFix( false ),
279
284
HasRestriction(false ), IsActive(false ), IsDisabled(false ),
280
285
IsDisabledForPerformance(false ), RememberChoice(false ), IsFavored(false ),
281
286
IsIsolated(false ),
@@ -833,7 +838,8 @@ Constraint *Constraint::create(ConstraintSystem &cs, ConstraintKind kind,
833
838
second->is <ProtocolType>());
834
839
835
840
// Create the constraint.
836
- unsigned size = totalSizeToAlloc<TypeVariableType*>(typeVars.size ());
841
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
842
+ typeVars.size (), /* hasFix=*/ 0 );
837
843
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
838
844
return ::new (mem) Constraint (kind, first, second, locator, typeVars);
839
845
}
@@ -852,7 +858,8 @@ Constraint *Constraint::create(ConstraintSystem &cs, ConstraintKind kind,
852
858
if (third->hasTypeVariable ())
853
859
third->getTypeVariables (typeVars);
854
860
855
- unsigned size = totalSizeToAlloc<TypeVariableType*>(typeVars.size ());
861
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
862
+ typeVars.size (), /* hasFix=*/ 0 );
856
863
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
857
864
return ::new (mem) Constraint (kind,
858
865
first, second, third,
@@ -892,7 +899,8 @@ Constraint *Constraint::createMember(ConstraintSystem &cs, ConstraintKind kind,
892
899
second->getTypeVariables (typeVars);
893
900
894
901
// Create the constraint.
895
- unsigned size = totalSizeToAlloc<TypeVariableType*>(typeVars.size ());
902
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
903
+ typeVars.size (), /* hasFix=*/ 0 );
896
904
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
897
905
return new (mem) Constraint (kind, first, second, member, useDC,
898
906
functionRefKind, locator, typeVars);
@@ -912,7 +920,8 @@ Constraint *Constraint::createValueWitness(
912
920
second->getTypeVariables (typeVars);
913
921
914
922
// Create the constraint.
915
- unsigned size = totalSizeToAlloc<TypeVariableType*>(typeVars.size ());
923
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
924
+ typeVars.size (), /* hasFix=*/ 0 );
916
925
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
917
926
return new (mem) Constraint (kind, first, second, requirement, useDC,
918
927
functionRefKind, locator, typeVars);
@@ -938,7 +947,8 @@ Constraint *Constraint::createRestricted(ConstraintSystem &cs,
938
947
second->getTypeVariables (typeVars);
939
948
940
949
// Create the constraint.
941
- unsigned size = totalSizeToAlloc<TypeVariableType*>(typeVars.size ());
950
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
951
+ typeVars.size (), /* hasFix=*/ 0 );
942
952
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
943
953
return new (mem) Constraint (kind, restriction, first, second, locator,
944
954
typeVars);
@@ -955,7 +965,8 @@ Constraint *Constraint::createFixed(ConstraintSystem &cs, ConstraintKind kind,
955
965
second->getTypeVariables (typeVars);
956
966
957
967
// Create the constraint.
958
- unsigned size = totalSizeToAlloc<TypeVariableType*>(typeVars.size ());
968
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
969
+ typeVars.size (), fix ? 1 : 0 );
959
970
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
960
971
return new (mem) Constraint (kind, fix, first, second, locator, typeVars);
961
972
}
@@ -974,7 +985,8 @@ Constraint *Constraint::createFixedChoice(ConstraintSystem &cs, Type type,
974
985
}
975
986
976
987
// Create the constraint.
977
- unsigned size = totalSizeToAlloc<TypeVariableType *>(typeVars.size ());
988
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
989
+ typeVars.size (), fix ? 1 : 0 );
978
990
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
979
991
return new (mem) Constraint (type, choice, useDC, fix, locator, typeVars);
980
992
}
@@ -1044,7 +1056,8 @@ Constraint *Constraint::createDisjunction(ConstraintSystem &cs,
1044
1056
#endif
1045
1057
1046
1058
// Create the disjunction constraint.
1047
- unsigned size = totalSizeToAlloc<TypeVariableType*>(typeVars.size ());
1059
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
1060
+ typeVars.size (), /* hasFix=*/ 0 );
1048
1061
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
1049
1062
auto disjunction = new (mem)
1050
1063
Constraint (ConstraintKind::Disjunction, cs.allocateCopy (constraints),
@@ -1063,7 +1076,8 @@ Constraint *Constraint::createConjunction(
1063
1076
// because each have to be solved in isolation.
1064
1077
1065
1078
assert (!constraints.empty () && " Empty conjunction constraint" );
1066
- unsigned size = totalSizeToAlloc<TypeVariableType*>(typeVars.size ());
1079
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
1080
+ typeVars.size (), /* hasFix=*/ 0 );
1067
1081
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
1068
1082
auto conjunction = new (mem)
1069
1083
Constraint (ConstraintKind::Conjunction, cs.allocateCopy (constraints),
@@ -1083,7 +1097,8 @@ Constraint *Constraint::createApplicableFunction(
1083
1097
calleeType->getTypeVariables (typeVars);
1084
1098
1085
1099
// Create the constraint.
1086
- unsigned size = totalSizeToAlloc<TypeVariableType*>(typeVars.size ());
1100
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
1101
+ typeVars.size (), /* hasFix=*/ 0 );
1087
1102
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
1088
1103
auto constraint = new (mem) Constraint (
1089
1104
ConstraintKind::ApplicableFunction, argumentFnType, calleeType, locator,
@@ -1125,7 +1140,8 @@ Constraint *Constraint::createSyntacticElement(ConstraintSystem &cs,
1125
1140
if (auto contextTy = context.getType ())
1126
1141
contextTy->getTypeVariables (typeVars);
1127
1142
1128
- unsigned size = totalSizeToAlloc<TypeVariableType *>(typeVars.size ());
1143
+ auto size = totalSizeToAlloc<TypeVariableType *, ConstraintFix *>(
1144
+ typeVars.size (), /* hasFix=*/ 0 );
1129
1145
void *mem = cs.getAllocator ().Allocate (size, alignof (Constraint));
1130
1146
return new (mem) Constraint (node, context, isDiscarded, locator, typeVars);
1131
1147
}
0 commit comments