Remove dead code from uws_sys, webcore bindings, crash_handler, and scripts

Merged
RO
3mo ago
+53-2600

Dead code sweep: net -2,547 lines across 37 files. Every removal was verified to have zero references across src/, vendor/, scripts/, test/, and regenerated build/debug/codegen output before deletion.

uws_sys (-470)

  • libuwsockets.cpp: 24 unused C API wrappers (uws_ws_send, uws_ws_publish, uws_app_listen_domain, uws_add_server_name, uws_remove_server_name, uws_missing_server_name, uws_constructor_failed, uws_get_native_handle, uws_ws_send_fragment, uws_ws_send_first_fragment, uws_ws_send_first_fragment_with_opcode, uws_ws_send_last_fragment, uws_ws_get_remote_address_as_text, uws_res_get_write_offset, uws_res_override_write_offset, uws_res_get_socket_data, uws_req_is_ancient, uws_req_get_yield, uws_req_for_each_header, uws_req_get_query, uws_loop_addPostHandler, uws_loop_removePostHandler, uws_loop_addPreHandler, uws_loop_removePreHandler). The *_with_options variants are the live paths and stay.
  • libuwsockets_h3.cpp: 14 equivalent uws_h3_* wrappers nothing declares or calls.
  • _libusockets.h: uws_missing_server_handler and uws_get_headers_server_handler typedefs, used only by deleted wrappers.
  • Rust side: the orphaned extern declarations plus unused wrappers Response/h3 override_write_offset, Loop add_pre_handler and add_post_handler (both platforms, including the Handler struct and LoopCtxCb alias only they used), SocketTCP::from_named_pipe (Windows callers use their own helpers in WindowsNamedPipeContext), us_fault_clear, LIBUS_LISTEN_DISALLOW_REUSE_PORT_FAILURE.

C++ bindings (-860)

  • webcore/DOMConstructors.h: trimmed the DOMConstructorID enum from 849 entries to the 51 bun actually references (the rest were WebKit-inherited Touch/ApplePay/WebGL/MediaKeys etc.). Also shrinks the per-GlobalObject constructor WriteBarrier array from 849 to 51 slots. No code casts the enum numerically and nothing reads the old count constants.
  • napi.h NAPI_PERISH macro, dh-primes.h OPENSSL_ARRAY_SIZE and TOBN macros (scaffolding for prime tables the header no longer contains), JSDOMWrapper.h hasCustomPtrTraits (upstream WebKit uses it, bun's copy does not), forward declarations JSPerformanceObject / Wasm::MemoryHandle / FragmentedSharedBuffer, commented-out KeyObject::createJwk declaration.

crash_handler (-270)

  • The error-return-trace apparatus: cold_handle_error_return_trace, handle_error_return_trace_extra, VERBOSE_ERROR_TRACE, HAVE_ERROR_RETURN_TRACING. Rust has no error return traces, so the whole path sat behind a const false (the code itself said so). Removing it also removes the always-None error_return_trace parameters of handle_root_error and panic_impl (plus the unreachable TraceSeed::ErrorReturn variant), the show_trace local whose branches had become indistinguishable, and the no-op --verbose-error-trace debug-build flag that only stored into the dead static.
  • The unused Display impl for StackLine (the symbolizer formats the address field directly).
  • The HandleOom trait: its Error/AllocError arms had no instantiations, and with one impl left the trait itself was ceremony. handle_oom is now a plain function over Result<T, AllocError>, matching its only caller (js_parser scan_imports).

Misc Rust (-20)

  • collections: Default impl for PriorityQueue (all construction goes through ::init).

Scripts and assets (-1,170)

  • scripts/clippy-loop/ (984 lines, 12 files): one-shot tooling for the clippy campaign completed in #31116 (2026-05); zero invokers in repo, package.json, .buildkite, or .github, and it hardcodes a machine path that no longer exists.
  • src/base64/neonbase64: orphan 17.6 KB LLVM bitcode blob with zero build-system references.
  • src/js/bun/sql.ts: commented-out $createPostgresError/$createSQLiteError/$createSQLError helpers native code never called.

Verification

  • cargo check passes on all 10 CI target triples (bun run rust:check-all), which also arbitrated the sweep: an earlier candidate (the semver formatter chain) turned out to be live via install's lockfile debug stringify and was restored, not deleted.
  • Full bun bd debug build passes; smoke ran websocket-server.test.ts (publish/send paths over the uws glue), node-stream.test.js, a bun:sqlite round trip, and a constructor smoke over the trimmed DOMConstructors set (TextEncoder, URLPattern, CookieMap, streams, MessageChannel, structuredClone).
  • This PR ships no test: the removals are pure deletions that the compiler and linker arbitrate, and the source lint that originally pinned them was dropped (5dcd63e) since the project does not keep tests for dead symbols.

Noted but deliberately not removed (for a future pass)

  • JSBufferList.cpp/.h and its ZigGlobalObject wiring (~640 lines): dead since the JS streams implementation replaced native BufferList (#11332), but the whole-file removal is coupled to its global-object accessors and IsoSubspace slots across shared headers, so it needs its own PR.
  • webcore/EventInterfaces.h: ~100 lines of ENABLE()-gated entries look removable but cascade into WebKit-imported switch code.
  • webcore/JSDOMConvertNull.h: IDLNull has no concrete instantiation, but JSDOMConvertUnion mentions it in template machinery.
  • MimallocWTFMalloc.h zeroedMalloc/tryZeroedMalloc/nextCapacity: zero refs in repo, but WTF malloc-policy templates duck-type these members.
  • scripts/lldb-inline*, find-dead-exports.ts, github-metrics.ts, gamble.ts: zero in-repo invokers but plausibly still used by hand.

[review] gate passed · iteration 4 · 38 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-uws-webcore-crash-scripts.test.ts
bun test v1.4.0 (8326d1bd3)

test/internal/source-lints/dead-symbols-uws-webcore-crash-scripts.test.ts:
80 |     ["src/runtime/cli/Arguments.rs", /verbose-error-trace|maybe_verbose_error_trace/],
81 |     // All PriorityQueue construction goes through ::init.
82 |     ["src/collections/lib.rs", /impl<T, C: Default> Default for PriorityQueue/],
83 |   ];
84 |   const resurrected = checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`);
85 |   expect(resurrected).toEqual([]);
                           ^
error: expect(received).toEqual(expected)

- []
+ [
+   "src/uws_sys/WebSocket.rs: uws_ws_send_fragment|uws_ws_send_first_fragment|uws_ws_get_remote_address_as_text",
+   "src/uws_sys/Response.rs: override_write_offset",
+   "src/uws_sys/h3.rs: override_write_offset",
+   "src/uws_sys/Loop.rs: add_pre_handler|add_post_handler|uws_loop_addPreHandler|uws_loop_addPostHandler",
+   "src/uws_sys/socket.rs: \bfrom_named_pipe\b",
+ 
... (truncated)

release without fix: 1 FAILED
bun test v1.4.0-canary.1 (8326d1bd3)

test/internal/source-lints/dead-symbols-uws-webcore-crash-scripts.test.ts:
80 |     ["src/runtime/cli/Arguments.rs", /verbose-error-trace|maybe_verbose_error_trace/],
81 |     // All PriorityQueue construction goes through ::init.
82 |     ["src/collections/lib.rs", /impl<T, C: Default> Default for PriorityQueue/],
83 |   ];
84 |   const resurrected = checks.filter(([file, re]) => re.test(src(file))).map(([file, re]) => `${file}: ${re.source}`);
85 |   expect(resurrected).toEqual([]);
                           ^
error: expect(received).toEqual(expected)

- []
+ [
+   "src/uws_sys/WebSocket.rs: uws_ws_send_fragment|uws_ws_send_first_fragment|uws_ws_get_remote_address_as_text",
+   "src/uws_sys/Response.rs: override_write_offset",
+   "src/uws_sys/h3.rs: override_write_offset",
+   "src/uws_sys/Loop.rs: add_pre_handler|add_post_handler|uws_loop_addPreHandler|uws_loop_addPostHandler",
+   "src/uws_sys/socket.rs: \bfrom_named_pipe\b",
+   "src/uws_sys/lib.rs: us_fault_clear\b|LIBUS_LISTEN_DISALLOW_REUSE_PORT_FAILURE",
+   "src/crash_handler/lib.rs: error_return_trace|VERBOSE_ERROR_TRACE|HAVE_ERROR_RETURN_TRACING|TraceSeed::ErrorRet
... (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-uws-webcore-crash-scripts.test.ts
bun test v1.4.0 (8326d1bd3)

test/internal/source-lints/dead-symbols-uws-webcore-crash-scripts.test.ts:
(pass) dead Rust symbols (uws_sys, crash_handler, collections) do not reappear [32.86ms]
(pass) dead uws_sys C wrappers do not reappear [38.57ms]
(pass) dead C++ bindings do not reappear [50.08ms]
(pass) deleted files stay deleted [19.02ms]

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

release with fix: all passed
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped) in 734ms (unchanged)
ninja: Entering directory `/workspace/bun/build/release'
[1/127] gen ZigGeneratedClasses.{cpp,h,rs}
Found 2 classes from /workspace/bun/src/jsc/resolve_message.classes.ts
  - ResolveMessage (15 fields)
  - BuildMessage (10 fields)
Found 1 classes from /workspace/bun/src/runtime/api/Archive.classes.ts
  - Archive (4 fields, 1 class fields)
Found 2 classes from /workspace/bun/src/runtime/api/BunObject.classes.ts
  - ResourceUsage (8 fields)
  - Subprocess (20 fields)
Found 1 classes from /workspace/bun/src/runtime/api/cron.classes.ts
  - CronJob (5 fields)
Found 3 classes from /workspace/bun/src/runtime/api/filesystem_router.classes.ts
  - FileSystemRouter (5 fields)
  - FrameworkFileSystemRouter (2 fields)
  - MatchedRoute (8 fields)
Found 1 classes from /workspace/bun/src/runtime/api/Glob.classes.ts
  - Glob (5 fields)
Found 1 classes from /workspace/bun/src/runtime/api/h2.classes.ts
  - H2FrameParser (32 fields)
Found 9 classes from /workspace/bun/src/runtime/api/html_rewriter.classes.ts
  - HTMLRewriter (3 fields)
  - TextChunk (7 fields)
  - DocType (5 fields
... (truncated)
diff hotspot
scripts/clippy-loop/apply-patches.ts               |  57 --
 scripts/clippy-loop/collect-all-targets.sh         |  88 ---
 scripts/clippy-loop/collect-pr-comments.sh         |  52 --
 scripts/clippy-loop/collect.sh                     |  26 -
 scripts/clippy-loop/de-unsafe.workflow.ts          | 107 ---
 scripts/clippy-loop/edit-round.workflow.ts         | 119 ---
 scripts/clippy-loop/fix-round.workflow.ts          | 158 ----
 scripts/clippy-loop/group-by-file.ts               | 132 ----
 scripts/clippy-loop/harvest.ts                     |  90 ---
 scripts/clippy-loop/review-round.workflow.ts       |  94 ---
 scripts/clippy-loop/shard.ts                       |  30 -
 scripts/clippy-loop/split-diags.ts                 |  31 -
 src/base64/neonbase64                              | Bin 17648 -> 0 bytes
 src/bun_core/lib.rs                                |  20 +-
 src/collections/lib.rs                             |   8 -
 src/crash_handler/handle_oom.rs                    |  93 +--
 src/crash_handler/lib.rs                           | 142 +---
 src/js/bun/sql.ts                                  |  28 -
 src/jsc/bindings/JSDOMWrapper.h                    |   1 -
 src/jsc/bindings/dh-primes.h                       |  12 -
 src/jsc/bindings/napi.h                            |   7 -
 src/jsc/bindings/node/crypto/KeyObject.h           |   1 -
 src/jsc/bindings/webcore/DOMConstructors.h         | 859 +--------------------
 src/jsc/bindings/webcore/JSPerformance.h           |   2 -
 src/jsc/bindings/webcore/SerializedScriptValue.h   |   2 -
 src/runtime/api/crash_handler_jsc.rs               |   4 +-
 src/runtime/cli/Arguments.rs                       |  21 -
 src/runtime/cli/mod.rs                             |   2 +-
 src/uws_sys/Loop.rs                                |  78 --
 src/uws_sys/Response.rs                            |  13 -
 src/uws_sys/WebSocket.rs                           |  27 -
 src/uws_sys/_libusockets.h                         |   7 -
 sr
... (truncated)

gate history · 5 passed · 2 rejected · iteration 4

evidence per changed file
file                                          reads  edits  tests
scripts/clippy-loop/apply-patches.ts              0      0      0
scripts/clippy-loop/collect-all-targets.sh        0      0      0
scripts/clippy-loop/collect-pr-comments.sh        0      0      0
scripts/clippy-loop/collect.sh                    0      0      0
scripts/clippy-loop/de-unsafe.workflow.ts         0      0      0
scripts/clippy-loop/edit-round.workflow.ts        0      0      0
scripts/clippy-loop/fix-round.workflow.ts         0      0      0
scripts/clippy-loop/group-by-file.ts              0      0      0
scripts/clippy-loop/harvest.ts                    0      0      0
scripts/clippy-loop/review-round.workflow.ts      0      0      0
scripts/clippy-loop/shard.ts                      0      0      0
scripts/clippy-loop/split-diags.ts                0      0      0
src/base64/neonbase64                             0      0      0
src/bun_core/lib.rs                               2      4      0
src/collections/lib.rs                            1      2      0
src/crash_handler/handle_oom.rs                   2      3      0
(+ 22 more files)