Skip to content

Remove dead code from the bun_runtime re-export hubs, bun_core, bun_css, bun_install, bun_bundler, the FFI crates, and the error-code table - #39582

Open
robobun wants to merge 9 commits into
mainfrom
claude/farm/a988bc98/dead-code-runtime-reexports-misc-v2
Open

Remove dead code from the bun_runtime re-export hubs, bun_core, bun_css, bun_install, bun_bundler, the FFI crates, and the error-code table#39582
robobun wants to merge 9 commits into
mainfrom
claude/farm/a988bc98/dead-code-runtime-reexports-misc-v2

Conversation

@robobun

@robobun robobun commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Rebase of #39319 (closed as stale) onto current main. Same content; the review on that PR was addressed there (the ServerInitContext report was a false positive, the comment nits are folded in), and per test/internal/source-lints/CLAUDE.md the dead-symbol lint test is not carried over. Net -400 lines in src/ (452 deleted, 52 added as reflowed import groups, visibility adjustments and comment updates), plus one inline-snapshot test in test/js/bun/test/snapshot-tests/bun-snapshots.test.ts that pins how ArrayBuffer values print (the one pretty_format match this PR edits). No behavior change.

Problem

bun_runtime re-export hubs (about 200 lines)

  • src/jsc/generated_classes_list.rs (116 lines), mounted as bun_runtime::GeneratedClassesList, was a flat alias namespace with no reader: generate-classes.ts resolves each .classes.ts class to its Rust type by walking the crate's own pub mod / pub use tree (rustModuleResolver, which only registers items at module depth 0, and everything in this file sat inside pub mod Classes { .. }), and the regenerated generated_classes.rs is byte-identical without the file. bun_runtime is also the only crate that can see its own re-export hubs (nothing but bun_bin depends on it, and bun_bin only calls Cli::start), so a hub entry rustc reports unused is unused everywhere.
  • api.rs still mirrored the old bun.api.* Zig namespace: 36 aliases (Image, Shell, Timer, Archive, Glob, HTMLRewriter, NativeZlib, Valkey, MySQL, Postgres, FFIObject, SocketHandlers, x509, the 18 process::* names other than Rusage, the five PTY types under bun::terminal, bun::H2FrameParser, posix_spawn, bun_spawn as spawn, ...) that no code and no generated code names. TCPSocket/TLSSocket stay: rustc reported them unused on linux, but socket/WindowsNamedPipeContext.rs imports them through api.
  • Same shape in bun.js.rs (pub use crate::{api, webcore}), webcore.rs (the five sink re-exports, form_data::{AsyncFormData, FormData}, and the webcore::jsc::codegen forwarding module whose own doc comment says it exists for call sites that "still spell" a path nothing spells), webcore/streams.rs (result::StreamResult), webcore/Request.rs (js_gen::from_js*), webcore/FormData.rs (get_boundary), s3/client.rs (multipart::{self}), bake/mod.rs (FrameworkRouter alias, DynamicRouteMap/EncodedPattern/Route/StaticRouteMap, production::{EntryPointMap, TypeAndFlags}), bake/dev_server/mod.rs (Assets, IncrementalGraph, RouteBundle, SourceMapStore), server/mod.rs (BunInfo, PreparedRequestFor, ServerInitContext, ServePluginsState), lib.rs (five cli::*_command crate-root aliases), cli/mod.rs (command::Command self-alias), cli/Arguments.rs (load_config), allocators/mod.rs, shell/interpreter.rs (Builtin), node/zlib/NativeZstd.rs (Context), api/JSBundler.rs (Config, MiniImportRecord), api/BunObject.rs (JSZstd::deallocator, whose own comment says "0 C++ refs, 0 Rust refs"), api/bun/Terminal.rs (from_js, from_js_direct) and api/bun/h2_frame_parser.rs (the CamelCase H2FrameParserConstructor twin of the snake_case alias the js2native thunk actually calls).
  • Seven items in server_body.rs, FrameworkRouter.rs and production.rs were reachable only through the deleted re-exports; they become pub(crate) (rustc's unreachable_pub demands it). ServerInitContext itself stays pub: it is still reachable through AnyRoute::from_js, and demoting it trips private_interfaces.

bun_runtime items (about 110 lines)

  • streams::Writable::{TemporaryAndDone, IntoArray, IntoArrayAndDone} are never produced (the StreamResult variants of the same names are; the Writable ones only had to_js arms). WritableFuture::Handler is never armed: the only construction is inside the run() arm that matches an existing Handler, so WritableHandler, WritableHandlerFn and that arm go with it.
  • Never-constructed variants and their match arms: DrainResult::Empty (webcore.rs, two matches! in Body.rs, one arm in ByteStream.rs), ReadableStream::Source::Direct (the C++ Tag::Direct maps to None in from_js; the FFI Tag enum itself is untouched), pretty_format::Tag::ArrayBuffer (JSType::ArrayBuffer maps to Tag::TypedArray; the now-unreachable _ => {} arm of print_as goes too), shell::IoKind::Stdin, node_fs_watcher::Event::Close (EventType::Close, which is used, stays), cron::CalendarError::OutOfMemory, thumbhash::DecodeError::OutOfMemory.
  • Trait items with no caller: ServerLike::{SSL_ENABLED, DEBUG_MODE, vm_mut} (RequestContext uses its own const generics; the inherent NewServer::vm_mut is still used and stays, and the two SAFETY comments that cited the trait item now cite it) and ResponseLike::upgrade with both impls (the HMR upgrade goes through the inherent uws methods).

Other crates (about 60 lines)

  • bun_core: the CodePointZero re-export in immutable.rs, and the ZERO_VALUE/MAX associated consts of CodePointZero (both impls; from_u32 is what the decoders use).
  • bun_css: css_parser::CustomMedia and IdentFns, the crate-root CustomIdentFns/DashedIdentFns, container::ContainerNameFns, selector::{_PrintErr, _Printer} ("re-export alias parity"), and the path re-export of the css_eql_partialeq! macro (every use is textual).
  • bun_install: PackageManager::{do_patch_commit, prepare_patch, GitResolver}, crate-root FolderResolution and PostinstallOptimizer, patch_install::PatchedDep.
  • bun_bundler: LinkerContext::{OutputFileListBuilder, StaticRouteVisitor, do_step5} module aliases, bundle_v2::{AdditionalFile, IndexStringMap}, options::BakeExtra. bun_collections::ArrayListAlignedIn and bun_sql_jsc::mysql::MySQLRequestQueue crate-level re-exports, bun_jsc::ZigErrorType crate-root re-export (the type is used by path).
  • FFI declarations with no caller on any target: windows_sys::kernel32::SetFileTime (its futimens caller was rewritten) and lsquic_sys::lsquic_conn_n_pending_streams.
  • ErrorCode.ts: 17 codes with no producer ($ERR_X( in src/js, ErrorCode::ERR_X in C++, ErrorCode::X in Rust, none in tests or docs; re-checked against today's main): ERR_BUFFER_CONTEXT_NOT_AVAILABLE, ERR_CRYPTO_INITIALIZATION_FAILED, ERR_CRYPTO_INVALID_COUNTER, ERR_CRYPTO_INVALID_TAG_LENGTH, ERR_CRYPTO_JOB_INIT_FAILED, ERR_CRYPTO_SCRYPT_INVALID_PARAMETER, ERR_EXECUTION_ENVIRONMENT_NOT_AVAILABLE, ERR_INVALID_ADDRESS, ERR_INVALID_PACKAGE_CONFIG, ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE, ERR_MISSING_PLATFORM_FOR_WORKER, ERR_NON_CONTEXT_AWARE_DISABLED, ERR_REQUIRE_ASYNC_MODULE, ERR_TLS_PSK_SET_IDENTITY_HINT_FAILED, ERR_WASI_NOT_STARTED, ERR_WORKER_INIT_FAILED, ERR_SECRETS_NOT_AVAILABLE. Everything that consumes the table is generated from it, so the renumbering is invisible.

Fix

  • Deletes the items above; the only other edits are the ones the deletions force (match arms, reflowed pub use groups, the seven pub -> pub(crate) changes, and the comments that named the removed items, including the VirtualMachine.rs LAYERING comments and the generate-classes.ts resolver comment that used removed api aliases as examples).
  • How the Rust candidates were found: the workspace builds with dead_code = deny, so the only dead Rust left is pub items, which rustc exempts. For every crate, pub was temporarily demoted to pub(crate) on the items no file outside the crate mentions (and, for bun_runtime, on everything the codegen output and bun_bin do not mention), and cargo check -p <crate> was run for x86_64-unknown-linux-gnu, x86_64-pc-windows-msvc and aarch64-apple-darwin. An item was only deleted when rustc reported it unused on all three; items it reported on one target only (ipc.rs, node_fs.rs, cron.rs's Windows and macOS error variants, the api.rs socket aliases) and items only reached through macros expanded in other crates (bun_alloc's zone methods, bun_clap's const-eval helpers, js_class_module!'s IntoRawMut) were kept.
  • Verified on the rebased tree: bun bd (regenerates the class, js2native, host-export and error-code codegen and links; generated_classes.rs and generated_js2native.rs are byte-identical to main's, generated_host_exports.rs differs only in line-number comments), bun run rust:check-all, and bun bd test on the stream, body, fs.watch, shell and error-code test files listed in the first comment. Checked line by line against the two dead-code PRs still open (Remove dead code from uws_sys, webcore bindings, crash_handler, and scripts #37181, Remove dead code from bun-uws, the native BufferList class, and built-in JS #37659): no shared deletions.

Left alone

  • strings::rsplit_once has no caller, but clippy.toml names it as the replacement for the disallowed str::rsplit_once / str::rsplitn / ByteSlice::rsplit_once_str, so it is kept (it was deleted in the first push of this PR and restored after review).
  • Still on main and unclaimed now that the PRs that used to cover them were closed as stale, so candidates for the next sweep rather than this rebase: webcore.rs's DOMExceptionCode re-export, install/lib.rs's TextLockfile, ffi/mod.rs's ffi_object_draft, streams.rs's never-produced StreamResult variants, the image/mod.rs / dns_jsc/mod.rs / node_fs.rs re-export groups, Blob.rs's structured-clone helpers, server/mod.rs's ref_, shell_body.rs's InvalidArguments/Todo, bindgen.rs's three marker structs, and the ERR_REDIS_* / ERR_KEY_GENERATION_JOB_FAILED codes.
  • Deliberately kept although rustc reports them: napi_status variants, SSRKind::Regular, serialized_failure::ErrorKind's JS variants and MessageId::Visualizer (external code tables), bake::Mode::ProductionDynamic (a documented mode placeholder), ERR_POSTGRES_INVALID_BYTE_SEQUENCE_FOR_ENCODING (documented in docs/runtime/sql.mdx), and the unused entries of the O::, EPOLL::, IN:: and POLL_* constant tables in bun_sys.

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

fails on main (without fix)
ASAN without fix: BUILD FAILED (no junit output)
$ BUN_DEBUG_QUIET_LOGS=1 bun scripts/build.ts --profile=debug --quiet test "--reporter=junit" "--reporter-outfile=/tmp/mechgate.xml" test/js/bun/test/snapshot-tests/bun-snapshots.test.ts
ninja: Entering directory `/workspace/bun/build/debug'
[1/182] gen ErrorCode+*.h
[2/182] gen bake.{client,server,error}.js
-> bake.client.js, bake.server.js, bake.error.js
[3/182] gen JSBuffer.lut.h
Generating /workspace/bun/build/debug/codegen/JSBuffer.lut.h from /workspace/bun/src/jsc/bindings/JSBuffer.cpp
[4/182] gen generated_host_exports.rs
generated_host_exports.rs: 92 exports (host=3, lazy=10, generic=79, rust=0); 241 extern-C blocks audited
[5/182] 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/
... (truncated)

release without fix: all passed
bun test v1.4.0-canary.1 (549023443)

test/js/bun/test/snapshot-tests/bun-snapshots.test.ts:
(pass) it will create a snapshot file if it doesn't exist [0.33ms]
(pass) ArrayBuffer values are serialized like typed arrays [0.06ms]
(pass) toMatchSnapshot errors > should throw if property matchers exist and received is not an object [0.05ms]
(pass) toMatchSnapshot errors > should throw if property matchers don't match [0.11ms]
(pass) toMatchSnapshot errors > should throw if arguments are in the wrong order [0.04ms]
(pass) toMatchSnapshot errors > should throw if expect.any() doesn't received a constructor [0.06ms]

 6 pass
 0 fail
 10 snapshots, 28 expect() calls
Ran 6 tests across 1 file. [171.00ms]
__F:0:S:0
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/js/bun/test/snapshot-tests/bun-snapshots.test.ts
bun test v1.4.0 (8326d1bd3)

test/js/bun/test/snapshot-tests/bun-snapshots.test.ts:
(pass) it will create a snapshot file if it doesn't exist [34.63ms]
(pass) ArrayBuffer values are serialized like typed arrays [4.57ms]
(pass) toMatchSnapshot errors > should throw if property matchers exist and received is not an object [3.76ms]
(pass) toMatchSnapshot errors > should throw if property matchers don't match [12.92ms]
(pass) toMatchSnapshot errors > should throw if arguments are in the wrong order [5.64ms]
(pass) toMatchSnapshot errors > should throw if expect.any() doesn't received a constructor [7.16ms]

 6 pass
 0 fail
 10 snapshots, 28 expect() calls
Ran 6 tests across 1 file. [2.71s]
__F:0:S:0

release with fix: all passed
$ bun scripts/build.ts --profile=release
[configured] bun-profile → bun (stripped) in 823ms (unchanged)
ninja: Entering directory `/workspace/bun/build/release'
[1/142] gen ErrorCode+*.h
[2/142] gen bake.{client,server,error}.js
-> bake.client.js, bake.server.js, bake.error.js
[3/142] gen JSBuffer.lut.h
Generating /workspace/bun/build/release/codegen/JSBuffer.lut.h from /workspace/bun/src/jsc/bindings/JSBuffer.cpp
[4/142] gen generated_host_exports.rs
generated_host_exports.rs: 92 exports (host=3, lazy=10, generic=79, rust=0); 241 extern-C blocks audited
[5/142] 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)
  - 
... (truncated)
diff hotspot
src/bun.js.rs                                      |   4 -
 src/bun_core/Global.rs                             |   2 +-
 src/bun_core/string/immutable.rs                   |   1 -
 src/bun_core/string/immutable/unicode.rs           |   9 +-
 src/bundler/LinkerContext.rs                       |   3 -
 src/bundler/bundle_v2.rs                           |   4 +-
 src/bundler/lib.rs                                 |   1 -
 src/codegen/generate-classes.ts                    |   4 +-
 src/collections/lib.rs                             |   1 -
 src/css/css_parser.rs                              |   3 +-
 src/css/generics.rs                                |   1 -
 src/css/lib.rs                                     |   2 +-
 src/css/rules/container.rs                         |   1 -
 src/css/selectors/selector.rs                      |   3 -
 src/install/PackageManager.rs                      |   4 +-
 src/install/lib.rs                                 |   2 -
 src/install/patch_install.rs                       |   2 -
 src/jsc/VirtualMachine.rs                          |   6 +-
 src/jsc/bindings/ErrorCode.ts                      |  17 ---
 src/jsc/generated.rs                               |   7 +-
 src/jsc/generated_classes_list.rs                  | 116 ---------------------
 src/jsc/lib.rs                                     |  11 +-
 src/lsquic_sys/lib.rs                              |   1 -
 src/runtime/allocators/mod.rs                      |   2 -
 src/runtime/api.rs                                 |  53 +---------
 src/runtime/api/BunObject.rs                       |   3 -
 src/runtime/api/JSBundler.rs                       |   6 +-
 src/runtime/api/bun/Terminal.rs                    |   4 +-
 src/runtime/api/bun/h2_frame_parser.rs             |   1 -
 src/runtime/api/cron.rs                            |   7 +-
 src/runtime/bake/DevServer.rs                      |  18 ----
 src/runtime/bake/FrameworkRouter.rs                |  10 +-
 src/runtime/bake
... (truncated)

gate history · 3 passed · 2 rejected · iteration 2

evidence per changed file
file                                      reads  edits  tests
src/bun.js.rs                                 1      1      0
src/bun_core/Global.rs                        0      0      0
src/bun_core/string/immutable.rs              0      0      0
src/bun_core/string/immutable/unicode.rs      0      0      0
src/bundler/LinkerContext.rs                  0      0      0
src/bundler/bundle_v2.rs                      0      0      0
src/bundler/lib.rs                            0      0      0
src/codegen/generate-classes.ts               1      0      0
src/collections/lib.rs                        0      0      0
src/css/css_parser.rs                         0      0      0
src/css/generics.rs                           0      0      0
src/css/lib.rs                                0      0      0
src/css/rules/container.rs                    0      0      0
src/css/selectors/selector.rs                 0      0      0
src/install/PackageManager.rs                 0      0      0
src/install/lib.rs                            0      0      0
(+ 44 more files)

…ss, bun_install, bun_bundler, the FFI crates, and the error-code table

Deletes src/jsc/generated_classes_list.rs (an alias namespace with no
reader), the unused aliases in bun_runtime's api.rs / webcore.rs / bake /
server / cli re-export hubs, a handful of never-constructed enum variants
(streams::Writable::{TemporaryAndDone, IntoArray, IntoArrayAndDone},
WritableFuture::Handler, DrainResult::Empty, Source::Direct,
pretty_format Tag::ArrayBuffer, shell IoKind::Stdin, fs watcher
Event::Close, CalendarError::OutOfMemory, thumbhash
DecodeError::OutOfMemory), the never-called ServerLike consts / vm_mut and
ResponseLike::upgrade, leftover re-exports and helpers in bun_core,
bun_css, bun_install, bun_bundler, bun_collections, bun_sql_jsc and
bun_jsc, two FFI declarations with no caller (SetFileTime,
lsquic_conn_n_pending_streams), and 17 error codes nothing produces.

Each Rust item was reported unused by rustc with the crate's pub items
demoted to pub(crate), on the linux, windows and darwin targets; verified
with bun bd, rust:check-all and the affected test files.

Rebase of #39319 onto current main.
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9a06d536-a579-4ae3-bbdc-0caa0adfb4af

📥 Commits

Reviewing files that changed from the base of the PR and between 1336918 and 5490234.

📒 Files selected for processing (58)
  • src/bun.js.rs
  • src/bun_core/string/immutable.rs
  • src/bun_core/string/immutable/unicode.rs
  • src/bundler/LinkerContext.rs
  • src/bundler/bundle_v2.rs
  • src/bundler/lib.rs
  • src/codegen/generate-classes.ts
  • src/collections/lib.rs
  • src/css/css_parser.rs
  • src/css/generics.rs
  • src/css/lib.rs
  • src/css/rules/container.rs
  • src/css/selectors/selector.rs
  • src/install/PackageManager.rs
  • src/install/lib.rs
  • src/install/patch_install.rs
  • src/jsc/VirtualMachine.rs
  • src/jsc/bindings/ErrorCode.ts
  • src/jsc/generated.rs
  • src/jsc/generated_classes_list.rs
  • src/jsc/lib.rs
  • src/lsquic_sys/lib.rs
  • src/runtime/allocators/mod.rs
  • src/runtime/api.rs
  • src/runtime/api/BunObject.rs
  • src/runtime/api/JSBundler.rs
  • src/runtime/api/bun/Terminal.rs
  • src/runtime/api/bun/h2_frame_parser.rs
  • src/runtime/api/cron.rs
  • src/runtime/bake/DevServer.rs
  • src/runtime/bake/FrameworkRouter.rs
  • src/runtime/bake/dev_server/mod.rs
  • src/runtime/bake/mod.rs
  • src/runtime/bake/production.rs
  • src/runtime/cli/Arguments.rs
  • src/runtime/cli/mod.rs
  • src/runtime/image/thumbhash.rs
  • src/runtime/lib.rs
  • src/runtime/node/node_fs_watcher.rs
  • src/runtime/node/zlib/NativeZstd.rs
  • src/runtime/server/RequestContext.rs
  • src/runtime/server/mod.rs
  • src/runtime/server/server_body.rs
  • src/runtime/shell/Builtin.rs
  • src/runtime/shell/interpreter.rs
  • src/runtime/test_runner/pretty_format.rs
  • src/runtime/webcore.rs
  • src/runtime/webcore/Body.rs
  • src/runtime/webcore/ByteStream.rs
  • src/runtime/webcore/FormData.rs
  • src/runtime/webcore/ReadableStream.rs
  • src/runtime/webcore/Request.rs
  • src/runtime/webcore/s3/client.rs
  • src/runtime/webcore/streams.rs
  • src/spawn/process.rs
  • src/sql_jsc/mysql.rs
  • src/windows_sys/externs.rs
  • test/js/bun/test/snapshot-tests/bun-snapshots.test.ts
💤 Files with no reviewable changes (28)
  • src/install/patch_install.rs
  • src/bun_core/string/immutable.rs
  • src/bun.js.rs
  • src/runtime/shell/interpreter.rs
  • src/css/generics.rs
  • src/bundler/lib.rs
  • src/runtime/allocators/mod.rs
  • src/install/lib.rs
  • src/runtime/image/thumbhash.rs
  • src/runtime/api/BunObject.rs
  • src/collections/lib.rs
  • src/runtime/api/bun/h2_frame_parser.rs
  • src/runtime/webcore/Request.rs
  • src/css/selectors/selector.rs
  • src/css/rules/container.rs
  • src/windows_sys/externs.rs
  • src/lsquic_sys/lib.rs
  • src/bundler/LinkerContext.rs
  • src/runtime/bake/dev_server/mod.rs
  • src/sql_jsc/mysql.rs
  • src/runtime/webcore.rs
  • src/jsc/generated_classes_list.rs
  • src/runtime/node/node_fs_watcher.rs
  • src/runtime/bake/DevServer.rs
  • src/bundler/bundle_v2.rs
  • src/runtime/cli/mod.rs
  • src/runtime/webcore/ReadableStream.rs
  • src/jsc/bindings/ErrorCode.ts

Included review availability: Your plan provides up to 5 included reviews per hour; 0 remain after this review.


Walkthrough

The pull request narrows public Rust and runtime exports, removes obsolete APIs and enum variants, restricts internal visibility, updates layering documentation, adjusts WebCore stream handling, and adds ArrayBuffer snapshot coverage.

Changes

API and runtime cleanup

Layer / File(s) Summary
Core and toolchain surface pruning
src/bun_core/..., src/bundler/..., src/css/..., src/collections/lib.rs, src/install/...
Public re-exports are removed across core, bundler, CSS, collections, and install modules. CodePointZero now requires from_u32.
JSC surface and documentation cleanup
src/jsc/...
Obsolete error mappings and JSC exports are removed. Generated-class and layering documentation is updated.
Runtime API and generated export reduction
src/runtime/api.rs, src/runtime/api/..., src/runtime/lib.rs, src/runtime/cli/..., src/runtime/node/zlib/NativeZstd.rs, src/runtime/shell/interpreter.rs
Runtime API, generated-class, CLI, terminal, bundler, and helper exports are reduced.
Bake and server contract reduction
src/runtime/bake/..., src/runtime/server/...
Bake types become crate-visible. WebSocket upgrade support is removed. Server exports and ServerLike requirements are reduced.
WebCore stream and binding cleanup
src/runtime/webcore/...
Obsolete WebCore exports and writable variants are removed. Empty drain results continue through native stream setup.
Runtime behavior and validation cleanup
src/runtime/image/..., src/runtime/node/..., src/runtime/shell/..., src/runtime/test_runner/..., src/spawn/process.rs, src/sql_jsc/mysql.rs, src/windows_sys/externs.rs, test/js/...
Obsolete runtime cases and declarations are removed. ArrayBuffer snapshot coverage is added.

Possibly related PRs

Suggested reviewers: jarred-sumner, dylan-conway, alii

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the primary change: removing dead code across the listed runtime, library, FFI, and error-code areas.
Description check ✅ Passed The description explains the changes, scope, rationale, and verification results, although it does not use the template headings.

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

@robobun

robobun commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 5:23 PM PT - Aug 18th, 2026

@robobun, your commit fa018227fcff08605248d9142da0972e8f939ef6 passed in Build #100885! 🎉


🧪   To try this PR locally:

bunx bun-pr 39582

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

bun-39582 --bun

@robobun

robobun commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

Status: ready for review. Rebase of #39319 onto current main, now at fa01822, waiting on CI (build 100885; the previous build on 5490234 had 172 of 179 jobs green with no failures when the comment-only push superseded it).

Verified on this tree:

  • bun bd builds and links; generated_classes.rs and generated_js2native.rs regenerated from this branch are byte-identical to main's, generated_host_exports.rs differs only in line-number comments.
  • bun run rust:check-all: 12 of 12 targets ok; cargo fmt --check and prettier clean.
  • bun bd test on test/js/web/streams/streams.test.js, test/js/web/fetch/body-stream.test.ts, test/js/node/watch/fs.watch.test.ts, test/js/bun/shell/bunshell.test.ts, test/js/bun/shell/commands/echo.test.ts, test/js/bun/http/serve-direct-readable-stream.test.ts, test/js/node/util/parse_args/parse-args-null-config.test.ts, test/js/node/url/url-fileurltopathbuffer.test.ts, test/js/node/crypto/crypto-oneshot.test.ts and test/js/bun/test/snapshot-tests/bun-snapshots.test.ts (carries the new ArrayBuffer inline snapshots): all pass.
  • The 17 error codes were re-grepped against today's main (still no producers), and the diff shares no deletions with the two dead-code PRs still open (Remove dead code from uws_sys, webcore bindings, crash_handler, and scripts #37181, Remove dead code from bun-uws, the native BufferList class, and built-in JS #37659).
  • Review: rsplit_once kept (clippy.toml names it); a tree-wide sweep confirms no comment still names a removed path; all threads resolved. Everything after e5b6757 is comments and formatting only.

Comment thread src/bun_core/string/immutable.rs
…lacement) and pin how ArrayBuffers print in snapshots
@robobun

robobun commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

e5b6757 does two things: restores strings::rsplit_once (the review thread is right that clippy.toml names it as the replacement for the disallowed std/bstr reverse splits, so it is intentionally caller-less), and adds two snapshots to test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts for a non-empty ArrayBuffer and an object containing one. Those go through the one pretty_format match arm this PR edits (ArrayBuffer values print via the typed-array printer), which is the only place in the diff with behavior worth pinning; the direct-stream and body-drain arms are already covered by serve-direct-readable-stream.test.ts and body-stream.test.ts. Description and status comment updated.

Comment thread src/runtime/api.rs
…pshots.test.ts and update the comments that named the removed api aliases
Comment thread src/codegen/generate-classes.ts Outdated
@robobun

robobun commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

d591490 and bd3b0bc: the ArrayBuffer coverage moved out of snapshot.test.ts (that file has an unrelated inline snapshot that only matches when output is colored, so it fails in any non-TTY run) into bun-snapshots.test.ts as two inline snapshots, and the remaining comments that used removed api aliases as examples or paths (VirtualMachine.rs x3, generate-classes.ts) are updated; codegen output is unchanged. All review threads are resolved.

Comment thread src/runtime/api.rs
Comment thread src/jsc/generated.rs Outdated
Comment thread src/runtime/api/cron.rs Outdated
Comment thread src/jsc/generated.rs Outdated
@robobun

robobun commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

e7a87c3 through 5490234 are the remaining comment follow-ups from the review: the four comments that still named removed api aliases are fixed or removed (the GenBlob doc also named a consumer function that never existed, so it is now a one-liner), and the cron.rs import groups that the removed comment used to separate are kept apart so rustfmt output is unchanged. No code changes since e5b6757; all review threads are resolved.

@robobun

robobun commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

Two phrases in the generated walkthrough above overstate things, for anyone skimming it: "WebSocket upgrade support is removed" refers only to the ResponseLike::upgrade trait method, which had no callers (the HMR socket upgrade goes through the inherent uws response methods, which are untouched), and DrainResult::Empty was never constructed, so nothing about drain handling changes. The review itself found nothing actionable; CI build 100865 is running on 5490234.

Comment thread src/runtime/server/mod.rs
@robobun

robobun commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator Author

fa01822 updates the last three comments that named removed paths (Global.rs, bundle_v2.rs, the Response.rs warning block), and a tree-wide sweep for every path this PR removes comes back clean, so this class of follow-up should be finished. Still comments only since e5b6757; CI is re-running as build 100885.

@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.

Automated review is now clean — the four earlier rounds (rsplit_once/clippy.toml, and three batches of stale comment references to removed api::*/server::*/bake::*/webcore::jsc::codegen paths) are all addressed as of fa01822, and this pass found nothing new. Given the breadth (60 files across the error-code table, stream/shell/server/fs-watcher enum variants, and ServerLike/ResponseLike trait surface), a maintainer sign-off is still worth having.

What was reviewed:

  • Spot-checked deleted error codes (ERR_REQUIRE_ASYNC_MODULE, ERR_INVALID_PACKAGE_CONFIG, ERR_CRYPTO_INVALID_TAG_LENGTH, ERR_WORKER_INIT_FAILED) — no producers in src/.
  • Confirmed Source::Direct and IoKind::Stdin have no remaining constructors or match sites.
  • Re-swept for comments naming removed paths after fa01822 — none found beyond the historical src/dns/lib.rs note the author already called out.
Extended reasoning...

Overview

Dead-code sweep across ~60 files in bun_runtime, bun_core, bun_css, bun_install, bun_bundler, bun_jsc, bun_collections, bun_sql_jsc, and the two FFI *_sys crates, plus 17 unused entries removed from ErrorCode.ts. Net −400 lines. The only non-deletion edits are forced by the deletions: match-arm removals for never-constructed variants, seven pubpub(crate) demotions, reflowed pub use groups, and comment updates. One inline-snapshot test added to pin ArrayBuffer pretty-format output (the one pretty_format match this PR touches).

Security risks

None identified. No auth, crypto, permission, or input-validation logic changes; the crypto-related deletions are unused error-code table rows only. The SetFileTime and lsquic_conn_n_pending_streams FFI extern removals have no callers on any target.

Level of scrutiny

Higher than a typical mechanical cleanup because of breadth: it removes enum variants (DrainResult::Empty, Source::Direct, Writable::{TemporaryAndDone,IntoArray,IntoArrayAndDone}, IoKind::Stdin, Event::Close, Tag::ArrayBuffer) whose match arms are deleted alongside them, drops trait methods from ServerLike/ResponseLike, and prunes the error-code table (which renumbers the generated enum). The methodology is sound — demote pubpub(crate) and let rustc report unused across linux/windows/macos, with codegen output diffed byte-identical — and bun run rust:check-all passing on all 12 targets is the strongest available signal that nothing platform-gated was missed. Still, the combination of scope and the number of subsystems touched puts this past what I'd approve without a human look.

Other factors

I reviewed this PR four times previously; each round surfaced only stale comment references to removed paths (no behavioral issues), and each was fixed promptly. After fa01822 the author ran a tree-wide sweep for every removed path in ::-qualified form and reported it clean; I re-checked a sample and agree. CI build 100885 is running on the head commit (the previous build on 5490234 was 172/179 green with no failures when superseded). The rsplit_once deletion was correctly reverted after review since clippy.toml names it as the sanctioned replacement.

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