Narrow crate-internal Rust visibility across all targets and delete the code it proves dead
Merged
JA
3mo ago+19389+19389+01234567890123456789012345678901234567890123456789-25175-25175-01234567890123456789012345678901234567890123456789
Summary
Runs a multi-target visibility analysis over the Rust workspace with a fork of Astral's hawk (multi-target support upstreamed as astral-sh/hawk#150) so that pub items with no cross-crate use on any shipped platform are narrowed to pub(crate)/private. Once narrowed, rustc's denied dead_code/unreachable_pub lints can prove code dead across crate boundaries, and that code is deleted.
Three commits:
- Make workspace test and doctest targets compile —
cargo check --workspace --all-targetsandcargo test --doc --workspacewere rotted (test targets never compile in the normal build); needed as a precondition for the analysis. Rotted test helpers deleted, doc-comment diagrams fenced. - Narrow crate-internal visibility across all targets and delete the code it proves dead — the narrowing (~1000 files, net-zero LOC) plus the deletions it enables (~230 crate files): unused fns/methods/consts/statics/fields (with their write sites)/enums/imports, APIs used only by their own tests (deleted with those tests; surviving APIs keep coverage), and the never-constructed
bun_safety::CriticalSectionmodule. Items read only on one platform are#[cfg(...)]-gated instead of deleted. - codegen: exempt generated Rust from dead_code/unreachable_pub lints — generators emit
#[allow(...)]on generated items so an unused generated item is a generator concern rather than a workspace compile error. Kept as a separate tip commit; happy to narrow tounreachable_pubonly or drop it if you'd rather keepdead_codelive on generated output.
Net: −1,941 lines over 1,061 files. (The narrowing is the enabler; the dead-public deletion pass — items no product root reaches at all — is the follow-up.)
Deliberately kept (reads invisible to rustc)
- Fields of
MultiArrayListelement structs (WatchItem,EntryPoint,JSMeta,InputFile,Store::Entry/Node, …) — read through generateditems::<"field">accessors. - Ownership/liveness anchors —
AsyncModule::ast_alloc_state,CurrentBundle::{bv2,heap,ast_alloc_state}, GC-protect handles,KEventWaker::machport_buf. - Types type-punned through raw-pointer casts (
SerializedSourceMap↔SerializedSourceMapLoaded). - FFI structs still named in
pub externsignatures;#[repr(...)]layouts untouched; no#[no_mangle]/externitems removed. PEFile::initkeeps its per-section alignment-overflow validation after dropping the write-only fields it computed.
Test plan
-
cargo check --workspace --all-targetsclean onx86_64-unknown-linux-gnu,aarch64-unknown-linux-musl,x86_64-unknown-freebsd,aarch64-apple-darwin,x86_64-pc-windows-msvc -
cargo checkwith--cfg=bun_asan --cfg=socket_fault_injectionclean -
cargo test --doc --workspacepasses -
bun bdbuilds and links; debug binary smoke-tested (eval, TS run,Bun.serveround-trip,node:fs/path/crypto, spawn) -
test/js/bun/util/inspect.test.js(73/73),test/js/node/path/parse-format.test.jsviabun bd test - Restored crate unit tests pass:
bun_collections34,bun_paths14,bun_clap9,bun_base643 - Full CI matrix