@@ -35,11 +35,11 @@ static std::optional<Type> checkTypeOfBinding(TypeVariableType *typeVar,
35
35
Type type);
36
36
37
37
bool BindingSet::forClosureResult () const {
38
- return Info. TypeVar ->getImpl ().isClosureResultType ();
38
+ return TypeVar->getImpl ().isClosureResultType ();
39
39
}
40
40
41
41
bool BindingSet::forGenericParameter () const {
42
- return bool (Info. TypeVar ->getImpl ().getGenericParameter ());
42
+ return bool (TypeVar->getImpl ().getGenericParameter ());
43
43
}
44
44
45
45
bool BindingSet::canBeNil () const {
@@ -54,10 +54,10 @@ bool BindingSet::isDirectHole() const {
54
54
return false ;
55
55
56
56
return Bindings.empty () && getNumViableLiteralBindings () == 0 &&
57
- Defaults.empty () && Info. TypeVar ->getImpl ().canBindToHole ();
57
+ Defaults.empty () && TypeVar->getImpl ().canBindToHole ();
58
58
}
59
59
60
- bool PotentialBindings:: isGenericParameter () const {
60
+ static bool isGenericParameter (TypeVariableType *TypeVar) {
61
61
auto *locator = TypeVar->getImpl ().getLocator ();
62
62
return locator && locator->isLastElement <LocatorPathElt::GenericParameter>();
63
63
}
@@ -178,7 +178,7 @@ bool BindingSet::involvesTypeVariables() const {
178
178
179
179
bool BindingSet::isPotentiallyIncomplete () const {
180
180
// Generic parameters are always potentially incomplete.
181
- if (Info. isGenericParameter ())
181
+ if (isGenericParameter (TypeVar ))
182
182
return true ;
183
183
184
184
// Key path literal type is incomplete until there is a
@@ -1168,7 +1168,8 @@ LiteralRequirement::isCoveredBy(const PotentialBinding &binding, bool canBeNil,
1168
1168
} while (true );
1169
1169
}
1170
1170
1171
- void PotentialBindings::addPotentialBinding (PotentialBinding binding) {
1171
+ void PotentialBindings::addPotentialBinding (TypeVariableType *TypeVar,
1172
+ PotentialBinding binding) {
1172
1173
assert (!binding.BindingType ->is <ErrorType>());
1173
1174
1174
1175
// If the type variable can't bind to an lvalue, make sure the
@@ -1430,7 +1431,7 @@ BindingSet ConstraintSystem::getBindingsFor(TypeVariableType *typeVar,
1430
1431
" not a representative" );
1431
1432
assert (!typeVar->getImpl ().getFixedType (nullptr ) && " has a fixed type" );
1432
1433
1433
- BindingSet bindings{ CG[typeVar].getCurrentBindings ()} ;
1434
+ BindingSet bindings (* this , typeVar, CG[typeVar].getCurrentBindings ()) ;
1434
1435
1435
1436
if (finalize) {
1436
1437
llvm::SmallDenseMap<TypeVariableType *, BindingSet> cache;
@@ -1473,7 +1474,9 @@ static std::optional<Type> checkTypeOfBinding(TypeVariableType *typeVar,
1473
1474
}
1474
1475
1475
1476
std::optional<PotentialBinding>
1476
- PotentialBindings::inferFromRelational (Constraint *constraint) {
1477
+ PotentialBindings::inferFromRelational (ConstraintSystem &CS,
1478
+ TypeVariableType *TypeVar,
1479
+ Constraint *constraint) {
1477
1480
assert (constraint->getClassification () ==
1478
1481
ConstraintClassification::Relational &&
1479
1482
" only relational constraints handled here" );
@@ -1669,7 +1672,7 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
1669
1672
// Since inference now happens during constraint generation,
1670
1673
// this hack should be allowed in both `Solving`
1671
1674
// (during non-diagnostic mode) and `ConstraintGeneration` phases.
1672
- if (isGenericParameter () &&
1675
+ if (isGenericParameter (TypeVar ) &&
1673
1676
(!CS.shouldAttemptFixes () ||
1674
1677
CS.getPhase () == ConstraintSystemPhase::ConstraintGeneration)) {
1675
1678
type = fnTy->withExtInfo (fnTy->getExtInfo ().withNoEscape (false ));
@@ -1778,7 +1781,9 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
1778
1781
// / Retrieve the set of potential type bindings for the given
1779
1782
// / representative type variable, along with flags indicating whether
1780
1783
// / those types should be opened.
1781
- void PotentialBindings::infer (Constraint *constraint) {
1784
+ void PotentialBindings::infer (ConstraintSystem &CS,
1785
+ TypeVariableType *TypeVar,
1786
+ Constraint *constraint) {
1782
1787
if (!Constraints.insert (constraint).second )
1783
1788
return ;
1784
1789
@@ -1799,11 +1804,11 @@ void PotentialBindings::infer(Constraint *constraint) {
1799
1804
case ConstraintKind::OptionalObject:
1800
1805
case ConstraintKind::UnresolvedMemberChainBase:
1801
1806
case ConstraintKind::LValueObject: {
1802
- auto binding = inferFromRelational (constraint);
1807
+ auto binding = inferFromRelational (CS, TypeVar, constraint);
1803
1808
if (!binding)
1804
1809
break ;
1805
1810
1806
- addPotentialBinding (*binding);
1811
+ addPotentialBinding (TypeVar, *binding);
1807
1812
break ;
1808
1813
}
1809
1814
case ConstraintKind::KeyPathApplication: {
@@ -1952,7 +1957,9 @@ void PotentialBindings::infer(Constraint *constraint) {
1952
1957
}
1953
1958
}
1954
1959
1955
- void PotentialBindings::retract (Constraint *constraint) {
1960
+ void PotentialBindings::retract (ConstraintSystem &CS,
1961
+ TypeVariableType *TypeVar,
1962
+ Constraint *constraint) {
1956
1963
if (!Constraints.erase (constraint))
1957
1964
return ;
1958
1965
@@ -2023,6 +2030,20 @@ void PotentialBindings::retract(Constraint *constraint) {
2023
2030
EquivalentTo.remove_if (hasMatchingSource);
2024
2031
}
2025
2032
2033
+ void PotentialBindings::reset () {
2034
+ Constraints.clear ();
2035
+ Bindings.clear ();
2036
+ Protocols.clear ();
2037
+ Literals.clear ();
2038
+ Defaults.clear ();
2039
+ DelayedBy.clear ();
2040
+ AdjacentVars.clear ();
2041
+ AssociatedCodeCompletionToken = ASTNode ();
2042
+ SubtypeOf.clear ();
2043
+ SupertypeOf.clear ();
2044
+ EquivalentTo.clear ();
2045
+ }
2046
+
2026
2047
void BindingSet::forEachLiteralRequirement (
2027
2048
llvm::function_ref<void (KnownProtocolKind)> callback) const {
2028
2049
for (const auto &literal : Literals) {
0 commit comments