488 lines
28 KiB
Markdown
488 lines
28 KiB
Markdown
# parallel-files
|
||
|
||
## Goal
|
||
|
||
Make `lucisv` format a whole RTL tree on all cores instead of one, and stop
|
||
walking into directories the repository already declares generated. Two
|
||
`TODO.md` §3 items in one change, because they touch the same loop:
|
||
formatting is a pure function of `(source, config)`, so the per-file loop in
|
||
`crates/lucisv/src/main.rs` parallelises with `rayon::par_iter` once panic
|
||
containment and output ordering are reworked for concurrency; and
|
||
`.gitignore` support is the other half of the file-discovery item whose
|
||
`--exclude` half already shipped with cli-polish. The user-visible contract
|
||
does not change: same stdout/stderr split, same exit codes, same per-file
|
||
error messages, and — critically — the same *byte-identical* output for the
|
||
same invocation, regardless of thread count.
|
||
|
||
## Assumptions
|
||
|
||
- **Formatting one file has no cross-file state.** `format_source` reads a
|
||
`&str` and a `Config` and returns a `String`; config discovery happens in
|
||
full before any file is formatted (`gather`), and each file's write targets
|
||
only itself. Nothing is shared between jobs but immutable data.
|
||
- **Determinism comes from ordering the *reporting*, not the work.** Files are
|
||
formatted in whatever order rayon's work-stealing picks. Every per-file
|
||
outcome (stdout text, error line, counter bucket) is captured into a value
|
||
and rendered afterwards in input order. Two runs of the same invocation
|
||
therefore produce byte-identical stdout and stderr.
|
||
- **Output is buffered until the run ends.** The price of ordered reporting is
|
||
that `--diff` / `--stdout` text is held in memory until every file is done,
|
||
rather than streaming. For the sizes lucisv targets (a large RTL tree is tens
|
||
of MiB of source) this is acceptable; it is the reason `--stdout` over a
|
||
huge tree is no longer incremental.
|
||
- **8 MiB of worker stack is enough.** Taken from
|
||
`docs/features/recursion-limit/README.md`, which measured the worst-case
|
||
full-pipeline peak at ~3.9 MiB in a debug build and ~0.5 MiB in release.
|
||
The pool is built with exactly that number; rayon's own default is 2 MiB,
|
||
which would silently reintroduce the stack-overflow crash that feature
|
||
fixed.
|
||
- **The `.gitignore` support is a documented subset, not git.** It is the
|
||
`--exclude` matcher plus anchoring, directory-only and negation. See
|
||
"gitignore subset" below for exactly what is and is not honoured. It is
|
||
not consulted for paths named directly on the command line, and it does
|
||
not know whether the tree is a git repository at all.
|
||
- **`.gitignore` files above the walk root are not read.** Only files at or
|
||
below a directory named on the command line participate.
|
||
- **stdin mode stays serial.** One buffer, one thread; nothing to parallelise.
|
||
|
||
## Behavior
|
||
|
||
### `--threads <N>`
|
||
|
||
- `--threads 0` or the flag absent: rayon's default, one worker per logical
|
||
CPU.
|
||
- `--threads 1`: a single worker. Useful for CI reproducibility, for
|
||
profiling, and for bisecting a suspected concurrency bug.
|
||
- Any `N`: that many workers. The value only changes *speed*: the bytes on
|
||
stdout and stderr and the exit code are identical for every `N`.
|
||
- Ignored in stdin mode.
|
||
|
||
### `.gitignore`
|
||
|
||
Honoured by default while walking directories; disabled with
|
||
`--no-gitignore`. Each directory the walk enters is checked for a
|
||
`.gitignore`, and its rules apply to that directory's subtree. Rules from a
|
||
deeper `.gitignore` are considered after (and so override) shallower ones,
|
||
and within one file the last matching line wins — git's own precedence.
|
||
|
||
Supported syntax:
|
||
|
||
| Form | Meaning |
|
||
|---|---|
|
||
| `# comment`, blank line | skipped |
|
||
| `build` | a file *or* directory named `build`, at any depth below this `.gitignore` |
|
||
| `*_gen.sv` | `*` matches any run of characters inside one path component; never crosses `/` |
|
||
| `/build`, `gen/rtl` | a `/` at the start or in the middle anchors the pattern to this `.gitignore`'s own directory |
|
||
| `build/` | trailing `/`: matches directories only |
|
||
| `!keep.sv` | negation: re-includes a path an earlier rule ignored |
|
||
|
||
Not supported (deliberately, and silently — these forms are matched
|
||
literally or as plain `*`, they are not errors):
|
||
|
||
- `**` has no special meaning; it is two `*`s inside one component, so
|
||
`a/**/z.sv` matches only `a/<one component>/z.sv`.
|
||
- `?` and character classes `[a-z]` are literal characters.
|
||
- `\` escapes (so a pattern cannot contain a literal `!`, `#` or trailing
|
||
space).
|
||
- The global ignore file (`core.excludesFile`), `.git/info/exclude`, and
|
||
`$GIT_DIR/info/exclude`.
|
||
- Git's "already-tracked files are not ignored" rule: lucisv has no index, so
|
||
a tracked file matching an ignore rule *is* skipped.
|
||
- Re-including a path inside an ignored directory. An ignored directory is
|
||
never descended into, so a `!` rule underneath it cannot bring anything
|
||
back. (Git behaves the same way, for the same reason.)
|
||
|
||
A path named directly on the command line is never ignored, exactly as with
|
||
`--exclude`.
|
||
|
||
## Handshakes
|
||
|
||
- **Consumes `docs/features/recursion-limit/README.md`'s request:** that
|
||
README asks whoever lands parallelism to build the rayon pool with
|
||
`stack_size(8 * 1024 * 1024)` or larger, because a 2 MiB worker cannot
|
||
reach `MAX_NESTING_DEPTH` in a debug build (~3.9 MiB measured). Done in
|
||
`main.rs::build_pool`, with a test (`deep_file_formats_under_the_pool`)
|
||
that fails if the stack size is ever removed.
|
||
- **Discharges `docs/features/cli-polish/README.md`'s handshake:** that
|
||
feature's `catch_panic` swapped the process-global panic hook with
|
||
`take_hook`/`set_hook` around every call, and flagged it as sound only
|
||
while single-threaded. It is replaced by a single hook installed at
|
||
startup, before the pool exists, that consults a thread-local flag; the
|
||
flag is set by `catch_panic` on the thread that is about to run contained
|
||
work. No hook is ever swapped again, so nothing races. **Anyone editing
|
||
`catch_panic` must keep it that way.**
|
||
- **Consumes `vlog_formatter::{format_source, Config}`** unchanged. Both are
|
||
`Send`/`Sync`-clean (`Config` is two `usize`s; `format_source` takes
|
||
`&str`). Nothing in `vlog_parser` / `vlog_formatter` was touched.
|
||
- **Promises to TODO.md §3's content-hash cache item:** the per-file unit of
|
||
work is `process_file(&Path, &Config, &Options) -> Outcome` in `main.rs`,
|
||
a pure-ish function whose only side effect is writing its own file. A cache
|
||
lookup belongs at the top of it; the `Outcome` enum is where a "cached,
|
||
unchanged" bucket would go.
|
||
- **Promises to CI users:** the exit-code contract frozen by cli-polish is
|
||
unchanged, and `--threads` does not affect it.
|
||
|
||
## Status / TODO
|
||
|
||
- [x] `rayon` as the workspace's first third-party dependency, pinned
|
||
exactly, justified below.
|
||
- [x] Global pool built once at startup with an 8 MiB worker stack.
|
||
- [x] One panic hook installed at startup; `catch_panic` uses a thread-local
|
||
flag instead of swapping hooks.
|
||
- [x] Per-file loop parallelised; outcomes reported in input order.
|
||
- [x] `--threads N`, documented in `--help` and `README.md`.
|
||
- [x] `.gitignore` support in `walk.rs` with `--no-gitignore`.
|
||
- [x] Tests: parallel-vs-`--threads 1` byte equality, contained panic under
|
||
parallelism, deep-nesting file under the pool, `--diff` ordering,
|
||
gitignore unit + CLI tests, per-file config under parallelism.
|
||
- [x] `TODO.md` §3 parallel + `.gitignore` boxes.
|
||
- [x] `cargo fmt`, `cargo clippy --all-targets`, `cargo test --workspace`.
|
||
|
||
## Dependency justification: `rayon = "=1.12.0"`
|
||
|
||
CLAUDE.md requires a written justification for every dependency; `TODO.md` §3
|
||
pre-sanctions this one by name. It is the workspace's first third-party
|
||
dependency, and `lucisv`'s only one.
|
||
|
||
**Why not hand-rolled threads.** The obvious alternative is *N* `std::thread`s
|
||
each draining a shared `Mutex<vec::IntoIter>`, about 30 lines. Three things
|
||
make that the worse choice here:
|
||
|
||
1. **Work stealing.** lucisv's per-file cost varies by two orders of magnitude
|
||
(a 20-line header vs. a 10 000-line generated netlist). A static chunking
|
||
leaves cores idle behind one slow file; a shared-queue design fixes that
|
||
but then contends on the mutex for short files. rayon's per-worker deques
|
||
with stealing get both, and this is the entire point of the feature.
|
||
2. **Panic propagation.** A panic on a hand-rolled worker either poisons the
|
||
shared mutex or is silently swallowed by a detached `JoinHandle`. rayon
|
||
propagates a worker panic to the thread that called `par_iter` — which
|
||
matters because lucisv's own containment (`catch_panic`) is the *inner*
|
||
layer, and anything that escapes it must still surface as a crash rather
|
||
than as a quietly missing file.
|
||
3. **Maintenance.** Thread count, stack size, worker naming, and clean
|
||
shutdown are all one builder call. The content-hash cache in TODO.md §3
|
||
and any future `par_bridge` over a streaming walk get the same machinery
|
||
for free.
|
||
|
||
**Cost.** Five transitive crates (`rayon-core`, `crossbeam-deque`,
|
||
`crossbeam-epoch`, `crossbeam-utils`, `either`), all from the same
|
||
well-maintained ecosystem, no build scripts, no `unsafe` in lucisv itself, and
|
||
~9 s of cold release compile time. The version is pinned with `=` rather than
|
||
a caret: a work-stealing scheduler is exactly the kind of dependency whose
|
||
minor releases can change thread behavior, and lucisv's determinism claim is
|
||
worth an explicit bump.
|
||
|
||
## Work log
|
||
|
||
### 2026-08-19 — dev agent
|
||
|
||
- Read CLAUDE.md, `TODO.md` §3, `docs/features/cli-polish/README.md`
|
||
(the panic-hook handshake), `docs/features/recursion-limit/README.md`
|
||
(Handshakes: the 8 MiB request) and all of `crates/lucisv/src` before
|
||
writing anything.
|
||
- **Blocked on the workspace for most of the run.** Another agent was
|
||
mid-flight creating `crates/vlog_semantic`; its `Cargo.toml` was in the
|
||
`[workspace] members` list before its `src/lib.rs` existed, so
|
||
`cargo build` failed to load the workspace manifest. Iterated in a
|
||
scratchpad copy of the workspace (that member removed) and re-ran
|
||
everything against the real tree at the end. My edit to the root
|
||
`Cargo.toml` is additive only (`[workspace.dependencies]`); the
|
||
`members` line was left exactly as the other agent wrote it.
|
||
|
||
**Pool and stacks.** `build_pool` (`main.rs`) calls
|
||
`ThreadPoolBuilder::new().num_threads(opts.thread_count()).stack_size(8 MiB)
|
||
.build_global()` once, right after `gather` and before any file is touched.
|
||
`--threads 0`/absent passes 0, which is rayon's "one per logical CPU".
|
||
|
||
The recursion-limit handshake asked for ≥ 8 MiB because a debug build needs
|
||
~3.9 MiB to reach `MAX_NESTING_DEPTH`. That is honoured, and pinned by a
|
||
test: `a_deeply_nested_file_formats_on_a_worker_thread` formats a 28-level
|
||
`if … begin` nest (a nested `if … begin` costs two depth levels, so 28 sits
|
||
just under the limit of 64). **Verified load-bearing**: with `WORKER_STACK`
|
||
temporarily set back to rayon's 2 MiB default in the scratchpad copy, that
|
||
test kills the process outright (no exit code at all — a stack overflow, not
|
||
a panic), exactly the failure mode recursion-limit was built to remove.
|
||
|
||
**Correction to the brief, worth recording.** The task assumed rayon's
|
||
`par_iter` also runs work on the calling thread, so the main thread's stack
|
||
would matter too. That is not how rayon 1.12 behaves when `par_iter` is
|
||
called from *outside* the pool: `Registry::in_worker` takes the cold path,
|
||
injects the job, and **blocks** the caller. A probe binary (scratchpad,
|
||
4 workers, 2000 jobs) saw work on exactly the four pool threads and never on
|
||
`"main"`, and `rayon::current_thread_index()` on the main thread is `None`.
|
||
The 2 MiB experiment above independently confirms it: if the main thread
|
||
formatted anything, the deep file would sometimes have landed on its 8 MiB
|
||
stack and the test would be flaky rather than deterministically fatal. So
|
||
**every** file is formatted on a pool worker with the configured stack, and
|
||
the main thread's own stack is irrelevant to this feature. That is the
|
||
stronger guarantee, so nothing needed to change — only the reasoning.
|
||
|
||
**Determinism.** The parallel pass produces no output at all. Each job
|
||
returns an `Outcome` (`Unchanged` / `Printed` / `Changed(text)` /
|
||
`Failed(message)`) carrying the exact bytes it wants printed;
|
||
`jobs.par_iter().map(process_file).collect::<Vec<_>>()` is an *indexed*
|
||
parallel iterator, so the collect restores input order; `run_files` then
|
||
walks that vector serially, printing and counting. Diff hunks and error
|
||
lines therefore cannot interleave, and the summary counters are derived
|
||
from the ordered vector rather than from shared counters. Verified at
|
||
corpus scale: `lucisv --diff` over the 860-file corpus produces 2 424 208
|
||
bytes of stdout and 66 019 bytes of stderr that are **byte-identical**
|
||
across `--threads 1`, `2`, `8`, the default, and a repeat run.
|
||
|
||
The one real cost is that stdout is now buffered to the end of the run
|
||
instead of streaming; recorded under Assumptions.
|
||
|
||
**Panic hook.** cli-polish's `catch_panic` took and re-set the process-global
|
||
hook around every call and flagged the race. Replaced by:
|
||
`install_panic_hook()` (a `std::sync::Once`, called from `main` before the
|
||
pool is built) installs one hook that consults a `thread_local!`
|
||
`CONTAINED: Cell<bool>`; `catch_panic` sets that flag on its own thread,
|
||
runs `catch_unwind`, clears it. No hook is ever swapped again, so there is
|
||
nothing to race on, and a panic *outside* `catch_panic` still gets the real
|
||
default hook and its backtrace — which the old blanket silencing would have
|
||
eaten if it were ever left installed. Verified both halves in the scratchpad:
|
||
|
||
- Sabotaged `format_source` (panic on a `SABOTAGE_<id>` marker), 44-file
|
||
tree, 4 panicking files. Parallel run: all four reported as
|
||
`error: …/boomNN.sv: panicked while formatting: sabotaged formatter: NN`
|
||
in input order with their own distinct payloads, `40 files reformatted,
|
||
4 files failed to format`, exit 2, the four files byte-identical
|
||
afterwards, zero `thread '…' panicked` noise. stderr **byte-identical**
|
||
to the same tree under `--threads 1`.
|
||
- A deliberate `panic!` in the driver *outside* `catch_panic` still prints
|
||
the full `thread 'main' panicked at … note: run with RUST_BACKTRACE=1`.
|
||
|
||
**`.gitignore`.** ~80 lines in `walk.rs`, no new dependency. The walk became
|
||
a small `Walk` struct because it now carries three things down the
|
||
recursion: the components of the current directory relative to the walk
|
||
root, the stack of `.gitignore` rule sets seen so far, and the base depth of
|
||
each of those sets. Rules reuse the existing `glob_component` matcher
|
||
unchanged, so `--exclude` and `.gitignore` glob identically.
|
||
|
||
Anchoring follows git's actual rule rather than a leading-`/`-only rule,
|
||
because git's rule *is* the `--exclude` split generalised: a `/` at the
|
||
start **or in the middle** anchors to the `.gitignore`'s own directory; no
|
||
`/` at all means "match this name at any depth below". Precedence is
|
||
implemented by concatenating the stack root-to-leaf and letting the last
|
||
matching rule win, which gives both "a deeper file overrides a shallower
|
||
one" and "the last line in a file wins" from one loop.
|
||
|
||
**Differential-tested against real git**, not just against my own
|
||
expectations: a scratchpad `git init` tree with a root `.gitignore`
|
||
(`build/`, `*_gen.sv`, `/anchored.sv`, `gen/rtl`, `sub/*.sv`, a comment) and
|
||
a nested `sub/.gitignore` (`!keep_gen.sv`, `drop.sv`) over 13 `.sv` files.
|
||
`git check-ignore` and lucisv agree on **every** file.
|
||
|
||
On the real corpus (28 `.gitignore` files across ibex, OpenTitan, PULP
|
||
common_cells and picorv32) the honoured rules change nothing: the same 860
|
||
files are visited with and without `--no-gitignore`, because those files
|
||
name build artifacts, not RTL. That is the right outcome and a useful
|
||
negative result — the subset does not over-ignore real repositories.
|
||
|
||
**Speedup** (informational; release build, 10 logical cores, warm cache,
|
||
best of 3, `--check` over the 860-file corpus):
|
||
|
||
| `--threads` | wall | speedup |
|
||
|---|---|---|
|
||
| 1 | 0.389 s | 1.00× |
|
||
| 2 | 0.232 s | 1.68× |
|
||
| 4 | 0.150 s | 2.60× |
|
||
| 8 | 0.108 s | 3.60× |
|
||
| default (10) | 0.107 s | 3.62× |
|
||
|
||
Below linear, and honestly so: 359 of the 860 corpus files fail to parse
|
||
early (unsupported syntax, tracked in corpus-check), so a large fraction of
|
||
the run is the serial directory walk plus 359 cheap early exits. The
|
||
parallel fraction is the 501 files that actually format.
|
||
|
||
**Not done, deliberately.** `gather` (the walk plus config discovery) stays
|
||
serial: it is I/O-bound, it owns a `&mut` discovery cache, and at corpus
|
||
scale it is a small share of a run that is now 0.1 s. Parallelising it is
|
||
the natural next step if profiling ever says so.
|
||
|
||
## QA log
|
||
|
||
### 2026-08-19 — QA agent
|
||
|
||
Read CLAUDE.md, this README, the diff (`main.rs`/`args.rs`/`walk.rs`/`cli.rs`,
|
||
root `Cargo.toml` + `Cargo.lock`, README.md, TODO.md §3), and the two
|
||
handshake documents it cites (`docs/features/recursion-limit/README.md`,
|
||
`docs/features/cli-polish/README.md`) — both handshakes are quoted
|
||
accurately; nothing fabricated. Did not touch `crates/vlog_semantic`
|
||
(another agent's work, now complete and compiling). No commits made.
|
||
|
||
**Verdict: pass on all seven claims, no blocking findings.**
|
||
|
||
1. **Pool.** `build_pool` (`main.rs:182`) is one `ThreadPoolBuilder` call,
|
||
`stack_size(8 MiB)`, called once from `run_files` before any file is
|
||
touched. Independently reproduced the "no work on the calling thread"
|
||
claim with a standalone probe (rayon 1.12.0, 4 workers, 2000 jobs,
|
||
`scratchpad/probe/main.rs`): `rayon::current_thread_index()` on `main` is
|
||
`None`, and the set of thread names that actually ran `for_each` work
|
||
never contains `"main"` — only unnamed pool workers. **Sabotage-checked**
|
||
the 2 MiB claim myself: temporarily changed `WORKER_STACK` to
|
||
`2 * 1024 * 1024`, rebuilt, ran
|
||
`a_deeply_nested_file_formats_on_a_worker_thread` — it fails with the
|
||
child process losing its exit code entirely (`panicked at
|
||
cli.rs:81:23: exit code`), i.e. a hard crash, not a graceful error;
|
||
restored the file and confirmed `git diff crates/lucisv/src/main.rs`
|
||
byte-identical to before the experiment (`diff` of the two captured
|
||
diffs was empty). **Pass.**
|
||
2. **Hook.** Single `Once`-guarded `install_panic_hook` (`main.rs:266`);
|
||
grepped the whole file for `take_hook`/`set_hook` — both appear exactly
|
||
once, inside that function. Reproduced both halves live: (a) a
|
||
sabotaged build (magic-marker panic injected into
|
||
`vlog_formatter::format_source` in a scratchpad copy of the repo) run
|
||
against a 44-file tree with 4 panicking files reports all four by name
|
||
in input order, exit 2, zero `thread '…' panicked` noise, and is
|
||
byte-identical between `--threads 1` and the default pool, both as a
|
||
single comparison and across 20 repeated parallel runs (one stdout hash,
|
||
one stderr hash, all 20). (b) Added a `panic!()` immediately after
|
||
`install_panic_hook()` in `main()` (outside `catch_panic`) in the same
|
||
scratchpad build: it still prints the full `thread 'main' panicked at
|
||
… note: run with RUST_BACKTRACE=1`, exit 101 — the default hook is
|
||
intact for real bugs. **Pass.**
|
||
3. **Determinism.** Ran `lucisv --diff` over the full 860-file corpus (not
|
||
just ~100) at `--threads` 1/2/8/default, 3 repeats each (12 runs) plus 2
|
||
more default-thread repeats (5 total for that setting): stdout hashes to
|
||
one value across all 12, stderr to one value across all 12 —
|
||
2,424,208 bytes stdout / 66,019 bytes stderr, matching the work log's
|
||
own numbers exactly once I used the same absolute-path invocation (my
|
||
first pass used a relative `corpus` argument, which shortens every diff
|
||
header and shrinks the totals — a harness artifact on my end, not a
|
||
product issue, resolved and reconciled). Also re-ran the 20×
|
||
panicking-scenario race hunt from claim 2 as the nondeterminism probe
|
||
for this claim too. Zero variance anywhere. **Pass.**
|
||
4. **`.gitignore`.** Built my own probe tree under a real `git init`
|
||
(`scratchpad/gitprobe/`) covering all four requested tricky cases plus
|
||
extras: a `!secret.sv` inside `build/` (ignored by the parent `build/`
|
||
rule — git prunes the directory before reading its `.gitignore`, and so
|
||
does lucisv); `/x.sv` anchored inside a *nested* `anchor_test/.gitignore`
|
||
(correctly scoped to that directory only, not its `sub2/`); `!keepdir/`
|
||
negating a directory while `*.sv` still catches the file inside it
|
||
(git: ignored; lucisv: ignored — negating the directory doesn't negate the
|
||
per-file pattern); and the `build/` vs. bare `build` directory-only
|
||
distinction (already covered by the existing unit test
|
||
`a_trailing_slash_matches_directories_only`, confirmed still green).
|
||
Ran `git check-ignore -q` against every `.sv` file in the tree, compared
|
||
to which files lucisv actually visited (16 files, 6 not ignored) —
|
||
**exact agreement, 0 discrepancies.** Corpus visited-set check: `--diff`
|
||
with and without `--no-gitignore` over the real 860-file corpus (28
|
||
`.gitignore` files) produced byte-identical stdout and stderr, matching
|
||
the "negative result" claim. `--threads 1000` (pool larger than the
|
||
3-file tree it ran on, and separately against a single file) and
|
||
`--threads 1000` against the full corpus all completed quickly and
|
||
correctly (no hang, no resource exhaustion). A directory whose
|
||
`.gitignore` contains only `*` yields `error: no Verilog files found
|
||
(extensions: v, sv, vh, svh)`, exit 2 — sane, and `--no-gitignore`
|
||
recovers the files as expected. `.gitignore` + `--exclude` together:
|
||
both apply simultaneously (verified with one pattern from each). **Pass.**
|
||
5. **Deps.** `cargo tree -p lucisv` shows exactly `rayon` → `either`,
|
||
`rayon-core` → `crossbeam-deque` → `crossbeam-epoch`/`crossbeam-utils`
|
||
(5 transitive crates as documented); `cargo metadata` confirms none of
|
||
the six packages (rayon included) declare a build script. `rayon` is
|
||
pinned `=1.12.0` in both `Cargo.toml` and `Cargo.lock`. Justification
|
||
section present and specific. **Pass.**
|
||
6. **Tools.** `cargo test -p lucisv`: 50 unit + 30 CLI, all green (0.01s +
|
||
0.14–0.21s). `cargo clippy -p lucisv --all-targets` and
|
||
`cargo fmt -p lucisv -- --check`: both silent/clean. Workspace-wide (now
|
||
that `vlog_semantic` compiles): `cargo build --workspace`,
|
||
`cargo clippy --workspace --all-targets` clean, `cargo test --workspace`
|
||
green across all crates. Note: workspace-wide `cargo fmt --check` is
|
||
*not* clean, but all 8 offending diffs are in
|
||
`crates/vlog_semantic/tests/qa_attack.rs` — outside this feature's scope
|
||
and outside the directive not to touch that crate; not a
|
||
parallel-files finding, flagging for whoever owns that crate.
|
||
Panic-under-parallelism scenario: see claim 2, reproduced with the exact
|
||
shape asked for (4 of 44 files panicking) and race-hunted 20× with zero
|
||
deviation. **Pass** (with the fmt note above filed separately, not
|
||
against this feature).
|
||
7. **Exit codes / stdin / per-file config.** Exit-code contract (0/1/2)
|
||
unchanged, exercised throughout the CLI suite and my own ad hoc runs.
|
||
`run_stdin` never calls `build_pool` — read from the source, confirmed:
|
||
stdin mode never touches rayon at all, not just "runs on one thread of
|
||
it". Per-file config under parallelism: exercised by
|
||
`every_file_keeps_its_own_config_when_formatted_in_parallel` (12 files ×
|
||
3 config layers) and `each_file_gets_the_config_of_its_own_directory`,
|
||
both green; did not find it necessary to add a third manual
|
||
two-dirs-two-configs run since these already cover more directories and
|
||
more files than that would. **Pass.**
|
||
|
||
**Race-hunting, beyond re-verifying the claims:**
|
||
- Panicking scenario (4/44) run 20× in parallel mode: one stdout hash, one
|
||
stderr hash across all 20, both identical to the `--threads 1` baseline.
|
||
- Corpus `--diff` run 5× at default threads plus 3× each at 1/2/8: 12 runs,
|
||
one hash each for stdout/stderr.
|
||
- `--threads 1000`: pool larger than the file count, both on a 3-file tree
|
||
and a single file, and separately against the full 860-file corpus
|
||
(0.2s wall, no anomalies).
|
||
- `.gitignore` that ignores everything: sane error, not a crash or silent
|
||
success.
|
||
- `.gitignore` + `--exclude` together: both filters active simultaneously.
|
||
- Deep-nesting file + panicking file + 10 good files in one parallel run
|
||
(`scratchpad/combo_tree`): all three outcome kinds correct at once — the
|
||
10 good files "would reformat" in input order, the deep file parses and
|
||
"would reformat"s normally (proving the pool's stack size, not luck, is
|
||
what saves it), the sabotaged file reports as a contained panic; exit 2
|
||
(error outranks would-reformat), no interleaving.
|
||
|
||
**One methodology note, not a product finding:** immediately after the
|
||
`WORKER_STACK` sabotage-and-restore in item 1, `cargo build -p lucisv`
|
||
reported "Finished in 0.01s" and silently kept serving the *stale* 2 MiB
|
||
binary — restoring the file with `mv` from a `sed -i.bak` backup left its
|
||
mtime older than the already-rebuilt (sabotaged) target, so Cargo's
|
||
mtime fast-path skipped recompilation despite the content being back to
|
||
the original 8 MiB source. This briefly made `cargo test --workspace`
|
||
report `a_deeply_nested_file_formats_on_a_worker_thread` and
|
||
`deeply_nested_file_does_not_kill_the_batch` as crashing. `touch`ing
|
||
`crates/lucisv/src/main.rs` and rebuilding made both pass again immediately,
|
||
and `git diff` on the file was unaffected throughout (content never
|
||
changed). Recorded here in case anyone else sees the same thing after a
|
||
`sed -i.bak` / `mv` round-trip on this codebase — it is a Cargo caching
|
||
quirk local to that workflow, not a lucisv bug.
|
||
|
||
**Severity summary:** no BLOCKING findings (zero nondeterminism observed
|
||
across ~40 varied repeated runs), no should-fix gitignore/git
|
||
disagreements (0 of many probe files disagreed). CLAUDE.md compliance:
|
||
no `unwrap`/`expect`/`panic!` in library code paths in `main.rs`/`args.rs`/
|
||
`walk.rs` outside `#[cfg(test)]` (grepped directly); all `pub` items carry
|
||
a one-line doc comment; feature stayed inside `crates/lucisv` +
|
||
`docs/features/parallel-files` as scoped, confirmed via `git status`/`git
|
||
diff --stat` against `HEAD`. README.md and TODO.md claims read as
|
||
accurate against what I independently measured.
|
||
|
||
## Review
|
||
|
||
**2026-08-19 — lead. Verdict: accepted; commits jointly with
|
||
vlog-semantic (both touch the root manifest).**
|
||
|
||
The project's first dependency, taken the right way: pre-sanctioned in
|
||
TODO §3, exact-pinned, five transitive crates audited for build
|
||
scripts, written justification. Three things stood out:
|
||
|
||
1. **The dev corrected the brief with evidence.** My premise that
|
||
rayon runs work on the calling thread is false for 1.12 — probed,
|
||
documented, and the conclusion (every file formats on an 8 MiB
|
||
worker) is *stronger* than the guarantee I asked for. Briefs are
|
||
hypotheses; this is the correct way to falsify one. QA then
|
||
independently re-proved it, and sabotage-verified that 2 MiB
|
||
workers die exactly as the handshake predicted.
|
||
2. **Both standing handshakes discharged on schedule**: the
|
||
recursion-limit stack requirement (8 MiB workers) and cli-polish's
|
||
single-install panic hook (Once + thread_local flag; uncontained
|
||
panics still get the real hook — verified live both ways).
|
||
3. **Determinism by construction** (collect indexed outcomes, print
|
||
serially in input order) held under a real race hunt: one stdout
|
||
hash and one stderr hash across 14 corpus-scale runs at four
|
||
thread counts. The buffered-stdout trade-off is documented.
|
||
|
||
The gitignore subset earning a 16/16 differential agreement with real
|
||
`git check-ignore` — including negation-inside-ignored-dir, the rule
|
||
most hand-rolled implementations get wrong — is the acceptance
|
||
evidence that matters. 3.6× wall-clock on the corpus is honest about
|
||
its sub-linearity (early parse failures).
|
||
|
||
QA's methodology note (Cargo mtime fingerprinting silently serving a
|
||
stale sabotaged build) is preserved in the QA log — future sabotage
|
||
checks should `touch` after restore.
|