Skip to content

Remove dead code from JSWebSocket, ArrayBuffer::alloc, and Subprocess - #46140

Open
robobun wants to merge 1 commit into
mainfrom
robobun/41cabed5/dead-code-sweep
Open

robobun wants to merge 1 commit into
mainfrom
robobun/41cabed5/dead-code-sweep

Conversation

@robobun

@robobun robobun commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Fix

  • Delete the function, the arm with its C++ function, and the two entries.
  • Add a const { assert!(..) } to alloc. A kind other than ArrayBuffer fails the build, as @compileError did in the Zig original.
  • Correct because a word search finds no use of a removed name, and a --gc-sections debug link drops both C++ functions.
  • Verified: bun bd, bun run rust:check-all (12 targets), cargo check --workspace --all-targets, and the tests in Notes. Self-reviewed: 23 concerns raised, 16 addressed (rejected ones in Notes).

Background

Downsides

  • A later caller of alloc::<{ JSType::Uint8Array }> must restore the arm and the C++ function. cargo check does not evaluate the assert. A full build does.
  • None found for users. Checked: the added lines of all 5,796 open pull requests.

Behaviour change: none

Notes

Removed

  • WebCore::getWebSocketConstructor (JSWebSocket.cpp, JSWebSocket.h, 7 lines). Its only caller was $cpp("JSWebSocket.cpp", "getWebSocketConstructor") in src/js/thirdparty/ws.js:149. WebSocket: real closing handshake, one failure path, ws rewritten on native transports (consolidates the open WebSocket PRs) #45223 replaced that file with ws.ts, which uses createWebSocketBindingForWs.
  • The JSType::Uint8Array arm of ArrayBuffer::alloc and the Bun__allocUint8ArrayForCopy extern (src/jsc/array_buffer.rs, 8 lines), and the C++ function (src/jsc/bindings/ZigGlobalObject.cpp, 12 lines). The three calls of alloc (src/runtime/node/node_crypto_binding.rs:618, :1244, :1266) pass JSType::ArrayBuffer.
  • stdout and stderr in codegen_cached_accessors!("Subprocess"; ...) (src/runtime/api/bun/subprocess.rs, 2 lines). No stdout_get_cached, stdout_set_cached, stdout_take_cached or Gc::stdout use exists, and the same holds for stderr. generate-classes.ts still emits the SubprocessPrototype__{stdout,stderr}{Get,Set}CachedValue shims and the js_Subprocess wrappers. This PR does not change them.

Added

  • const { assert!(KIND.0 == JSType::ArrayBuffer.0, "ArrayBuffer::alloc: KIND not implemented") } in alloc, the pattern of src/uws_sys/socket.rs:718. On the pinned toolchain a Uint8Array instantiation passes a metadata-only compile (cargo check) and fails a full build with error[E0080]: evaluation panicked: ArrayBuffer::alloc: KIND not implemented. The match and its panic! arm stay as they are. create has the same run-time panic! arm for a kind it does not handle. This PR does not touch it.

Reverses an earlier hold

Found dead and left alone

How the items were found

  • A link of the debug build with -Wl,--gc-sections -Wl,--print-gc-sections: the linker drops 229 hand-written C and C++ functions. Open pull requests delete 160 of them.
  • cargo mordant (unused_pub) for Linux, Windows and macOS: 160 findings, equal to mordant-baseline.toml.
  • No lint reports the items of this PR: two are C++, one is a match arm on a const generic, and two are proc-macro output.

Open pull requests

Open PR Effect of this branch
#39929 gains a conflict in JSWebSocket.cpp (7 to 8 files). It deletes toWrapped next to the removed function. Keep both deletions.
#30747 JSWebSocket.cpp conflict hunks 1 to 2
#45243 loses its conflict in JSWebSocket.cpp (11 to 10 files)

Self-review

Where each check ran

  • bun bd, cargo check --workspace --all-targets and the tests below: b1a896d on main 9634520.
  • bun run rust:check-all (12 targets): ac09a8c, the same diff on main 3880151.
  • On main 9634520 a word search still finds no other use of a removed name.

Tests (debug build, bun bd test)

  • test/js/first_party/ws (21 files): 20 files pass (3,106 pass, 80 skip). ws-syscall-fault.test.ts needs more than the 5 s default on the debug build: 3 pass with --timeout 60000 (5.3 s to 5.6 s each).
  • test/js/web/websocket/websocket-client.test.ts: 104 pass
  • test/regression/issue/11866.test.ts: 1 pass
  • test/js/node/crypto/crypto-random.test.ts: 23 pass, 1 skip
  • test/js/node/crypto/scrypt.test.ts: 4 pass
  • test/js/bun/spawn/spawn.test.ts: 181 pass, 8 skip, 2 fail: gcTick > spawn > stdout can be read (5 s timeout on the debug build) and the BUN_FEATURE_FLAG_FORCE_WAITER_THREAD case that runs the file again. The same timeout occurred on a debug build of main 3880151 without this change.

no test proof · iteration 1 · the description declares no behaviour change, so there is no failing test to prove; the existing suite in CI is the check

@robobun

robobun commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 2:44 PM PT - Oct 21st, 2026

❌ @robobun, your commit b1a896d has 1 failures in Build #130194 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 46140

That installs a local version of the PR into your bun-46140 executable, so you can run:

bun-46140 --bun

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: oven-sh/bun/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 6ef662ee-52f8-4f34-8889-97d123cf3f06
📥 Commits

Reviewing files that changed from the base of the PR and between ede1b9f and b1a896d.

📒 Files selected for processing: 2
  • src/jsc/array_buffer.rs
  • src/jsc/bindings/ZigGlobalObject.cpp
💤 Files with no reviewable changes: 1
  • src/jsc/bindings/ZigGlobalObject.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

Changes

ArrayBuffer allocator

Layer / File(s) Summary
ArrayBuffer allocation path
src/jsc/array_buffer.rs, src/jsc/bindings/ZigGlobalObject.cpp
Removes the Uint8Array allocation helper and its FFI declaration. ArrayBuffer::alloc now requires KIND to be ArrayBuffer; other kinds still panic.

WebSocket constructor helper

Layer / File(s) Summary
WebSocket constructor helper
src/jsc/bindings/webcore/JSWebSocket.h, src/jsc/bindings/webcore/JSWebSocket.cpp
Removes the getWebSocketConstructor declaration and definition.

Subprocess cached accessors

Layer / File(s) Summary
Subprocess cached accessors
src/runtime/api/bun/subprocess.rs
Removes generated cached accessors for stdout and stderr.

Suggested reviewers: jarred-sumner

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to b1a89

The cleanup preserves the existing repository behavior and public APIs, so it is mergeable with normal checks.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: removing unused code from JSWebSocket, ArrayBuffer::alloc, and Subprocess.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description clearly explains the problem, the removed code, the compile-time assertion, the lack of intended behavior change, and the verification performed. It does not use the template headings …
Full details: Description check

Explanation

The description clearly explains the problem, the removed code, the compile-time assertion, the lack of intended behavior change, and the verification performed. It does not use the template headings exactly, but it provides the required information and includes detailed test results and known baseline failures.

✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

@robobun

robobun commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: ready for review. The diff is green. The one red CI job is not from this change.

  • The change deletes 29 lines that no code names and adds one compile-time assert. It has no test of its own, and the body carries Behaviour change: none.
  • How it was checked: bun bd, cargo check --workspace --all-targets and the test files in the Notes, at b1a896d on main 9634520. bun run rust:check-all (12 targets) ran on the same diff at ac09a8c.
  • CI on b1a896d (build 130194): 180 of 181 jobs passed. One job failed, test/cli/install/bun-audit.test.ts on Ubuntu 25.04 x64: bun audit fix --dry-run crashed with Segmentation fault at address 0x40 in drop_glue::<bun_http::decompressor::Decompressor>, called from HTTPClient::start. This PR does not touch bun_http, bun_zlib or the audit command, and the same test passed on the other Linux lanes. Every other reported test passed on a retry.
  • Open pull requests: the branch was compared with the heads of all 5,796 open pull requests at 2026-10-20 00:45 UTC. No open pull request uses a removed name, and none removes the same lines.

- getWebSocketConstructor: no caller since the ws module moved to the
  native binding.
- ArrayBuffer::alloc: no caller passes JSType::Uint8Array, so the arm and
  Bun__allocUint8ArrayForCopy have no user. A const assert makes any
  other kind fail the build.
- Subprocess: nothing calls the stdout and stderr cached accessors.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants