Skip to content

Remove dead code from bun_core, bun_css, bun_jsc, and the FFI crates - #38703

Open
robobun wants to merge 1 commit into
mainfrom
claude/farm/be1bba73/dead-code-hawk-sweep
Open

Remove dead code from bun_core, bun_css, bun_jsc, and the FFI crates#38703
robobun wants to merge 1 commit into
mainfrom
claude/farm/be1bba73/dead-code-hawk-sweep

Conversation

@robobun

@robobun robobun commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Net -631 lines of Rust source (49 files), plus a 139-line source lint that keeps the symbols from coming back.

Method: ran the repo's hawk setup (tools/hawk/, dead_public only) once per target for linux-gnu, linux-musl, android, freebsd, darwin and windows-msvc, and kept only the items reported unreachable on every target (test targets included). Items whose file is touched by one of the currently open dead-code PRs were dropped if that PR removes the same symbol (checked against each PR's diff), so nothing here duplicates an open PR. Every remaining item was then re-checked by hand with rg over src/, src/codegen/ and freshly regenerated build/debug/codegen/ before deletion; that pass caught a few hawk false positives, listed at the bottom.

bun_css (-203)

The inherent eql / to_css / parse forwarders that predate the CssEql / ToCss / Parse trait impls; every caller already goes through the traits.

  • Calc::eql, MathFunction::eql and the private eql_calc_list they shared (values/calc.rs)
  • CalcValue::eql trait hook and its six impls: its only caller was Calc::eql. That in turn made the UFCS-only inherent Time::eql and Angle::eql dead (Angle::eql is pub(crate), so rustc flagged it once the trait hook was gone); both removed
  • Token::eql, Num::eql, Dimension::eql (css_parser.rs) and generics::implement_eql, which only they called
  • generics::parse<T: Parse> free function
  • DefaultAtRule::to_css (whole impl block)
  • GenericSelectorList::to_css, GenericSelector::to_css, GenericComponent::to_css, Combinator::to_css: #[deprecated] tombstones that unconditionally unreachable!()
  • TokenList::parse_with_options, CssStringFns::parse (and the css::CssResult as Result import only it used)

bun_jsc (-175)

  • BuiltinName::get and the private BUILTIN_NAME_MAP comptime map that only it read (lib.rs)
  • MarkedArrayBuffer::to_js (every holder goes through to_node_buffer / destroy)
  • TopExceptionScope::new, ExceptionValidationScope::new (all construction goes through init / init_guard*)
  • JSGlobalObject::to_js, JSGlobalObject::ref_, JSGlobalObject::ctx (the latter two were already marked for deletion in a comment)
  • AbortReason::to_js (whole impl block, plus the CommonAbortReasonExt import only it used), JSCell::to_js, JSValue::cast, ErrorBuilder::new (values are built with a struct literal), TagPayload::get, task::new, JsPtr::on_js_thread, Completion::off_thread, UUID::ZERO

bun_core, bun_alloc, bun_ast, bun_ptr (-134)

  • bun_core: RawSlice::from_raw, the buffer concat in lib.rs (callers use strings::concat), SliceWithUnderlyingString::from_utf8, BoundedArrayAligned::get, ExternalShared::as_ptr, ExternalSharedOptional::get, Unaligned::new, Mutex::get_mut, RwLock::get_mut, GenericIndexOptional::{is_some, is_none, get}, Timespec::new, and the write::Result alias (bun_io defines its own)
  • bun_alloc: impl AllocError { name } (wrapping error types hardcode the string), the top-level usable_size (the default_alloc::usable_size everyone calls stays), BSSList::init (bss_singleton! uses init_at)
  • bun_ast: symbol::Map::init
  • bun_ptr: BackRef::shared, DetachablePtr::as_ptr

sys crates (-119)

  • bun_sys: both cfg variants of UTIME_OMIT and its c:: re-export, the raw posix::read wrapper, DynLib::handle
  • bun_uws_sys: NewSocketHandler::group and AnySocket::group, the SocketTcp / SocketTls type aliases and their re-exports (the same-named AnySocket variants are what everything uses), AnyResponse::init, SocketGroup::is_empty, PosixLoop::wake, PosixLoop::run, Opcode::Close (the Opcode::Close in bun_http is a different type), and the non-Windows WindowsLoop stub alias (its only users are #[cfg(windows)])
  • bun_windows_sys: the WaitForSingleObject Result wrapper and its raw extern (bun_sys and the install shim each declare their own; the shim's dead re-export of it is dropped too), NTSTATUS::raw
  • bun_boringssl_sys: GeneralNames::is_empty, X509_V_OK, SSL_SESS_CACHE_CLIENT
  • bun_cares_sys: impl AddrInfo_hints { is_empty }
  • bun_zlib_sys: the z_alloc_fn / z_free_fn legacy aliases and their re-export, Byte
  • bun_tcc_sys: SymbolCallback alias and its re-export

Comment lines that named a removed item were trimmed; no comments were added.

Verification

  • cargo check --workspace on all ten CI triples (bun run rust:check-all), plus --cfg bun_debug --cfg bun_asan and --cfg bun_codegen_embed --all-targets on linux: clean, so no dead_code / unused_imports fallout is left behind
  • cargo fmt --check clean; full bun bd builds
  • bun bd test on test/js/bun/css/{css,color}.test.ts, test/bundler/css/css-modules.test.ts, test/js/web/abort/abort.test.ts, test/js/bun/util/inspect.test.js, test/js/node/zlib/deflate-streaming.test.ts, test/js/bun/net/localhost-loopback-contract.test.ts: all pass
  • test/internal/source-lints/dead-symbols-cross-crate-sweep.test.ts: every one of its 67 entries fires against the pre-PR sources and none fire after

Found dead but deliberately left alone

Cross-crate reachability analysis over the Rust workspace (intersected
across linux-gnu, linux-musl, android, freebsd, darwin and windows-msvc,
test targets included) found these pub items unreachable from any shipped
root. Deletes the inherent eql/to_css/parse forwarders in bun_css that the
trait impls replaced (including the CalcValue::eql hook that only they
called), leftover helpers in bun_core/bun_alloc/bun_ast/bun_ptr/bun_jsc,
and unused wrappers, aliases and constants in the sys crates.

Verified with cargo check --workspace on all ten CI triples (plus the
bun_debug/bun_asan cfgs and --all-targets on linux) and a full debug
build. A source lint in test/internal/source-lints keeps the symbols from
coming back.
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e90d13a7-e0cc-4d06-b948-0db19dbb9558

📥 Commits

Reviewing files that changed from the base of the PR and between 9805144 and c426ed6.

📒 Files selected for processing (49)
  • src/ast/symbol.rs
  • src/boringssl_sys/boringssl.rs
  • src/bun_alloc/lib.rs
  • src/bun_core/bounded_array.rs
  • src/bun_core/external_shared.rs
  • src/bun_core/lib.rs
  • src/bun_core/string/mod.rs
  • src/bun_core/string/write.rs
  • src/bun_core/util.rs
  • src/cares_sys/c_ares.rs
  • src/css/css_parser.rs
  • src/css/generics.rs
  • src/css/lib.rs
  • src/css/properties/custom.rs
  • src/css/rules/mod.rs
  • src/css/selectors/parser.rs
  • src/css/values/angle.rs
  • src/css/values/calc.rs
  • src/css/values/css_string.rs
  • src/css/values/time.rs
  • src/css_derive/lib.rs
  • src/install/windows-shim/main.rs
  • src/jsc/AbortSignal.rs
  • src/jsc/ConsoleObject.rs
  • src/jsc/ErrorCode.rs
  • src/jsc/JSCell.rs
  • src/jsc/JSGlobalObject.rs
  • src/jsc/JSValue.rs
  • src/jsc/Task.rs
  • src/jsc/TopExceptionScope.rs
  • src/jsc/array_buffer.rs
  • src/jsc/job.rs
  • src/jsc/lib.rs
  • src/jsc/uuid.rs
  • src/ptr/lib.rs
  • src/sys/lib.rs
  • src/sys/linux_syscall.rs
  • src/sys/windows/mod.rs
  • src/tcc_sys/lib.rs
  • src/tcc_sys/tcc.rs
  • src/uws_sys/Loop.rs
  • src/uws_sys/Response.rs
  • src/uws_sys/SocketGroup.rs
  • src/uws_sys/lib.rs
  • src/uws_sys/socket.rs
  • src/windows_sys/externs.rs
  • src/zlib_sys/posix.rs
  • src/zlib_sys/shared.rs
  • test/internal/source-lints/dead-symbols-cross-crate-sweep.test.ts

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this PR and didn't find any bugs. Given the breadth — ~67 public items removed across 49 files in foundational crates (bun_core, bun_jsc, bun_sys, bun_css, and eight FFI *_sys crates), including a required trait method on CalcValue — a human pass would still be worthwhile.

What was reviewed:

  • Spot-checked the higher-risk removals: the shim's kernel32::WaitForSingleObject re-export (shim has its own local extern in bun_shim_impl.rs mod k32), UTIME_OMIT (only comment/libuv-header references remain), bun_uws_sys::Opcode::Close (bun_http defines its own Opcode enum), and posix::read (linux_syscall::read_raw still used by linux::read).
  • Confirmed the CalcValue::eql trait-method removal is closed: all six impls dropped it, and structural equality goes through the surviving PartialEq for Calc<V> / MathFunction<V>.
  • The new source-lint follows the existing test/internal/source-lints/dead-symbols-*.test.ts pattern.
Extended reasoning...

Overview

This PR removes ~631 lines of dead Rust across 49 files in bun_core, bun_alloc, bun_ast, bun_ptr, bun_css, bun_jsc, bun_sys, and eight FFI *_sys crates (boringssl, cares, tcc, uws, windows, zlib), plus adds a 139-line source-lint test guarding against reintroduction. Every removed item was identified via cross-target (6 OS triples) hawk dead_public analysis, deduplicated against ~11 open dead-code PRs, and re-verified with rg over src/, src/codegen/, and regenerated build/debug/codegen/. Verification included cargo check --workspace on all 10 CI triples plus --cfg bun_debug --cfg bun_asan and --cfg bun_codegen_embed --all-targets, a full bun bd build, and targeted test runs.

Security risks

Two BoringSSL constants (X509_V_OK, SSL_SESS_CACHE_CLIENT) and GeneralNames::is_empty are removed. These are unused constant declarations / trivial helpers — removing them cannot weaken any security check (no callers exist). No auth/crypto/permission logic is modified.

Level of scrutiny

This warrants human review despite being pure deletions. The individual removals are mechanical, but the aggregate touches foundational infrastructure that every other crate depends on: a required trait method (CalcValue::eql) is dropped from a public trait, cfg-gated re-exports are pruned across platform boundaries (Windows shim, UTIME_OMIT, WindowsLoop non-Windows alias), and ~67 items across 8 FFI-sys crates are removed. A single false-positive in the reachability analysis (e.g., a macro-generated call site, a codegen path not exercised in the regenerated output, or an in-flight PR not in the deduplication list) would break the build for downstream work. The methodology is exemplary and my spot-checks all confirm correctness, but 49 files across the lowest tiers of the crate graph is beyond the "simple and self-contained" bar for auto-approval.

Other factors

  • The new test file follows the established test/internal/source-lints/dead-symbols-*.test.ts pattern (three siblings already exist), so it is not novel test infrastructure.
  • The PR description's "deliberately left alone" section demonstrates careful judgment on hawk false positives (const-generic positions, cfg-gated callers, clippy.toml references, in-flight PR #36225), which raises confidence.
  • Comment-only edits in rules/mod.rs, css_derive/lib.rs, selectors/parser.rs, sys/windows/mod.rs, etc. correctly trim references to removed items without adding new prose.
  • No prior reviews or comments to address; CodeRabbit was rate-limited and did not review.

@robobun

robobun commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 4:45 PM PT - Aug 14th, 2026

@robobun, your commit c426ed6 has 4 failures in Build #96672 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 38703

That installs a local version of the PR into your bun-38703 executable, so you can run:

bun-38703 --bun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants