From a8aefa57c8a1ed7e861c31a77ed1b680cb0817a3 Mon Sep 17 00:00:00 2001 From: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com> Date: Mon, 23 Nov 2026 23:29:43 +0200 Subject: [PATCH] refactor(heap,index): compile test and bench support only for tests and benches (#5491) `ide_heap::testing` (~430 lines of `.hprof` fixture builders) and `ide_index::bench_support` (`SyntheticIndex`) were `#[doc(hidden)] pub mod`s, so they were compiled into the desktop app and `openidea-server` and were part of the public API of both crates. Only tests and benches use them. They are now behind a `testing` feature (`ide-heap`) and a `bench-support` feature (`ide-index`), plus `cfg(test)` for in-crate tests. This follows what `ide-ssh` already does. `bench-support` is named for what it holds: a bench-only builder, not shared test fixtures. Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com> --- Cargo.lock | 2 ++ crates/ide-heap/Cargo.toml | 6 ++++++ crates/ide-heap/src/lib.rs | 2 +- crates/ide-host/Cargo.toml | 1 + crates/ide-index/Cargo.toml | 6 ++++++ crates/ide-index/src/lib.rs | 2 +- 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index befd88a5a..9b3ab7613 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4432,6 +4432,7 @@ version = "0.1.50" dependencies = [ "criterion", "ide-core", + "ide-heap", "libc", "memmap2", "proptest", @@ -4547,6 +4548,7 @@ dependencies = [ "dunce", "globset", "ide-core", + "ide-index", "ide-language", "ignore", "nucleo-matcher", diff --git a/crates/ide-heap/Cargo.toml b/crates/ide-heap/Cargo.toml index 745117087..60a6e2b52 100644 --- a/crates/ide-heap/Cargo.toml +++ b/crates/ide-heap/Cargo.toml @@ -18,7 +18,13 @@ uuid.workspace = true [target.'cfg(unix)'.dependencies] libc = "0.2" +[features] +# `testing`: the `.hprof` fixture builders, for tests and benches of this crate and of crates built on it. +testing = [] + [dev-dependencies] +# Self dev-dependency: turns `testing` on for this crate's benches, so a plain `cargo bench -p ide-heap` builds them. +ide-heap = { workspace = true, features = ["testing"] } criterion = { version = "0.5", default-features = false } proptest.workspace = true tempfile.workspace = true diff --git a/crates/ide-heap/src/lib.rs b/crates/ide-heap/src/lib.rs index 91a8ba9ad..fdd0056a3 100644 --- a/crates/ide-heap/src/lib.rs +++ b/crates/ide-heap/src/lib.rs @@ -20,7 +20,7 @@ mod strings; #[cfg(test)] mod test_index; /// Fixture builders shared by this crate's tests and by dependants' tests and benches; not API. -#[doc(hidden)] +#[cfg(any(test, feature = "testing"))] pub mod testing; pub use analysis::{AnalyzeOptions, analyze}; diff --git a/crates/ide-host/Cargo.toml b/crates/ide-host/Cargo.toml index d74b93e73..87fc1b81a 100644 --- a/crates/ide-host/Cargo.toml +++ b/crates/ide-host/Cargo.toml @@ -78,6 +78,7 @@ zip.workspace = true quick-xml = "0.42" [dev-dependencies] +ide-heap = { workspace = true, features = ["testing"] } ide-ssh = { workspace = true, features = ["testing"] } tokio = { workspace = true, features = ["rt-multi-thread", "macros", "io-util", "test-util"] } criterion = { version = "0.5", default-features = false } diff --git a/crates/ide-index/Cargo.toml b/crates/ide-index/Cargo.toml index 29d8a6163..99470c9c9 100644 --- a/crates/ide-index/Cargo.toml +++ b/crates/ide-index/Cargo.toml @@ -24,7 +24,13 @@ postcard = { version = "1.1", default-features = false, features = ["use-std"] } [build-dependencies] blake3.workspace = true +[features] +# `bench-support`: a synthetic in-memory index for `benches/index.rs`. +bench-support = [] + [dev-dependencies] +# Self dev-dependency: turns `bench-support` on for this crate's benches, so a plain `cargo bench -p ide-index` builds them. +ide-index = { workspace = true, features = ["bench-support"] } tempfile.workspace = true criterion = { version = "0.5", default-features = false } diff --git a/crates/ide-index/src/lib.rs b/crates/ide-index/src/lib.rs index 8e8a651a9..ed33addf2 100644 --- a/crates/ide-index/src/lib.rs +++ b/crates/ide-index/src/lib.rs @@ -536,7 +536,7 @@ impl Drop for ProjectIndex { mod tests; /// Synthetic in-memory index for benchmarks (`benches/index.rs`); not a stable API. -#[doc(hidden)] +#[cfg(any(test, feature = "bench-support"))] pub mod bench_support { use super::*; use crate::data::{FileEntry, FileRecord, IndexData, StoredSymbol};