Repository navigation
Remove dead code from the web streams bindings, the test runner formatter, and the bindgen codegen - #41445
Remove dead code from the web streams bindings, the test runner formatter, and the bindgen codegen#41445robobun wants to merge 7 commits into
Conversation
…tter, and the bindgen codegen Delete the cross-realm transform stream state that nothing creates, the unused IDLTypes.h trait aliases, the MessageLevel parameter of JestPrettyFormat that every caller set to Debug, the bindgen type constructors with no users, and a few stale commented-out blocks.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Essentials Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review. WalkthroughChangesPublic API and type cleanup
Web Streams cross-realm removal
Test formatter simplification
Obsolete code cleanup
Possibly related PRs
Merge Risk: ⚪ Minimal · up to This change removes unused code and simplifies internal interfaces without an identified remaining behavior or production-impact risk. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
|
Updated 12:27 PM PT - Sep 5th, 2026
✅ @robobun, your commit 3e1b3375daf0bb8245ee39511a6bea5a43beda34 passed in 🧪 To try this PR locally: bunx bun-pr 41445That installs a local version of the PR into your bun-41445 --bun |
|
Status: this PR removes code with zero references and changes no behavior, so no test can fail before the change and pass after it. |
Every builtin in `t` must report its name as its kind and lower to a C ABI type, and only dictionaries are object types.
…e unchanged The break after each Transform arm belonged to the removed CrossRealm arm. The TaggedObject removal is left out because bun-native-plugin is a published crate and the struct is part of its public API.
There was a problem hiding this comment.
LGTM — both earlier nits are addressed (the orphaned break; statements after the Transform arms are gone, and packages/bun-native-plugin-rs is no longer touched).
What was reviewed on this push: re-checked the three SinkKind switches in JSWritableStreamDefaultController.cpp — each arm now returns and falls through to RELEASE_ASSERT_NOT_REACHED() cleanly; grepped src/ for CrossRealm, strictBoolean, externalClass, kValidateObjectNone, and MessageLevel — remaining hits are unrelated same-named symbols in console/webview/worker code, none in the touched subsystems. Also weighed bindgen-type-dsl.test.ts against the source-lints CLAUDE.md — it asserts positive invariants on the live t DSL (kind↔name, C-ABI lowering, isObjectType), not that a removed symbol stays removed.
Extended reasoning...
Overview
Dead-code sweep across three independent subsystems: the C++ web-streams bindings (removes the never-constructed CrossRealm transferable-streams machinery — two files deleted, enum arms and iso-subspace/structure-table entries pruned), the Rust test-runner formatter (removes MessageLevel and the level parameter that every caller set to Debug), and the bindgen type DSL (removes t.strictBoolean/t.externalClass and their switch arms). Also removes commented-out code in three C++ files, an unused m_done field, unused IDLTypes.h aliases, and kValidateObjectNone. Adds one source-lint test exercising the bindgen DSL's internal consistency. Net ~+56/−287 across 26 files.
Security risks
None. This is pure removal of unreferenced code plus a build-time source-lint test. No auth, crypto, network parsing, or user-input handling is touched. The removed CrossRealm arms were RELEASE_ASSERT_NOT_REACHED() bodies — nothing constructed them.
Level of scrutiny
Moderate, focused on completeness rather than behavior: for enum-variant removals the risk is a missed switch site, which in C++ would either fail to compile or fall through to the existing RELEASE_ASSERT_NOT_REACHED(). A repo-wide grep for the removed identifiers shows no remaining references in the affected subsystems (remaining MessageLevel/CrossRealm hits are unrelated symbols in console, webview, and worker code). The Rust side would fail dead_code = "deny" if a caller were missed.
Other factors
Both of my prior optional comments were addressed in commit bc09c4e: the three orphaned break; statements after RELEASE_AND_RETURN in the SinkKind switches were deleted, and the TaggedObject<T> removal from the crates.io-published bun-native-plugin crate was reverted (no diff under packages/bun-native-plugin-rs/ remains). No CODEOWNERS entry covers the changed paths, no third-party CHANGES_REQUESTED is outstanding, and the bug-hunting run exited on dry_streak with no findings. The new bindgen-type-dsl.test.ts was weighed against test/internal/source-lints/CLAUDE.md ("do not add tests for dead symbols") and REVIEW.md — it is not a dead-stays-dead check; it enumerates the live t builtins and asserts each lowers to a C ABI type and reports its own kind, which is a positive invariant on shipping codegen surface.
…al-field cells, Http2Response, and the WebView ObjC wrappers (#42816) ### Problem - Four native class members exist only for built-in JS, and nothing calls them: the SQL connection `connected` getter and `onconnect` accessor, `NodeHTTPResponse.ended`, and `crash_handler.getFeaturesAsVLQ`. - Thirteen `JSInternalFieldObjectImpl` subclasses carry a copied `static size_t allocationSize(Checked<size_t>)`. Each `create()` uses `allocateCell<T>(vm)`, which takes `sizeof(T)`. JavaScriptCore calls `allocationSize` only on its own classes. - Other leftovers have no reader: two WebCore members, eight `Http2Response` members and the `socketData` field behind one of them, two `ObjCRuntime` wrappers, `.typos.toml`, and `packages/bun-error/img/*`. ### Fix - Delete each item: 31 files, 154 lines and 4 images removed. The Notes list every symbol. - Correct because every removed name has zero references in `src/`, `packages/`, `scripts/`, `test/` and `build/debug/codegen/` outside its own definition. No removed member is documented or typed API. - Verified: `bun bd` and `bun run rust:check-all` (12 targets) pass. The sql, `node:http`, streams, `serve-http2`, node error-code, performance and crash-handler test files pass. `ObjCRuntime` compiles only on macOS, so CI is the compile check for those 13 lines. ### Background - A `*.classes.ts` file declares the members of a native class. The generator emits the C++ wrapper and the Rust glue. The generated thunk is `#[no_mangle]`, so neither rustc nor the linker reports a member that no JS reads. - `values: ["onconnect", ...]` in `sql.classes.ts` declares a GC-visited slot on the wrapper. Native code uses the slot through `onconnect_get_cached` / `onconnect_set_cached`. The removed accessor was a JS-facing route to the same slot. The slot stays. - 34 other dead-code pull requests are open. This one deletes nothing that they delete. Six files overlap on other lines (listed in the Notes). <details><summary>Notes</summary> No test is added. The change deletes code that has no user, so it has no behavior to cover, and REVIEW.md says not to add tests that check dead code stays dead. Overlap with open pull requests: - No deleted line is a line that one of the 34 open dead-code pull requests deletes (checked line by line against their diffs). - Six files also change in one of them, on other lines: `scripts/glob-sources.ts` (#40232), `src/jsc/bindings/ErrorCode.h` (#39929), `JSOneShotDirectSink.h` (#41385), `JSStreamAlgorithmContexts.h` (#41445), `src/runtime/api/crash_handler_jsc.rs` (#41385), `src/sql_jsc/postgres/PostgresSQLConnection.rs` (#40824). - The diffs of the 227 open pull requests (newest 2,500) that touch the `node:http`, sql, crash-handler, streams-header, webview or uws HTTP/2 files add no user of a removed name. Removed, one line each: - `PostgresSQLConnection.connected` / `MySQLConnection.connected` and both `get_connected`. Every `.connected` in `src/js/internal/sql/` and `src/js/bun/sql.ts` is `PooledConnectionState.connected`. `test/js/sql` mentions it in comments only. - `PostgresSQLConnection.onconnect` / `MySQLConnection.onconnect` accessor and the two `(get_on_connect, set_on_connect => ...)` lines of `cached_prop_hostfns!`. Every JS `onconnect` is on the options object (`connectionInfo.onconnect`, `ret.onconnect`). - `NodeHTTPResponse.ended` / `get_ended`. The `_http_*` modules read `handle.flags & NodeHTTPResponseFlags.ended`. The other `.ended` hits are `queued.ended`, `_readableState.ended`, and the JS handle in `http1_server_fallback.ts`. - `crash_handler.getFeaturesAsVLQ` / `js_get_features_as_vlq`, and the `BoundedArray` import that only it used. `getFeatureData` and the other entries have users in `test/`, `scripts/` or `packages/bun-release`. - `allocationSize` in `InternalModuleRegistry.h`, `ErrorCode.h` (`ErrorCodeCache`), `BunStreamSource.h`, `JSAsyncIteratorSourceOperation.h`, `JSDirectStreamSource.h`, `JSOneShotDirectSink.h`, `JSReadRequest.h` (2), `JSReadStreamIntoSinkOperation.h`, `JSReadableStreamIntoArrayOperation.h`, `JSStreamAlgorithmContexts.h`, `JSStreamTeeState.h`, `JSStreamPipeToOperation.h`. `rg allocationSize src packages build/debug/codegen` found the 14 definitions and no call. The debug objects contain no `allocationSize` symbol for a bun class. The fourteenth copy, in `JSCrossRealmTransformState.h`, stays because #41445 deletes that file. - #41268 lists `InternalModuleRegistry::allocationSize` under "Kept on purpose" because it corrects the base class version, which returns `sizeof(JSInternalFieldObjectImpl)`. That reason does not hold. Nothing calls either version for these classes, `allocateCell<T>(vm)` sizes the cell from `sizeof(T)`, and four other subclasses (`ModuleLoader.h`, `JSSocketHandlers.h`, `JSNextTickQueue.h`, `JSMockFunction.h`) never had the copy. - `JSPerformanceResourceTiming::protectedWrapped`. The callers of `protectedWrapped()` are on `JSDOMURL`, `JSAbortSignal` and the `CookieMap` wrapper. - `ResourceLoadTiming::isolatedCopy`. No caller. - `Http2Response::getWriteOffset`, `overrideWriteOffset`, `getSocketData`, `prepareForSendfile`, `uncork`, `isCorked`, `getNativeHandle`, `isConnectRequest` (`packages/bun-uws/src/Http2Context.h`), and `Http2ResponseData::socketData`, which only `getSocketData` read and nothing wrote. The callers of the last four names in `libuwsockets.cpp` are on `HttpResponse<SSL>` and `AsyncSocket<SSL>`. `libuwsockets_h2.cpp` uses none of the eight. #40294 removes the same-named members of `HttpResponse` and `Http3Response`. - `ObjCRuntime`: `struct NSObject` (only member: `describe()`), `Ref::s_description`, `WKWebView::isLoading()`, `WKWebView::s_isLoading`. Each name has only its declaration, definition and `sel(...)` initializer. - `.typos.toml`. Its runner, `.github/workflows/typos.yml`, was deleted in 126f468 (2025-11-05). - `packages/bun-error/img/{close.png,error.png,powered-by.png,powered-by.webp}`, last touched 2021-09-11. `bun-error.css` uses inline `data:` URIs. The `img/*` glob in `scripts/glob-sources.ts` goes with them. Tests run with the debug build: `test/js/sql/sql-onconnect-onclose-throw.test.ts` (9), `sql-connection-socket-uaf.test.ts` (2), `sql-mysql-clean-reentry.test.ts` (1), `sql-mysql.test.ts`, `sql.test.ts`, `test/js/node/http/node-http.test.ts` (159), `node-http-uaf.test.ts` (9), `test/js/web/streams/streams.test.js` (563), `test/js/bun/http/serve-http2.test.ts` (90), `test/js/web/timers/performance-entries.test.ts`, `test/cli/run/run-crash-handler.test.ts` (28), `test/js/node/errors/` (2 files), `test/js/bun/util/error-code-mirror.test.ts`. How the candidates were found: - A repo-wide identifier index (definitions with zero other mentions, comments stripped). - A compiler pass over a scratch copy of the workspace: every `pub` item that no other crate names becomes `pub(crate)`, then `cargo check --force-warn dead_code` runs for linux (dev and release), windows and macos. A loop restores `pub` at each definition that a privacy error points to. 131 leaf items came out of it. - A second compiler pass marks each of those 131 items `#[deprecated]` in an unmodified copy and checks all four configurations again. 88 had a real user. The first pass misses them because a private inherent method silently loses method resolution to a trait method of the same name. 43 had none. - Manual review dropped all 43: unit-test users (`CowSlice::init_dupe`, `clap::SliceIterator`, `Imports::ALL_SORTED`, the `h2::Connection` send path), names that `generate-classes.ts` emits (`host_fn_setter`, `host_fn_this_value`), a FreeBSD-only user (`O::EVTONLY`), the `__IsFreeze` autoref const, and errno or fault-injection tables that mirror C. - A mark-and-sweep over the relocations of the `-O0 -ffunction-sections` debug objects for C++. Almost every hit is in a function that one of the open pull requests already deletes. - A per-binding comparison of every native object and `*.classes.ts` member that built-in JS consumes against `src/js`, `packages/bun-types` and `test/`. Self-reviewed: three changes requested, all made. The other four `Http2Response` stubs and `socketData` go too, three more `allocationSize` copies go too, and the `sys/Error.rs` entry is back. Found, not deleted here: - `"sys/Error.rs"` in `rustIdentifierPaths` (`src/codegen/generate-js2native.ts`): no `$newRustFunction` call site on main since 2b3f660, but #40854 adds one. - `FrameworkFileSystemRouter.match` (the `bun:internal-for-testing` router binding, 67 lines with `route_to_json_inverse`): no user on main, but #40731 and #33232 add tests that call it. - `bun_core::strings::split_once`: no user, but #40824 deletes the adjacent `rsplit_once`. - The SQL `queries` getter is never read, so `queries_set_cached` never runs and `get_queries_array()` always returns `undefined`. The `if (queries)` branches in `onResolve*`/`onReject*` (`mysql.ts`, `postgres.ts`) and the `queries` argument of about 12 native call sites are dead. That is a refactor of the resolve path, not a deletion. - `NodeHTTPResponse.ref`: no JS caller, but `unref` has one, and a one-sided pair reads like a bug. - `MySQLConnection.ref`/`unref`: no caller, but `sql.classes.ts` generates both drivers from one loop. - 36 of the 48 `X_getter` functions that `WEBCORE_GENERATED_CONSTRUCTOR_GETTER` defines in `ZigGlobalObject.cpp` have no user. The macro also defines the live `XConstructorCallback`, so this needs a macro split. - `IDLByte`, `IDLShort` and `IDLLongLong` converters: never instantiated, but `src/codegen/bindgen.ts` can emit the type names. - `ERR_REDIS_INVALID_DATABASE` in `ErrorCode.ts`: no user, but three open pull requests edit the adjacent lines. - `internalBinding("quic")` constants that `quic.ts` does not read: the object mirrors Node's list and is returned whole. </details> <!-- robobun:evidence:begin --> --- **no test proof** · iteration 2 · platform-specific test(s) that do not run on this machine, deferring to CI, which covers all platforms: test/cli/run/run-crash-handler.test.ts <!-- robobun:evidence:end -->
|
Closing as stale: this PR conflicts with main, and its last commit is from 2026-09-05. The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR. |
Problem
JSCrossRealmTransformState,CrossRealmTransform.cpp,SourceKind::CrossRealm,SinkKind::CrossRealm) that nothing creates. Bun does not transfer streams throughpostMessage, so the only handler body isRELEASE_ASSERT_NOT_REACHED().IDLTypes.h, aMessageLevelenum in the test runner formatter that every caller sets toDebug, two bindgen type constructors, and some commented-out code that has been stale for over a year.Fix
JSCrossRealmTransformState.{h,cpp}andCrossRealmTransform.cpp. Remove theCrossRealmenumerators, theircasearms, the structure table entry, the reaction handler macro, the iso subspace slots, and the forward declaration. Remove the write-onlyJSStreamFromIterableContext::m_donefield.IDLTypes.h: remove theInnerType,InnerParameterType,StorageType,ConversionResultType, andNullableConversionResultTypealiases. No converter reads them.pretty_format::MessageLeveland thelevelparameter ofJestPrettyFormat::format. All three callers passedDebug, so theErrorbranches never ran.t.externalClass(a byte-identical copy oft.ref) andt.strictBoolean(no C++ mapping, no.bind.tsuser) with their switch arms. Also removekValidateObjectNonefrominternal/validatorsand commented-out code inPerformance.cpp,JSMessageChannelCustom.cpp, andJSHTTPParserPrototype.cpp.test/internal/source-lints/bindgen-type-dsl.test.tschecks that every builtin intreports its name as its kind, lowers to a C ABI type, and is not an object type, so the DSL cannot offer a kind the generator cannot emit.src/,build/debug/codegen/,packages/,scripts/, andtest/outside its definition.bun bdbuilds.test/js/web/streams/streams.test.js,test/js/bun/test/expect/,test/js/bun/test/expect-extend.test.js,test/js/web/timers/performance-entries.test.ts, andtest/js/node/test/parallel/test-validators.jspass.test/internal/source-lints/bindgen-type-dsl.test.tspasses under the debug build and the released bun.Background
SourceKindorSinkKindtag instead of stored closures. Each non-JavaScript arm carries a context cell.CrossRealmwas the arm for the WHATWG transferable streams feature.JSStreamsRuntimecaches oneStructureper internal cell class per global object through theFOR_EACH_WEB_STREAMS_INTERNAL_STRUCTUREtable. The reaction handler tables register the promise callbacks each.cppowns.src/codegen/bindgen-lib.tsis the type DSL for.bind.tsfiles.TypeKindis derived from the keys oft, so removing a constructor also removes its switch arms inbindgen-lib-internal.ts.Notes
Net change: 23 files, about +50 / -145 lines including the new test. The scan covered the web streams, top-level, webcrypto, node, v8, and vm C++ bindings, the
bun_runtimecrate (node, cli, test_runner, socket, webview, image, crypto, ffi, napi, dns, valkey, timer), allpubitems across the remaining workspace crates,src/js/node,src/js/bun,src/js/internal,src/js/builtins,src/node-fallbacks,src/codegen, andscripts/build. The workspace lintsdead_code = "deny"andunreachable_pub = "deny"already reject intra-crate dead Rust, so the Rust candidates were cross-cratepubitems only. Areas that 23 other open dead-code PRs already touch were skipped.Probably dead but left alone:
packages/bun-native-plugin-rs/src/lib.rsTaggedObject<T>has no constructor and no user since dcf0b71. It stays because the crate is published to crates.io and the struct is public API. Remove it with the next version bump.src/runtime/cli/Arguments.rsBun__Node__CAStoreis a#[no_mangle]static that is written and never read (the siblingBun__Node__UseSystemCAis read byroot_certs.cpp).#[cfg(test)]modules inbun_runtime(assert/myers_diff.rs,test_runner/expect.rs,test_runner/diff/text_diff.rs, about 640 lines). No CI job runscargo teston that crate.src/jsc/bindings/v8/*API mirrors with one hit (Isolate::GCCallback,kInternalFieldsInWeakCallback,Oddball::Kind::kInvalid, CPU profiler enumerators). They mirror V8 headers for addon compatibility.src/jsc/bindings/webcore/JSDOMConvertNumbers.cppconvertToIntegerClampspecializations other thanuint16_t. The bindgen mapsclampto them, so they are feature surface.src/js/internal/fs/glob.tsvendored minimatch exports (filter,defaults,braceExpand,makeRe,match,escape,unescape). The file is marked as vendored verbatim.src/js/node/wasi.tsWASI_ENOTSUP,WASI_FILETYPE_SOCKET_DGRAM,WASI_DIRCOOKIE_STARTconstants in the vendored wasi-js.src/js/internal/quic/quic.tsexport keysgetQuicStreamState,getQuicSessionState(Node parity for internal tests).