Skip to content

Remove dead code across foundation crates#32000

Open
alii wants to merge 6 commits into
mainfrom
claude/split/foundations
Open

Remove dead code across foundation crates#32000
alii wants to merge 6 commits into
mainfrom
claude/split/foundations

Conversation

@alii

@alii alii commented Jun 8, 2026

Copy link
Copy Markdown
Member

What this does

Small dead-code deletions and helper dedups across the foundation crates: collections (unused StaticHashMap/array_list/bit_set items), threading, paths, semver, sourcemap, ini, clap_macros, bun_core output/string, io (PipeWriter/event-loop macro extraction), router (deletes orphaned cfg(test) fixture scaffolding and its dev-dependency), and url (re-exports bun_opaque handle types; Cargo.lock updated accordingly). Net −1.5k lines.

This is the base of a small stacked chain (install-cli → jsc-runtime → webcore will be based on it).

Split from #31912 (whole-repo simplification pass; closing that PR in favor of module-scoped splits). This PR only moves and removes code — zero intended behavior change. Verified there by a per-file behavioral-equivalence audit and full CI (green on build 61383); verified here by a standalone full-workspace compile check.

Why no new test files

This diff removes unused code and dedups identical implementations, so there is no behavior change for a new test to pin down. Regression coverage is the existing suite, which already exercises every touched path: bundler/transpiler snapshots for the string printer, the io and spawn suites for FilePoll/PipeWriter (Windows lanes cover windows_event_loop), the install suites for semver string interning, and test/cli/install/public-hoist-pattern.test.ts for the ini matcher path. multi_array_list keeps its in-crate #[test] coverage.

Merge resolution (main at a830e9d)

Two hand-resolved points:

  • src/io/posix_event_loop.rs: Add process.on('memoryPressure') event #32594 added Flags::PollMemoryPressure to is_registered(), which this PR moves into impl_file_poll_flag_methods!(). Carried the new flag into the macro body (so the Windows expansion picks it up too; harmless there: the FilePoll Flags::MemoryPressure registration in memory_pressure.rs is #[cfg(not(windows))]-gated, Windows uses a uv_async_t backend, so the flag is never set on a Windows FilePoll, same as the pre-existing PollMachport clause. Cross-checked cargo check -p bun_io --target x86_64-pc-windows-msvc).
  • src/collections/array_hash_map.rs: restored get_index_mut, which gained a caller in src/react_compiler/collections.rs via React Compiler integration #32504 after this PR was authored. The other two deletions in that file (ensure_total_capacity_context, StringHashMap::put_owned) remain dead and are still removed.

Swept every other public item this PR deletes against current origin/main; none gained callers. Full cargo check --workspace is green after the merge.

@robobun

robobun commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator
Updated 10:11 PM PT - Jun 23rd, 2026

@robobun, your commit 42995f5 has 2 failures in Build #64431 (All Failures):

  • ❌ CPU instruction violation on Linux x64 — 1 check(s) failed
  • The baseline build contains instructions not available on Nehalem (SSE4.2, no AVX/AVX2/AVX512).

    • Static instruction scan

    Static scan violations

    llint_op_enter_wide32  [AVX]  (1 insns)
    

    If these are runtime-dispatched behind a CPUID gate: add each symbol to scripts/verify-baseline-static/allowlist-x64.txt with a comment pointing at the gate.

    If there's no gate: this is a real bug — a -march leaked into a subbuild.

  • test/js/web/streams/streams-leak.test.ts - code 1 on 🐧 13 x64

🧪   To try this PR locally:

bunx bun-pr 32000

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

bun-32000 --bun

@alii alii marked this pull request as ready for review June 9, 2026 20:18
@alii

alii commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@robobun adopt

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR consolidates shared output tag rewriting logic, optimizes string escaping through const-generic encoding dispatch, abstracts event loop storage behind a trait for cross-platform code reuse, and removes approximately 30 unused public APIs across collections and utilities while refactoring internal data structures including semver strings, URL FFI handles, and sourcemap generation.

Changes

Shared Output Tag Rewriting and String Escaping Optimization

Layer / File(s) Summary
Shared ANSI Tag Rewriting Library and Integration
src/bun_output_tags/lib.rs, src/clap_macros/lib.rs, src/bun_core/output.rs
bun_output_tags::pretty_fmt_runtime is introduced as the canonical runtime tag processor that scans bytes, expands known tags to ANSI sequences, handles escaped literals, and drops unknown tags. bun_core/output.rs removes its duplicated local implementation and color_map wrapper, then re-exports the shared function. clap_macros calls the shared function at macro-expansion time to precompute tag-stripped help text instead of using a local helper.
Const-Generic String Escaping for Monomorphization Reduction
src/bun_core/string/mod.rs
New Encoding enum (Ascii, Utf8, Latin1, Utf16) with ConstParamTy becomes a const-generic parameter to write_pre_quoted_string_inner, consolidating per-encoding loop logic and code-point extraction. can_print_without_escape becomes public. $ lookahead uses the same const-generic decoding path. quote_for_json is updated to call the UTF-8 specialized escaping path with updated buffer pre-growth heuristics.

Event Loop Storage Abstraction and Cross-Platform Unification

Layer / File(s) Summary
POSIX PollSlot Trait and Generic PollStore Infrastructure
src/io/posix_event_loop.rs
Introduces PollSlot unsafe trait to abstract intrusive free-list linkage (next_to_free, set_next_to_free) and flag manipulation (ignore_updates). Replaces concrete POSIX Store with generic PollStore<P: PollSlot>. impl_file_poll_flag_methods!() macro consolidates FilePoll flag accessors (is_active, is_watching, is_registered, can_unref, file_descriptor, and flag consumption helpers) into generated code.
POSIX Deferred-Free Processing with Generic PollSlot
src/io/posix_event_loop.rs
Updates process_deferred_frees to traverse the intrusive free-list using P::next_to_free and P::set_next_to_free trait methods. Updates PollStore::put to manipulate the intrusive free-list and apply IgnoreUpdates generically over P. Adjusts the deferred-free callback thunk to cast context to Self and call process_deferred_frees().
Windows Event Loop Migration to Shared Abstraction
src/io/windows_event_loop.rs
Removes Windows-specific Store struct (with intrusive deferred-free list and extern "C" thunk), raw-pointer accessors, and explicit flag methods. Adopts posix::PollStore<FilePoll> as a type alias and invokes impl_poll_slot!(FilePoll) macro to implement the PollSlot trait. Consolidates flag methods to use the shared macro from POSIX, eliminating code duplication.

Systematic API Surface Reduction

Layer / File(s) Summary
Collections API Surface Reduction
src/collections/StaticHashMap.rs, src/collections/array_hash_map.rs, src/collections/array_list.rs, src/collections/bit_set.rs, src/collections/lib.rs, src/collections/multi_array_list.rs, src/collections/pool.rs
Removes put_context from HashMap, ensure_total_capacity_context from ArrayHashMap, and put_owned from StringHashMap. Removes unused insertion/capacity/access methods from ArrayListAlignedIn (from_owned_slice_sentinel, into_unmanaged_with_allocator, add_many_at, replace_range_assume_capacity, append_unaligned_slice, get_last_mut). Deletes non-mutating set operations (complement, union_with, intersect_with, xor_with, difference_with) from IntegerBitSet and ArrayBitSet. Removes masks_ptr and set_exclude_two from DynamicBitSetUnmanaged. Removes insert_slice_assume_capacity from SmallList. Removes span-based sorting (sort_span, sort_span_unstable) from MultiArrayList. In pool, removes remove_next and find_last from Node<T> and adds count_children to iterate and count successor nodes.
Threading and Path Utilities API Reduction
src/threading/WaitGroup.rs, src/threading/channel.rs, src/threading/guarded.rs, src/threading/work_pool.rs, src/paths/lib.rs, src/paths/resolve_path.rs
Removes add_unsynchronized from WaitGroup. Removes init_dynamic constructor and try_write_item non-blocking writer from Channel. Removes raw_mutex accessor from GuardedBy. Removes schedule_batch from WorkPool. Deletes dir_or_dot convenience accessor from PathName and init_for_kit_built_in constructor from Path. Removes get_last_separator_func const fn from Platform.

Data Structure Refactoring

Layer / File(s) Summary
Semver, URL, and Sourcemap Data Structure Changes
src/semver/lib.rs, src/semver/Version.rs, src/url/lib.rs, src/url/Cargo.toml, src/sourcemap/Chunk.rs, src/sourcemap/lib.rs
Semver String inline-eligibility consolidated through can_inline (clarifying the MAX_INLINE_LEN top-bit rule) and inline_bytes helper; init, init_inline, and init_append_if_needed now drive behavior through these centralized helpers. URL FFI handle redefined via bun_opaque::opaque_ffi! macro; from_string now consumes owned String and adds helper methods file_url_from_string and path_from_file_url; new unsafe destroy method deallocates heap pointers. Sourcemap printing changes from print_source_map_contents (direct VLQ) to print_source_map_contents_from_internal (blob-based re-encoding). Removes VersionType::sort_gt boolean wrapper, leaving order_fn as canonical comparison. Removes append_source_mapping_url_remote helper from sourcemap lib.
INI Matcher Consolidation and I/O Synchronization
src/ini/lib.rs, src/io/PipeWriter.rs
Switches .npmrc public-hoist-pattern and hoist-pattern matching from local pnpm_matcher_from_expr helper to bun_install_types::NodeLinker::PnpmMatcher::from_expr, eliminating bump allocator parameter and narrowing imports. Introduces write_sync_file internal helper to centralize Source::SyncFile blocking write behavior (encoding via write_or_fallback, looping over remaining bytes via sys::write, computing progress, resetting buffer, returning WriteResult). Refactors write_internal_u8 and write_internal_u16 to delegate to write_sync_file instead of inlining the blocking loops.
Build and Test Cleanup
src/router/Cargo.toml, src/router/lib.rs
Removes bun_js_parser from [dev-dependencies] section. Simplifies test module header by removing mock fixture infrastructure (request context, server, watcher types, scratch-file fixture, test resolver, and route-loader builders).

Possibly related PRs

  • oven-sh/bun#30901: Direct alignment with the main PR's refactor of write_pre_quoted_string_inner/quote_for_json escaping logic in src/bun_core/string/mod.rs; both PRs modify the same quoting/escaping code path family.

Suggested reviewers

  • dylan-conway
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main objective: removing dead code across multiple foundation crates.
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 PR description comprehensively explains what is being done, why, how it was verified, and includes detailed merge resolution notes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@robobun

robobun commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Adopted. Full diff audited as behavior-preserving; the one external consumer of the changed URL::from_string signature (hosted_git_info) goes through from_utf8 so it is unaffected.

Merged main at a830e9d with two manual resolutions (carried PollMemoryPressure from #32594 into the impl_file_poll_flag_methods macro; restored ArrayHashMap::get_index_mut for #32504's new caller; details in the PR body). Merge strategy used because #32022 stacks on this branch. Full workspace cargo check green on linux + the windows io crate.

Bot review state: claude[bot] found no behavioral issues and recommends a human pass given the refactor density on the string escaper and PollStore; its two style nits are fixed in 7ad9fc9 and 42995f5. CodeRabbit findings declined (tag-grammar withdrawn; output.rs comments are main's code via #32520; /// rustdoc is not subject to the // 3-line cap). All review threads resolved.

CI on build 64431 (head 42995f5): 284 jobs passed, 2 failed, both unrelated to this diff:

  • streams-leak.test.ts chunk-count (>20, got 10/8) on one debian-x64 shard. Passed on debian-asan and both Windows lanes in the same build. Known flake: Jarred's unmerged deflake f1dd6f4af5 says it "fails intermittently on busy machines" and relaxes the threshold to >2.
  • x64-musl-baseline verify-baseline flags one AVX Vmulpd inside JSC's llint_op_enter_wide32 (WebKit offlineasm, not touched by this PR). The glibc x64-baseline lane in this build and main's x64-musl-baseline at the same merge point both report 0 violations, and the 28 runtime SIMD tests in the same job all pass. The scanner linear-sweeps the whole .text section (one iced_x86::Decoder, no per-symbol restart), and its README documents exactly this VEX-in-data false-positive class; this PR's Rust code-size changes just shift the decode offset into LLInt's embedded tables on the musl link layout.

Ready for a maintainer to retry those two jobs or merge on the strength of the 284 green.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/bun_output_tags/lib.rs`:
- Around line 125-143: The parser currently consumes raw '>' and drops a
trailing backslash at EOF; update the match arms handling b'\\' and b'>' so only
recognized tag/escape sequences are consumed: in the b'>' arm, push the literal
b'>' into out (instead of swallowing it) and advance i; in the b'\\' arm, if i+1
>= fmt.len() (trailing backslash) push the b'\\' into out and stop/advance
appropriately, otherwise keep the existing escape handling for recognized '<' or
'>' and for unknown escapes push both the backslash and the following byte
unchanged. Locate these edits around the match on fmt[i] in lib.rs where fmt,
out, and i are used.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e0b240f7-9211-43b1-aa09-cbf027083864

📥 Commits

Reviewing files that changed from the base of the PR and between 09703da and 2f2b483.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (29)
  • src/bun_core/output.rs
  • src/bun_core/string/mod.rs
  • src/bun_output_tags/lib.rs
  • src/clap_macros/lib.rs
  • src/collections/StaticHashMap.rs
  • src/collections/array_hash_map.rs
  • src/collections/array_list.rs
  • src/collections/bit_set.rs
  • src/collections/lib.rs
  • src/collections/multi_array_list.rs
  • src/collections/pool.rs
  • src/ini/lib.rs
  • src/io/PipeWriter.rs
  • src/io/posix_event_loop.rs
  • src/io/windows_event_loop.rs
  • src/paths/lib.rs
  • src/paths/resolve_path.rs
  • src/router/Cargo.toml
  • src/router/lib.rs
  • src/semver/Version.rs
  • src/semver/lib.rs
  • src/sourcemap/Chunk.rs
  • src/sourcemap/lib.rs
  • src/threading/WaitGroup.rs
  • src/threading/channel.rs
  • src/threading/guarded.rs
  • src/threading/work_pool.rs
  • src/url/Cargo.toml
  • src/url/lib.rs
💤 Files with no reviewable changes (16)
  • src/collections/StaticHashMap.rs
  • src/semver/Version.rs
  • src/collections/lib.rs
  • src/threading/guarded.rs
  • src/paths/resolve_path.rs
  • src/router/Cargo.toml
  • src/threading/work_pool.rs
  • src/threading/WaitGroup.rs
  • src/sourcemap/lib.rs
  • src/collections/array_hash_map.rs
  • src/sourcemap/Chunk.rs
  • src/collections/array_list.rs
  • src/threading/channel.rs
  • src/collections/pool.rs
  • src/paths/lib.rs
  • src/collections/bit_set.rs

Comment thread src/bun_output_tags/lib.rs
Resolved src/io/posix_event_loop.rs: #32594 added PollMemoryPressure to
is_registered(), which this branch moved into impl_file_poll_flag_methods;
carried the flag into the macro body.

Restored ArrayHashMap::get_index_mut: gained a caller in
react_compiler/collections.rs via #32504.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/bun_core/output.rs`:
- Around line 765-768: The comments near the ENABLE_LOGS and SCOPED_FILE_WRITER
code exceed the 3-line maximum as per coding guidelines. Reduce both comments
(one at lines 765-768 and another at lines 2607-2610) to 3 lines or fewer by
condensing the explanatory text while preserving the key information about why
ENABLE_LOGS gates readers and why initialization occurs under debug_assertions
to prevent SCOPED_FILE_WRITER from being zeroed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e50342ba-4ac9-4dd0-b493-c2930eb3c4db

📥 Commits

Reviewing files that changed from the base of the PR and between 2f2b483 and 9efe40b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • src/bun_core/output.rs
  • src/collections/array_hash_map.rs
  • src/ini/lib.rs
  • src/io/PipeWriter.rs
  • src/io/posix_event_loop.rs

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

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/bun_core/output.rs`:
- Around line 765-768: The comments near the ENABLE_LOGS and SCOPED_FILE_WRITER
code exceed the 3-line maximum as per coding guidelines. Reduce both comments
(one at lines 765-768 and another at lines 2607-2610) to 3 lines or fewer by
condensing the explanatory text while preserving the key information about why
ENABLE_LOGS gates readers and why initialization occurs under debug_assertions
to prevent SCOPED_FILE_WRITER from being zeroed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e50342ba-4ac9-4dd0-b493-c2930eb3c4db

📥 Commits

Reviewing files that changed from the base of the PR and between 2f2b483 and 9efe40b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • src/bun_core/output.rs
  • src/collections/array_hash_map.rs
  • src/ini/lib.rs
  • src/io/PipeWriter.rs
  • src/io/posix_event_loop.rs
🛑 Comments failed to post (1)
src/bun_core/output.rs (1)

765-768: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Trim the new comments to the 3-line maximum.

Both new explanatory comments span four lines.

Proposed comment compaction
-        // `ENABLE_LOGS` gates every reader, but initialize under
-        // `debug_assertions` too so `SCOPED_FILE_WRITER` is never observed
-        // zeroed if a `#[cfg(debug_assertions)]` path reaches it in
-        // release-asan/release-assertions. Cheap (one static write).
+        // `ENABLE_LOGS` gates readers, but initialize under `debug_assertions`
+        // too so `SCOPED_FILE_WRITER` is not zeroed if a debug-assertions path
+        // reaches it in release-asan/release-assertions. Cheap (one static write).
-    // All callers are already gated on `Environment::ENABLE_LOGS`; this is a
-    // Debug-build self-check (release-asan/release-assertions enable
-    // `debug_assertions` with `ENABLE_LOGS == false`, so keying on
-    // `debug_assertions` would turn it into a guaranteed abort there).
+    // All callers are gated on `Environment::ENABLE_LOGS`; this is a
+    // debug-build self-check, not a `debug_assertions` check, because
+    // release-asan/release-assertions run with `ENABLE_LOGS == false`.

As per coding guidelines, "Keep code comments to 3 lines max."

Also applies to: 2607-2610

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/bun_core/output.rs` around lines 765 - 768, The comments near the
ENABLE_LOGS and SCOPED_FILE_WRITER code exceed the 3-line maximum as per coding
guidelines. Reduce both comments (one at lines 765-768 and another at lines
2607-2610) to 3 lines or fewer by condensing the explanatory text while
preserving the key information about why ENABLE_LOGS gates readers and why
initialization occurs under debug_assertions to prevent SCOPED_FILE_WRITER from
being zeroed.

Source: Coding guidelines

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

No behavioral issues found, but this touches a lot of load-bearing surface area for a dead-code pass — the const-generic string-escaper rewrite, the genericized PollStore over unsafe raw-pointer code shared across POSIX/Windows, and the URL FFI handle/signature change — so it's worth a human pass before the stacked chain lands on top of it.

Extended reasoning...

Overview

This PR spans 30 files across the foundation crates (collections, threading, paths, semver, sourcemap, ini, clap_macros, bun_core, io, router, url) and nets roughly −1.5k lines. The bulk is genuinely mechanical: deleting unused public methods (put_context, add_many_at, complement/xor_with/difference_with, sort_span, schedule_batch, try_write_item, raw_mutex, add_unsynchronized, etc.), removing orphaned #[cfg(test)] fixture scaffolding from router, and dropping the corresponding bun_js_parser dev-dependency. Those parts are low-risk.

However, several hunks are non-trivial refactors rather than deletions:

  • bun_core/string/mod.rs: write_pre_quoted_string is restructured around a const-generic Encoding parameter. The UTF-16 path switches from cast_slice::<u8, u16> to manual two-byte little-endian reads via a code_unit_at! macro, the $ lookahead is rewritten to use code_unit_at!(i + clamped_width), and quote_for_json gains a heuristic 12.5% pre-grow. These are claimed behavior-preserving but change indexing structure on a hot transpiler path.
  • io/posix_event_loop.rs + windows_event_loop.rs: the per-platform Store is replaced by a generic PollStore<P: PollSlot> with a new unsafe trait PollSlot and two macro_rules! (impl_file_poll_flag_methods!, impl_poll_slot!). This consolidates ~100 lines of duplicated unsafe raw-pointer / Stacked-Borrows-sensitive code into one definition that both platforms instantiate.
  • semver/lib.rs: three open-coded length-match ladders collapse into can_inline + inline_bytes helpers.
  • url/lib.rs: the opaque URL handle is redefined via bun_opaque::opaque_ffi! (now !Send/!Sync), from_string changes from &String to owned String, and destroy/file_url_from_string/path_from_file_url helpers are added.
  • bun_output_tags/lib.rs: pretty_fmt_runtime is moved verbatim from bun_core/output.rs (now #![no_std] + alloc), with the capacity heuristic dropped from * 4 to * 2 and a new rationale comment.

Security risks

None apparent. No auth, crypto, permissions, or untrusted-input parsing surfaces are touched. The closest thing is the URL FFI handle change, but that's a type-level wrapper around an existing C++ pointer with no new attack surface.

Level of scrutiny

Medium-high. The pure deletions and the pretty_fmt_runtime move are low-risk and well-covered by existing tests (parity tests in output.rs, install/bundler suites). But the string-escaper and PollStore refactors sit on hot/critical paths (JS printer output correctness; event-loop deferred-free under Stacked Borrows on both POSIX and Windows lanes), and this PR is explicitly the base of a stacked chain — regressions here propagate. The PR description states a per-file behavioral-equivalence audit was done and full CI is green (build 61383/61692), which is reassuring, but the refactor density exceeds what I'd auto-approve.

Other factors

  • The only finding from the bug hunt is a cosmetic comment-accuracy nit ("5-byte" → "4-byte"); no functional issues surfaced.
  • CodeRabbit's one substantive finding (> / trailing-\\ handling in pretty_fmt_runtime) was a misread of the tag grammar and was withdrawn; that thread is resolved.
  • robobun has adopted the PR and confirmed CI is effectively green modulo two expired darwin shards unrelated to the diff.
  • No human reviewer has weighed in yet despite the PR being open ~16 days; given it gates a stack, a maintainer sign-off seems appropriate.

Comment thread src/bun_output_tags/lib.rs Outdated
Comment thread src/bun_core/string/mod.rs Outdated

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/bun_core/string/mod.rs (1)

2462-2465: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Trim these new comments to the three-line cap.

Both doc blocks exceed the repository’s comment-length rule; they can be compressed without losing the invariant/perf rationale.

Suggested wording
-    /// `strings::Encoding` stand-in that derives `ConstParamTy` so it can be
-    /// used as a const-generic parameter (`const ENCODING: Encoding`). The
-    /// variant set is identical; convert at the boundary if a
-    /// `strings::Encoding` is ever needed.
+    /// `strings::Encoding` stand-in deriving `ConstParamTy` for const-generic use.
+    /// Variants mirror `strings::Encoding`; convert at the boundary when a
+    /// runtime encoding is needed.
@@
-    /// `quote_char` / `ascii_only` / `json` are runtime args: the branches on
-    /// them are cheap and well-predicted, and collapsing the monomorphizations
-    /// keeps the hot transpile pages dense. `ENCODING` stays `const` — it
-    /// changes the code-unit indexing structure of the loop, so a per-encoding
-    /// copy is genuinely different code.
+    /// Keep formatting flags runtime-dispatched to collapse monomorphizations;
+    /// `ENCODING` stays const because it changes the loop's code-unit indexing
+    /// structure, so each encoding is genuinely different code.

As per coding guidelines, “Keep code comments to 3 lines max.”

Also applies to: 2500-2504

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/bun_core/string/mod.rs` around lines 2462 - 2465, The doc comments at the
Encoding type definition exceed the repository's 3-line maximum limit. Trim the
doc comment starting around line 2462 that describes the strings::Encoding
stand-in and its const-generic parameter capability down to 3 lines or fewer,
retaining the key information that it derives ConstParamTy for const-generic
usage and that the variant set is identical. Also apply the same compression to
the similar doc comment block around line 2500-2504 to meet the coding
guidelines.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/bun_core/string/mod.rs`:
- Around line 2462-2465: The doc comments at the Encoding type definition exceed
the repository's 3-line maximum limit. Trim the doc comment starting around line
2462 that describes the strings::Encoding stand-in and its const-generic
parameter capability down to 3 lines or fewer, retaining the key information
that it derives ConstParamTy for const-generic usage and that the variant set is
identical. Also apply the same compression to the similar doc comment block
around line 2500-2504 to meet the coding guidelines.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d4457bd8-6c9e-48a3-9a7b-4a1a10bdb0c7

📥 Commits

Reviewing files that changed from the base of the PR and between 7ad9fc9 and 42995f5.

📒 Files selected for processing (2)
  • src/bun_core/string/mod.rs
  • src/clap_macros/lib.rs

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

Thanks for addressing both nits — I didn't find any behavioral issues, but the const-generic rework of write_pre_quoted_string_inner (hot-path escaper) and the unsafe PollStore<P> genericization across POSIX/Windows are dense enough that a human pass is worth it before this lands as the base of the stacked chain.

Extended reasoning...

Overview

30 files, net −1.5k lines across foundation crates. Roughly three buckets:

  • Pure deletions of uncalled public items (collections ArrayList/BitSet/MultiArrayList/StaticHashMap/SmallList/pool, threading WaitGroup/Channel/GuardedBy/WorkPool, paths, sourcemap, semver sort_gt, router #[cfg(test)] fixture scaffolding + dev-dep).
  • Dedup moves: pretty_fmt_runtime hoisted into bun_output_tags and re-exported from bun_core::output / called from clap_macros; PipeWriter SyncFile blocking loop extracted to write_sync_file; semver inline-string init collapsed through can_inline/inline_bytes; ini pnpm_matcher_from_expr replaced by PnpmMatcher::from_expr.
  • Non-trivial refactors: write_pre_quoted_string split into a runtime-encoding adapter + #[inline(never)] const-generic write_pre_quoted_string_inner<W, const ENCODING> (changes UTF-16 indexing to manual from_le_bytes, fuses the two write_all calls in the ASCII/UTF-8 fast path, reroutes $ lookahead through code_unit_at!, adds a grow_if_needed heuristic in quote_for_json); Store → generic PollStore<P: PollSlot> with a new PollSlot unsafe trait + impl_poll_slot!/impl_file_poll_flag_methods! macros, Windows Store deleted and aliased to posix::PollStore<FilePoll>; whatwg::URL switched to opaque_ffi! and from_string now takes String by value.

Security risks

None identified. No auth/crypto/permissions surface; the URL FFI change is a handle-type swap (opaque_ffi!) plus an owned-vs-borrowed parameter change whose only external caller goes through from_utf8 (per the adoption comment). The unsafe code touched (PollStore intrusive list, impl_poll_slot!) preserves the existing Stacked-Borrows discipline (raw-pointer field ops only, no &mut P materialized while &mut PollStore is live) and adds a const { assert!(!needs_drop::<P>()) } guard.

Level of scrutiny

High, for two specific hunks:

  • src/bun_core/string/mod.rswrite_pre_quoted_string_inner is the escaper behind the JS printer and quote_for_json; the diff changes loop structure (fused write_all, manual little-endian UTF-16 unit reads replacing cast_slice, clamped_width-based $ lookahead) in ways that are equivalence-by-inspection rather than mechanical. A wrong byte here surfaces as snapshot diffs across the bundler/transpiler suite, but it's hot enough that a human should confirm the equivalence reasoning.
  • src/io/{posix,windows}_event_loop.rs — the Windows Store is now the POSIX PollStore<FilePoll> instantiation. The merge resolution carries PollMemoryPressure into the macro so Windows is_registered() now also tests it (previously did not); the PR body calls this intentional and harmless since nothing sets that flag on Windows, but it is a behavior delta on a platform I can't exercise here.

The rest (deletions, pretty_fmt_runtime move, PipeWriter extraction, semver inline helper) is mechanical and low-risk.

Other factors

  • Both of my prior inline nits (4-byte vs 5-byte capacity comment; CLAUDE.md 3-line comment cap) were addressed in 7ad9fc9 and 42995f5 and are resolved.
  • CodeRabbit's one substantive flag was withdrawn after the tag-grammar was clarified; no open reviewer threads remain.
  • CI is running on the current head; the PR body reports green full-workspace cargo check (linux + windows io crate) post-merge.
  • This PR is the base of a stacked chain (#32022 etc.), which raises the cost of a latent regression slipping through.

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