Remove dead code from C++ bindings, src/js builtins, CSS, and Rust util crates

Closed
RO
3mo ago
+148-1506

Deletes ~1170 net lines of dead code across 46 files. Follows #35002 into areas that sweep didn't reach (C++ bindings, built-in JS) plus CSS option chains that are provably unreachable.

C++ bindings (src/jsc/bindings/, ~610 lines)

Whole headers with zero #include references:

  • objects.h (254 lines, entirely commented-out since the initial port)
  • ZigLazyStaticFunctions-inlines.h

extern "C" functions with zero callers across src/**/*.rs, vendor/, packages/, and build/debug/codegen/:
JSC__JSValue__fastGetOwn, JSC__JSValue__createRopeString, JSC__VM__externalMemorySize, JSC__JSValue__dateInstanceFromNullTerminatedString, JSC__JSValue__DateNowISOString, DOMFormData__toQueryString, Bun__REPL__formatValue, bun_ignore_sigpipe, Bun__disableSOLinger, getJSCBytecodeCacheVersion, Zig__GlobalObject__getModuleRegistryMap, Zig__GlobalObject__resetModuleRegistryMap, JSGlobalObject__requestTermination, functionFulfillModuleSync, JSC__createEmptyObjectWithStructure, JSC__putDirectOffset, highway_json_index, Bake__getSSRResponseConstructor, StringBuilder__appendUtf16, StringBuilder__appendQuotedJsonString, Bun__JSBigIntStatFSObjectConstructor, Bun__JSStatFSObjectConstructor, ScriptExecutionContextIdentifier__forGlobalObject, Yarr__RegularExpression__matchedLength, Yarr__RegularExpression__searchRev, Cookie__fromJS, jsFetchHeaders_getRawKeys

Built-in JS (src/js/, ~260 lines)

  • builtins/CommonJS.ts: 131-line commented-out loadEsmIntoCjs__dead block (legacy pre-module-loader-rewrite implementation)
  • builtins/JSBufferPrototype.ts: setBigUint64 (no jsBufferPrototypeSetBigUint64CodeGenerator consumer in C++)
  • internal/http.ts: 27 Symbol consts that are declared and exported but never imported anywhere, plus getRawKeys, emitCloseNTAndComplete, ClientRequestEmitState
  • $fulfillModuleSync private builtin (only referenced from the removed CommonJS.ts block)

CSS option chains (src/css/, ~350 lines)

Every PrinterOptions construction in the tree uses ..Default::default() with only minify and targets set. These option fields are never set to non-default, so their downstream branches are unreachable:

  • PrinterOptions.analyze_dependencies: DependencyOptions, Dependency, ImportDependency, UrlDependency, Printer.dependencies, Printer.remove_imports, and the dep-collection branches in rules/import.rs, rules/mod.rs, properties/custom.rs, values/url.rs, values/image.rs; also Url::is_absolute (only caller was a removed branch). dependencies::Location stays (live users).
  • PrinterOptions.pseudo_classes: the PseudoClasses struct and the pseudo! macro indirection in selectors/selector.rs
  • PrinterErrorKind::ambiguous_url_in_custom_property and ::invalid_css_modules_pattern_in_grid (never constructed)

Rust util crates (~25 lines)

  • bun_core/util.rs: FdOptional (unused; only re-exported)
  • bun_core/env_var.rs: BUN_NEEDS_PROC_SELF_WORKAROUND, MI_VERBOSE, TODIUM

Cargo.toml

Unused dependencies dropped from collections, paths, io, glob, css (21 entries).

Verification

  • bun bd builds clean (no warnings)
  • bun run rust:check-all passes on all 10 targets
  • css.test.ts, css-modules.test.ts, css-loader.test.ts, node:http smoke test, dead-code-escapes.test.ts all pass
  • Each extern "C" symbol grepped against vendor/WebKit/ (caught Bun__analyzeTranspiledModule, which is live via weak-override and was left alone)

Not removed

  • src/react_compiler/ has ~3.4k lines of unreferenced debug/print modules, but DESIGN.md marks hir/, diagnostics/, validation/ as byte-for-byte upstream ports kept for the sync workflow; left untouched.
  • MinifyOptions.unused_symbols chain (~95 lines): also provably unreachable, but removing it cascades a parent_is_unused: bool parameter through ~20 minify() signatures. Left for a separate change.

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

fails on main (without fix)
ASAN without fix: 4 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-35437.test.ts"
bun test v1.4.0 (0506a51ec)

test/internal/source-lints/dead-symbols-35437.test.ts:
28 |     ["src/jsc/bindings/SQLClient.cpp", /\bJSC__createEmptyObjectWithStructure\b/],
29 |     ["src/jsc/bindings/RegularExpression.cpp", /\bYarr__RegularExpression__searchRev\b/],
30 |     ["src/jsc/bindings/webcore/JSFetchHeaders.cpp", /\bjsFetchHeaders_getRawKeys\b/],
31 |   ];
32 |   const resurrected = checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`);
33 |   expect(resurrected).toEqual([]);
                           ^
error: expect(received).toEqual(expected)

- []
+ [
+   "src/jsc/bindings/ZigGlobalObject.cpp: \bfunctionFulfillModuleSync\b",
+   "src/jsc/bindings/ZigGlobalObject.cpp: \bZig__GlobalObject__resetModuleRegistryMap\b",
+   "src/jsc/bindings/bindings.cpp: \bBun__REPL__formatValue\b",
+   "src/jsc/bindings/bindings.cpp: \bJSC__JSValue__DateNowISOString\b",
+   "src/jsc/bindings/bindings.cpp: \bDOMFormData__toQueryString\b",
+   "src/j
... (truncated)

release without fix: 4 FAILED
bun test v1.4.0-canary.1 (ad5d2dfec)

test/internal/source-lints/dead-symbols-35437.test.ts:
28 |     ["src/jsc/bindings/SQLClient.cpp", /\bJSC__createEmptyObjectWithStructure\b/],
29 |     ["src/jsc/bindings/RegularExpression.cpp", /\bYarr__RegularExpression__searchRev\b/],
30 |     ["src/jsc/bindings/webcore/JSFetchHeaders.cpp", /\bjsFetchHeaders_getRawKeys\b/],
31 |   ];
32 |   const resurrected = checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`);
33 |   expect(resurrected).toEqual([]);
                           ^
error: expect(received).toEqual(expected)

- []
+ [
+   "src/jsc/bindings/ZigGlobalObject.cpp: \bfunctionFulfillModuleSync\b",
+   "src/jsc/bindings/ZigGlobalObject.cpp: \bZig__GlobalObject__resetModuleRegistryMap\b",
+   "src/jsc/bindings/bindings.cpp: \bBun__REPL__formatValue\b",
+   "src/jsc/bindings/bindings.cpp: \bJSC__JSValue__DateNowISOString\b",
+   "src/jsc/bindings/bindings.cpp: \bDOMFormData__toQueryString\b",
+   "src/jsc/bindings/c-bindings.cpp: \bBun__disableSOLinger\b",
+   "src/jsc/bindings/SQLClient.cpp: \bJSC__createEmptyObjectWithStructure\b",
+   "src/jsc/bindings/RegularExpression.cpp: \
... (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-35437.test.ts"
bun test v1.4.0 (0506a51ec)

test/internal/source-lints/dead-symbols-35437.test.ts:
(pass) dead extern C symbols removed in #35437 do not reappear [28.87ms]
(pass) dead JS builtins removed in #35437 do not reappear [11.88ms]
(pass) dead CSS option chains removed in #35437 do not reappear [10.58ms]
(pass) dead Rust pub items removed in #35437 do not reappear [7.20ms]

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

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

[13.17s] Bundled "src/js" for production
  2558 kb
  193 internal modules
  13 native modules
  89 internal functions across 19 files
[4/139] 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)
   Compilin
... (truncated)
diff hotspot
Cargo.lock                                         |  21 --
 src/base64/Cargo.toml                              |   3 +-
 src/bun_core/env_var.rs                            |   5 -
 src/bun_core/util.rs                               |  17 --
 src/collections/Cargo.toml                         |   2 -
 src/css/Cargo.toml                                 |   5 -
 src/css/css_modules.rs                             |  21 +-
 src/css/css_parser.rs                              |  15 +-
 src/css/dependencies.rs                            |  71 +-----
 src/css/error.rs                                   |  15 --
 src/css/lib.rs                                     |   4 +-
 src/css/media_query.rs                             |   4 +-
 src/css/printer.rs                                 |  71 +-----
 src/css/properties/custom.rs                       |  94 ++------
 src/css/properties/properties_generated.rs         |   6 +-
 src/css/rules/font_face.rs                         |   2 +-
 src/css/rules/font_palette_values.rs               |   2 +-
 src/css/rules/import.rs                            |  24 +-
 src/css/rules/mod.rs                               |  24 --
 src/css/rules/unknown.rs                           |   4 +-
 src/css/selectors/selector.rs                      |  26 +--
 src/css/values/image.rs                            |  38 +--
 src/css/values/syntax.rs                           |   2 +-
 src/css/values/url.rs                              |  86 +------
 src/glob/Cargo.toml                                |   5 -
 src/install/NetworkTask.rs                         |  10 +-
 src/install/PackageManager/runTasks.rs             |   2 +-
 src/install/TarballStream.rs                       |   2 +-
 src/io/Cargo.toml                                  |   4 -
 src/js/builtins.d.ts                               |   1 -
 src/js/builtins/BunBuiltinNames.h                  |   1 -
 src/js/builtins/CommonJS.ts                        | 132 -----------
 src/js/bu
... (truncated)

gate history · 8 passed · 0 rejected · iteration 2

evidence per changed file
file                                        reads  edits  tests
Cargo.lock                                      0      0      0
src/base64/Cargo.toml                           1      2      0
src/bun_core/env_var.rs                         0      0      0
src/bun_core/util.rs                            0      0      0
src/collections/Cargo.toml                      0      0      0
src/css/Cargo.toml                              0      0      0
src/css/css_modules.rs                          1      1      0
src/css/css_parser.rs                           1      1      0
src/css/dependencies.rs                         1      2      0
src/css/error.rs                                0      0      0
src/css/lib.rs                                  0      0      0
src/css/media_query.rs                          1      2      0
src/css/printer.rs                              2      1      0
src/css/properties/custom.rs                    1      2      0
src/css/properties/properties_generated.rs      1      1      0
src/css/rules/font_face.rs                      0      0      0
(+ 50 more files)

root cause · written by the author bot

The bug was residual dead code left behind by an API cleanup that applied its own removal criterion inconsistently: PrinterOptions.project_root was never set to a non-default value at any construction site, so its entire downstream chain through CssModule::new was unreachable, and similar dead surface remained in the unused is_custom_property parameter and stale comments referencing the removed hive get() API. The fix removes project_root along with its capture, parameter, and argument chain, the unreachable branch in css_modules.rs, and the struct's now-unneeded lifetime paramete…