Skip to content

Remove dead code from the bake client, uSockets, uWS HTTP/2, uws_sys, and the CI pipeline script - #43976

Merged
Jarred-Sumner merged 1 commit into
mainfrom
robobun/d5746ba3/dead-code-sweep
Sep 26, 2026
Merged

Jarred-Sumner merged 1 commit into
mainfrom
robobun/d5746ba3/dead-code-sweep

Conversation

@robobun

@robobun robobun commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Behaviour change: none

Problem

  • Eleven files hold items that nothing reads or calls: write-only fields, an uncalled method, four unused types, and CI options that are parsed and dropped.
  • No tool reports them. C and C++ have no dead-code lint. TypeScript counts x += n as a read. The Rust types come from a macro.

Fix

  • TypeScript: remove DataViewReader.u16(), DataViewWriter.capacity, the totalCount local in updateBuildErrorOverlay, and a commented-out block from 2024 in src/js/node/dgram.ts.
  • C and C++: remove us_udp_socket_t.connected, us_quic_stream_s.headers_delivered and Http2ResponseData::totalSize (each is only written), and #undef FD_BITS (nothing defines it).
  • Rust and CI: remove the opaque types us_loop_t, us_socket_context_t, us_udp_socket_t, us_udp_packet_buffer_t from src/uws_sys/lib.rs. In .buildkite/ci.ts, remove dryRun, Platform.features, four emoji entries, and the union members "amazonlinux" and "eol".
  • Verified: rg -w for each symbol over src, packages, scripts, test and build/debug/codegen finds no other use. bun bd, bun run rust:check-all (12 targets) and tsc pass. Self-reviewed: 1 concern raised, 1 addressed.

Background

  • DataViewReader and DataViewWriter decode and encode the binary messages between the dev server and its browser client.
  • us_udp_socket_t and us_quic_stream_s are private C structs of uSockets. Rust holds them as opaque pointers, so no Rust struct mirrors their layout.
  • bun_core::opaque_extern! declares a zero-sized Rust type for a C struct. Rust code names Loop, udp::Socket and udp::PacketBuffer, not the four removed types.

Downsides

  • None found. Checked each removed symbol for users in Rust, C, C++, TypeScript, generated code, tests, and open pull requests.
Notes

Evidence per removal

Item Evidence
DataViewReader.u16() rg '\.u16\(' over src/runtime/bake, test/bake, test/cli/inspect: no hit.
DataViewWriter.capacity The only hit of .capacity in the bake TypeScript is the assignment in the constructor. initCapacity is the only caller of the constructor.
totalCount Two hits: the declaration and one +=.
dgram.ts block git blame: 589f941, 2024-04-26. replaceHandle and startListening are not defined in the file.
us_udp_socket_t.connected Two hits, both udp->connected = 0;.
us_quic_stream_s.headers_delivered Two hits in quic.c: the field and one = 1. The struct is private to quic.c.
Http2ResponseData::totalSize One member access: data.totalSize = totalSize;. The other hits of totalSize are the function parameter.
#undef FD_BITS The only hit of FD_BITS in src and packages.
Four opaque types Each name has one non-comment hit in all Rust sources and generated Rust: the macro call.
dryRun Four hits in ci.ts: the field, two assignments, one destructure. Nothing reads the binding.
Platform.features One hit.
Emoji, Distro, Tier entries No platform in ci.ts or image in scripts/build/ci-images/spec.ts carries them. Emoji is keyof typeof emojiMap, so a remaining caller would fail tsc -p scripts/tsconfig.json. It passes.

Taken out because an open pull request uses or removes the item

Tests run with the debug build, all pass

test/js/bun/udp/udp_socket.test.ts (218), test/js/bun/udp/dgram.test.ts (62), test/js/bun/http/serve-http2.test.ts (93), test/js/bun/http/serve-http3.test.ts (73), test/bake/dev/bundle.test.ts (23), test/bake/dev/esm.test.ts (17), test/bake/hmr-socket-protocol.test.ts (4), test/cli/inspect/BunFrontendDevServer.test.ts (7). test/js/node/dgram/node-dgram.test.js passes 3 of 4: the IPv6 multicast test fails with ENODEV in the test container, with and without this change. prettier and cargo fmt --check report no change.

Overlap with open pull requests

Each removed line was compared with the diffs of the 35 open dead-code pull requests. None removes the same lines. Five files are also touched by an open pull request, in hunks more than 6 lines away: internal.h and quic.c (#40294, #42431), dgram.ts (#42431), overlay.ts (#43378, #42075, #39488), src/uws_sys/lib.rs (#43010). The added lines of the 122 open pull requests that were updated since 2026-09-18 and touch the bake, uSockets, uWS, uws_sys, server, socket or CI sources name none of the removed symbols.

What was scanned

Probably dead, left alone on purpose

… and the CI pipeline script

- bake client: remove `DataViewReader.u16()`, the write-only
  `DataViewWriter.capacity` field with its constructor parameter, and the
  write-only `totalCount` local in `updateBuildErrorOverlay`.
- node:dgram: remove a commented-out block from 2024 that names two
  functions which do not exist.
- uSockets: remove the write-only `us_udp_socket_t.connected` bit, the
  write-only `us_quic_stream_s.headers_delivered` field, and an `#undef`
  of a macro that is never defined.
- uWS HTTP/2: remove the write-only `Http2ResponseData::totalSize` field.
- uws_sys: remove four opaque types that no Rust code names.
- .buildkite/ci.ts: remove the `dryRun` option (parsed, never read),
  `Platform.features`, and the emoji, distro and tier entries that no
  platform produces.
@robobun

robobun commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 5:34 AM PT - Sep 25th, 2026

✅ @robobun, your commit 8c2a4372bfc1b5c9d0e9a2c9bb6220c685ab0ede passed in Build #120600! 🎉


🧪   To try this PR locally:

bunx bun-pr 43976

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

bun-43976 --bun

@robobun

robobun commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

Status: ready for review.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: Essentials

Run ID: 4ffc5aa9-197f-4a43-b5ea-0d735597af0f

📥 Commits

Reviewing files that changed from the base of the PR and between 29d9638 and 8c2a437.

📒 Files selected for processing (11)
  • .buildkite/ci.ts
  • packages/bun-usockets/src/internal/eventing/epoll_kqueue.h
  • packages/bun-usockets/src/internal/internal.h
  • packages/bun-usockets/src/quic.c
  • packages/bun-usockets/src/udp.c
  • packages/bun-uws/src/Http2Context.h
  • packages/bun-uws/src/Http2ResponseData.h
  • src/js/node/dgram.ts
  • src/runtime/bake/client/data-view.ts
  • src/runtime/bake/client/overlay.ts
  • src/uws_sys/lib.rs
💤 Files with no reviewable changes (8)
  • src/js/node/dgram.ts
  • packages/bun-usockets/src/internal/eventing/epoll_kqueue.h
  • packages/bun-usockets/src/quic.c
  • packages/bun-usockets/src/udp.c
  • packages/bun-usockets/src/internal/internal.h
  • packages/bun-uws/src/Http2Context.h
  • src/runtime/bake/client/overlay.ts
  • packages/bun-uws/src/Http2ResponseData.h

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


Walkthrough

The PR removes obsolete CI options and type members, native socket state, HTTP/2 response state, runtime data-view APIs, and unused runtime code. QUIC header callbacks are no longer limited by a stored delivery flag.

Changes

Obsolete state and option cleanup

Layer / File(s) Summary
CI option and type cleanup
.buildkite/ci.ts
CI types and parsing no longer include obsolete distribution, tier, platform, and dry-run values.
QUIC header delivery state
packages/bun-usockets/src/quic.c
QUIC stream state no longer latches header delivery after the first decoded header block.
Native socket and FFI cleanup
packages/bun-usockets/src/internal/eventing/epoll_kqueue.h, packages/bun-usockets/src/internal/internal.h, packages/bun-usockets/src/udp.c, src/uws_sys/lib.rs
UDP initialization no longer writes the removed connected bitfield. The opaque FFI declarations retain only the remaining handles. The epoll/kqueue header no longer undefines FD_BITS.
HTTP/2 response state cleanup
packages/bun-uws/src/Http2Context.h, packages/bun-uws/src/Http2ResponseData.h
Http2ResponseData no longer stores totalSize, and Http2Response::internalEnd no longer assigns it.
Data view API cleanup
src/runtime/bake/client/data-view.ts
DataViewReader no longer exposes u16(). DataViewWriter no longer stores or accepts capacity.
Runtime dead-code cleanup
src/js/node/dgram.ts, src/runtime/bake/client/overlay.ts
The dgram bind path removes commented-out implementation code. Build-error overlay updates remove the unused totalCount value and accumulation.

Suggested reviewers: dylan-conway

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 8c2a4

The reviewed cleanup preserves the examined request, response, and bake-client behavior. No material current-head issue is identified.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: removing dead code across the bake client, uSockets, uWS HTTP/2, uws_sys, and CI pipeline.
Description check ✅ Passed The description explains the problem, lists the removals, documents verification, and notes the known environment-specific test failure. It does not use the exact template headings, but it provides th…
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.

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

@robobun

robobun commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator Author

The review reports no actionable comments, so the PR stays as it is. One line of the walkthrough needs a correction, because it reads as a behavior change.

The walkthrough says that QUIC header callbacks are no longer limited by a stored delivery flag. No flag limited them before this change:

  • On main, us_quic_stream_s.headers_delivered has two uses in packages/bun-usockets/src/quic.c: the field (line 127) and the assignment s->headers_delivered = 1; (line 699). Nothing reads it.
  • us_quic_deliver_hset calls on_stream_headers for each decoded header block, with and without the field.
  • The Rust field of the same name (src/http/h3_client/Stream.rs:39) belongs to a different struct. This PR does not touch it.

To check: git grep -n headers_delivered origin/main -- packages/bun-usockets.

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

LGTM — pure dead-code deletions, each removed item verified to have no remaining readers.

What was reviewed:

  • Grepped all Rust sources and src/codegen for the four opaque types dropped from opaque_extern! — only doc comments name them; udp.rs declares its own opaque Socket/PacketBuffer, so no Rust type mirrors us_udp_socket_t layout and the connected bitfield removal cannot shift anything Rust reads.
  • Checked C/C++ callers: FD_BITS is defined nowhere in the repo, headers_delivered had one write and no read in quic.c, and Http2ResponseData::totalSize had no data.totalSize reads (all remaining totalSize hits are the internalEnd parameter).
  • Confirmed DataViewWriter is constructed only via initCapacity, .u16() has no callers in src/ or test/, and dryRun/Platform.features/removed emoji keys have no remaining references in .buildkite or scripts/.
Extended reasoning...

The change is a single commit (+6/-43) that only deletes write-only fields, an uncalled method, unused type aliases/union members, and a never-read CI option across the bake client, uSockets, uWS HTTP/2, uws_sys, and .buildkite/ci.ts. It touches no security-sensitive surface: no auth, crypto, parsing, or input-validation paths change, and the C struct field removals affect only structs that are opaque to Rust and private to their C translation units. None of the changed files is covered by CODEOWNERS, and the bug hunt ran dry with five candidates ruled out. Static greps independently confirmed every removed symbol has zero remaining readers, which is what decided approve.

alii added a commit that referenced this pull request Sep 25, 2026
… 10 crates (#43010)

Behaviour change: none

### Problem
- Six trait impls in `bun_css` and `bun_semver` have no user on any
target. A `--gc-sections` link of the debug objects discards all their
methods, and no source line needs them.
- Ten crates re-export 24 names that no other crate imports. With `pub`
rewritten to `pub(crate)`, rustc reports each one as `unused_imports`.

### Fix
- Delete the impls: `DeepClone` and `CssEql` for the arena `ArrayList`
and for `bun_ast::Loc`, the helper `eql_list`, `PartialCmp` for
`CSSInteger`, and `Slicable` for `ExternalString`.
- Trim the 24 names from the `pub use` lists. Four `bun_ini` structs
lose their only outside path and become `pub(crate)`. The non-unix `FdT`
alias loses its only user and is deleted.
- Correct because nothing instantiates the removed impls, and the
workspace compiles on every target triple with the deny lints on (what
ran where is in Notes).
- No new test: no caller can observe a difference. Existing tests that
cover this code: `test/js/bun/css/css.test.ts`,
`test/cli/install/semver.test.ts`, `test/js/bun/ini/ini.test.ts`,
`test/cli/run/env.test.ts`.

### Background
- The workspace denies `dead_code`, but rustc exempts each `pub` item
that a crate root can reach. A `pub` impl or re-export can stay after
its last user is gone.
- `DeepClone`, `CssEql`, and `PartialCmp` are the CSS value protocol
traits in `src/css/generics.rs`. Generated and hand-written CSS types
call them through trait bounds.
- `Slicable` lets `Lockfile::str` read a semver string out of the
lockfile string buffer. Only `semver::String` is passed to it.

<details><summary>Notes</summary>

Removed items:

- `src/css/generics.rs`: `impl DeepClone for ArrayList<'bump, T>`, `impl
DeepClone for bun_ast::Loc`, `fn eql_list`, `impl CssEql for
ArrayList<'bump, T>`, `impl CssEql for bun_ast::Loc`, `impl PartialCmp
for CSSInteger`. `rg -w eql_list src` has no other hit.
- `src/semver/lib.rs`: `impl Slicable for ExternalString`.
- `src/dotenv/lib.rs`: re-export `DirEntryProbe`.
- `src/ini/lib.rs`: re-exports `ConfigIterator`, `ScopeItem`,
`ScopeIterator`, `ToStringFormatter`. The four structs become
`pub(crate)` because `unreachable_pub` is denied. All four are still
used inside the crate.
- `src/install/isolated_install/Store.rs`: re-export
`StoreKeyFormatter`.
- `src/js_parser_jsc/lib.rs`: re-export `toml_datetime_to_js`.
- `src/paths/lib.rs`: re-exports `PlatformT`, `RelPathFacts`,
`windows_volume_name_len`, `EnvPathInput`, `PathComponentBuilder`.
- `src/spawn_sys/lib.rs`: re-exports `FdT`, `IoCounters`, `WinRusage`,
`WinTimeval`.
- `src/spawn_sys/spawn_process.rs`: the alias `#[cfg(not(unix))] pub
type FdT = i32;`. Every use of `FdT` is in `#[cfg(unix)]` code, so the
re-export was the only thing that named the non-unix alias. The
`mordant` job found this (`unused_pub`, 1 finding over a baseline of 0).
The comment on the `bun_windows_sys` dependency in
`src/spawn_sys/Cargo.toml` named the removed re-export, so it now names
the alias in `spawn_process.rs`.
- `src/tcc_sys/lib.rs`: re-exports `ErrorFunc`, `TCCErrorFunc`,
`TCCState`.
- `src/threading/lib.rs`: re-export `GuardedLock`.
- `src/uws_sys/lib.rs`: re-export `PosixLoop`.
- `src/watcher/lib.rs`: re-exports `MAX_EVICTION_COUNT`, `WatchItem`,
`WatchItemIndex`.

For each re-exported name, `rg -w <name>` finds it in no other crate, in
no generated Rust under the codegen directory, and in no path of the
form `crate::<name>` or `<crate>::<name>`. Except for the non-unix `FdT`
alias, the items themselves stay, because each one is still used inside
its own crate.

How the candidates were found:

1. The debug objects were linked again with `--gc-sections
--print-gc-sections`. 615 Rust functions, methods, and trait impls
outside the files of the open dead-code PRs have no surviving symbol.
2. All 615 were deleted at once. `cargo check` ran in a loop for
linux-gnu, linux-gnu `--tests`, windows-msvc, apple-darwin, freebsd,
android, and musl. Each item that an error named was restored. 12 items
survived. Most of the others are Windows-only or macOS-only code.
3. Each crate was checked once with `pub` rewritten to `pub(crate)`.
This shows the re-exports and items that are unused inside their own
crate. Names that appear in any other crate were kept.

Candidates that compiled without them but are not dead, and so are not
in this PR:

- `ArrayBufferSink::flush`, `FetchRequestBodySink::flush`,
`BorderImageSideWidth::deep_clone`. A macro-generated trait method
forwards to each inherent method (`Self::flush(self)`,
`<$t>::deep_clone(self, bump)`). Without the inherent method the trait
method calls itself. The `unconditional_recursion` lint catches it.
- `bun_zstd::inflate_embedded` and `inflate_embedded_nul`.
`embed_compressed!` calls them only under `cfg(bun_codegen_embed)`,
which only release builds set.

A removed impl is not always a compile error. A call like `a.eql(&b)` on
two `ArrayList` values falls back to `impl CssEql for [T]` through
auto-deref. That impl compares the length and then each element, the
same as the removed `eql_list`. On the base of the first commit, no
symbol of a removed impl survived the link, so no reachable code called
one.

Overlap with other open dead-code PRs: #43976 also edits
`src/uws_sys/lib.rs`, in other hunks. No other file in this PR is
touched by one.

What ran on which tree:

- First commit (base 2dee3bd): `bun bd`, `bun run rust:check-all` (12
of 12), and these test files with the debug build:
`test/js/bun/css/css.test.ts`, `test/cli/install/semver.test.ts`,
`test/js/bun/ini/ini.test.ts`, `test/cli/run/env.test.ts`,
`test/internal/source-lints/` (174 tests),
`test/js/bun/resolve/toml/toml.test.js`,
`test/js/node/path/resolve.test.js`, `test/js/bun/ffi/cc.test.ts`,
`test/cli/install/bun-lock.test.ts`.
- After the merge of main (f063852) plus the `FdT` commit: `cargo
check --workspace` for the host, and `bun run rust:check-all` for both
Windows triples (2 of 2). The `FdT` commit changes only code that is
compiled out on unix, and CI built the merge commit on every platform
(build 120695). The debug build and the test files were not run again
locally.

</details>

<!-- robobun:evidence:begin -->

---

**[policy-decision:dep]** gate passed · iteration 6 · 14 files touched

<details><summary>passes on PR (with fix)</summary>

```console
Dependency/toolchain change; no test proof to run.
```

</details>

<details><summary>diff hotspot</summary>

```
src/css/generics.rs                   | 52 -----------------------------------
 src/dotenv/lib.rs                     |  4 +--
 src/ini/lib.rs                        | 13 ++++-----
 src/install/isolated_install/Store.rs |  2 +-
 src/js_parser_jsc/lib.rs              |  3 +-
 src/paths/lib.rs                      |  7 ++---
 src/semver/lib.rs                     |  6 ----
 src/spawn_sys/Cargo.toml              |  2 +-
 src/spawn_sys/lib.rs                  |  4 +--
 src/spawn_sys/spawn_process.rs        |  2 --
 src/tcc_sys/lib.rs                    |  4 +--
 src/threading/lib.rs                  |  2 +-
 src/uws_sys/lib.rs                    |  2 +-
 src/watcher/lib.rs                    |  6 ++--
 14 files changed, 21 insertions(+), 88 deletions(-)
```

</details>

**gate history** · 1 passed · 3 rejected · iteration 6

<details><summary>evidence per changed file</summary>

```
file                                   reads  edits  tests
src/css/generics.rs                        0      0      1
src/dotenv/lib.rs                          0      0      1
src/ini/lib.rs                             0      0      1
src/install/isolated_install/Store.rs      0      0      1
src/js_parser_jsc/lib.rs                   0      0      1
src/paths/lib.rs                           0      0      1
src/semver/lib.rs                          0      0      1
src/spawn_sys/Cargo.toml                   1      2      0
src/spawn_sys/lib.rs                       0      0      2
src/spawn_sys/spawn_process.rs             1      1      2
src/tcc_sys/lib.rs                         0      0      1
src/threading/lib.rs                       0      0      1
src/uws_sys/lib.rs                         0      0      2
src/watcher/lib.rs                         0      0      1
```

</details>

<!-- robobun:evidence:end -->

---------

Co-authored-by: Alistair Smith <hi@alistair.sh>
@Jarred-Sumner
Jarred-Sumner merged commit 36cd151 into main Sep 26, 2026
12 of 13 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the robobun/d5746ba3/dead-code-sweep branch September 26, 2026 07:43
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