@@ -33,6 +33,31 @@ bool ConstraintSystem::PotentialBinding::isViableForJoin() const {
33
33
!isDefaultableBinding ();
34
34
}
35
35
36
+ bool ConstraintSystem::PotentialBindings::isFullyBound () const {
37
+ if (!DelayedBy.empty ())
38
+ return true ;
39
+
40
+ if (isHole ()) {
41
+ auto *locator = TypeVar->getImpl ().getLocator ();
42
+ assert (locator && " a hole without locator?" );
43
+
44
+ // Delay resolution of the code completion expression until
45
+ // the very end to give it a chance to be bound to some
46
+ // contextual type even if it's a hole.
47
+ if (locator->directlyAt <CodeCompletionExpr>())
48
+ return true ;
49
+
50
+ // Delay resolution of the `nil` literal to a hole until
51
+ // the very end to give it a change to be bound to some
52
+ // other type, just like code completion expression which
53
+ // relies solely on contextual information.
54
+ if (locator->directlyAt <NilLiteralExpr>())
55
+ return true ;
56
+ }
57
+
58
+ return false ;
59
+ }
60
+
36
61
bool ConstraintSystem::PotentialBindings::isPotentiallyIncomplete () const {
37
62
// Generic parameters are always potentially incomplete.
38
63
if (isGenericParameter ())
@@ -555,19 +580,6 @@ void ConstraintSystem::PotentialBindings::finalize(
555
580
// very last moment possible, just like generic parameters.
556
581
auto *locator = TypeVar->getImpl ().getLocator ();
557
582
558
- // Delay resolution of the code completion expression until
559
- // the very end to give it a chance to be bound to some
560
- // contextual type even if it's a hole.
561
- if (locator->directlyAt <CodeCompletionExpr>())
562
- FullyBound = true ;
563
-
564
- // Delay resolution of the `nil` literal to a hole until
565
- // the very end to give it a change to be bound to some
566
- // other type, just like code completion expression which
567
- // relies solely on contextual information.
568
- if (locator->directlyAt <NilLiteralExpr>())
569
- FullyBound = true ;
570
-
571
583
// If this type variable is associated with a code completion token
572
584
// and it failed to infer any bindings let's adjust hole's locator
573
585
// to point to a code completion token to avoid attempting to "fix"
@@ -776,7 +788,7 @@ bool ConstraintSystem::PotentialBindings::isViable(
776
788
777
789
bool ConstraintSystem::PotentialBindings::favoredOverDisjunction (
778
790
Constraint *disjunction) const {
779
- if (isHole () || FullyBound )
791
+ if (isHole () || isFullyBound () )
780
792
return false ;
781
793
782
794
// If this bindings are for a closure and there are no holes,
@@ -872,7 +884,7 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
872
884
if (auto *typeVar = first->getAs <TypeVariableType>()) {
873
885
if (typeVar->getImpl ().isClosureType ()) {
874
886
result.InvolvesTypeVariables = true ;
875
- result.FullyBound = true ;
887
+ result.DelayedBy . push_back (constraint) ;
876
888
return None;
877
889
}
878
890
}
@@ -918,7 +930,7 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
918
930
if (type->is <DependentMemberType>()) {
919
931
if (!ConstraintSystem::typeVarOccursInType (typeVar, type,
920
932
&result.InvolvesTypeVariables )) {
921
- result.FullyBound = true ;
933
+ result.DelayedBy . push_back (constraint) ;
922
934
}
923
935
924
936
return None;
@@ -1056,7 +1068,7 @@ bool ConstraintSystem::PotentialBindings::infer(
1056
1068
// delaying bindings for as long as possible.
1057
1069
if (isExpr<ForceValueExpr>(anchor) && !type->is <LValueType>()) {
1058
1070
addPotentialBinding (binding->withType (LValueType::get (type)));
1059
- FullyBound = true ;
1071
+ DelayedBy. push_back (constraint) ;
1060
1072
}
1061
1073
1062
1074
// If this is a type variable representing closure result,
@@ -1076,9 +1088,6 @@ bool ConstraintSystem::PotentialBindings::infer(
1076
1088
break ;
1077
1089
}
1078
1090
case ConstraintKind::KeyPathApplication: {
1079
- if (FullyBound)
1080
- return false ;
1081
-
1082
1091
// If this variable is in the application projected result type, mark the
1083
1092
// result as `FullyBound` to ensure we delay binding until we've bound
1084
1093
// other type variables in the KeyPathApplication constraint. This ensures
@@ -1087,8 +1096,9 @@ bool ConstraintSystem::PotentialBindings::infer(
1087
1096
SmallPtrSet<TypeVariableType *, 4 > typeVars;
1088
1097
findInferableTypeVars (cs.simplifyType (constraint->getThirdType ()),
1089
1098
typeVars);
1090
- if (typeVars.count (TypeVar))
1091
- FullyBound = true ;
1099
+ if (typeVars.count (TypeVar)) {
1100
+ DelayedBy.push_back (constraint);
1101
+ }
1092
1102
1093
1103
break ;
1094
1104
}
@@ -1162,15 +1172,12 @@ bool ConstraintSystem::PotentialBindings::infer(
1162
1172
case ConstraintKind::ApplicableFunction:
1163
1173
case ConstraintKind::DynamicCallableApplicableFunction:
1164
1174
case ConstraintKind::BindOverload: {
1165
- if (FullyBound && InvolvesTypeVariables)
1166
- return false ;
1167
-
1168
1175
// If this variable is in the left-hand side, it is fully bound.
1169
1176
SmallPtrSet<TypeVariableType *, 4 > typeVars;
1170
1177
findInferableTypeVars (cs.simplifyType (constraint->getFirstType ()),
1171
1178
typeVars);
1172
1179
if (typeVars.count (TypeVar))
1173
- FullyBound = true ;
1180
+ DelayedBy. push_back (constraint) ;
1174
1181
1175
1182
if (InvolvesTypeVariables)
1176
1183
return false ;
@@ -1203,7 +1210,7 @@ bool ConstraintSystem::PotentialBindings::infer(
1203
1210
if (ConstraintSystem::typeVarOccursInType (
1204
1211
TypeVar, cs.simplifyType (constraint->getSecondType ()),
1205
1212
&InvolvesTypeVariables)) {
1206
- FullyBound = true ;
1213
+ DelayedBy. push_back (constraint) ;
1207
1214
}
1208
1215
break ;
1209
1216
0 commit comments