@@ -731,7 +731,7 @@ BindingSet::BindingScore BindingSet::formBindingScore(const BindingSet &b) {
731731 return std::make_tuple (b.isHole (), numNonDefaultableBindings == 0 ,
732732 b.isDelayed (), b.isSubtypeOfExistentialType (),
733733 b.involvesTypeVariables (),
734- static_cast <unsigned char >(b.getLiteralKind ()),
734+ static_cast <unsigned char >(b.getLiteralForScore ()),
735735 -numNonDefaultableBindings);
736736}
737737
@@ -1567,18 +1567,26 @@ void PotentialBindings::retract(Constraint *constraint) {
15671567 EquivalentTo.remove_if (hasMatchingSource);
15681568}
15691569
1570- LiteralBindingKind BindingSet::getLiteralKind () const {
1571- LiteralBindingKind kind = LiteralBindingKind::None;
1572-
1570+ void BindingSet::forEachLiteralRequirement (
1571+ llvm::function_ref<void (KnownProtocolKind)> callback) const {
15731572 for (const auto &literal : Literals) {
15741573 auto *protocol = literal.first ;
15751574 const auto &info = literal.second ;
15761575
15771576 // Only uncovered defaultable literal protocols participate.
15781577 if (!info.viableAsBinding ())
15791578 continue ;
1579+
1580+ if (auto protocolKind = protocol->getKnownProtocolKind ())
1581+ callback (*protocolKind);
1582+ }
1583+ }
15801584
1581- switch (*protocol->getKnownProtocolKind ()) {
1585+ LiteralBindingKind BindingSet::getLiteralForScore () const {
1586+ LiteralBindingKind kind = LiteralBindingKind::None;
1587+
1588+ forEachLiteralRequirement ([&](KnownProtocolKind protocolKind) {
1589+ switch (protocolKind) {
15821590 case KnownProtocolKind::ExpressibleByDictionaryLiteral:
15831591 case KnownProtocolKind::ExpressibleByArrayLiteral:
15841592 case KnownProtocolKind::ExpressibleByStringInterpolation:
@@ -1594,8 +1602,7 @@ LiteralBindingKind BindingSet::getLiteralKind() const {
15941602 kind = LiteralBindingKind::Atom;
15951603 break ;
15961604 }
1597- }
1598-
1605+ });
15991606 return kind;
16001607}
16011608
@@ -1662,7 +1669,7 @@ void BindingSet::dump(llvm::raw_ostream &out, unsigned indent) const {
16621669 attributes.push_back (" delayed" );
16631670 if (isSubtypeOfExistentialType ())
16641671 attributes.push_back (" subtype_of_existential" );
1665- auto literalKind = getLiteralKind ();
1672+ auto literalKind = getLiteralForScore ();
16661673 if (literalKind != LiteralBindingKind::None) {
16671674 std::string literalAttrStr;
16681675 literalAttrStr.append (" [literal: " );
0 commit comments