@@ -830,27 +830,24 @@ PotentialBindings ConstraintSystem::inferBindingsFor(TypeVariableType *typeVar,
830
830
}
831
831
832
832
Optional<PotentialBinding>
833
- ConstraintSystem::getPotentialBindingForRelationalConstraint (
834
- PotentialBindings &result, Constraint *constraint) const {
833
+ PotentialBindings::inferFromRelational (Constraint *constraint) {
835
834
assert (constraint->getClassification () ==
836
835
ConstraintClassification::Relational &&
837
836
" only relational constraints handled here" );
838
837
839
- auto *typeVar = result.TypeVar ;
840
-
841
- auto first = simplifyType (constraint->getFirstType ());
842
- auto second = simplifyType (constraint->getSecondType ());
838
+ auto first = CS.simplifyType (constraint->getFirstType ());
839
+ auto second = CS.simplifyType (constraint->getSecondType ());
843
840
844
841
if (first->is <TypeVariableType>() && first->isEqual (second))
845
842
return None;
846
843
847
844
Type type;
848
845
AllowedBindingKind kind;
849
- if (first->getAs <TypeVariableType>() == typeVar ) {
846
+ if (first->getAs <TypeVariableType>() == TypeVar ) {
850
847
// Upper bound for this type variable.
851
848
type = second;
852
849
kind = AllowedBindingKind::Subtypes;
853
- } else if (second->getAs <TypeVariableType>() == typeVar ) {
850
+ } else if (second->getAs <TypeVariableType>() == TypeVar ) {
854
851
// Lower bound for this type variable.
855
852
type = first;
856
853
kind = AllowedBindingKind::Supertypes;
@@ -863,7 +860,7 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
863
860
// of bindings for them until closure's body is opened.
864
861
if (auto *typeVar = first->getAs <TypeVariableType>()) {
865
862
if (typeVar->getImpl ().isClosureType ()) {
866
- result. DelayedBy .push_back (constraint);
863
+ DelayedBy.push_back (constraint);
867
864
return None;
868
865
}
869
866
}
@@ -874,8 +871,8 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
874
871
findInferableTypeVars (first, typeVars);
875
872
findInferableTypeVars (second, typeVars);
876
873
877
- if (typeVars.erase (typeVar )) {
878
- result. AdjacentVars .insert (typeVars.begin (), typeVars.end ());
874
+ if (typeVars.erase (TypeVar )) {
875
+ AdjacentVars.insert (typeVars.begin (), typeVars.end ());
879
876
}
880
877
881
878
return None;
@@ -885,11 +882,11 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
885
882
if (type->hasError ())
886
883
return None;
887
884
888
- if (auto *locator = typeVar ->getImpl ().getLocator ()) {
885
+ if (auto *locator = TypeVar ->getImpl ().getLocator ()) {
889
886
if (locator->isKeyPathType ()) {
890
887
auto *BGT =
891
888
type->lookThroughAllOptionalTypes ()->getAs <BoundGenericType>();
892
- if (!BGT || !isKnownKeyPathDecl (getASTContext (), BGT->getDecl ()))
889
+ if (!BGT || !isKnownKeyPathDecl (CS. getASTContext (), BGT->getDecl ()))
893
890
return None;
894
891
}
895
892
}
@@ -915,8 +912,8 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
915
912
for (auto *var : referencedVars) {
916
913
// Add all type variables encountered in the type except
917
914
// to the current type variable.
918
- if (var != typeVar ) {
919
- result. AdjacentVars .insert (var);
915
+ if (var != TypeVar ) {
916
+ AdjacentVars.insert (var);
920
917
continue ;
921
918
}
922
919
@@ -927,7 +924,7 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
927
924
// let's mark bindings as delayed until dependent member type
928
925
// is resolved.
929
926
if (!containsSelf)
930
- result. DelayedBy .push_back (constraint);
927
+ DelayedBy.push_back (constraint);
931
928
932
929
return None;
933
930
}
@@ -941,25 +938,25 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
941
938
// should be allowed to escape. As a result we allow anything
942
939
// passed in to escape.
943
940
if (auto *fnTy = type->getAs <AnyFunctionType>())
944
- if (typeVar-> getImpl (). getGenericParameter () && !shouldAttemptFixes ())
941
+ if (isGenericParameter () && !CS. shouldAttemptFixes ())
945
942
type = fnTy->withExtInfo (fnTy->getExtInfo ().withNoEscape (false ));
946
943
947
944
// Check whether we can perform this binding.
948
945
// FIXME: this has a super-inefficient extraneous simplifyType() in it.
949
- if (auto boundType = checkTypeOfBinding (typeVar , type)) {
946
+ if (auto boundType = CS. checkTypeOfBinding (TypeVar , type)) {
950
947
type = *boundType;
951
948
if (type->hasTypeVariable ()) {
952
949
SmallVector<TypeVariableType *, 4 > referencedVars;
953
950
type->getTypeVariables (referencedVars);
954
- result. AdjacentVars .insert (referencedVars.begin (), referencedVars.end ());
951
+ AdjacentVars.insert (referencedVars.begin (), referencedVars.end ());
955
952
}
956
953
} else {
957
954
auto *bindingTypeVar = type->getRValueType ()->getAs <TypeVariableType>();
958
955
959
956
if (!bindingTypeVar)
960
957
return None;
961
958
962
- result. AdjacentVars .insert (bindingTypeVar);
959
+ AdjacentVars.insert (bindingTypeVar);
963
960
964
961
// If current type variable is associated with a code completion token
965
962
// it's possible that it doesn't have enough contextual information
@@ -968,7 +965,7 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
968
965
// available.
969
966
if (auto *locator = bindingTypeVar->getImpl ().getLocator ()) {
970
967
if (locator->directlyAt <CodeCompletionExpr>())
971
- result. AssociatedCodeCompletionToken = locator->getAnchor ();
968
+ AssociatedCodeCompletionToken = locator->getAnchor ();
972
969
}
973
970
974
971
switch (constraint->getKind ()) {
@@ -977,18 +974,18 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
977
974
case ConstraintKind::ArgumentConversion:
978
975
case ConstraintKind::OperatorArgumentConversion: {
979
976
if (kind == AllowedBindingKind::Subtypes) {
980
- result. SubtypeOf .insert ({bindingTypeVar, constraint});
977
+ SubtypeOf.insert ({bindingTypeVar, constraint});
981
978
} else {
982
979
assert (kind == AllowedBindingKind::Supertypes);
983
- result. SupertypeOf .insert ({bindingTypeVar, constraint});
980
+ SupertypeOf.insert ({bindingTypeVar, constraint});
984
981
}
985
982
break ;
986
983
}
987
984
988
985
case ConstraintKind::Bind:
989
986
case ConstraintKind::BindParam:
990
987
case ConstraintKind::Equal: {
991
- result. EquivalentTo .insert ({bindingTypeVar, constraint});
988
+ EquivalentTo.insert ({bindingTypeVar, constraint});
992
989
break ;
993
990
}
994
991
@@ -1002,14 +999,14 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
1002
999
// Make sure we aren't trying to equate type variables with different
1003
1000
// lvalue-binding rules.
1004
1001
if (auto otherTypeVar = type->getAs <TypeVariableType>()) {
1005
- if (typeVar ->getImpl ().canBindToLValue () !=
1002
+ if (TypeVar ->getImpl ().canBindToLValue () !=
1006
1003
otherTypeVar->getImpl ().canBindToLValue ())
1007
1004
return None;
1008
1005
}
1009
1006
1010
- if (type->is <InOutType>() && !typeVar ->getImpl ().canBindToInOut ())
1007
+ if (type->is <InOutType>() && !TypeVar ->getImpl ().canBindToInOut ())
1011
1008
type = LValueType::get (type->getInOutObjectType ());
1012
- if (type->is <LValueType>() && !typeVar ->getImpl ().canBindToLValue ())
1009
+ if (type->is <LValueType>() && !TypeVar ->getImpl ().canBindToLValue ())
1013
1010
type = type->getRValueType ();
1014
1011
1015
1012
// BindParam constraints are not reflexive and must be treated specially.
@@ -1043,8 +1040,7 @@ bool PotentialBindings::infer(Constraint *constraint) {
1043
1040
case ConstraintKind::ArgumentConversion:
1044
1041
case ConstraintKind::OperatorArgumentConversion:
1045
1042
case ConstraintKind::OptionalObject: {
1046
- auto binding =
1047
- CS.getPotentialBindingForRelationalConstraint (*this , constraint);
1043
+ auto binding = inferFromRelational (constraint);
1048
1044
if (!binding)
1049
1045
break ;
1050
1046
0 commit comments