Repository navigation
Conversation
…urcemap, threading, url
Resolved src/bun_core/string/mod.rs: #33909 switched return types to crate::CrateResult<()> in write_pre_quoted_string and quote_for_json, which this branch restructures into the const-generic write_pre_quoted_string_inner; carried CrateResult<()> into both the adapter and _inner signatures. Resolved src/router/lib.rs and src/sourcemap/Chunk.rs: #33909 touched return types inside blocks this branch deletes (orphaned router test scaffolding, uncalled print_source_map_contents); kept the deletions after re-verifying zero callers on current main. Restored Node::find_last in src/collections/pool.rs: gained a test caller via #33311.
…update --interactive
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. Because it restructures unsafe ownership-transfer code in subprocess stdin setup and introduces a new macro abstraction across four shell builtins, a human look would still be worthwhile.
Checked that buffered_stdin_writer preserves the ManuallyDrop/ptr::read semantics of both original call sites, and that the collapsed Writable::init/Readable::init matches in subproc.rs produce the same per-platform arms (including the new SocketFd). Verified impl_output_task_vtable! expands to the hand-written impls it replaces for cp/ls/mkdir/touch; the mkdir Idle/Done panic relaxation is noted in the description and Idle still panics via next(). Confirmed Kind::Dirname.usage_string() matches the old hardcoded literal, and the shell_cmd_args_from_js extraction is testing-API-only.
Extended reasoning...
Overview
This PR is split 4 of 8 from #32023, which a maintainer asked to be broken up. It touches 10 files across the shell interpreter, shell builtins, and subprocess stdio setup — roughly 450 lines removed and 250 added. The changes are three deduplications:
buffered_stdin_writer(subprocess/Writable.rs): extracts the Blob/ArrayBuffer →StaticPipeWritersetup into a generic helper shared byBun.spawnand the shell'sWritable::init(four call sites collapsed to one helper).subproc.rsmatch collapse:Writable::initandReadable::initeach had two near-identical#[cfg(windows)]/#[cfg(not(windows))]match blocks; these are merged into one match with per-armcfgblocks where behavior differs.impl_output_task_vtable!(interpreter.rs): a declarative macro that stamps out theOutputTaskVTableimpl andon_io_writer_chunkfor cp/ls/mkdir/touch, parameterized on where the output queue lives (queue_in_execvsqueue_on_self). Separately,basename/dirnameare unified intoPathBuiltin<T: PathTransform>.
A minor fourth change extracts a shared argument-parsing prologue for the shell_lex/shell_parse internal-for-testing APIs in shell_body.rs.
Security risks
None identified. No user-facing input parsing changes, no auth/crypto/permissions surface. The shell_body.rs change is confined to bun:internal-for-testing entry points.
Level of scrutiny
Medium-high. While framed as pure code motion, the change:
- Moves
unsafe { core::ptr::read }+ManuallyDropownership-transfer logic forStdio::Blobinto a shared helper — a mistake here would double-drop or leak a Blob across every stdin-buffered spawn. - Restructures cross-platform
cfg-gated match arms in subprocess stdio setup, where a mis-merged arm on the non-compiled platform would go unnoticed until Windows CI. - Introduces a ~140-line declarative macro that generates
unsafecode (OutputTask::on_io_writer_chunk) at four expansion sites. The macro relies on unhygienic identifiers (State,Builtin,State::Exec,State::WaitingWriteErr) resolving in each caller's module. - Carries one documented behavior change: mkdir's
on_io_writer_chunkno longer panics onState::Done(it now falls through tonext()→Builtin::done(0)). The description arguesDoneis unreachable there; I agree, but it is still a change a maintainer should sign off on.
I traced each macro expansion against the deleted hand-written impl and confirmed they match (modulo the mkdir relaxation above). I also traced every arm of the collapsed Writable::init/Readable::init against both old platform blocks and confirmed identical outcomes, including the newly-added Stdio::SocketFd arm. The PathBuiltin<T> unification preserves dirname's exact usage string via Kind::Dirname.usage_string() (verified against Builtin.rs:184).
Other factors
- Part of a stacked series a maintainer explicitly requested; that maintainer is the natural reviewer for whether the split boundaries and the macro design are what they had in mind.
- No new tests, justified as behavior-preserving; existing coverage (bunshell.test.ts, shell/commands/*, spawn-streaming-stdin) was run locally per the description.
- The macro is a new cross-cutting abstraction — per the repo's own review guidelines ("new cross-cutting abstractions need maintainer agreement"), that alone warrants a human look before merge.
2f5dd36 to
9ae3ff5
Compare
|
Updated 5:05 AM PT - Aug 11th, 2026
❌ @alii, your commit a573a6c has some failures in 🧪 To try this PR locally: bunx bun-pr 37361That installs a local version of the PR into your bun-37361 --bun |
b5b9aaa to
23cbfb4
Compare
What this does
Two dedups. (1)
shell/subproc.rshad its own copy of the Blob/ArrayBuffer stdin buffering setup fromsubprocess/Writable.rs; the latter now exposesbuffered_stdin_writerand the shell calls it.Readable::initin subproc also collapses its windows/non-windows duplicate match arms into one match with per-armcfgblocks. (2) Six shell builtins (basename,cp,dirname,ls,mkdir,touch) each hand-wrote the sameOutputTaskVTableimpl pluson_io_writer_chunk; these are now generated byimpl_output_task_vtable!ininterpreter.rs, parameterized on where the builtin keeps its output queue.Split 4 of 8 from #32023, which alii asked to be broken up. Pure code motion and deletion; no intended behavior change. Stacked on
claude/split/install-cli(merge order: foundations → install-cli → these, in any order among themselves).Notes from rebasing against main
Main added
Stdio::SocketFd(#32363); the arm is carried into both the unifiedReadable::initmatch and theWritable::initmatch.mkdirwas the only builtin whoseon_io_writer_chunkpanicked explicitly onIdle/Done; the macro emits theif let Exec … else Noneshape the other five already used.Idlestill panics insidenext(), andDoneis unreachable there because chunks are only enqueued while inExec.Verification
cargo check), and the union of all eight splits is byte-identical to Deduplicate jsc bindings, runtime api, test matchers, and shell builtins #32023's headf29ce8fe4, which CI ran at 285/286 green (the one red was the fleet-widenapi.test.tsGC-timing flake on windows x64-baseline).