@@ -731,7 +731,7 @@ BindingSet::BindingScore BindingSet::formBindingScore(const BindingSet &b) {
731
731
return std::make_tuple (b.isHole (), numNonDefaultableBindings == 0 ,
732
732
b.isDelayed (), b.isSubtypeOfExistentialType (),
733
733
b.involvesTypeVariables (),
734
- static_cast <unsigned char >(b.getLiteralKind ()),
734
+ static_cast <unsigned char >(b.getLiteralForScore ()),
735
735
-numNonDefaultableBindings);
736
736
}
737
737
@@ -1567,18 +1567,26 @@ void PotentialBindings::retract(Constraint *constraint) {
1567
1567
EquivalentTo.remove_if (hasMatchingSource);
1568
1568
}
1569
1569
1570
- LiteralBindingKind BindingSet::getLiteralKind () const {
1571
- LiteralBindingKind kind = LiteralBindingKind::None;
1572
-
1570
+ void BindingSet::forEachLiteralRequirement (
1571
+ llvm::function_ref<void (KnownProtocolKind)> callback) const {
1573
1572
for (const auto &literal : Literals) {
1574
1573
auto *protocol = literal.first ;
1575
1574
const auto &info = literal.second ;
1576
1575
1577
1576
// Only uncovered defaultable literal protocols participate.
1578
1577
if (!info.viableAsBinding ())
1579
1578
continue ;
1579
+
1580
+ if (auto protocolKind = protocol->getKnownProtocolKind ())
1581
+ callback (*protocolKind);
1582
+ }
1583
+ }
1580
1584
1581
- switch (*protocol->getKnownProtocolKind ()) {
1585
+ LiteralBindingKind BindingSet::getLiteralForScore () const {
1586
+ LiteralBindingKind kind = LiteralBindingKind::None;
1587
+
1588
+ forEachLiteralRequirement ([&](KnownProtocolKind protocolKind) {
1589
+ switch (protocolKind) {
1582
1590
case KnownProtocolKind::ExpressibleByDictionaryLiteral:
1583
1591
case KnownProtocolKind::ExpressibleByArrayLiteral:
1584
1592
case KnownProtocolKind::ExpressibleByStringInterpolation:
@@ -1594,8 +1602,7 @@ LiteralBindingKind BindingSet::getLiteralKind() const {
1594
1602
kind = LiteralBindingKind::Atom;
1595
1603
break ;
1596
1604
}
1597
- }
1598
-
1605
+ });
1599
1606
return kind;
1600
1607
}
1601
1608
@@ -1662,7 +1669,7 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
1662
1669
attributes.push_back (" delayed" );
1663
1670
if (isSubtypeOfExistentialType ())
1664
1671
attributes.push_back (" subtype_of_existential" );
1665
- auto literalKind = getLiteralKind ();
1672
+ auto literalKind = getLiteralForScore ();
1666
1673
if (literalKind != LiteralBindingKind::None) {
1667
1674
std::string literalAttrStr;
1668
1675
literalAttrStr.append (" [literal: " );
0 commit comments