Skip to content

Commit b09c673

Browse files
committed
Sema: Change a few fields of PotentialBindings from SmallDenseSet to SmallVector
These are not going to have duplicates by construction.
1 parent 4b1cb12 commit b09c673

File tree

2 files changed

+40
-38
lines changed

2 files changed

+40
-38
lines changed

include/swift/Sema/CSBindings.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,17 @@ struct PotentialBindings {
233233
/// bindings (contained in the binding type e.g. `Foo<$T0>`), or
234234
/// reachable through subtype/conversion relationship e.g.
235235
/// `$T0 subtype of $T1` or `$T0 arg conversion $T1`.
236-
llvm::SmallDenseSet<std::pair<TypeVariableType *, Constraint *>, 2>
237-
AdjacentVars;
238-
239-
ASTNode AssociatedCodeCompletionToken = ASTNode();
236+
llvm::SmallVector<std::pair<TypeVariableType *, Constraint *>, 2> AdjacentVars;
240237

241238
/// A set of all not-yet-resolved type variables this type variable
242239
/// is a subtype of, supertype of or is equivalent to. This is used
243240
/// to determine ordering inside of a chain of subtypes to help infer
244241
/// transitive bindings and protocol requirements.
245-
llvm::SmallSetVector<std::pair<TypeVariableType *, Constraint *>, 4> SubtypeOf;
246-
llvm::SmallSetVector<std::pair<TypeVariableType *, Constraint *>, 4> SupertypeOf;
247-
llvm::SmallSetVector<std::pair<TypeVariableType *, Constraint *>, 4> EquivalentTo;
242+
llvm::SmallVector<std::pair<TypeVariableType *, Constraint *>, 4> SubtypeOf;
243+
llvm::SmallVector<std::pair<TypeVariableType *, Constraint *>, 4> SupertypeOf;
244+
llvm::SmallVector<std::pair<TypeVariableType *, Constraint *>, 4> EquivalentTo;
245+
246+
ASTNode AssociatedCodeCompletionToken = ASTNode();
248247

249248
/// Add a potential binding to the list of bindings,
250249
/// coalescing supertype bounds when we are able to compute the meet.

lib/Sema/CSBindings.cpp

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,8 +1646,9 @@ PotentialBindings::inferFromRelational(ConstraintSystem &CS,
16461646
findInferableTypeVars(second, typeVars);
16471647

16481648
if (typeVars.erase(TypeVar)) {
1649-
for (auto *typeVar : typeVars)
1650-
AdjacentVars.insert({typeVar, constraint});
1649+
for (auto *typeVar : typeVars) {
1650+
AdjacentVars.emplace_back(typeVar, constraint);
1651+
}
16511652
}
16521653

16531654
// Infer a binding from `inout $T <convertible to> Unsafe*Pointer<...>?`.
@@ -1772,7 +1773,7 @@ PotentialBindings::inferFromRelational(ConstraintSystem &CS,
17721773
// Add all type variables encountered in the type except
17731774
// to the current type variable.
17741775
if (var != TypeVar) {
1775-
AdjacentVars.insert({var, constraint});
1776+
AdjacentVars.emplace_back(var, constraint);
17761777
continue;
17771778
}
17781779

@@ -1833,26 +1834,26 @@ PotentialBindings::inferFromRelational(ConstraintSystem &CS,
18331834
case ConstraintKind::ArgumentConversion:
18341835
case ConstraintKind::OperatorArgumentConversion: {
18351836
if (kind == AllowedBindingKind::Subtypes) {
1836-
SubtypeOf.insert({bindingTypeVar, constraint});
1837+
SubtypeOf.emplace_back(bindingTypeVar, constraint);
18371838
} else {
18381839
assert(kind == AllowedBindingKind::Supertypes);
1839-
SupertypeOf.insert({bindingTypeVar, constraint});
1840+
SupertypeOf.emplace_back(bindingTypeVar, constraint);
18401841
}
18411842

1842-
AdjacentVars.insert({bindingTypeVar, constraint});
1843+
AdjacentVars.emplace_back(bindingTypeVar, constraint);
18431844
break;
18441845
}
18451846

18461847
case ConstraintKind::Bind:
18471848
case ConstraintKind::BindParam:
18481849
case ConstraintKind::Equal: {
1849-
EquivalentTo.insert({bindingTypeVar, constraint});
1850-
AdjacentVars.insert({bindingTypeVar, constraint});
1850+
EquivalentTo.emplace_back(bindingTypeVar, constraint);
1851+
AdjacentVars.emplace_back(bindingTypeVar, constraint);
18511852
break;
18521853
}
18531854

18541855
case ConstraintKind::UnresolvedMemberChainBase: {
1855-
EquivalentTo.insert({bindingTypeVar, constraint});
1856+
EquivalentTo.emplace_back(bindingTypeVar, constraint);
18561857

18571858
// Don't record adjacency between base and result types,
18581859
// this is just an auxiliary constraint to enforce ordering.
@@ -1864,8 +1865,9 @@ PotentialBindings::inferFromRelational(ConstraintSystem &CS,
18641865
// an un-inferred optional is adjacent to a type
18651866
// variable that presents such optional (`bindingTypeVar`
18661867
// in this case).
1867-
if (kind == AllowedBindingKind::Supertypes)
1868-
AdjacentVars.insert({bindingTypeVar, constraint});
1868+
if (kind == AllowedBindingKind::Supertypes) {
1869+
AdjacentVars.emplace_back(bindingTypeVar, constraint);
1870+
}
18691871
break;
18701872
}
18711873

@@ -2088,33 +2090,34 @@ void PotentialBindings::retract(ConstraintSystem &CS,
20882090
}),
20892091
Bindings.end());
20902092

2091-
{
2092-
llvm::SmallPtrSet<TypeVariableType *, 2> unviable;
2093-
for (const auto &adjacent : AdjacentVars) {
2094-
if (adjacent.second == constraint)
2095-
unviable.insert(adjacent.first);
2096-
}
2097-
2098-
for (auto *adjacentVar : unviable)
2099-
AdjacentVars.erase(std::make_pair(adjacentVar, constraint));
2100-
}
2101-
2102-
auto isMatchingConstraint = [&constraint](Constraint *existing) {
2103-
return existing == constraint;
2104-
};
2105-
2106-
DelayedBy.erase(llvm::remove_if(DelayedBy, isMatchingConstraint),
2107-
DelayedBy.end());
2093+
DelayedBy.erase(
2094+
llvm::remove_if(DelayedBy,
2095+
[&constraint](Constraint *existing) {
2096+
return existing == constraint;
2097+
}),
2098+
DelayedBy.end());
21082099

21092100
auto hasMatchingSource =
21102101
[&constraint](
21112102
const std::pair<TypeVariableType *, Constraint *> &adjacency) {
21122103
return adjacency.second == constraint;
21132104
};
21142105

2115-
SubtypeOf.remove_if(hasMatchingSource);
2116-
SupertypeOf.remove_if(hasMatchingSource);
2117-
EquivalentTo.remove_if(hasMatchingSource);
2106+
AdjacentVars.erase(
2107+
llvm::remove_if(AdjacentVars, hasMatchingSource),
2108+
AdjacentVars.end());
2109+
2110+
SubtypeOf.erase(
2111+
llvm::remove_if(SubtypeOf, hasMatchingSource),
2112+
SubtypeOf.end());
2113+
2114+
SupertypeOf.erase(
2115+
llvm::remove_if(SupertypeOf, hasMatchingSource),
2116+
SupertypeOf.end());
2117+
2118+
EquivalentTo.erase(
2119+
llvm::remove_if(EquivalentTo, hasMatchingSource),
2120+
EquivalentTo.end());
21182121
}
21192122

21202123
void PotentialBindings::reset() {

0 commit comments

Comments
 (0)