[ConstraintSystem] Compute whether bindings are bound only by existentials on demand

This commit is contained in:
Pavel Yaskevich
2020-11-11 14:19:49 -08:00
parent 7f228b0e31
commit 4ed9794547
2 changed files with 15 additions and 16 deletions

View File

@@ -4744,9 +4744,6 @@ private:
/// Whether this type variable has literal bindings.
LiteralBindingKind LiteralBinding = LiteralBindingKind::None;
/// Whether this type variable is only bound above by existential types.
bool SubtypeOfExistentialType = false;
/// Tracks the position of the last known supertype in the group.
Optional<unsigned> lastSupertypeIndex;
@@ -4764,6 +4761,19 @@ private:
/// Determine whether the set of bindings is non-empty.
explicit operator bool() const { return !Bindings.empty(); }
/// Determine if the bindings only constrain the type variable from above
/// with an existential type; such a binding is not very helpful because
/// it's impossible to enumerate the existential type's subtypes.
bool isSubtypeOfExistentialType() const {
if (Bindings.empty())
return false;
return llvm::all_of(Bindings, [](const PotentialBinding &binding) {
return binding.BindingType->isExistentialType() &&
binding.Kind == AllowedBindingKind::Subtypes;
});
}
unsigned getNumDefaultableBindings() const {
return llvm::count_if(Bindings, [](const PotentialBinding &binding) {
return binding.isDefaultableBinding();
@@ -4777,7 +4787,7 @@ private:
return std::make_tuple(b.IsHole,
!hasNoDefaultableBindings,
b.FullyBound,
b.SubtypeOfExistentialType,
b.isSubtypeOfExistentialType(),
b.InvolvesTypeVariables,
static_cast<unsigned char>(b.LiteralBinding),
-(b.Bindings.size() - numDefaults));
@@ -4925,7 +4935,7 @@ public:
out << "potentially_incomplete ";
if (FullyBound)
out << "fully_bound ";
if (SubtypeOfExistentialType)
if (isSubtypeOfExistentialType())
out << "subtype_of_existential ";
if (LiteralBinding != LiteralBindingKind::None)
out << "literal=" << static_cast<int>(LiteralBinding) << " ";