[ty] Use upstream GetSize implementation for OrderMap and OrderSet (#22374)

This commit is contained in:
Micha Reiser
2026-01-04 20:54:03 +01:00
committed by GitHub
parent 46a4bfc478
commit b85c0190c5
6 changed files with 3 additions and 29 deletions

1
Cargo.lock generated
View File

@@ -3246,7 +3246,6 @@ name = "ruff_memory_usage"
version = "0.0.0"
dependencies = [
"get-size2",
"ordermap",
]
[[package]]

View File

@@ -93,6 +93,7 @@ get-size2 = { version = "0.7.3", features = [
"smallvec",
"hashbrown",
"compact-str",
"ordermap"
] }
getrandom = { version = "0.3.1" }
glob = { version = "0.3.1" }

View File

@@ -12,7 +12,6 @@ license = { workspace = true }
[dependencies]
get-size2 = { workspace = true }
ordermap = { workspace = true }
[lints]
workspace = true

View File

@@ -1,7 +1,6 @@
use std::cell::RefCell;
use get_size2::{GetSize, StandardTracker};
use ordermap::{OrderMap, OrderSet};
thread_local! {
pub static TRACKER: RefCell<Option<StandardTracker>>= const { RefCell::new(None) };
@@ -42,16 +41,3 @@ pub fn heap_size<T: GetSize>(value: &T) -> usize {
}
})
}
/// An implementation of [`GetSize::get_heap_size`] for [`OrderSet`].
pub fn order_set_heap_size<T: GetSize, S>(set: &OrderSet<T, S>) -> usize {
(set.capacity() * T::get_stack_size()) + set.iter().map(heap_size).sum::<usize>()
}
/// An implementation of [`GetSize::get_heap_size`] for [`OrderMap`].
pub fn order_map_heap_size<K: GetSize, V: GetSize, S>(map: &OrderMap<K, V, S>) -> usize {
(map.capacity() * (K::get_stack_size() + V::get_stack_size()))
+ (map.iter())
.map(|(k, v)| heap_size(k) + heap_size(v))
.sum::<usize>()
}

View File

@@ -14364,7 +14364,7 @@ impl KnownUnion {
}
}
#[salsa::interned(debug, heap_size=IntersectionType::heap_size)]
#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)]
pub struct IntersectionType<'db> {
/// The intersection type includes only values in all of these types.
#[returns(ref)]
@@ -14653,11 +14653,6 @@ impl<'db> IntersectionType<'db> {
pub(crate) fn is_simple_negation(self, db: &'db dyn Db) -> bool {
self.positive(db).is_empty() && self.negative(db).len() == 1
}
fn heap_size((positive, negative): &(FxOrderSet<Type<'db>>, FxOrderSet<Type<'db>>)) -> usize {
ruff_memory_usage::order_set_heap_size(positive)
+ ruff_memory_usage::order_set_heap_size(negative)
}
}
/// # Ordering

View File

@@ -202,7 +202,7 @@ impl<'a, 'db> InferableTypeVars<'a, 'db> {
/// # Ordering
/// Ordering is based on the context's salsa-assigned id and not on its values.
/// The id may change between runs, or when the context was garbage collected and recreated.
#[salsa::interned(debug, constructor=new_internal, heap_size=GenericContext::heap_size)]
#[salsa::interned(debug, constructor=new_internal, heap_size=ruff_memory_usage::heap_size)]
#[derive(PartialOrd, Ord)]
pub struct GenericContext<'db> {
#[returns(ref)]
@@ -689,12 +689,6 @@ impl<'db> GenericContext<'db> {
Self::from_typevar_instances(db, variables)
}
fn heap_size(
(variables,): &(FxOrderMap<BoundTypeVarIdentity<'db>, BoundTypeVarInstance<'db>>,),
) -> usize {
ruff_memory_usage::order_map_heap_size(variables)
}
}
fn inferable_typevars_cycle_initial<'db>(