Remove dead code from install, event_loop, dns, mysql protocol, C++ bindings, and JS internals

Merged
RO
3mo ago
+155-353

Removes code verified to have zero references across src/, scripts/, test/, and freshly regenerated build/debug/codegen/ output. Every candidate was grepped for bare-name, quoted-string, and $-prefixed references before deletion; items referenced from generated bindings, .classes.ts files, attribute-macro exports (uws_callback(export = ...)), or extern "C" surfaces were left alone. The vendored WebKit tree is part of the reference scan as well: Bun__errorInstance__finalize was initially removed here, then restored once the darwin LTO link surfaced its __attribute__((weak)) reference from JSC's ErrorInstance.cpp (weak references satisfy non-LTO links silently).

Rust

  • bun_install::Error: variants FileTooBig, ProcessFdQuotaExceeded, ReadOnlyFileSystem, FileSystem, FileBusy were never constructed (the same-named live variants belong to bun_runtime's separate error enum; node_fs.rs maps onto that one)
  • hosted_git_info::Representation::Ssh: every ssh-flavored protocol maps to Sshurl
  • FromTextLockfileError::InvalidSemver plus its only mention, an unreachable match arm in bun.lock.rs (ParseError::InvalidSemver stays and is still produced)
  • MigratePnpmLockfileError::{PnpmLockfileInvalidOverride, PnpmLockfileInvalidPatchedDependency}: never produced by the pnpm migration
  • windows-shim FailReason::InvalidShimDataSize: no size check produces it
  • bun_event_loop::EventLoopTimer::TimerCallback struct, its Tag variant, and the dispatch arm in runtime/dispatch.rs: nothing ever constructed one, so the tag could never be dispatched
  • bun_dns::Family::Unix: neither the string map nor the JS numeric mapping yields it (AF_UNIX on the result path is a different, live match)
  • MySQL wire structs: write-only fields OKPacket::{warnings, info, session_state_changes}, EOFPacket::warnings, StmtPrepareOKPacket::warning_count, LocalInfileRequest::filename. The wire reads stay so packet parsing consumes the same bytes; only the dead stores and their zero-initializers are gone.

C++ bindings

  • NodeValidator.cpp: host functions jsFunction_validateString / jsFunction_validateFunction / jsFunction_validateBoolean and their declarations. Their $newCppFunction bindings were removed in an earlier sweep (#36937 removed the sibling trio); the V::validate* overloads they forwarded to are live and stay.
  • ImportMetaObject.cpp: jsFunctionRequireResolve and its only callee functionRequireResolve (static, 76 lines; the live require.resolve is built elsewhere)
  • BunString.cpp: BunString__toWTFString (no Rust-side caller; the regenerated cpp.rs drops the import)
  • sliceAnsi.cpp: never-instantiated struct HyperlinkInfo (wrapAnsi.cpp's HyperlinkState is the live one)
  • NodeFSStatFSBinding.cpp: getStatFSPrototype<bool>, a template with zero instantiations
  • Declarations with no definition: functionBunPeek / functionBunPeekStatus (BunObject.h), callBakeResponse / constructBakeResponse (JSBakeResponse.cpp), jsSqlStatementGetHasMultipleStatements (JSSQLStatement.cpp), bn_set_words (dh-primes.h)
  • Commented-out blocks from 2023-2024: the ErrorCaptureStackTrace experiment in BunProcess.cpp, the deleteProperty block in JSAbortSignal.cpp, the setOnEachMicrotaskTick block in BakeGlobalObject.cpp

Built-in JS internals

Export-default entries no requirer ever destructures (verified against every require() site, C++ getDirect lookups, and test/ imports of internal modules); backing functions that are still used in-file stay:

  • internal/repl/node-shims.js: isWritable, runScriptInThisContext, kEmptyObject, addAbortListener, promisify (none of repl.js / internal/repl/* touch them)
  • internal/streams/iter/from.ts: normalizeAsyncSource, normalizeSyncSource, normalizeSyncValue, primitiveToUint8Array
  • internal/sql/sqlite.ts: SQLCommand, commandToString, parseSQLQuery, SQLiteQueryHandle (sole requirer pulls only SQLiteAdapter)
  • internal/sql/shared.ts: parseDefinitelySqliteUrl, buildDefinedColumnsAndQuery, normalizeSSLMode
  • internal/http1_server_fallback.ts: createHttp1FallbackResponseHandle, kHttp1ActiveRequests
  • one-line entries: setTid (trace_events), FixedCircularBuffer (fixed_queue), EXECUTION_CONTEXT_ID (inspector/cdp), defineCustomPromisify (promisify), SQLQueryStatus (sql/query), allUint8Array (streams/iter/utils)

Build config and orphaned files

  • scripts/build/flags.ts: defines IS_BUILD, WITH_BORINGSSL=1, STATICALLY_LINKED_WITH_BMALLOC=1, BUN_SINGLE_THREADED_PER_VM_ENTRY_SCOPE=1 have zero readers in src/, packages/, or the pinned WebKit checkout (WebKit reads the lowercase STATICALLY_LINKED_WITH_bmalloc, which is not what we were defining)
  • src/runtime/ffi/libtcc1.a.macos-aarch64: prebuilt 30KB archive from 2022 with zero references (libtcc1.c is embedded via include_bytes! and compiled at runtime)

Verification

  • cargo check --workspace and bun run rust:check-all (10 ok, 0 failed) so platform-gated uses would have surfaced
  • full bun bd debug build, which regenerates codegen and relinks the C++ side
  • smoke tests: test/js/bun/repl/repl.test.ts (148 pass), test/cli/install/migration/migrate.test.ts (20 pass), test/js/sql/wire-frames.test.ts, test/js/sql/sql-mysql-clean-reentry.test.ts against MariaDB, test/js/sql/adapter-override.test.ts, fixed-queue node tests, plus module-load smokes for repl/stream/trace_events/http2/util
  • test/internal/source-lints/ suite passes, including the new dead-symbols-install-sql-bindings.test.ts that pins these removals
  • checked against all open robobun PRs at deletion granularity: a planned removal of the install lifecycle-script time log was dropped from this PR because #36587 restores that feature, and the mysql CharacterSet collation table plus the Bun__CryptoHasherExtern__* helpers were left alone after verification showed they are referenced (label() at MySQLConnection.rs:661, C++ wrappers in CryptoUtil.cpp)

Verified-dead but deliberately not removed (for a future pass, pending maintainer judgment)

  • windows-shim read_without_launch / FromBunShellContext (~120 lines): zero callers, but the crate docs describe it as the staged in-process path for the shell
  • src/runtime/bake/incremental_visualizer.html + memory_visualizer.html (~808 lines): the /_bun/incremental_visualizer route that served them was never ported from the Zig dev server, while the websocket topic plumbing they rely on is live and tested
  • src/jsc/bindings/webcrypto/*.idl (29 files, ~1055 lines): nothing in the build reads .idl, but they are maintained alongside the handwritten bindings as spec reference (SubtleCrypto.idl was edited in July)

[review] gate passed · iteration 2 · 43 files touched

fails on main (without fix)
ASAN without fix: 1 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-install-sql-bindings.test.ts
bun test v1.4.0 (fc376a388)

test/internal/source-lints/dead-symbols-install-sql-bindings.test.ts:
79 |   expect(reprEnd).toBeGreaterThan(reprStart);
80 |   const reprBody = hosted.slice(reprStart, reprEnd);
81 |   if (/^\s*Ssh,$/m.test(reprBody)) {
82 |     resurrected.push("src/install/hosted_git_info.rs: Representation::Ssh");
83 |   }
84 |   expect(resurrected).toEqual([]);
                           ^
error: expect(received).toEqual(expected)

- []
+ [
+   "src/install/error.rs: ^\s*FileTooBig,$",
+   "src/install/error.rs: ^\s*ProcessFdQuotaExceeded,$",
+   "src/install/error.rs: ^\s*ReadOnlyFileSystem,$",
+   "src/install/error.rs: ^\s*FileSystem,$",
+   "src/install/error.rs: ^\s*FileBusy,$",
+   "src/install/resolution.rs: \bInvalidSemver\b",
+   "src/install/pnpm.rs: PnpmLockfileInvalidOverride|PnpmLockfileInvalidPatchedDependency",
+   "src/install/windows-shim/bun_shim_impl.rs: \bInvalidShimDataSize\b",
+   "src/event_loop/EventLoopTimer.rs: \bTimerCallbac
... (truncated)

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

test/internal/source-lints/dead-symbols-install-sql-bindings.test.ts:
79 |   expect(reprEnd).toBeGreaterThan(reprStart);
80 |   const reprBody = hosted.slice(reprStart, reprEnd);
81 |   if (/^\s*Ssh,$/m.test(reprBody)) {
82 |     resurrected.push("src/install/hosted_git_info.rs: Representation::Ssh");
83 |   }
84 |   expect(resurrected).toEqual([]);
                           ^
error: expect(received).toEqual(expected)

- []
+ [
+   "src/install/error.rs: ^\s*FileTooBig,$",
+   "src/install/error.rs: ^\s*ProcessFdQuotaExceeded,$",
+   "src/install/error.rs: ^\s*ReadOnlyFileSystem,$",
+   "src/install/error.rs: ^\s*FileSystem,$",
+   "src/install/error.rs: ^\s*FileBusy,$",
+   "src/install/resolution.rs: \bInvalidSemver\b",
+   "src/install/pnpm.rs: PnpmLockfileInvalidOverride|PnpmLockfileInvalidPatchedDependency",
+   "src/install/windows-shim/bun_shim_impl.rs: \bInvalidShimDataSize\b",
+   "src/event_loop/EventLoopTimer.rs: \bTimerCallback\b",
+   "src/runtime/dispatch.rs: \bTimerCallback\b",
+   "src/dns/lib.rs: ^\s*Unix,$",
+   "src/sql/mysql/protocol/OKPacket.rs: session_state_changes|pub info:|pub warnings:",
+   "src/sql/m
... (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-install-sql-bindings.test.ts
bun test v1.4.0 (fc376a388)

test/internal/source-lints/dead-symbols-install-sql-bindings.test.ts:
(pass) dead Rust symbols (install, event_loop, dns, mysql protocol) do not reappear [30.77ms]
(pass) dead C++ bindings do not reappear [66.65ms]
(pass) the WebKit weak error finalizer stays defined [5.74ms]
(pass) dead built-in JS exports and build defines do not reappear [32.43ms]

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

release with fix: all passed
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped) in 666ms (unchanged)
ninja: Entering directory `/workspace/bun/build/release'
[1/144] gen generated_host_exports.rs
generated_host_exports.rs: 94 exports (host=3, lazy=10, generic=81, rust=0); 239 extern-C blocks audited
[2/144] gen cpp.rs (cppbind)
[3/144] gen BunProcess.lut.h
Generating /workspace/bun/build/release/codegen/BunProcess.lut.h from /workspace/bun/src/jsc/bindings/BunProcess.cpp
[4/144] gen JS modules (bundle-modules)
Preprocess modules (8773ms)
Bundle modules (47ms)
Postprocesss modules (48ms)
Bundle Functions (653ms)
Generate Code (28ms)

[9.56s] Bundled "src/js" for production
  2571 kb
  193 internal modules
  13 native modules
  84 internal functions across 17 files
[4/143] 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)
   Compi
... (truncated)
diff hotspot
scripts/build/flags.ts                             |   4 -
 src/dns/lib.rs                                     |   2 -
 src/event_loop/EventLoopTimer.rs                   |   9 --
 src/install/error.rs                               |  15 ---
 src/install/hosted_git_info.rs                     |   2 -
 src/install/lockfile/bun.lock.rs                   |   8 --
 src/install/migration.rs                           |   2 -
 src/install/pnpm.rs                                |   4 -
 src/install/resolution.rs                          |   2 -
 src/install/windows-shim/bun_shim_impl.rs          |   2 -
 src/js/internal/fixed_queue.ts                     |   1 -
 src/js/internal/http1_server_fallback.ts           |   2 -
 src/js/internal/inspector/cdp.ts                   |   1 -
 src/js/internal/promisify.ts                       |   1 -
 src/js/internal/repl/node-shims.js                 |  23 ----
 src/js/internal/sql/query.ts                       |   1 -
 src/js/internal/sql/shared.ts                      |   3 -
 src/js/internal/sql/sqlite.ts                      |   4 -
 src/js/internal/streams/iter/from.ts               |   4 -
 src/js/internal/streams/iter/utils.ts              |   1 -
 src/js/internal/trace_events.ts                    |   1 -
 src/jsc/bindings/BunObject.h                       |   2 -
 src/jsc/bindings/BunProcess.cpp                    |  18 ---
 src/jsc/bindings/BunString.cpp                     |  21 ---
 src/jsc/bindings/ErrorStackTrace.cpp               |   1 +
 src/jsc/bindings/ImportMetaObject.cpp              |  89 -------------
 src/jsc/bindings/JSBakeResponse.cpp                |   3 -
 src/jsc/bindings/NodeFSStatFSBinding.cpp           |  10 --
 src/jsc/bindings/NodeValidator.cpp                 |  38 ------
 src/jsc/bindings/NodeValidator.h                   |   3 -
 src/jsc/bindings/dh-primes.h                       |   2 -
 src/jsc/bindings/headers-handwritten.h             |   1 -
 src/jsc/bindings/sliceAnsi.cpp     
... (truncated)

gate history · 4 passed · 1 rejected · iteration 2

evidence per changed file
file                                       reads  edits  tests
scripts/build/flags.ts                         1      1      0
src/dns/lib.rs                                 1      2      0
src/event_loop/EventLoopTimer.rs               1      4      0
src/install/error.rs                           2      3      0
src/install/hosted_git_info.rs                 1      1      0
src/install/lockfile/bun.lock.rs               1      1      0
src/install/migration.rs                       1      1      0
src/install/pnpm.rs                            1      1      0
src/install/resolution.rs                      1      1      0
src/install/windows-shim/bun_shim_impl.rs      1      2      0
src/js/internal/fixed_queue.ts                 1      1      0
src/js/internal/http1_server_fallback.ts       1      2      0
src/js/internal/inspector/cdp.ts               1      1      0
src/js/internal/promisify.ts                   1      1      0
src/js/internal/repl/node-shims.js             3      6      0
src/js/internal/sql/query.ts                   1      1      0
(+ 27 more files)