[ty] Avoid caching trivial is-redundant-with calls

This commit is contained in:
Micha Reiser 2025-12-15 18:24:16 +01:00
parent 4e1cf5747a
commit f0789bbfb6
No known key found for this signature in database
1 changed files with 16 additions and 3 deletions

View File

@ -1987,12 +1987,25 @@ impl<'db> Type<'db> {
/// Return `true` if it would be redundant to add `self` to a union that already contains `other`. /// Return `true` if it would be redundant to add `self` to a union that already contains `other`.
/// ///
/// See [`TypeRelation::Redundancy`] for more details. /// See [`TypeRelation::Redundancy`] for more details.
#[salsa::tracked(cycle_initial=is_redundant_with_cycle_initial, heap_size=ruff_memory_usage::heap_size)]
pub(crate) fn is_redundant_with(self, db: &'db dyn Db, other: Type<'db>) -> bool { pub(crate) fn is_redundant_with(self, db: &'db dyn Db, other: Type<'db>) -> bool {
self.has_relation_to(db, other, InferableTypeVars::None, TypeRelation::Redundancy) #[salsa::tracked(cycle_initial=is_redundant_with_cycle_initial, heap_size=ruff_memory_usage::heap_size)]
fn is_redundant_with_impl<'db>(
db: &'db dyn Db,
self_ty: Type<'db>,
other: Type<'db>,
) -> bool {
self_ty
.has_relation_to(db, other, InferableTypeVars::None, TypeRelation::Redundancy)
.is_always_satisfied(db) .is_always_satisfied(db)
} }
if self == other {
return true;
}
is_redundant_with_impl(db, self, other)
}
fn has_relation_to( fn has_relation_to(
self, self,
db: &'db dyn Db, db: &'db dyn Db,