Skip to content

Commit 41623ab

Browse files
committed
[CSBindings] Compute literal information on demand
1 parent 650c54b commit 41623ab

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4773,9 +4773,6 @@ class ConstraintSystem {
47734773

47744774
ASTNode AssociatedCodeCompletionToken = ASTNode();
47754775

4776-
/// Whether this type variable has literal bindings.
4777-
LiteralBindingKind LiteralBinding = LiteralBindingKind::None;
4778-
47794776
/// A set of all not-yet-resolved type variables this type variable
47804777
/// is a subtype of, supertype of or is equivalent to. This is used
47814778
/// to determine ordering inside of a chain of subtypes to help infer
@@ -4901,7 +4898,7 @@ class ConstraintSystem {
49014898
b.isDelayed(),
49024899
b.isSubtypeOfExistentialType(),
49034900
b.involvesTypeVariables(),
4904-
static_cast<unsigned char>(b.LiteralBinding),
4901+
static_cast<unsigned char>(b.getLiteralKind()),
49054902
-numNonDefaultableBindings);
49064903
}
49074904

@@ -4945,23 +4942,33 @@ class ConstraintSystem {
49454942
return x.isPotentiallyIncomplete() < y.isPotentiallyIncomplete();
49464943
}
49474944

4948-
void foundLiteralBinding(ProtocolDecl *proto) {
4949-
switch (*proto->getKnownProtocolKind()) {
4950-
case KnownProtocolKind::ExpressibleByDictionaryLiteral:
4951-
case KnownProtocolKind::ExpressibleByArrayLiteral:
4952-
case KnownProtocolKind::ExpressibleByStringInterpolation:
4953-
LiteralBinding = LiteralBindingKind::Collection;
4954-
break;
4945+
LiteralBindingKind getLiteralKind() const {
4946+
LiteralBindingKind kind = LiteralBindingKind::None;
49554947

4956-
case KnownProtocolKind::ExpressibleByFloatLiteral:
4957-
LiteralBinding = LiteralBindingKind::Float;
4958-
break;
4948+
for (const auto &binding : Bindings) {
4949+
auto *proto = binding.getDefaultedLiteralProtocol();
4950+
if (!proto)
4951+
continue;
49594952

4960-
default:
4961-
if (LiteralBinding != LiteralBindingKind::Collection)
4962-
LiteralBinding = LiteralBindingKind::Atom;
4963-
break;
4953+
switch (*proto->getKnownProtocolKind()) {
4954+
case KnownProtocolKind::ExpressibleByDictionaryLiteral:
4955+
case KnownProtocolKind::ExpressibleByArrayLiteral:
4956+
case KnownProtocolKind::ExpressibleByStringInterpolation:
4957+
kind = LiteralBindingKind::Collection;
4958+
break;
4959+
4960+
case KnownProtocolKind::ExpressibleByFloatLiteral:
4961+
kind = LiteralBindingKind::Float;
4962+
break;
4963+
4964+
default:
4965+
if (kind != LiteralBindingKind::Collection)
4966+
kind = LiteralBindingKind::Atom;
4967+
break;
4968+
}
49644969
}
4970+
4971+
return kind;
49654972
}
49664973

49674974
void addDefault(Constraint *constraint);
@@ -5055,8 +5062,9 @@ class ConstraintSystem {
50555062
out << "delayed ";
50565063
if (isSubtypeOfExistentialType())
50575064
out << "subtype_of_existential ";
5058-
if (LiteralBinding != LiteralBindingKind::None)
5059-
out << "literal=" << static_cast<int>(LiteralBinding) << " ";
5065+
auto literalKind = getLiteralKind();
5066+
if (literalKind != LiteralBindingKind::None)
5067+
out << "literal=" << static_cast<int>(literalKind) << " ";
50605068
if (involvesTypeVariables())
50615069
out << "involves_type_vars ";
50625070

lib/Sema/CSBindings.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,6 @@ void ConstraintSystem::PotentialBindings::addPotentialBinding(
644644
return;
645645
}
646646

647-
if (auto *literalProtocol = binding.getDefaultedLiteralProtocol())
648-
foundLiteralBinding(literalProtocol);
649-
650647
// If the type variable can't bind to an lvalue, make sure the
651648
// type we pick isn't an lvalue.
652649
if (!TypeVar->getImpl().canBindToLValue() &&

0 commit comments

Comments
 (0)