Remove dead code from shell, bake dev server, sql, install, cli, css, and websocket client

Merged
RO
3mo ago
+49-530

Removes 477 lines of verified-dead code across the shell interpreter, bake dev server, SQL wire protocol, package manager, CLI, CSS, websocket client, subprocess glue, and build config (net -436 after the guard lint).

Every deletion was verified with word-boundary searches across src/, scripts/, packages/, and regenerated build/debug/codegen/ output (including C++ callers, $zig/$cpp string references, and EnumString by-name reverse parses), then validated by cargo check on all 10 CI target triples and a full debug build. The workspace denies dead_code, so what survives the lint is mostly never-constructed pub enum variants and the unreachable chains behind their match arms; that is what this PR removes.

shell interpreter

  • WriterTag::{Pipeline,Subshell,If} were never constructed (every ChildPtr::new passes Builtin/Cmd/CondExpr; subprocess capture uses Subproc), so their dispatch arms and the two on_io_writer_chunk handlers reachable only through them were unreachable.
  • Never-assigned states: SubshellState::{Expanding,WaitWriteErr}, IfState::{WaitingWriteErr,Done} (the Done arm was panic!("This code should not be reachable")), CondExprState::Done, CatState::Done (plus the local Branch::Done it fed).
  • Yield::Start (spawners call interp.start_node() directly), ParseFlagResult::ShowUsage (no FlagParser impl returns it), EntryKindHint::File (rm constructs only Idk/Dir).

bake dev server

  • route_bundle::State::EvaluationFailure was never constructed. Deleted its arm, both EnsureRouteCtx::on_failure impls (which would have unwraped the always-None Framework.evaluate_failure field), the field, and ErrorPageKind (every live caller passed Bundler, so the page title is now a constant).
  • MessageId::{BrowserMessage,BrowserMessageClear,RequestHandlerError}: wire bytes the server never sends and no client handles. generated.ts regenerated via the bake codegen.

sql

  • mysql CommandType: kept the three commands bun sends (COM_QUERY, COM_STMT_PREPARE, COM_STMT_EXECUTE); the other 28 had zero references. The enum is only used as as u8 in packet writers, no decode path.
  • mysql StatusFlag: kept SERVER_MORE_RESULTS_EXISTS (the only flag StatusFlags::has is asked about). Decode is unaffected; StatusFlags stores the raw u16.
  • Never-constructed error variants and their arms: mysql InvalidState, postgres InvalidByteSequenceForEncoding and InvalidTimeFormat. These names are also not producible via the EnumString reverse parse in From<crate::Error> (no other sql error enum carries them). Postgres Overflow stays: mysql's constructed Overflow could reach it through that by-name parse.

install / cli

  • Subcommand::Scan plus its two arms (28 lines of help text): bun pm scan dispatches under Subcommand::Pm.
  • Step::{Copyfile,Linking,Patching}: InstallResult::fail is only called with the other four variants.
  • The lifecycle script time log: the entry struct was empty, the list was never read, and the timer field feeding it was never set to Some, so the whole chain (structs, append_concurrent, the PackageManager field, the timer field, manager_mut) was a write-only no-op left from the port.
  • PackageInstall.file_count carried a literal "TODO: this is never read" comment; error handling at the four assignment sites is preserved.
  • PackError::MissingPackageJSON (never constructed; the live same-named variants are on different enums) and ExampleTag::Unknown (zero references; the compiler confirmed by flagging the _ => unreachable!() arm as unreachable once it was gone).

css / websocket / subprocess / timer / watcher / C++ / js

  • css crate_error::Error::CSSPrintError (never constructed; the live CSSPrintError spellings are the separate PrintErr enum) and two uncalled inherent parse_with_options helpers on GenericSelectorList/GenericSelector.
  • websocket ErrorCode::{HeadersTooLarge,CompressionFailed,ExpectedControlFrame,ProtocolError,ProxyConnectionRefused}: never constructed. Discriminants are explicit, so the remaining values still line up with the C++ WebSocketErrorCode table.
  • WTFTimer__runIfImminent: an extern "C" export with zero references in C++, vendor/WebKit, or codegen (the imminent-GC path runs via __bun_run_wtf_timer).
  • Subprocess Readable::{on_close,on_ready} / Writable::on_ready stubs with no callers (teardown goes through Subprocess::on_close_io and the UpstreamSource impl).
  • fs-watcher EventType::Abort was never sent (C++ EventNames.cpp keeps its by-value string table entry).
  • C++ KeyObject::getKeyObjectFromHandle: declaration + definition pair with zero callers.
  • js: two unread repl internalBinding('util') shim constants and a write-only minimatch debug property.
  • Cargo.toml: unused boilerplate deps in bun_glob/bun_router and bundler's unused bun_router dependency; a dead root re-export in bun_s3_signing.

Verification

  • cargo check via bun run rust:check-all: 10 ok, 0 failed.
  • Full bun bd debug build.
  • bun bd test on the touched areas: bunshell.test.ts (418 pass), shell command tests, bun-pack.test.ts (76 pass), bun-install-lifecycle-scripts.test.ts (115 pass), websocket permessage-deflate, css.test.ts (1209 pass), bake/dev/esm.test.ts, repl.test.ts (148 pass), glob/match.test.ts, fs.watch.test.ts, spawn exit-code/stream tests. The only local failures are container artifacts (tests running as root, tests hitting external websocket endpoints, and PATH shims that expect a binary literally named bun), identical under the released bun.
  • Adds test/internal/source-lints/dead-symbols-shell-bake-sql-install.test.ts pinning every removal so the symbols do not come back.

Follow-up note (not in this diff): bun_install::npm decodes a manifest file_count that may also be write-only, and the shell PromptBehaviour::Once { removed_count } field is written but unread pending -i support; both left alone as plausible in-flight scaffolding.


[review] gate passed · iteration 3 · 47 files touched

fails on main (without fix)
ASAN without fix: 5 FAILED
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/internal/source-lints/dead-symbols-shell-bake-sql-install.test.ts
bun test v1.4.0 (c5c1ab8a7)

test/internal/source-lints/dead-symbols-shell-bake-sql-install.test.ts:
65 |     ["src/runtime/shell/interpreter.rs", /ParseFlagResult::ShowUsage/],
66 |     // EntryKindHint::File: rm constructs only Idk and Dir.
67 |     ["src/runtime/shell/builtin/rm.rs", /EntryKindHint::File/],
68 |   ];
69 |   const resurrected = checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`);
70 |   expect(resurrected).toEqual([]);
                           ^
error: expect(received).toEqual(expected)

- []
+ [
+   "src/runtime/shell/IOWriter.rs: ^\s*Pipeline,$",
+   "src/runtime/shell/IOWriter.rs: ^\s*Subshell,$",
+   "src/runtime/shell/states/Pipeline.rs: fn on_io_writer_chunk",
+   "src/runtime/shell/states/Subshell.rs: fn on_io_writer_chunk",
+   "src/runtime/shell/states/Subshell.rs: \bExpanding\b",
+   "src/runtime/shell/states/Subshell.rs: \bWaitWriteErr\b",
+   "src/runtime/shell/states/If.rs: \bWaitingWriteEr
... (truncated)

release without fix: 5 FAILED
bun test v1.4.0-canary.1 (a62a49a95)

test/internal/source-lints/dead-symbols-shell-bake-sql-install.test.ts:
65 |     ["src/runtime/shell/interpreter.rs", /ParseFlagResult::ShowUsage/],
66 |     // EntryKindHint::File: rm constructs only Idk and Dir.
67 |     ["src/runtime/shell/builtin/rm.rs", /EntryKindHint::File/],
68 |   ];
69 |   const resurrected = checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`);
70 |   expect(resurrected).toEqual([]);
                           ^
error: expect(received).toEqual(expected)

- []
+ [
+   "src/runtime/shell/IOWriter.rs: ^\s*Pipeline,$",
+   "src/runtime/shell/IOWriter.rs: ^\s*Subshell,$",
+   "src/runtime/shell/states/Pipeline.rs: fn on_io_writer_chunk",
+   "src/runtime/shell/states/Subshell.rs: fn on_io_writer_chunk",
+   "src/runtime/shell/states/Subshell.rs: \bExpanding\b",
+   "src/runtime/shell/states/Subshell.rs: \bWaitWriteErr\b",
+   "src/runtime/shell/states/If.rs: \bWaitingWriteErr\b",
+   "src/runtime/shell/states/CondExpr.rs: ^\s*Done,$",
+   "src/runtime/shell/builtin/cat.rs: CatState::Done",
+   "src/runtime/shell/Yield.rs: \bStart\(NodeId\)",
+   "src/runtime/shell/i
... (truncated)
passes on PR (with fix)
ASAN with fix: all passed
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/internal/source-lints/dead-symbols-shell-bake-sql-install.test.ts
bun test v1.4.0 (c5c1ab8a7)

test/internal/source-lints/dead-symbols-shell-bake-sql-install.test.ts:
(pass) dead shell interpreter symbols do not reappear [31.32ms]
(pass) dead bake dev server symbols do not reappear [13.81ms]
(pass) dead SQL wire-protocol enum variants do not reappear [10.18ms]
(pass) dead install/cli symbols do not reappear [23.29ms]
(pass) dead websocket/timer/subprocess/watcher/css symbols do not reappear [15.19ms]
(pass) dead C++/JS symbols do not reappear (committed tree) [34.75ms]

 6 pass
 0 fail
 16 expect() calls
Ran 6 tests across 1 file. [2.52s]
__F:0:S:0

release with fix: all passed
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped) in 634ms (unchanged)
ninja: Entering directory `/workspace/bun/build/release'
[1/32] gen bake.{client,server,error}.js
-> bake.client.js, bake.server.js, bake.error.js
[2/32] gen generated_host_exports.rs
generated_host_exports.rs: 93 exports (host=3, lazy=10, generic=80, rust=0); 239 extern-C blocks audited
[3/32] gen cpp.rs (cppbind)
[4/32] gen JS modules (bundle-modules)
Preprocess modules (8785ms)
Bundle modules (35ms)
Postprocesss modules (215ms)
Bundle Functions (686ms)
Generate Code (27ms)

[9.76s] Bundled "src/js" for production
  2610 kb
  197 internal modules
  13 native modules
  91 internal functions across 17 files
[4/23] cargo bun_bin → libbun_rust.a (--target x86_64-unknown-linux-gnu)

  nightly-2026-07-20-x86_64-unknown-linux-gnu unchanged - rustc 1.99.0-nightly (9f36de775 2026-07-19)

   Compiling bun_core v0.0.0 (/workspace/bun/src/bun_core)
   Compiling bun_errno v0.0.0 (/workspace/bun/src/errno)
   Compiling bun_ptr v0.0.0 (/workspace/bun/src/ptr)
   Compiling bun_boringssl_sys v0.0.0 (/workspace/bun/src/borin
... (truncated)
diff hotspot
Cargo.lock                                         |  12 --
 src/bundler/Cargo.toml                             |   1 -
 src/css/crate_error.rs                             |   3 -
 src/css/selectors/parser.rs                        |  21 ---
 src/glob/Cargo.toml                                |   6 -
 src/http_jsc/websocket_client.rs                   |   5 -
 src/install/PackageInstall.rs                      | 117 +++++-------
 src/install/PackageInstaller.rs                    |   1 -
 src/install/PackageManager.rs                      |  11 +-
 src/install/PackageManager/CommandLineArguments.rs |  26 ---
 .../PackageManager/PackageManagerLifecycle.rs      |  17 --
 src/install/lifecycle_script_runner.rs             |  30 ---
 src/install/patch_install.rs                       |   1 -
 src/js/internal/fs/glob.ts                         |   1 -
 src/js/internal/repl/node-shims.js                 |   4 -
 src/jsc/bindings/node/crypto/KeyObject.cpp         |  19 --
 src/jsc/bindings/node/crypto/KeyObject.h           |   1 -
 src/jsc/bindings/webcore/WebSocket.cpp             |  20 --
 src/jsc/bindings/webcore/WebSocketErrorCode.h      |   5 -
 src/router/Cargo.toml                              |   5 -
 src/runtime/api/bun/subprocess/Readable.rs         |   7 -
 src/runtime/api/bun/subprocess/Writable.rs         |   2 -
 src/runtime/bake/DevServer.rs                      |  86 +--------
 src/runtime/bake/dev_server/mod.rs                 |   3 -
 src/runtime/bake/dev_server/route_bundle.rs        |   4 -
 src/runtime/cli/create_command.rs                  |   2 -
 src/runtime/cli/pack_command.rs                    |   9 -
 src/runtime/cli/publish_command.rs                 |   6 -
 src/runtime/node/node_fs_watcher.rs                |   1 -
 src/runtime/shell/IOWriter.rs                      |  15 +-
 src/runtime/shell/Yield.rs                         |   4 -
 src/runtime/shell/builtin/cat.rs                   |   6 +-
 src/runtime/shell/builtin/rm.rs 
... (truncated)

gate history · 2 passed · 1 rejected · iteration 3

evidence per changed file
file                                                   reads  edits  tests
Cargo.lock                                                 0      0      0
src/bundler/Cargo.toml                                     1      1      0
src/css/crate_error.rs                                     1      1      0
src/css/selectors/parser.rs                                1      1      0
src/glob/Cargo.toml                                        1      1      0
src/http_jsc/websocket_client.rs                           1      2      0
src/install/PackageInstall.rs                             10      9      0
src/install/PackageInstaller.rs                            0      0      0
src/install/PackageManager.rs                              1      3      0
src/install/PackageManager/CommandLineArguments.rs         1      1      0
src/install/PackageManager/PackageManagerLifecycle.rs      1      1      0
src/install/lifecycle_script_runner.rs                     2      3      0
src/install/patch_install.rs                               0      0      0
src/js/internal/fs/glob.ts                                 1      1      0
src/js/internal/repl/node-shims.js                         1      1      0
src/jsc/bindings/node/crypto/KeyObject.cpp                 1      1      0
(+ 31 more files)