Skip to content

Commit 4ed9794

Browse files
committed
[ConstraintSystem] Compute whether bindings are bound only by existentials on demand
1 parent 7f228b0 commit 4ed9794

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

include/swift/Sema/ConstraintSystem.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4744,9 +4744,6 @@ class ConstraintSystem {
47444744
/// Whether this type variable has literal bindings.
47454745
LiteralBindingKind LiteralBinding = LiteralBindingKind::None;
47464746

4747-
/// Whether this type variable is only bound above by existential types.
4748-
bool SubtypeOfExistentialType = false;
4749-
47504747
/// Tracks the position of the last known supertype in the group.
47514748
Optional<unsigned> lastSupertypeIndex;
47524749

@@ -4764,6 +4761,19 @@ class ConstraintSystem {
47644761
/// Determine whether the set of bindings is non-empty.
47654762
explicit operator bool() const { return !Bindings.empty(); }
47664763

4764+
/// Determine if the bindings only constrain the type variable from above
4765+
/// with an existential type; such a binding is not very helpful because
4766+
/// it's impossible to enumerate the existential type's subtypes.
4767+
bool isSubtypeOfExistentialType() const {
4768+
if (Bindings.empty())
4769+
return false;
4770+
4771+
return llvm::all_of(Bindings, [](const PotentialBinding &binding) {
4772+
return binding.BindingType->isExistentialType() &&
4773+
binding.Kind == AllowedBindingKind::Subtypes;
4774+
});
4775+
}
4776+
47674777
unsigned getNumDefaultableBindings() const {
47684778
return llvm::count_if(Bindings, [](const PotentialBinding &binding) {
47694779
return binding.isDefaultableBinding();
@@ -4777,7 +4787,7 @@ class ConstraintSystem {
47774787
return std::make_tuple(b.IsHole,
47784788
!hasNoDefaultableBindings,
47794789
b.FullyBound,
4780-
b.SubtypeOfExistentialType,
4790+
b.isSubtypeOfExistentialType(),
47814791
b.InvolvesTypeVariables,
47824792
static_cast<unsigned char>(b.LiteralBinding),
47834793
-(b.Bindings.size() - numDefaults));
@@ -4925,7 +4935,7 @@ class ConstraintSystem {
49254935
out << "potentially_incomplete ";
49264936
if (FullyBound)
49274937
out << "fully_bound ";
4928-
if (SubtypeOfExistentialType)
4938+
if (isSubtypeOfExistentialType())
49294939
out << "subtype_of_existential ";
49304940
if (LiteralBinding != LiteralBindingKind::None)
49314941
out << "literal=" << static_cast<int>(LiteralBinding) << " ";

lib/Sema/CSBindings.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -513,17 +513,6 @@ void ConstraintSystem::PotentialBindings::finalize(
513513
std::rotate(AnyTypePos, AnyTypePos + 1, Bindings.end());
514514
}
515515
}
516-
517-
// Determine if the bindings only constrain the type variable from above with
518-
// an existential type; such a binding is not very helpful because it's
519-
// impossible to enumerate the existential type's subtypes.
520-
if (!Bindings.empty()) {
521-
SubtypeOfExistentialType =
522-
llvm::all_of(Bindings, [](const PotentialBinding &binding) {
523-
return binding.BindingType->isExistentialType() &&
524-
binding.Kind == AllowedBindingKind::Subtypes;
525-
});
526-
}
527516
}
528517

529518
Optional<ConstraintSystem::PotentialBindings>

0 commit comments

Comments
 (0)