Remove dead code from C++ webcore headers, src/js, and pretty_format

Closed
RO
3mo ago
+2-1115

Net -1063 lines (+107 -1170) across 26 files. Each symbol was verified to have zero callers across src/, build/debug/codegen/, and src/codegen/ before deletion; a full debug build plus smoke tests (http2, url, mime, expect, Bun.plugin) pass without them.

No overlap with open dead-code PRs #34965, #34759, #35559, #35437.

C++ webcore headers (never #include'd anywhere, 725 lines)

Leftover from the initial WebKit webcore copy; none are referenced by any #include, cmake glob, or codegen script.

  • EventSender.h (116)
  • JSDOMConstructorNotCallable.h (85)
  • JSDOMConvertVariadic.h (74)
  • JSDOMConvertXPathNSResolver.h (55)
  • JSDOMConvertScheduledAction.h (53)
  • BroadcastChannelIdentifier.h, PortIdentifier.h, WebSocketIdentifier.h (35 each)
  • JSDOMBindingInternalsBuiltins.{h,cpp} (237; every line already commented out)

C++ static helpers and extern "C" functions with zero callers (~195 lines)

  • JSMIMEType.cpp: isHTTPQuotedStringChar, isNotHTTPQuotedStringChar, findFirstInvalidHTTPQuotedStringChar, removeBackslashes, escapeQuoteOrBackslash, encodeParamValue. JSMIMEParams.cpp has its own copies of all of these which are used; the JSMIMEType.cpp copies were never called.
  • BunPlugin.cpp: jsFunctionAppendOn{Load,Resolve}Plugin{Node,Browser}. setupBunPlugin only ever wires the *Bun variants via putDirectNativeFunction.
  • FormatStackTraceForJS.cpp: formatStackTraceToJSValueWithoutPrepareStackTrace (static, never called).
  • BunProcess.cpp: Process_defaultSetter (not in BunProcess.lut.h, not referenced by name).
  • windows/rescle-binding.cpp: rescle__setIcon (its Rust caller was removed in #35002; rescle__setWindowsMetadata is the unified replacement).
  • napi.cpp: napi_set_ref, napi_internal_get_version (non-standard N-API symbols; not in any vendor/nodejs header, not referenced by any .rs/.cpp/.ts).
  • node/crypto/CryptoUtil.cpp: Bun__NodeCrypto__createCryptoError.
  • ErrorStackTrace.cpp: Bun__errorInstance__finalize (empty body, never called).

src/js built-in modules (~170 lines)

  • node/child_process.ts: ~130 lines of commented-out E()/makeNodeErrorWithCode/getMessage/ERR_INVALID_ARG_TYPE factory. Replaced by $ERR_* intrinsics; this block has been commented out since be108c0f (2022-11-06).
  • node/url.ts: commented-out fileURLToPath(...args) override.
  • node/http2.ts: top-level consts defined and never referenced: bunTLSConnectOptions, RegExpPrototypeExec, DatePrototypeToUTCString, DatePrototypeGetMilliseconds, kSettingNames (the inverse map kSettingIds is what getUnpackedSettings uses), and throwNotImplemented in the internal/shared destructure.
  • internal/shared.ts: kGetNativeReadableProto symbol (never read anywhere in src/js/ or native).

Rust (~80 lines)

  • runtime/test_runner/pretty_format.rs: ZigFormatter struct + new + Display impl. There are two ZigFormatter types in the tree; every call site (mod.rs, host_fn.rs, RequestContext.rs, JSValue.rs, node_cluster_binding.rs) resolves to bun_jsc::console_object::formatter::ZigFormatter (2-arg new). This 3-arg duplicate over pretty_format::Formatter was unreachable.
  • runtime/bake/dev_server/serialized_failure.rs: 17 lines of commented-out Zig writeJsValue with @panic("TODO").
  • runtime/shell/subproc.rs: 11 lines of commented-out Zig Pipe struct definition.

Verification

  • bun bd builds clean
  • bun bd test on http2, url, mime-api, expect, bun-build-api (plugin), child_process pass (child_process has 3 pre-existing failures on main unrelated to this diff)
  • test/internal/source-lints/dead-symbols-cpp-webcore.test.ts guards against reintroduction; fails on main, passes here

Followups (not in this PR, noted for future sweeps)

  • src/jsc/bindings/JSS3File.cpp customHasInstance + Rust JSS3File__hasInstance: StructureFlags does not include OverridesHasInstance so neither is wired, but S3File.rs is in the area of open PR #35559.
  • src/jsc/bindings/ares_build.h: a stale checked-in copy superseded by scripts/build/deps/cares.ts generation; not touched here because the include-path ordering is non-obvious.

[review] gate passed · iteration 2 · 26 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-cpp-webcore.test.ts
bun test v1.4.0 (4a83700b7)

test/internal/source-lints/dead-symbols-cpp-webcore.test.ts:
27 |     ["src/jsc/bindings/webcore/JSMIMEType.cpp", /static String removeBackslashes/],
28 |     ["src/jsc/bindings/webcore/JSMIMEType.cpp", /static String escapeQuoteOrBackslash/],
29 |     ["src/jsc/bindings/webcore/JSMIMEType.cpp", /static String encodeParamValue/],
30 |     ["src/jsc/bindings/webcore/JSMIMEType.cpp", /static inline bool isHTTPQuotedStringChar/],
31 |   ];
32 |   expect(resurrected(checks)).toEqual([]);
                                   ^
error: expect(received).toEqual(expected)

- []
+ [
+   "src/jsc/bindings/webcore/JSMIMEType.cpp: static int findFirstInvalidHTTPQuotedStringChar",
+   "src/jsc/bindings/webcore/JSMIMEType.cpp: static String removeBackslashes",
+   "src/jsc/bindings/webcore/JSMIMEType.cpp: static String escapeQuoteOrBackslash",
+   "src/jsc/bindings/webcore/JSMIMEType.cpp: static String encodeParamValue",
+   "src/jsc/bindings/webcore/JSMIMEType.cpp
... (truncated)

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

test/internal/source-lints/dead-symbols-cpp-webcore.test.ts:
27 |     ["src/jsc/bindings/webcore/JSMIMEType.cpp", /static String removeBackslashes/],
28 |     ["src/jsc/bindings/webcore/JSMIMEType.cpp", /static String escapeQuoteOrBackslash/],
29 |     ["src/jsc/bindings/webcore/JSMIMEType.cpp", /static String encodeParamValue/],
30 |     ["src/jsc/bindings/webcore/JSMIMEType.cpp", /static inline bool isHTTPQuotedStringChar/],
31 |   ];
32 |   expect(resurrected(checks)).toEqual([]);
                                   ^
error: expect(received).toEqual(expected)

- []
+ [
+   "src/jsc/bindings/webcore/JSMIMEType.cpp: static int findFirstInvalidHTTPQuotedStringChar",
+   "src/jsc/bindings/webcore/JSMIMEType.cpp: static String removeBackslashes",
+   "src/jsc/bindings/webcore/JSMIMEType.cpp: static String escapeQuoteOrBackslash",
+   "src/jsc/bindings/webcore/JSMIMEType.cpp: static String encodeParamValue",
+   "src/jsc/bindings/webcore/JSMIMEType.cpp: static inline bool isHTTPQuotedStringChar",
+ ]

- Expected  - 1
+ Received  + 7

      at <anonymous> (/workspace/bun/test/internal/source-lints/dead-symbols-cpp-webcore.test.ts:32:
... (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-cpp-webcore.test.ts
bun test v1.4.0 (4a83700b7)

test/internal/source-lints/dead-symbols-cpp-webcore.test.ts:
(pass) dead C++ static helpers in JSMIMEType.cpp do not reappear [24.82ms]
(pass) dead extern C functions do not reappear [38.53ms]
(pass) dead src/js items do not reappear [29.06ms]
(pass) dead Rust items do not reappear [14.05ms]

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

release with fix: all passed
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped)
  target       linux-x64-gnu
  build type   Release
  build dir    ./build/release
  revision     4a83700b7a
  features     baseline

22 deps, 108 codegen, 1171 objects in 5560ms

ninja: Entering directory `/workspace/bun/build/release'
[1/1234] gen bindgenv2
[2/1234] gen .bind.ts → GeneratedBindings.cpp
[3/1234] gen JSBuffer.lut.h
Generating /workspace/bun/build/release/codegen/JSBuffer.lut.h from /workspace/bun/src/jsc/bindings/JSBuffer.cpp
[4/1234] gen ProcessBindingBuffer.lut.h
Generating /workspace/bun/build/release/codegen/ProcessBindingBuffer.lut.h from /workspace/bun/src/jsc/bindings/ProcessBindingBuffer.cpp
[5/1234] gen ProcessBindingConstants.lut.h
Generating /workspace/bun/build/release/codegen/ProcessBindingConstants.lut.h from /workspace/bun/src/jsc/bindings/ProcessBindingConstants.cpp
[6/1234] gen ProcessBindingFs.lut.h
Generating /workspace/bun/build/release/codegen/ProcessBindingFs.lut.h from /workspace/bun/src/jsc/bindings/ProcessBindingFs.cpp
[7/1234] fetch zlib
[zlib] up to date
[8/1234] fetch libjpeg-turbo
[libjpeg-turbo] up to date
[9/1234] fetch tinycc
[tinyc
... (truncated)
diff hotspot
src/js/internal/shared.ts                          |   1 -
 src/js/node/child_process.ts                       | 131 -----------------
 src/js/node/http2.ts                               |  16 +--
 src/js/node/url.ts                                 |  24 ----
 src/jsc/bindings/BunPlugin.cpp                     |  20 ---
 src/jsc/bindings/BunProcess.cpp                    |  11 --
 src/jsc/bindings/ErrorStackTrace.cpp               |   5 -
 src/jsc/bindings/FormatStackTraceForJS.cpp         |  18 ---
 src/jsc/bindings/napi.cpp                          |  16 ---
 src/jsc/bindings/node/crypto/CryptoUtil.cpp        |   6 -
 .../bindings/webcore/BroadcastChannelIdentifier.h  |  35 -----
 src/jsc/bindings/webcore/EventSender.h             | 116 ---------------
 .../webcore/JSDOMBindingInternalsBuiltins.cpp      |  78 ----------
 .../webcore/JSDOMBindingInternalsBuiltins.h        | 159 ---------------------
 .../bindings/webcore/JSDOMConstructorNotCallable.h |  85 -----------
 .../bindings/webcore/JSDOMConvertScheduledAction.h |  53 -------
 src/jsc/bindings/webcore/JSDOMConvertVariadic.h    |  74 ----------
 .../bindings/webcore/JSDOMConvertXPathNSResolver.h |  55 -------
 src/jsc/bindings/webcore/JSMIMEType.cpp            | 106 --------------
 src/jsc/bindings/webcore/PortIdentifier.h          |  35 -----
 src/jsc/bindings/webcore/WebSocketIdentifier.h     |  35 -----
 src/jsc/bindings/windows/rescle-binding.cpp        |  12 --
 src/runtime/bake/dev_server/serialized_failure.rs  |  18 ---
 src/runtime/shell/subproc.rs                       |  12 --
 src/runtime/test_runner/pretty_format.rs           |  51 +------
 .../source-lints/dead-symbols-cpp-webcore.test.ts  |  86 +++++++++++
 26 files changed, 88 insertions(+), 1170 deletions(-)

gate history · 2 passed · 1 rejected · iteration 2

evidence per changed file
file                                                      reads  edits  tests
src/js/internal/shared.ts                                     1      1      0
src/js/node/child_process.ts                                  1      1      0
src/js/node/http2.ts                                          2      2      0
src/js/node/url.ts                                            1      1      0
src/jsc/bindings/BunPlugin.cpp                                1      1      0
src/jsc/bindings/BunProcess.cpp                               1      1      0
src/jsc/bindings/ErrorStackTrace.cpp                          1      1      0
src/jsc/bindings/FormatStackTraceForJS.cpp                    1      1      0
src/jsc/bindings/napi.cpp                                     2      1      0
src/jsc/bindings/node/crypto/CryptoUtil.cpp                   1      1      0
src/jsc/bindings/webcore/BroadcastChannelIdentifier.h         0      0      0
src/jsc/bindings/webcore/EventSender.h                        0      0      0
…/jsc/bindings/webcore/JSDOMBindingInternalsBuiltins.cpp      0      0      0
src/jsc/bindings/webcore/JSDOMBindingInternalsBuiltins.h      0      0      0
src/jsc/bindings/webcore/JSDOMConstructorNotCallable.h        0      0      0
src/jsc/bindings/webcore/JSDOMConvertScheduledAction.h        0      0      0
(+ 10 more files)