Skip to content

Commit 94494b6

Browse files
committed
Sema: Make PotentialBindings::infer() and ::retract() idempotent
1 parent b885c29 commit 94494b6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

include/swift/Sema/CSBindings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ struct PotentialBindings {
223223

224224
TypeVariableType *TypeVar;
225225

226+
/// The set of all constraints that have been added via infer().
227+
llvm::SmallPtrSet<Constraint *, 2> Constraints;
228+
226229
/// The set of potential bindings.
227230
llvm::SmallVector<PotentialBinding, 4> Bindings;
228231

lib/Sema/CSBindings.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,9 @@ PotentialBindings::inferFromRelational(Constraint *constraint) {
17691769
/// representative type variable, along with flags indicating whether
17701770
/// those types should be opened.
17711771
void PotentialBindings::infer(Constraint *constraint) {
1772+
if (!Constraints.insert(constraint).second)
1773+
return;
1774+
17721775
switch (constraint->getKind()) {
17731776
case ConstraintKind::Bind:
17741777
case ConstraintKind::Equal:
@@ -1937,6 +1940,9 @@ void PotentialBindings::infer(Constraint *constraint) {
19371940
}
19381941

19391942
void PotentialBindings::retract(Constraint *constraint) {
1943+
if (!Constraints.erase(constraint))
1944+
return;
1945+
19401946
Bindings.erase(
19411947
llvm::remove_if(Bindings,
19421948
[&constraint](const PotentialBinding &binding) {

0 commit comments

Comments
 (0)