From f0789bbfb6f6a93dfba357452c23d2b414c0b21d Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 15 Dec 2025 18:24:16 +0100 Subject: [PATCH] [ty] Avoid caching trivial is-redundant-with calls --- crates/ty_python_semantic/src/types.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index b318638742..2e285d46a7 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -1987,10 +1987,23 @@ impl<'db> Type<'db> { /// Return `true` if it would be redundant to add `self` to a union that already contains `other`. /// /// 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 { - self.has_relation_to(db, other, InferableTypeVars::None, TypeRelation::Redundancy) - .is_always_satisfied(db) + #[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) + } + + if self == other { + return true; + } + + is_redundant_with_impl(db, self, other) } fn has_relation_to(