# one-parse ## Goal TODO §4's "one parse, two tools", delivered on the linter side: parse a file once and lint from those products, instead of every consumer re-lexing and re-parsing text somebody already parsed. `LintContext` gains a constructor that accepts pre-built parse products; `lucisv check` builds the products once per file; and `lucisv_server` — which already holds a fully analyzed `Document` per buffer — lints from that document's own tokens and tree rather than paying two extra lexes and an extra tolerant parse per keystroke. Behavior is the hard gate: every finding, position, fix, diagnostic and exit code is byte-identical to before; only duplicated work is removed. ## Assumptions - **Behavior identity over speed.** Anywhere "share the parse" and "identical output" could conflict, identity wins. Concretely: on a file that fails to *lex*, the shared-parse paths fall back to `parse_source_tolerant` (which re-lexes the rare broken file once more) rather than hand-rolling the lex-error tree, so the tree and diagnostics are the old code path's own. - **The token stream and the tree are two products, and the parser consumes its tokens.** `parse_tolerant(tokens, source)` takes `Vec` by value, so a consumer that needs both (the linter does: waivers and text rules read tokens, AST rules read the tree) clones the token vector once. One clone is cheaper than the lex it replaces, and changing `vlog_parser`'s signature is out of scope (that crate is another round's). - **`SourceFile` is not `Clone`.** This is what forces the borrowing design below: the server's `Document` owns one tree that must serve semantics, diagnostics *and* linting, so the lint context has to borrow it — `std::borrow::Cow` cannot hold a non-`Clone` type, and a per-request tree clone is exactly the duplicated work this round removes. - **Parse diagnostics are not a lint product.** No rule reads them (`LintContext::new` always discarded them), so `from_parse` does not take them and `ParsedSource` does not store them. The server, which does publish them, keeps them where they always were: on `Document`. - **The `--fix` loop's per-round re-parse is inherent.** Each round rewrites the text, and products of the old text describe nothing. Only the *first* round of `lucisv check --fix` (and all of a plain `lucisv check`) saves work. - **Per-change recompute stays the server's model.** This round removes duplicate work *within* one change/request; it adds no caching or invalidation machinery beyond what `Document` already is (TODO §6: "per-file recompute is fine at Verilog file sizes"). ## Handshakes **Promised by `vlog_linter`** (additive; everything previously public is unchanged in behavior): - `LintContext` is now `LintContext<'a>`. Rule authors are untouched: the `Rule::check(&self, ctx: &LintContext)` signature, and every accessor (`source()`, `tokens()`, `file()`, `line_index()`, ...), read exactly as before — the lifetime elides. - `pub fn LintContext::from_parse(source: &'a str, tokens: &'a [Token], file: &'a SourceFile, line_index: &'a LineIndex, path: Option) -> LintContext<'a>` — the pre-built-products constructor linter-core's Handshakes predicted. Borrows everything big; `path` stays owned because a `PathBuf` clone per lint run is noise. **Caller contract (documented at the item): the four products must describe the same text** — tokens lexed from `source`, `file` the tolerant parse of those tokens, `line_index` built over `source`. `Document` and `ParsedSource` both satisfy it by construction. - `pub struct ParsedSource` + `ParsedSource::parse(source) -> ParsedSource` + `ParsedSource::context(&self, path) -> LintContext<'_>` — the owned bundle of products for callers with no `Document` of their own (`lucisv check`, and `run`/`LintContext::new` internally). `parse` lexes **once** and builds the tree from a clone of the token stream. - `LintContext::new(source, path)` **stays**, as the convenience wrapper the task requires: it is one line, `Backing::Owned(ParsedSource::parse(source))` through the same private assembly `from_parse` uses — a single code path derives the string-literal spans and defaults. (`new` cannot literally call `from_parse` and then own the products — that would be a self-borrow — so "single code path" is the shared assembly function, and `ParsedSource::parse` is the single place the parse recipe lives.) - Dependency list unchanged: `vlog_parser` + std. **Consumed** - `vlog_parser::parse_tolerant(tokens, source)` — newly consumed by `vlog_linter` and `lucisv_server` (both already depended on the crate; it was already `pub`). Relied on: with the same tokens it returns exactly the tree `parse_source_tolerant(source)` would (that function *is* `tokenize` + `parse_tolerant`), and on a well-formed file the tree equals `parse`'s. - `vlog_formatter::fence::protected_regions(&str)` — still called with text, still re-parses internally, **on purpose**; see the decision below. **Changed call sites** - `crates/lucisv/src/lint.rs::run_rules` — parses once via `ParsedSource` and hands the products to the context. - `crates/lucisv_server/src/state.rs::Document` — gains the `tree: SourceFile` field (it was parsed and thrown away after `analyze`), and `Document::new` lexes once instead of twice. - `crates/lucisv_server/src/lint.rs::{violations, fixable}` — the one call site server-lint's README predicted: both lint from the document's own products via `from_parse` instead of re-parsing `doc.text`. ## The server's redundant-work catalog Every place the server re-tokenized or re-parsed text it already held products for, per request, as of the start of this round: | Site | Duplicate work per request | Verdict | |---|---|---| | `lint::violations` (every didOpen/didChange/didSave publish) | 2 lexes + 1 tolerant parse of `doc.text` (via `vlog_linter::run` → `LintContext::new`) | **Eliminated** — `from_parse` over `Document`'s products | | `lint::fixable` (every codeAction request) | 2 lexes + 1 tolerant parse (via `LintContext::new`) | **Eliminated** — same | | `lint::fixable` → `fence::protected_regions(&doc.text)` | 1 lex + 1 tolerant parse inside `vlog_formatter` | **Kept** — see the protected_regions decision below | | `Document::new` (every buffer change) | the text lexed twice: `tokenize` for `doc.tokens`, then `parse_source_tolerant`'s internal `tokenize` | **Eliminated** — one lex, tree built by `parse_tolerant` over a clone of the tokens; the lex-error fallback still goes through `parse_source_tolerant` so the error tree and diagnostic are byte-identical | | `format::formatting` / `range_formatting` | `format_source`/`format_range` lex+parse strictly inside `vlog_formatter` | **Kept** — the formatter's parse is the *strict* one (a tree `Document` does not hold), and the runtime safety net (equivalence + convergence) is defined over `format_source` doing its own work; sharing would need `vlog_formatter` API changes, which is the concurrent round's crate and a different feature | | `Workspace::rebuild_index` (initialize + every didSave) | re-reads and re-parses every workspace file inside `WorkspaceIndex::build`, open unchanged buffers included | **Kept** — the documented full-scan index model (TODO §6 defers incrementality to salsa); making it incremental is invalidation machinery this round explicitly must not build | | `semanticTokens`, `hover`, `definition`, `references`, `documentSymbol`, `workspace/symbol`, `diagnostics::diagnostics` | none — all already read `doc.tokens` / `doc.semantics` / `doc.defines` / `doc.diagnostics` | already clean (verified by grep for `tokenize`/`parse` over `crates/lucisv_server/src`) | ## The protected_regions decision: left alone `fence::protected_regions` takes `&str` and re-parses internally. shared-fence-filter's Assumptions choose that signature deliberately: a products-accepting variant would let the two front ends feed different trees and get different fence answers, which is the exact drift that feature exists to end. Could this round argue both callers "always hold the same tree by construction"? Almost — the server would pass `doc.tree` and the CLI its current round's tree — but "almost" is the problem: the CLI's `--fix` loop rebuilds text every round, and a future caller passing last round's tree is precisely the bug the `&str` signature makes unwritable. The cost lands only on fix-application paths (`lucisv check --fix`, `textDocument/codeAction`), never on the per-keystroke diagnostics path. Two further reasons to leave it: it is `vlog_formatter`'s code, which belongs to the concurrent dynamic-types round this session; and the interior parse is of the *current* text by construction, which is the property being bought. **Decision: keep the double parse there, documented as the acceptable price of one fence answer.** ## Status / TODO - [x] `vlog_linter`: `LintContext<'a>`, `from_parse`, `ParsedSource`, `new` kept as the wrapper; single-lex parse recipe in one place. - [x] Rules, visitors, waivers untouched (they compile and read unchanged). - [x] `crates/lucisv/src/lint.rs`: `run_rules` parses once via `ParsedSource`. - [x] `crates/lucisv_server`: `Document.tree` kept; `Document::new` single-lex; `lint::violations`/`fixable` lint from the document's products. - [x] Server catalog above; semanticTokens/hover verified already clean. - [x] protected_regions decision written (left alone). - [x] Tests: products-in == source-in property over rule-test inputs; lex-error and broken-file paths; existing CLI + server suites green **unmodified**. - [x] Byte-identity: corpus `lucisv check` (text + JSON) vs a HEAD worktree binary; server diagnostics vs a HEAD worktree binary over a real stdio session. - [x] Timing before/after. - [x] TODO §4 checkbox + linter-core / server-lint annotation lines. - [ ] **Not done, deliberately:** `lucisv format` sharing the parse. The formatter requires a *strict* parse and runs its safety net over its own products; wiring `lucisv check --fix --format` workflows is a future feature and is not blocked by anything here. - [ ] **Not done, deliberately:** any caching/invalidation in the server beyond `Document`'s per-change recompute. ## Work log ### 2026-08-19 — dev - Read `CLAUDE.md`, TODO §4, and the linter-core / server-lint / shared-fence-filter READMEs in full (QA logs and Reviews included) before writing anything, then the code: `vlog_linter`'s `context.rs`/`lib.rs`, `crates/lucisv/src/lint.rs`, and every file in `crates/lucisv_server/src`. - **The design was forced by one fact: `SourceFile` is not `Clone`.** The server's `Document` owns one tree that must serve semantics, published diagnostics *and* linting, so the products constructor has to borrow — and the task's requirement that `LintContext::new(source, path)` survive as a self-contained convenience means the context must also be able to own. Hence the private `Backing` enum (`Owned(ParsedSource)` / `Borrowed { .. }`) rather than `Cow` fields (`Cow` needs `Clone`) or a lifetime-only struct (which would have killed `new`). Every accessor signature is unchanged, so the twelve rule files, `visit.rs` and `waiver.rs` compile byte-for-byte untouched — verified by `git diff` (only `context.rs`, `lib.rs`'s one `pub use` line, and the test helper changed in the crate). - **`new` cannot literally call `from_parse`** — that would borrow a local and return it — so the single code path is `assemble` (one place derives string-literal spans and defaults) plus `ParsedSource::parse` (one place holds the parse recipe). Recorded here so nobody "fixes" it into a self-borrow later. - **The single-lex recipe and its one deliberate exception.** Today's `LintContext::new` lexed the text twice (its own `tokenize`, then `parse_source_tolerant`'s internal one). `ParsedSource::parse` and `Document::new` now lex once and build the tree via `parse_tolerant(tokens.clone(), source)` — identical tree by definition, since `parse_source_tolerant` *is* `tokenize` + `parse_tolerant`. A text that fails to lex keeps the old `parse_source_tolerant` path (a second lex of a rare broken file) because `parser::error_file` is `pub(crate)` and hand-rolling the all-error tree here is how two subtly different trees are born. The recipe exists in exactly two places because they need different outputs: `ParsedSource` discards diagnostics (no rule reads them), `Document` publishes them. - Server: `Document` gained the `tree: SourceFile` field it was already paying to build (it parsed, analyzed, and threw the tree away); `lint::violations` and `lint::fixable` now share a four-line `context(doc)` helper over `from_parse`. `vlog_linter::run` is no longer imported there. The catalog above was compiled by grepping `tokenize|parse` over `crates/lucisv_server/src` and reading each hit. - **Tests.** The products-in == source-in property was put where it covers the most ground: inside the rule-test harness's `assert_lint_with`, so all 55 inline-marker cases (every rule × fires/quiet/waived/unused-waiver, plus the fence and class-body cases) assert that `ParsedSource` products produce a `Debug`-identical violation list — rule, message, span and fix. Two new unit tests in `context.rs`: borrowed-vs-owned accessor equality, and the lex-error fallback producing the exact old error tree. Existing CLI and server suites pass **unmodified** (`git diff` on `crates/lucisv/tests`, `crates/lucisv_server` tests: empty). - Did not touch `vlog_parser`, `vlog_formatter`, `vlog_semantic`, `lucisv_core`, `editors/**`, or any `Cargo.toml`/`Cargo.lock` (no dependency moved; `parse_tolerant` was already `pub`). Did not run `git commit`/`git push`. - **Concurrency note.** A dynamic-types round was announced live in `vlog_parser`/`vlog_formatter` this session. `git status` stayed clean of their crates for the whole round (only this feature's files are modified), so the scratchpad-copy fallback was prepared but never needed; the HEAD worktree used for baselines doubles as the clean snapshot. Gates below are from the real tree. **Results.** - `cargo test -p vlog_linter`: 118 unit + 55 integration + 1 doctest, green (118 was 116: the two new `context.rs` tests). `cargo test -p lucisv`: green including all 69 CLI integration tests, unmodified. `cargo test -p lucisv_server`: 115 unit + 6 e2e, green, unmodified. `cargo test --workspace`: **770 passed, 0 failed**. - `cargo clippy --workspace --all-targets`: silent. `cargo fmt -p vlog_linter -p lucisv -p lucisv_server -- --check`: clean (scoped, per the concurrency rule). No `#[allow]`, no `unwrap`/`expect`/`panic!`/`unsafe` outside `#[cfg(test)]` in anything touched. - **Byte-identity, CLI** (HEAD worktree binary at `e9008b6` vs this tree, both release): - `lucisv check corpus/`: stdout, stderr and exit code (1) identical. - `lucisv check corpus/ --output-format json`: **2 418 071 bytes of JSON, byte-identical**, stderr identical, exit identical. - `check --fix` over ten crafted shapes in twin directories (tabs + trailing whitespace, fence, fence-in-broken-file, waiver, lex failure, case-missing-default, module-filename mismatch, multi-byte + tab, unclosed fence, empty file): every rewritten file byte-identical, stdout/stderr identical (paths normalized), exit 1 from both. - **Byte-identity, server**: a real stdio session (hand-framed JSON-RPC, `scratchpad/lsp_probe.py`) over three scratch files — lint-only, parse error + lint + module-filename, and error-recovery + fence + lex-error — each opened and then edited once (edits flip the filename rule, add a waiver, and heal the lex error). All **6 published diagnostic lists byte-identical** between the two binaries, canonicalized only by stripping the differing scratch-dir prefix from the URI. - **Timing, CLI** (release, median of 7, 860-file corpus): `lucisv check corpus/` **265.5 → 207.9 ms** at `--threads 1` (−22 %), **79.7 → 70.5 ms** at the default thread count (−12 %). The single-thread number is the honest one (the pool hides latency); the saving matches the arithmetic — the lint pipeline did 2 lexes + 1 parse per file and now does 1 lex + 1 token-clone + 1 parse. - **Timing, server** (informational): didChange → publishDiagnostics, median of 15 full-text changes, empty workspace root: `picorv32.v` (3049 lines) **18.0 → 11.0 ms**, `ibex_core.sv` (2026 lines) **7.6 → 3.4 ms**. Larger than the CLI's relative win because the server was paying the duplicate work twice over — `Document::new`'s double lex *and* the lint path's full re-lex-and-parse — and now pays one lex, one clone, one parse per change. ### 2026-08-19 — dev (post-interruption verification) - The session was cut by a usage limit after the results above were captured; on resume, disk state was re-verified intact (all six code files, this README, TODO §4, both annotation files — nothing lost). - Mid-resume the concurrent dynamic-types round landed in-progress edits to `vlog_parser`/`vlog_formatter`/`vlog_semantic` that briefly broke the workspace *test* build (`tests/spans.rs` vs their new `ExprKind::NamedArg` — their crate, their fix). Gates were therefore re-run with the scratchpad-copy technique: a fresh worktree at HEAD `e9008b6` with **only this round's six files** overlaid — `cargo test --workspace` **770 passed, 0 failed**, `cargo clippy --workspace --all-targets` **silent**, scoped `cargo fmt -- --check` **clean**. Identical numbers to the pre-drift merged run recorded above. - The merged tree recovered while this was running (the other agent fixed their spans test): merged `cargo test --workspace` **770 passed, 0 failed**, clippy clean, as of this writing — noted with the caveat that their round is still in motion, so the isolated-copy numbers are this feature's own evidence. - Provenance of the identity/timing evidence above: captured **before** any concurrent drift existed — at capture time `git status` showed only this round's files modified, so the "new" binaries were exactly HEAD + one-parse, vs. the HEAD-worktree baseline binaries. That evidence stands as recorded. ## QA log ### 2026-08-19 — QA **Setup / isolation.** The concurrent dynamic-types round had by now modified `vlog_parser/src/{ast,parser}.rs`, `vlog_parser/tests/spans.rs`, `vlog_formatter/src/format.rs`, `vlog_formatter/tests/verification.rs` and `vlog_semantic/src/bind.rs` in the shared tree, so every gate and every identity run below was done in an **isolated copy**: `scratchpad/qa-new` = a byte copy of the dev's HEAD worktree (`scratchpad/head-wt`, verified clean at `e9008b6`) with **exactly this round's six code files** overlaid. `diff -rq head-wt qa-new` reports those six files and nothing else. The baseline binaries are `head-wt/target/release/{lucisv,lucisv-server}`; the "new" ones were rebuilt from `qa-new`. `corpus/` was never written to — the `--fix` runs used copies. **Claim-by-claim.** 1. *Constructor design* — **PASS.** `SourceFile` is `#[derive(Debug)]` only at `e9008b6:crates/vlog_parser/src/ast.rs:125`, so `Cow` is genuinely unavailable and the `Backing` enum is forced. `git diff --name-only HEAD -- crates/vlog_linter` returns exactly `src/context.rs`, `src/lib.rs`, `tests/rules.rs` — all twelve rule files, `visit.rs`, `waiver.rs`, `registry.rs`, `naming.rs`, `violation.rs`, `rule_docs.rs` byte-untouched. `crates/vlog_linter/Cargo.toml` still lists `vlog_parser` and nothing else. Diagnostics genuinely unread by any rule: `grep -rn diagnostic crates/vlog_linter/src` hits only doc comments, the discarded binding at `context.rs:46`, and `visit.rs`'s own `#[cfg(test)]` block. `new` → `assemble` is the single path, and `parse_source_tolerant`'s Ok arm at `e9008b6:crates/vlog_parser/src/lib.rs:37` is literally `parse_tolerant(tokens, source)`, so the substitution is exact by definition, not by hope. 2. *`ParsedSource::parse` lexes once; lex errors fall back* — **PASS.** Independent probe (scratch `tests/qa_probe.rs`, deleted after the run) over four lex-failing texts — unterminated block comment, unterminated string, a bare `"`, a `/*` at EOF: tokens empty in every case, the `Debug` form of `ParsedSource::parse(src).context(None).file()` equal to `parse_source_tolerant(src).0`, and `run(src, …)` equal to `lint(&parsed.context(None), …)`. End to end the same fallback shows up in the server session below (`f1 v4 lex error` publishes `unterminated block comment` + `no-tabs`, identical on both binaries). 3. *Server catalog complete* — **PASS.** `grep -rn 'tokenize|parse_source_tolerant|parse_tolerant|format_source|format_range| rebuild_index' crates/lucisv_server/src` returns exactly the sites the catalog names: `state.rs:56-61` (`Document::new`, one lex), `format.rs:57,87` (kept, strict parse), `state.rs:123/137` + `server.rs:251` (`rebuild_index`, kept), `lint.rs:54` (`protected_regions`, kept). The only other `vlog_linter::run` left in the crate is at `code_action.rs:157`, inside `#[cfg(test)]` — not a per-request parse. **No uncataloged redundant parse survives.** `doc.tree` is read (not dead): `lint.rs`'s `context(doc)` and `state.rs:64`'s `analyze(&tree, …)`. 4. *`protected_regions` left alone* — **PASS.** `git diff --name-only -- crates/vlog_formatter/src/fence.rs` is empty; the file is untouched by this round (and by the concurrent one). 5. *Behavior identity* — **PASS, re-run from scratch, not taken on trust.** - `lucisv check corpus/` (820 files): stdout **692 198 bytes identical**, stderr identical, exit 1 both. - `--output-format json`: **2 418 071 bytes identical** (matches the dev's figure exactly), stderr identical, exit 1 both. - Flag matrix on a 13-file crafted directory, stdout+stderr+exit compared each time: `--select`, `--ignore`, `--select a,b --output-format json`, `--indent 4`, `--threads 1`, an unknown rule name (exit 2 both), a missing file (exit 2 both), `--unsafe-fixes`, a single file, an empty file, `check - --stdin-filename`, and `--select case-missing-default,module-filename` over the whole corpus. **12/12 identical.** - `check --fix` over 13 crafted shapes (multi-round tab+trailing, a real `// verilog_format: off/on` fence, the `// lucisv: off/on` alias, an unclosed fence, `// lucisv: waive`, unused + malformed + unknown-rule waivers, a lex-error file, a filename mismatch, CRLF, multi-byte + emoji + tab, an empty file, a class body, a parse-error file): every rewritten file byte-identical, stdout (path-normalized) and stderr identical, exit 1 both. Fenced regions provably untouched — the tab and the trailing run inside the fence survive byte-for-byte while the violations are still *reported*. - **`check --fix` over a full copy of `corpus/` (820 files, 48 rewritten): every file byte-identical old-vs-new**, stdout (309 lines) and stderr identical, exit 1 both. This is a much wider `--fix` net than the ten shapes in the work log and it holds. - Server: an independent hand-written stdio driver (`scratchpad/qa_lsp.py`, not the dev's) over 3 scratch files and **13 publishes** — parseable → parse-error → clean → lex-error → healed → empty → back; a filename-rule flip; a fence + error-recovery file losing its fence then being fixed. All 13 diagnostic lists **byte-identical** between the two binaries after stripping the scratch-dir prefix. - Server, `fixable`/codeAction (the other `from_parse` call site, which the work log did not exercise): `textDocument/codeAction` over the whole buffer for 6 shapes (plain, fenced, waived, parse-error, lex-error, multi-byte) — **16 379 bytes of diagnostics + actions, identical**, including the fence filter correctly withholding quick fixes. 6. *Timing direction* — **PASS.** Release, median of 9, 820-file corpus, warm cache: `--threads 1` **294.7 → 235.3 ms (−20.2 %)**; default threads **98.6 → 87.2 ms (−11.6 %)**. Absolute numbers run ~10 % above the dev's on this machine's load, the *direction and magnitude* reproduce. Server didChange → publishDiagnostics, median of 15 full-text changes: `picorv32.v` (3049 lines) **20.1 → 12.6 ms**, `ibex_core.sv` (2026 lines) **8.2 → 3.7 ms** (informational; dev reported 18.0 → 11.0 and 7.6 → 3.4). 7. *Gates* — **PASS.** In the isolated tree: `cargo test --workspace` **770 passed, 0 failed** (27 result lines; vlog_linter 118 unit + 55 integration + 1 doctest, lucisv 30 unit + 69 CLI, lucisv_server 115 unit + 6 e2e — every count the work log claims). `cargo clippy --workspace --all-targets` exit 0, **zero warnings**. `cargo fmt --all -- --check` clean (not just the scoped set). In the *merged* tree the scoped crates are also green (`cargo test -p vlog_linter -p lucisv -p lucisv_server`: 30/69/115/ 6/118/55/1) with scoped clippy and fmt clean. Test churn is zero: `git diff --numstat crates/vlog_linter/tests/rules.rs` is **12 added, 0 removed**, and no other test file in `lucisv`/`lucisv_server`/`vlog_linter` is touched. No `unwrap`/`expect`/`panic!`/`unsafe`/`#[allow]` outside `#[cfg(test)]` in any of the six files. **Attacks.** - *Borrowed vs Owned, beyond the shipped property test.* 14 inputs (plain, tabs+trailing, fence, waiver, unused waiver, class body, parse-error, two lex-error shapes, CRLF, CJK+emoji+combining, empty, whitespace-only, case-without-default) × 3 path values (none, matching, mismatching) × 4 construction routes (`LintContext::new`, `ParsedSource::context`, a hand-built `from_parse` with independently produced products, and `run`). All `Debug`-identical violation lists — rule, message, span, fix, applicability — plus equal `source()`, `tokens().len()`, `Debug` of `file()`, and `comments().len()`. **No divergence.** - *The four-products contract, violated on purpose.* Five mismatch shapes (tree of B over text A, tokens of B over text A, line index of B over text A, everything-but-the-text from B, and short products over long text), with A deliberately 14 bytes and B 111. Result: **no panic, no abort, no unsoundness** — the crate contains no `unsafe`, so it cannot be otherwise. The cost is exactly *wrong findings*: `module-filename` reported a module name that is not in the text, and its **reported span (7..33) pointed past the end of a 14-byte buffer**. Corruption is nonetheless impossible even then: `apply_fixes` (`crates/vlog_linter/src/violation.rs:118`) already skips any edit with `end > source.len()` or a non-char-boundary start, and all five shapes applied cleanly with in-bounds output. See finding QA-2 for the one thing the README should add. - *The `--fix` loop.* Multi-round convergence survives the parse-once first round: `\twire a;\t\n` converges to ` wire a;\n` (tab expanded in one round, the trailing run removed in a later one), and a second `--fix` invocation over the already-fixed directory is a **no-op** (`diff -rq` clean), i.e. the loop still terminates at a fixed point. Fenced fixes are still refused, for both fence spellings and for an unclosed fence. - *Server, stale-tree.* The `parseable → broken → parseable` cycle tracks correctly: the parse diagnostic appears at v2 and is **gone** at v3, the lex diagnostic appears at v4 and is gone at v5, `module-filename` clears the moment the module is renamed, a waiver added at v3 clears the lint. Nothing from an older version leaks into a newer publish. `Document` is rebuilt whole per change (`Workspace::set_document` → `Document::new`), so there is no reuse point to go stale. - *Sabotage.* Made `Workspace::set_document` keep the previous version's tree (`doc.tree = old.tree`) while everything else refreshed — the exact bug this round newly makes possible. It **is** a real, user-visible bug: the stdio session immediately diverges (a stale `module-filename` warning for the old module name survives the rename and persists into the next version). But see finding QA-1. Sabotage reverted; `diff` against the working tree's `state.rs` clean, and a rebuilt server reproduces the baseline 13-publish log byte-for-byte. The scratch `qa_probe.rs` was deleted; `diff -rq head-wt qa-new` is back to exactly the six feature files. **Findings.** - **QA-1 (MEDIUM — missing coverage, not a defect in shipped behavior).** The stale-tree bug that this round newly makes possible is caught by **no test in the workspace**. With the sabotage above in place, `cargo test -p lucisv_server` passes **115 unit + 6 e2e, 0 failed**, and `cargo test --workspace` passes **773, 0 failed** (770 + 3 scratch probes). Only a live stdio session caught it. `Document.tree` is now a cached derivation of `Document.text`, and nothing asserts they agree. The cheapest guard is one `#[cfg(test)]` case in `crates/lucisv_server/src/lint.rs` or `state.rs`: `set_document` a buffer whose module name mismatches the filename, then `set_document` the renamed text, and assert `violations` no longer contains `module-filename` — an AST-rule finding, which is exactly the class that reads `doc.tree`. Reported rather than fixed: writing a new test into another feature's crate is the dev's call, not QA's. - **QA-2 (LOW — documentation).** `from_parse`'s caller contract says what the caller must supply but not what breaking it costs. The measured answer is worth one sentence at the item and in Assumptions: *violating it yields wrong findings and spans that may point outside the text; it is never unsound (no `unsafe`) and never corrupts a file, because `apply_fixes` independently bounds-checks every edit.* Left for the dev to word, since Assumptions is theirs. - **QA-3 (INFORMATIONAL).** `LintContext::new` is declared inside `impl<'a> LintContext<'a>` but returns `LintContext<'static>`, so its `'a` is unused. Compiles, clippy-clean, callers unaffected; noted only so a later reader does not mistake it for an accident. - **QA-4 (INFORMATIONAL, pre-existing, out of scope).** On CRLF input, `no-trailing-whitespace` does not fix the run before `\r\n` (observed on a crafted `crlf.sv`: `wire a; \r\n` survives `--fix`). Byte-identical on both binaries, so it predates this round entirely — recorded here only because the CRLF shape was part of the identity matrix and someone will otherwise re-find it. **Verdict: no BLOCKING findings.** No behavior divergence old-vs-new was found anywhere — 820-file corpus check (text and JSON), 820-file corpus `--fix`, a 12-case flag matrix, 13 crafted `--fix` shapes, 13 server publishes and 6 codeAction rounds all byte-identical. No stale-tree reuse in the shipped code. No memory unsafety is reachable, by construction. The one thing this round leaves behind is an untested invariant (QA-1), not a broken one. ## Review **2026-08-19 — lead. Verdict: accepted; commits with round 19. The duplicated-parse debt is paid: check is 20% faster single-threaded and the editor's per-keystroke latency roughly halved, with behavior identity proven at the byte level.** Points reviewed and accepted: 1. **The Backing enum was forced, not chosen** — SourceFile is !Clone, so borrowing was the only non-duplicating shape, and QA verified the constraint at the type level. Keeping `new()` as a one-line wrapper through the same private assemble is what kept all 12 rule files byte-untouched: an API migration with zero consumer churn. 2. **The four-products contract was violated on purpose and the cost measured**: wrong findings, possibly out-of-text spans, never unsoundness, never a bad write (apply_fixes independently rejects out-of-range edits). That measured answer is now in the doc comment (lead fix, QA-2). 3. **The server catalog is complete** — QA's grep found no uncataloged redundant parse, and the kept-with-reasons list (protected_regions' anti-drift signature, the strict format parse, the documented rebuild-on-save index) shows restraint where restraint was correct. 4. **QA-1 closed by lead fix**: the sabotage that kept a stale tree passed all 773 tests — nothing pinned text/tree agreement. The new `set_document_rebuilds_the_tree_so_diagnostics_track_the_text` guard in diagnostics.rs fails on exactly that sabotage (premise asserted through the merged all() path, where the stale lint warning actually lives — the first draft checked the parse-only path and was corrected before landing). 5. QA-3 (the unused 'a on new()) stands as a noted quirk; QA-4 (CRLF trailing-whitespace fix gap) is pre-existing and joins the linter's known-gaps list.