Skip to content

Commit c0238db

Browse files
committed
Sema: Split up BindingSet::inferTransitiveBindings() into three methods
1 parent ab72c53 commit c0238db

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

include/swift/Sema/CSBindings.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ class BindingSet {
540540
/// Check if this binding is favored over a conjunction.
541541
bool favoredOverConjunction(Constraint *conjunction) const;
542542

543+
void inferTransitiveKeyPathBindings();
544+
543545
/// Detect `subtype` relationship between two type variables and
544546
/// attempt to infer supertype bindings transitively e.g.
545547
///
@@ -549,9 +551,9 @@ class BindingSet {
549551
///
550552
/// \param inferredBindings The set of all bindings inferred for type
551553
/// variables in the workset.
552-
void inferTransitiveBindings();
554+
void inferTransitiveSupertypeBindings();
553555

554-
void inferTransitiveKeyPathBindings();
556+
void inferTransitiveUnresolvedMemberRefBindings();
555557

556558
/// Detect subtype, conversion or equivalence relationship
557559
/// between two type variables and attempt to propagate protocol

lib/Sema/CSBindings.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,7 @@ void BindingSet::inferTransitiveKeyPathBindings() {
558558
}
559559
}
560560

561-
void BindingSet::inferTransitiveBindings() {
562-
inferTransitiveKeyPathBindings();
563-
561+
void BindingSet::inferTransitiveSupertypeBindings() {
564562
for (const auto &entry : Info.SupertypeOf) {
565563
auto &node = CS.getConstraintGraph()[entry.first];
566564
if (!node.hasBindingSet())
@@ -626,7 +624,9 @@ void BindingSet::inferTransitiveBindings() {
626624
/*isTransitive=*/true);
627625
}
628626
}
627+
}
629628

629+
void BindingSet::inferTransitiveUnresolvedMemberRefBindings() {
630630
if (!hasViableBindings()) {
631631
if (auto *locator = TypeVar->getImpl().getLocator()) {
632632
if (locator->isLastElement<LocatorPathElt::MemberRefBase>()) {
@@ -1193,7 +1193,9 @@ std::optional<BindingSet> ConstraintSystem::determineBestBindings(
11931193
// produce a default type.
11941194
bool isViable = isViableForRanking(bindings);
11951195

1196-
bindings.inferTransitiveBindings();
1196+
bindings.inferTransitiveKeyPathBindings();
1197+
bindings.inferTransitiveSupertypeBindings();
1198+
bindings.inferTransitiveUnresolvedMemberRefBindings();
11971199

11981200
if (!bindings.finalizeKeyPathBindings())
11991201
continue;

unittests/Sema/BindingInferenceTests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ TEST_F(SemaTest, TestIntLiteralBindingInference) {
125125

126126
cs.getConstraintGraph()[floatLiteralTy].initBindingSet();
127127

128-
bindings.inferTransitiveBindings();
128+
bindings.inferTransitiveKeyPathBindings();
129+
bindings.inferTransitiveSupertypeBindings();
130+
bindings.inferTransitiveUnresolvedMemberRefBindings();
129131
(void) bindings.finalizeKeyPathBindings();
130132
bindings.finalizeUnresolvedMemberChainResult();
131133
bindings.determineLiteralCoverage();

unittests/Sema/SemaFixture.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,14 @@ BindingSet SemaTest::inferBindings(ConstraintSystem &cs,
141141

142142
auto &bindings = node.getBindingSet();
143143

144-
// FIXME: This is also called in inferTransitiveBindings(), why do we need
145-
// to call it again?
144+
// FIXME: This is also called in inferTransitiveUnresolvedMemberRefBindings(),
145+
// why do we need to call it here too?
146146
bindings.inferTransitiveProtocolRequirements();
147147

148-
bindings.inferTransitiveBindings();
148+
bindings.inferTransitiveKeyPathBindings();
149+
bindings.inferTransitiveSupertypeBindings();
150+
bindings.inferTransitiveUnresolvedMemberRefBindings();
151+
149152
(void) bindings.finalizeKeyPathBindings();
150153
bindings.finalizeUnresolvedMemberChainResult();
151154
bindings.determineLiteralCoverage();

0 commit comments

Comments
 (0)