@@ -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
@@ -1418,7 +1419,7 @@ BindingSet ConstraintSystem::getBindingsFor(TypeVariableType *typeVar,
1418
1419
" not a representative" );
1419
1420
assert (!typeVar->getImpl ().getFixedType (nullptr ) && " has a fixed type" );
1420
1421
1421
- BindingSet bindings{ CG[typeVar].getCurrentBindings ()} ;
1422
+ BindingSet bindings (* this , typeVar, CG[typeVar].getCurrentBindings ()) ;
1422
1423
1423
1424
if (finalize) {
1424
1425
llvm::SmallDenseMap<TypeVariableType *, BindingSet> cache;
@@ -1461,7 +1462,9 @@ static std::optional<Type> checkTypeOfBinding(TypeVariableType *typeVar,
1461
1462
}
1462
1463
1463
1464
std::optional<PotentialBinding>
1464
- PotentialBindings::inferFromRelational (Constraint *constraint) {
1465
+ PotentialBindings::inferFromRelational (ConstraintSystem &CS,
1466
+ TypeVariableType *TypeVar,
1467
+ Constraint *constraint) {
1465
1468
assert (constraint->getClassification () ==
1466
1469
ConstraintClassification::Relational &&
1467
1470
" only relational constraints handled here" );
@@ -1657,7 +1660,7 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
1657
1660
// Since inference now happens during constraint generation,
1658
1661
// this hack should be allowed in both `Solving`
1659
1662
// (during non-diagnostic mode) and `ConstraintGeneration` phases.
1660
- if (isGenericParameter () &&
1663
+ if (isGenericParameter (TypeVar ) &&
1661
1664
(!CS.shouldAttemptFixes () ||
1662
1665
CS.getPhase () == ConstraintSystemPhase::ConstraintGeneration)) {
1663
1666
type = fnTy->withExtInfo (fnTy->getExtInfo ().withNoEscape (false ));
@@ -1766,7 +1769,9 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
1766
1769
// / Retrieve the set of potential type bindings for the given
1767
1770
// / representative type variable, along with flags indicating whether
1768
1771
// / those types should be opened.
1769
- void PotentialBindings::infer (Constraint *constraint) {
1772
+ void PotentialBindings::infer (ConstraintSystem &CS,
1773
+ TypeVariableType *TypeVar,
1774
+ Constraint *constraint) {
1770
1775
if (!Constraints.insert (constraint).second )
1771
1776
return ;
1772
1777
@@ -1787,11 +1792,11 @@ void PotentialBindings::infer(Constraint *constraint) {
1787
1792
case ConstraintKind::OptionalObject:
1788
1793
case ConstraintKind::UnresolvedMemberChainBase:
1789
1794
case ConstraintKind::LValueObject: {
1790
- auto binding = inferFromRelational (constraint);
1795
+ auto binding = inferFromRelational (CS, TypeVar, constraint);
1791
1796
if (!binding)
1792
1797
break ;
1793
1798
1794
- addPotentialBinding (*binding);
1799
+ addPotentialBinding (TypeVar, *binding);
1795
1800
break ;
1796
1801
}
1797
1802
case ConstraintKind::KeyPathApplication: {
@@ -1940,7 +1945,9 @@ void PotentialBindings::infer(Constraint *constraint) {
1940
1945
}
1941
1946
}
1942
1947
1943
- void PotentialBindings::retract (Constraint *constraint) {
1948
+ void PotentialBindings::retract (ConstraintSystem &CS,
1949
+ TypeVariableType *TypeVar,
1950
+ Constraint *constraint) {
1944
1951
if (!Constraints.erase (constraint))
1945
1952
return ;
1946
1953
@@ -2011,6 +2018,23 @@ void PotentialBindings::retract(Constraint *constraint) {
2011
2018
EquivalentTo.remove_if (hasMatchingSource);
2012
2019
}
2013
2020
2021
+ void PotentialBindings::reset () {
2022
+ if (CONDITIONAL_ASSERT_enabled ()) {
2023
+ ASSERT (Constraints.empty ());
2024
+ ASSERT (Bindings.empty ());
2025
+ ASSERT (Protocols.empty ());
2026
+ ASSERT (Literals.empty ());
2027
+ ASSERT (Defaults.empty ());
2028
+ ASSERT (DelayedBy.empty ());
2029
+ ASSERT (AdjacentVars.empty ());
2030
+ ASSERT (SubtypeOf.empty ());
2031
+ ASSERT (SupertypeOf.empty ());
2032
+ ASSERT (EquivalentTo.empty ());
2033
+ }
2034
+
2035
+ AssociatedCodeCompletionToken = ASTNode ();
2036
+ }
2037
+
2014
2038
void BindingSet::forEachLiteralRequirement (
2015
2039
llvm::function_ref<void (KnownProtocolKind)> callback) const {
2016
2040
for (const auto &literal : Literals) {
0 commit comments