Skip to content

Commit 1817ddc

Browse files
committed
[CSBindings] Always finalize binding set unless explicitly asked not to
1 parent 3177145 commit 1817ddc

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4637,7 +4637,7 @@ class ConstraintSystem {
46374637

46384638
/// Get bindings for the given type variable based on current
46394639
/// state of the constraint system.
4640-
BindingSet getBindingsFor(TypeVariableType *typeVar);
4640+
BindingSet getBindingsFor(TypeVariableType *typeVar, bool finalize = true);
46414641

46424642
private:
46434643
/// Add a constraint to the constraint system.

lib/Sema/CSBindings.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ Optional<BindingSet> ConstraintSystem::determineBestBindings() {
694694
// First, let's collect all of the possible bindings.
695695
for (auto *typeVar : getTypeVariables()) {
696696
if (!typeVar->getImpl().hasRepresentativeOrFixed()) {
697-
cache.insert({typeVar, getBindingsFor(typeVar)});
697+
cache.insert({typeVar, getBindingsFor(typeVar, /*finalize=*/false)});
698698
}
699699
}
700700

@@ -943,12 +943,20 @@ bool BindingSet::favoredOverDisjunction(Constraint *disjunction) const {
943943
return !involvesTypeVariables();
944944
}
945945

946-
BindingSet ConstraintSystem::getBindingsFor(TypeVariableType *typeVar) {
946+
BindingSet ConstraintSystem::getBindingsFor(TypeVariableType *typeVar,
947+
bool finalize) {
947948
assert(typeVar->getImpl().getRepresentative(nullptr) == typeVar &&
948949
"not a representative");
949950
assert(!typeVar->getImpl().getFixedType(nullptr) && "has a fixed type");
950951

951-
return {CG[typeVar].getCurrentBindings()};
952+
BindingSet bindings{CG[typeVar].getCurrentBindings()};
953+
954+
if (finalize) {
955+
llvm::SmallDenseMap<TypeVariableType *, BindingSet> cache;
956+
bindings.finalize(cache);
957+
}
958+
959+
return bindings;
952960
}
953961

954962
/// Check whether the given type can be used as a binding for the given

unittests/Sema/SemaFixture.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ BindingSet SemaTest::inferBindings(ConstraintSystem &cs,
127127

128128
for (auto *typeVar : cs.getTypeVariables()) {
129129
if (!typeVar->getImpl().hasRepresentativeOrFixed())
130-
cache.insert({typeVar, cs.getBindingsFor(typeVar)});
130+
cache.insert({typeVar, cs.getBindingsFor(typeVar, /*finalize=*/false)});
131131
}
132132

133133
for (auto *typeVar : cs.getTypeVariables()) {

0 commit comments

Comments
 (0)