@@ -35,11 +35,11 @@ static std::optional<Type> checkTypeOfBinding(TypeVariableType *typeVar,
3535 Type type);
3636
3737bool BindingSet::forClosureResult () const {
38- return Info. TypeVar ->getImpl ().isClosureResultType ();
38+ return TypeVar->getImpl ().isClosureResultType ();
3939}
4040
4141bool BindingSet::forGenericParameter () const {
42- return bool (Info. TypeVar ->getImpl ().getGenericParameter ());
42+ return bool (TypeVar->getImpl ().getGenericParameter ());
4343}
4444
4545bool BindingSet::canBeNil () const {
@@ -54,10 +54,10 @@ bool BindingSet::isDirectHole() const {
5454 return false ;
5555
5656 return Bindings.empty () && getNumViableLiteralBindings () == 0 &&
57- Defaults.empty () && Info. TypeVar ->getImpl ().canBindToHole ();
57+ Defaults.empty () && TypeVar->getImpl ().canBindToHole ();
5858}
5959
60- bool PotentialBindings:: isGenericParameter () const {
60+ static bool isGenericParameter (TypeVariableType *TypeVar) {
6161 auto *locator = TypeVar->getImpl ().getLocator ();
6262 return locator && locator->isLastElement <LocatorPathElt::GenericParameter>();
6363}
@@ -178,7 +178,7 @@ bool BindingSet::involvesTypeVariables() const {
178178
179179bool BindingSet::isPotentiallyIncomplete () const {
180180 // Generic parameters are always potentially incomplete.
181- if (Info. isGenericParameter ())
181+ if (isGenericParameter (TypeVar ))
182182 return true ;
183183
184184 // Key path literal type is incomplete until there is a
@@ -1168,7 +1168,8 @@ LiteralRequirement::isCoveredBy(const PotentialBinding &binding, bool canBeNil,
11681168 } while (true );
11691169}
11701170
1171- void PotentialBindings::addPotentialBinding (PotentialBinding binding) {
1171+ void PotentialBindings::addPotentialBinding (TypeVariableType *TypeVar,
1172+ PotentialBinding binding) {
11721173 assert (!binding.BindingType ->is <ErrorType>());
11731174
11741175 // If the type variable can't bind to an lvalue, make sure the
@@ -1418,7 +1419,7 @@ BindingSet ConstraintSystem::getBindingsFor(TypeVariableType *typeVar,
14181419 " not a representative" );
14191420 assert (!typeVar->getImpl ().getFixedType (nullptr ) && " has a fixed type" );
14201421
1421- BindingSet bindings{ CG[typeVar].getCurrentBindings ()} ;
1422+ BindingSet bindings (* this , typeVar, CG[typeVar].getCurrentBindings ()) ;
14221423
14231424 if (finalize) {
14241425 llvm::SmallDenseMap<TypeVariableType *, BindingSet> cache;
@@ -1461,7 +1462,9 @@ static std::optional<Type> checkTypeOfBinding(TypeVariableType *typeVar,
14611462}
14621463
14631464std::optional<PotentialBinding>
1464- PotentialBindings::inferFromRelational (Constraint *constraint) {
1465+ PotentialBindings::inferFromRelational (ConstraintSystem &CS,
1466+ TypeVariableType *TypeVar,
1467+ Constraint *constraint) {
14651468 assert (constraint->getClassification () ==
14661469 ConstraintClassification::Relational &&
14671470 " only relational constraints handled here" );
@@ -1657,7 +1660,7 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
16571660 // Since inference now happens during constraint generation,
16581661 // this hack should be allowed in both `Solving`
16591662 // (during non-diagnostic mode) and `ConstraintGeneration` phases.
1660- if (isGenericParameter () &&
1663+ if (isGenericParameter (TypeVar ) &&
16611664 (!CS.shouldAttemptFixes () ||
16621665 CS.getPhase () == ConstraintSystemPhase::ConstraintGeneration)) {
16631666 type = fnTy->withExtInfo (fnTy->getExtInfo ().withNoEscape (false ));
@@ -1766,12 +1769,14 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
17661769// / Retrieve the set of potential type bindings for the given
17671770// / representative type variable, along with flags indicating whether
17681771// / those types should be opened.
1769- void PotentialBindings::infer (Constraint *constraint) {
1772+ void PotentialBindings::infer (ConstraintSystem &CS,
1773+ TypeVariableType *TypeVar,
1774+ Constraint *constraint) {
17701775 if (!Constraints.insert (constraint).second )
17711776 return ;
17721777
17731778 // Record the change, if there are active scopes.
1774- if (CS.isRecordingChanges ())
1779+ if (CS.solverState && !CS. solverState -> Trail . isUndoActive ())
17751780 CS.recordChange (SolverTrail::Change::InferredBindings (TypeVar, constraint));
17761781
17771782 switch (constraint->getKind ()) {
@@ -1787,11 +1792,11 @@ void PotentialBindings::infer(Constraint *constraint) {
17871792 case ConstraintKind::OptionalObject:
17881793 case ConstraintKind::UnresolvedMemberChainBase:
17891794 case ConstraintKind::LValueObject: {
1790- auto binding = inferFromRelational (constraint);
1795+ auto binding = inferFromRelational (CS, TypeVar, constraint);
17911796 if (!binding)
17921797 break ;
17931798
1794- addPotentialBinding (*binding);
1799+ addPotentialBinding (TypeVar, *binding);
17951800 break ;
17961801 }
17971802 case ConstraintKind::KeyPathApplication: {
@@ -1940,12 +1945,14 @@ void PotentialBindings::infer(Constraint *constraint) {
19401945 }
19411946}
19421947
1943- void PotentialBindings::retract (Constraint *constraint) {
1948+ void PotentialBindings::retract (ConstraintSystem &CS,
1949+ TypeVariableType *TypeVar,
1950+ Constraint *constraint) {
19441951 if (!Constraints.erase (constraint))
19451952 return ;
19461953
19471954 // Record the change, if there are active scopes.
1948- if (CS.isRecordingChanges ())
1955+ if (CS.solverState && !CS. solverState -> Trail . isUndoActive ())
19491956 CS.recordChange (SolverTrail::Change::RetractedBindings (TypeVar, constraint));
19501957
19511958 LLVM_DEBUG (
@@ -2011,6 +2018,23 @@ void PotentialBindings::retract(Constraint *constraint) {
20112018 EquivalentTo.remove_if (hasMatchingSource);
20122019}
20132020
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+
20142038void BindingSet::forEachLiteralRequirement (
20152039 llvm::function_ref<void (KnownProtocolKind)> callback) const {
20162040 for (const auto &literal : Literals) {
0 commit comments