Skip to content

Remove dead code and deduplicate helpers across src/ - #31912

Closed
alii wants to merge 18 commits into
mainfrom
claude/simplify-dead-code-pass
Closed

Remove dead code and deduplicate helpers across src/#31912
alii wants to merge 18 commits into
mainfrom
claude/simplify-dead-code-pass

Conversation

@alii

@alii alii commented Jun 5, 2026

Copy link
Copy Markdown
Member

What this is

A repo-wide cleanup pass over src/: deleting dead code and consolidating duplicated logic into shared helpers. Net −17,825 lines (206 files, +11,497 / −29,322 vs the base commit).

What changed

Dead code removed:

  • Parallel "draft" FFI implementation (host_fns.rs + draft types in ffi/mod.rs, ~620 lines) — only reference was an unused re-export
  • #[cfg(any())]-parked 1,188-variant MS-ERREF error table in src/sys/windows/mod.rs (~2,800 lines)
  • Duplicate WinsockError table + caller-less converter (−219)
  • Bundler-local copy of bun_resolver::cache::Fs (every live caller already used the resolver's)
  • Caller-less helpers, orphaned imports, and stale wrappers across cli/bake/zlib

Duplication consolidated (monomorphization-preserving — macros/const generics, no vtables added):

  • Shell builtins' copy-pasted OutputTaskVTable impls → one macro
  • JSON/TOML lexers' identical ~80-line decimal scanner → shared #[inline] generic in src/parsers/number_scan.rs (diffed against both reference implementations)
  • mysql/postgres/sqlite pooled-connection and query-constructor logic → src/js/internal/sql/shared.ts, src/sql/shared/
  • bake init_transpiler twins, link/unlink and outdated/update-interactive CLI helper blocks, bundler parse-task dispatch tail, cron/node_fs/CryptoHasher/hosted_git_info helper dedups

Verification

  • Build green; baseline test scope identical before/after (406 pass + 1 skip, 56,060 expects; runtime 5.27s vs 6.49s baseline)
  • No tests removed or weakened
  • Windows code is heavily touched (~3.5k gated lines deleted) and this was built on macOS, so cargo check was additionally run for x86_64-pc-windows-msvc and x86_64-unknown-linux-gnu — both pass, all 10 workspace cross-targets green
  • Per-change adversarial review for behavior preservation and perf: 0 regressions found; all 11 added clone sites match copies the old code already made or are cold CLI paths

Reviewer notes

  • src/css/compat.rs was converted from a generated match to a data table (equal-or-faster, verified) — but it's no longer regenerable by build-prefixes.js as-is. If we'd rather keep it generator-owned, I can revert that one commit's hunk or update the generator to emit the table form.
  • Zero behavior change is a hard goal of this PR: a 202-file behavioral-equivalence audit (one reviewer per changed file vs main, adversarially verified, plus a follow-up sweep) was run, and every confirmed divergence — error-message wording in bun add/update, postgres NoticeResponse short-length tolerance, macro-map parsing, JSON5/YAML space handling, SQL driver failure timing, pool slot guards — has been reverted to match main exactly. Where a dedup could not preserve behavior, the dedup itself was reverted.
  • The dead-code-escapes guard initially flagged a new #[allow(dead_code)] in src/router/lib.rs; resolved by deleting the orphaned cfg(test) fixture scaffolding (266 lines, plus its now-unused dev-dependency), not by updating the inventory.
  • CI triage (build 61383): bunx.test.ts "requires node 24" failure is pre-existing on main; the darwin AsyncLocalStorage-tracking fs-watch exit segfault is the known FSEventsLoop shutdown race (fs.watch(macOS): make FSEventsLoop Sync and retain the CFRunLoop across shutdown #30758 — identical stack, fault address 0xC, filed before this branch existed; every file in that crash path is byte-identical to main here).
  • This PR only moves and removes code; purely internal consolidation.

@robobun

robobun commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator
Updated 2:44 PM PT - Jun 8th, 2026

@alii, your commit 350764d has 2 failures in Build #61383 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 31912

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

bun-31912 --bun

@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. sql: deduplicate and remove dead code across the MySQL/Postgres drivers #31664 - Also deduplicates and removes dead code across the MySQL/Postgres SQL drivers, with overlapping changes in src/sql_jsc/shared/, src/sql_jsc/mysql/, and src/sql_jsc/postgres/

🤖 Generated with Claude Code

@alii
alii force-pushed the claude/simplify-dead-code-pass branch from 590c8d0 to 3cd193f Compare June 6, 2026 03:42
@alii
alii force-pushed the claude/simplify-dead-code-pass branch from 1157bd2 to 46ad414 Compare June 6, 2026 18:48
alii added a commit that referenced this pull request Aug 11, 2026
## What this does
Dedupes webcore lifecycle boilerplate with zero intended behavior
change:

- `impl_file_closer!` (Blob.rs): shared `FileCloser` impl for blob
`ReadFile`/`WriteFile`. The two hand-written impls were functionally
identical; `ReadFile` gains `bun_io::intrusive_io_request!` so both
recover the parent through `IntrusiveIoRequest` instead of an open-coded
`from_field_ptr!`. `ReadFileUV` keeps its own impl (different shape).
- `impl_js_sink_forwarders!` (Sink.rs, next to `impl_js_sink_abi!`): the
eight 1:1 `JsSinkType` forwarders shared by `ArrayBufferSink`,
`FileSink`, `FetchRequestBodySink`, `HTTPServerWritable`, and
`NetworkSink`. Per-sink items (`finalize`, `construct`, `end_from_js`,
`source`, `done`, `HAS_*`) stay hand-written.
- `CopyFile::fallback_read_write`: the `read_write_fallback` call plus
error recording appeared three times in `do_copy_file_range`.
- `Blob::set_content_type_from_js` and `S3File::finish_s3_blob`: the
write-path `options.type` override (in `do_write` and `get_writer`) and
the S3 constructor epilogue (in both
`construct_s3_file_with_s3_credentials*` fns) were each duplicated
verbatim.
- `S3File::parse_s3_path_or_blob`/`resolve_s3_blob` and
`S3Client::construct_blob`/`blob_and_options`: shared argument parsing
for the S3 static and instance methods. `MissingPathError` preserves the
per-method split between `MISSING_ARGS` and invalid-argument errors
(`unlink` always reports `MISSING_ARGS`; the others only when no
argument was passed).
- The explicit 14-arm typed-array `JSType` lists in Blob construction
use the existing `JSType::is_array_buffer_like()` (same 14-type set).

Net -401 lines of src.

## History
Originally the top of the foundations/install-cli/jsc-runtime stack
split from #31912. Main moved far enough that every file conflicted, so
this was re-derived against current main and retargeted at `main`; it
has no code dependency on the other PRs in that stack.

## Tests
The consolidated paths had no coverage of their error contracts, so this
adds characterization tests pinning them:

- `test/js/bun/s3/s3-argument-validation.test.ts`: per-method static
rejection messages (including `stat` reusing the "get size" wording),
the instance-method `ERR_MISSING_ARGS` vs `ERR_INVALID_ARG_TYPE` split,
`unlink` always reporting `MISSING_ARGS`, and the S3 `writer()`
non-string `type` rejection
- `test/js/web/fetch/blob-write.test.ts`: `Bun.file().write()`
`options.type` contract (non-string throws, valid types lowercased,
known types resolved through the mime table, invalid types ignored)
- `test/js/web/fetch/blob.test.ts`: Blob construction from all 14
ArrayBuffer-like types, as a direct body value and as an array part

Because this is a behavior-preserving refactor, these tests pass
identically with and without the src changes by design; that is the
equivalence check, not a gap.

## Verification
- Line-by-line audit against main for each consolidation: error
messages, argument-eating order, drop order, and the unsafe
parent-pointer recovery in `schedule_close`/`on_close_io_request` are
unchanged (the macro's two trampolines are `WriteFile`'s current impl
statement for statement, differing only in fully-qualified paths;
`ReadFile` moves from its older `&mut *from_field_ptr!` form onto that
same already-landed shape)
- `bun run rust:check-all`: all 10 CI target triples pass
- Debug (ASAN) build: the three test files above (102 pass), sink suites
plus request-body and server-response stream suites (9161 pass),
`Bun.write` including both `copyFileRange`-unavailable fallback tests,
local S3 suites (38 pass), blob/FormData suites (165 pass). The
large-file fallback test needs more than the 5s default on this ASAN box
with or without the change.

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

---

**no test proof** · iteration 17 · Platform-specific test(s) that do not
run on this machine. Deferring to CI, which covers all platforms:
test/js/web/fetch/blob.test.ts

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

---------

Co-authored-by: robobun <117481402+robobun@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants