Skip to content

Commit 5f2db0c

Browse files
committed
Sema: Pull call to determineLiteralCoverage() out of BindingSet::finalize()
1 parent 23a7ca0 commit 5f2db0c

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

include/swift/Sema/CSBindings.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,10 @@ class BindingSet {
556556
/// requirements down the subtype or equivalence chain.
557557
void inferTransitiveProtocolRequirements();
558558

559+
/// Check whether the given binding set covers any of the
560+
/// literal protocols associated with this type variable.
561+
void determineLiteralCoverage();
562+
559563
/// Finalize binding computation for this type variable by
560564
/// inferring bindings from context e.g. transitive bindings.
561565
///
@@ -586,10 +590,6 @@ class BindingSet {
586590

587591
void addDefault(Constraint *constraint);
588592

589-
/// Check whether the given binding set covers any of the
590-
/// literal protocols associated with this type variable.
591-
void determineLiteralCoverage();
592-
593593
StringRef getLiteralBindingKind(LiteralBindingKind K) const {
594594
#define ENTRY(Kind, String) \
595595
case LiteralBindingKind::Kind: \

lib/Sema/CSBindings.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,8 +668,6 @@ bool BindingSet::finalize(bool transitive) {
668668
if (transitive)
669669
inferTransitiveBindings();
670670

671-
determineLiteralCoverage();
672-
673671
if (auto *locator = TypeVar->getImpl().getLocator()) {
674672
if (locator->isLastElement<LocatorPathElt::MemberRefBase>()) {
675673
// If this is a base of an unresolved member chain, as a last
@@ -1198,6 +1196,8 @@ std::optional<BindingSet> ConstraintSystem::determineBestBindings(
11981196
if (!bindings.finalize(true))
11991197
continue;
12001198

1199+
bindings.determineLiteralCoverage();
1200+
12011201
if (!bindings.hasViableBindings() && !bindings.isDirectHole())
12021202
continue;
12031203

@@ -1595,6 +1595,7 @@ BindingSet ConstraintSystem::getBindingsFor(TypeVariableType *typeVar) {
15951595

15961596
BindingSet bindings(*this, typeVar, CG[typeVar].getPotentialBindings());
15971597
bindings.finalize(false);
1598+
bindings.determineLiteralCoverage();
15981599

15991600
return bindings;
16001601
}

unittests/Sema/BindingInferenceTests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ TEST_F(SemaTest, TestIntLiteralBindingInference) {
126126
cs.getConstraintGraph()[floatLiteralTy].initBindingSet();
127127

128128
bindings.finalize(/*transitive=*/true);
129+
bindings.determineLiteralCoverage();
129130

130131
// Inferred a single transitive binding through `$T_float`.
131132
ASSERT_EQ(bindings.Bindings.size(), (unsigned)1);

unittests/Sema/SemaFixture.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ BindingSet SemaTest::inferBindings(ConstraintSystem &cs,
142142
auto &bindings = node.getBindingSet();
143143
bindings.inferTransitiveProtocolRequirements();
144144
bindings.finalize(/*transitive=*/true);
145+
bindings.determineLiteralCoverage();
145146
}
146147

147148
auto &node = cs.getConstraintGraph()[typeVar];

0 commit comments

Comments
 (0)