Merge branch 'wip-header-recovery'

# Conflicts:
#	crates/vlog_linter/src/visit.rs
This commit is contained in:
lucio committed 2026-09-04 03:01:49 -05:00
commit 4ba6eafa2d
64 files changed
+2270 -483

No files matched your search

+30 -9
View File
@@ -129,7 +129,19 @@ structure at all.
`for (i = 0; i < ; i = i + 1)` fails inside the header, resyncs at the `;`
*inside* the header, and reports again on the remains. Every extra
diagnostic is at a real position and the file still parses to the end; no
attempt is made to suppress cascades.
attempt is made to suppress cascades. *(Amended 2026-09-03: that `for` is
now one diagnostic — its `;`s are inside the header's own brackets and the
seeded counter makes them invisible. See `docs/features/header-recovery/
README.md`; cascades in general are still not suppressed.)*
- **A broken *header* distorts the tree around it, not just the header.**
This is the shape a consumer had to expect before header recovery landed:
an error anywhere inside a port list, parameter list, formal list or
connection list escapes to the nearest enclosing *item or statement list*,
so the whole `Module`/`FunctionDecl`/`Instantiation` becomes one error node,
its body re-parses at the enclosing scope, and its `endmodule` is orphaned
into a second error item — 2 diagnostics and a misleading tree for one typo.
*(Amended 2026-09-03: `docs/features/header-recovery/README.md` closes this;
the sentence stays because the Review below refers to it.)*
- **Comments attached to a construct that failed to parse are dropped from the
tolerant tree.** They were harvested into the failed node's `Meta` before
the error, and comments *inside* the skipped range survive only as bytes of
@@ -246,6 +258,14 @@ signatures.
`module`, `wire [7:`, `sub u0 (.a(`, garbage between two modules (six
kinds), error inside a generate block, error inside a function body,
all-garbage file, stray `endmodule`, lex error, empty file.
*(Amended 2026-09-03: two of these changed outcome when header recovery
landed, and their pins were rewritten to match. `sub u0 (.a(` no longer
costs the item — the instantiation keeps its name and its typed
connection, the half-typed one is an error **element**, and the `wire w;`
under it is a sibling item again; `for (i = 0; i < ; i = i + 1)` costs
one diagnostic instead of two. Every other shape here is unchanged, byte
for byte. The full before/after table is in
`docs/features/header-recovery/README.md`.)*
- [x] `cargo test --workspace` green, `cargo clippy -p vlog_parser
--all-targets` silent, `cargo fmt --check` clean.
- [x] TODO.md §6 error-tolerant checkbox.
@@ -253,14 +273,15 @@ signatures.
- [ ] **Not done:** cascade suppression (a "don't report twice within N
tokens" rule). Wait for the LSP to show whether the cascades are
actually noisy in practice.
- [ ] **Not done:** recovery inside headers and lists (port lists, parameter
lists, for-headers). Those need per-construct resync points, and the
first consumer should say whether the coarse-grained answer is enough.
Note (QA finding, lead-confirmed): today a broken *header* doesn't just
go unrecovered — it distorts the surrounding tree (the module body
re-parses as file-scope items and the orphaned `endmodule` becomes a
second error item, 2 diagnostics for one typo). The LSP consumer
should expect that shape until header recovery lands.
- [x] **Done, 2026-09-03, by a feature of its own:** recovery inside headers
and lists (port lists, parameter lists, formal lists, connection lists,
for-headers). The per-construct resync points this asked for are the
list-local, bracket-seeded sync set in `parser/recover_list.rs`, and the
QA finding above is closed: the module keeps its name, its typed
elements and its body, and the shape that cost 3 items and 2 diagnostics
costs 1 and 1. `docs/features/header-recovery/README.md` is the feature;
the mechanism in *this* README — item and statement lists — is
unchanged and still handles everything outside a header.
## Work log
+663
View File
@@ -0,0 +1,663 @@
# header-recovery
## Goal
`docs/features/error-recovery/README.md` recovers in item and statement
**lists** only, so an error anywhere inside a *header* escapes to the nearest
enclosing list and takes the whole construct with it: a typo in a port list,
parameter list, formal list or connection list destroys the `Module`,
`FunctionDecl` or `Instantiation` it was written in, the body then re-parses at
the wrong scope, and the orphaned `endmodule` becomes a second error item. Two
diagnostics and a misleading tree for one missing comma — the state an editor
buffer is in most of the time. This feature (TODO §32) adds recovery *inside*
those headers: a list element that does not parse becomes an
`ListElem::Error(RawText)` element of its list, a statement header's condition
that does not parse becomes an `ExprKind::Error(RawText)`, and the construct
around it keeps its name, the elements that were typed and its body. Strict
parsing is untouched — every new branch sits behind `self.tolerant` on the
error path — so the formatter's "zero errors or nothing" contract and the
byte-identity of every corpus file are unchanged.
## Assumptions
- **A header's error element is a leaf, not a guess.** The parser does not try
to work out what the user meant by the text it skipped; the element records
the bytes and its span, and every consumer decides what to do with it. The
variant exists so that consumers *must* decide: a `Vec<AnsiPort>` that
silently hid the hole would let the LSP mislabel what follows it.
- **The skip is list-local and bracket-seeded.** The bracket counter starts at
one — the list's own open bracket, already consumed — so a `;` inside a
`for (…; …; …)` header is invisible and no skip can run past the bracket that
closes the list it is in.
- **One line-based rule.** A skip stops at the first token of a new line. It is
the only line-based rule in the parser, and it is what makes
`module m (input logic a, inp⏎ output b);` cost one comma instead of the rest
of the list.
- **A recovered element ends its list unless a `,` follows it.** The skip stops
at the separator when there is one; no separator means the list is not there
any more and what follows belongs to the enclosing construct. That is what
leaves the `wire w;` under a half-typed `sub u (.a(` an item of the module.
- **Recovery declines on a conditional-compilation directive.** A list element
that fails on `` `ifdef ``/`` `else ``/`` `endif `` is one arm of a construct
written across the arms of a region, and the enclosing item or statement
captures the whole of it verbatim (`split.rs`). Recovering it here would take
that rescue away and give a file the strict parser reads *correctly* a
different tree.
- **Recovery is not silence.** Every shape still yields at least one
diagnostic; a list read on past a missing comma says so, and a bracket or `;`
missing behind an already-reported typo is the only thing taken silently.
- **A recovered header may still swallow the line the failure was on.** The
expression grammar is greedy: `for (int i = 0; i <⏎ x = 1;` reads `x` as the
right operand of `<`, so the error node covers that line. The loop survives;
the statement that was on the line does not.
## Handshakes
**Consumed from `docs/features/error-recovery/README.md`:** the tolerant flag,
`recover`, `skip_to_sync`, `at_sync_stop`, `at_body_end` and `expect_closer`
are unchanged and still own item- and statement-list recovery. This feature
adds a second, smaller mechanism beside them (`parser/recover_list.rs`) and
does not touch the first.
**Promised to `vlog_formatter`:** `format_source` still calls the strict
parser, so `ListElem::Error` and `ExprKind::Error` cannot appear in a tree the
formatter builds. Three arms were added anyway, because the new variants make
its exhaustive matches fail to compile: `ListItem::from_raw` (a header list's
error element, printed verbatim), the `ExprKind::Error` arm in `format/expr.rs`
(`raw_inline`), and `Fmt::list_elem`, the one-line adapter every header list
now maps through. Each says at its definition that it is unreachable from
`format_source`, exactly as `ItemKind::Error` does. `verify.rs` is untouched.
**Promised to `vlog_semantic`:** an error element declares nothing and binds
nothing — `bind_param_ports`, `bind_tf_args`, the port-list arms and the new
`bind_connections` all skip them, mirroring `bind/item.rs`'s `ItemKind::Error`
arm.
**Requested of the §33 linter lane (Handshake, not a silent edit; needs
re-applying at merge — this branch predates 0.36.0's linter):** three
places in `crates/vlog_linter` had to change for the new variants —
`visit.rs`'s `walk_param_ports` (one `filter_map(ListElem::ok)`, since an error
element has no name or type for a rule to judge) and `signals.rs`'s two
connection loops (an error element's span joins the same opaque-span bucket a
connection's does). The lead pre-agreed exhaustive-match arms in that crate;
these are that, plus the two-line `match` `signals.rs` needed to keep pushing a
span. Named here and in the report for the merge.
**`vlog_refactor` and `lucisv_server`:** both read tolerant trees (the server's
`FileFacts` is `tokenize` + `parse_tolerant` + `analyze`), so both had to
decide. Refactor skips error elements for every *name* question and keeps their
spans where it asks where the list's text *is* (`ports/list.rs::elem_spans`).
The server skips them in `type_def`, and `inlay` declines to hint a list that
holds one at all: which port a position names is exactly what the skipped text
decides, and a wrong hint is worse than none.
## Status / TODO
- [x] 32.1 `ListElem<T>` (`Ok` / `Error(RawText)`) in the five header lists —
a module's and a class's parameter ports, ANSI and non-ANSI ports, a
subroutine's formals, named and ordered connections — plus
`ExprKind::Error`, with the cross-crate arms above.
- [x] 32.2 `element_or_recover` and the list-local, bracket-seeded sync set
(`,`, the list's own `)`, `;`, a line change) in
`parser/recover_list.rs`.
- [x] 32.3 headers keep their node: the four list parsers are infallible in
tolerant mode, closers go through `close_list`, and a header that has
already reported something takes its `;` silently
(`expect_after_recovery`).
- [x] 32.4 `for` / `if` / `while` / `repeat` / `case` / `do…while` conditions
recover inside the parentheses (`cond_or_recover`, `error_expr`), with
`body_after_recovery` so a header truncated above an `end` does not eat
it.
- [x] 32.5 parser pins per shape with exact counts (9 new tests in
`tests/error_recovery.rs`, the half-typed-instantiation pin inverted as
planned); `error_recovery.rs`'s walkers and `tests/spans.rs`'s exhaustive
walker extended to the new shapes; the 550-source strict/tolerant
equality test green.
- [x] 32.6 server pins: one diagnostic, the module still in the outline with
the ports either side of the typo, `pairs::missing_end_diagnostics`
silent (`diagnostics.rs`), and the inlay rule (`inlay.rs`).
- [x] 32.6 the completion pin: `a_broken_header_still_completes_from_the_
modules_scope` — with a half-typed parameter above the cursor, the
module still has a scope and `visible_symbols` still answers from it.
- [x] 32.6 the three validity probes (`inline.rs`, `templates.rs`,
`completion/tiers.rs`) keep their verdicts, and each now has a pin for
the other direction: broken text still reports, so the probe is still
discriminating.
- [x] 32.7 measurements: `parse_tolerant` timing before/after on the largest
corpus file, and the truncated-at-midpoint corpus census. Numbers in the
work log.
- [x] 32.7 docs: the error-recovery README's Assumptions sentence, its
inverted "Not done" line and its mid-edit-shapes note;
`docs/coverage_gaps.md` M10 closed; TODO §32 ticked.
- [x] Gates: `cargo fmt -p` per crate, `cargo clippy --all-targets
--workspace` (0 warnings), `cargo test --workspace` (3 259 / 0 / 42),
corpus 814/820 with `--stdout` byte-identical to the 0.36.0 baseline
over all 820 files, and the read-only opentitan sweep unchanged.
## Work log
### 2026-09-03 — dev agent (paused; internet outage)
**Where this stands.** The tree **builds** (`cargo build --workspace` clean,
`cargo check --workspace --all-targets` silent). 32.1–32.5 are in and green;
32.6 is half in; 32.7 (docs, measurements) is not started. Nothing is
committed. The work sits on `wip-header-recovery` in
`.claude/worktrees/recovery`, on top of 6a15594.
**The two failures the lead reported are both fixed, and both were mine.**
1. **The runaway (6 GB, machine down).** Root cause, found by a probe that
printed every fuzz input before parsing it: deleting the `#` from
`sv_features.sv:268` turns `#(parameter …)` into a *port list*, which is
read as **non-ANSI** (it opens with the keyword `parameter`, not a type or a
direction). `parse_non_ansi_port` reads its own trailing `,`, so I took the
loop's `comma` from the element — and an **error** element never got that
far, leaving the `,` under the cursor. The next iteration then failed at the
same `,`, consumed nothing (a `,` is not a list end, so the always-advance
bump declined it, and the skip stops before it), and pushed another empty
error element: an allocating spin. My termination argument had assumed every
loop ate the comma, which two of the six did not.
**The fix is structural, not an argument.** `Parser::list_ends` now takes
the cursor the iteration began at and ends the list whenever it has not
moved — no reasoning about element parsers or skips can make one of these
loops spin, because the loop refuses to go round again on an unmoved cursor.
The two loops that read their own separator (non-ANSI ports, positional
connections) also eat the `,` after an error element now, so recovery still
resumes at the next element rather than merely stopping.
2. **The strict-mode parity failure.** `tolerant_parse_equals_strict_parse_on_
valid_sources` failed on `directive_in_statements.cases`: an instantiation
(and, in a second case, a formal list) written across the arms of a
`` `ifdef `` fails in strict mode *by design* and is rescued at item level by
`split.rs`, which captures the whole construct verbatim. My list recovery
swallowed that failure into an error element, so the rescue never ran and
the tolerant tree held an `Instantiation` where the strict tree holds a
`Verbatim`. Fix: `element_or_recover` declines — passes the error out
untouched — when the cursor stands on a conditional-compilation directive.
Balanced directives never reach it (`take_list_directives` harvests those),
so this costs nothing else.
**Measured shapes (a)–(g), after both fixes.** Each is now a pin in
`tests/error_recovery.rs`:
| shape | diagnostics | tree |
|---|---|---|
| `module m #(parameter W = , parameter X = 4) (input a); wire ok; endmodule` | 1 | one `Module m`, `param_ports` = [error, `X`], port `a`, body `wire ok;` |
| `module m (input logic a, inp⏎ output b);` | 1 (`expected \`,\``) | ports `a`, `inp`, `b` — no error element |
| `module m #(parameter W = 8,` at EOF | 2 (unclosed `)`, unclosed module) | `Module m` with parameter `W` |
| `for (i = 0; i < ; i = i + 1) x = 1;` | 1 (was 2) | `For` with an `Error` condition, body `x = 1;`, the next statement intact |
| `for (int i = 0; i <⏎ end` | 1 | `For` with an `Error` condition and an **empty** error body — the `end` its block waits for is not eaten |
| `sub u (.a(x), .b(⏎ wire w;` | 1 | the instantiation keeps `.a(x)` and one error element; `wire w;` is a **sibling item** (the old pin inverted, as planned) |
| `function int f(input int a,⏎ f = a;⏎ endfunction` | 1 | the function and the module both intact |
| `if (a &&⏎ x = 1;⏎ y = 2;` | 1 | `If` with an `Error` condition and `y = 2;` as its branch |
**Design decisions worth the lead's attention.**
- **One generic `ListElem<T>` rather than four bespoke enums.** Same two
variants in all five lists; one type means one place says what an error
element is. Consumers read it through `ok()` / `error()` / `is_error()`.
- **"Has this header already reported something?" is asked of the diagnostic
count** (`diags_mark` / `recovered_since`), not of the elements. It is always
0 in strict mode, so every question asked of it answers "no" there, and it
covers a missing closer as well as a broken element.
- **`body_after_recovery`** gives a recovered statement header an *empty* error
leaf for its body where the enclosing block has already ended, rather than
inventing a `;` the source never wrote.
- **Cost of the shape change.** `Vec<T>` → `Vec<ListElem<T>>` in five lists
touched ~60 sites across six crates. Most are one-line filters; the test
churn is absorbed by an `oks()` helper in each test module (strict parses
never build an error element, so it is the whole list).
**Fuzzers, under `tools/guard.sh`.** The truncate-anywhere *and*
delete-any-character sweeps over every formatter fixture complete with
`-m 4 -t 900` (they exceeded 3 GB before the fix, and 6 GB in the lead's run).
`cargo test -p vlog_parser` is green: 365 unit + 26 spans + 31 error-recovery,
0 failed. `cargo test --workspace` had one failure left when I stopped — the
inlay test below, which I then updated and re-ran green in isolation; the
workspace run has **not** been repeated since.
**Server pins.** `diagnostics.rs` gained
`a_broken_port_list_publishes_one_error_and_keeps_its_module` (one diagnostic,
`missing_end_diagnostics` silent, the module and the ports either side of the
typo in the outline). `inlay.rs`'s
`a_buffer_that_does_not_parse_hints_nothing_rather_than_guessing` was replaced
by `a_truncated_list_hints_and_a_recovered_one_does_not`: a truncated list now
parses, and every position in it is where it was written, so it is hinted; a
list with a *hole* is declined whole. `completion/module.rs`'s
`a_module_with_an_attribute_near_its_header_is_not_indexed_at_all` split in
two — an attribute on a **port** is now one error element and the module is
indexed and its header slices, which is the re-audit that test's old message
asked for; an attribute between the name and the `#(` is inside no list and is
unchanged.
**Next steps, in order:** the completion pin and the three validity probes
(32.6); the `parse_tolerant` timing and the truncated-corpus census (32.7); the
error-recovery README amendments, `coverage_gaps.md` M10 and the TODO ticks;
then the full gates — `cargo fmt -p` per touched crate,
`cargo clippy --all-targets --workspace`, `cargo test --workspace` with counts,
the corpus byte-identity run against `/tmp/lucisv-0.35.0-baseline`, and the
read-only opentitan sweep. All of them through `tools/guard.sh`.
### 2026-09-04 — dev agent (finished: 32.6, 32.7, docs, gates)
**32.6, completed.** `completion/tiers.rs` gained
`a_broken_header_still_completes_from_the_modules_scope`: with
`#(parameter W = , parameter DEPTH = 4)` above the cursor and the cursor inside
the port list, `DEPTH` is still offered at `TIER_SCOPE` — the module has a
scope again, so the scope chain covering that offset is the module's. The three
validity probes keep their verdicts (they assert an *empty* diagnostic list for
generated text, and that text still parses); each file also gained a pin for
the direction that actually matters after this round — recovery widened what a
tolerant parse reads, so a probe is only worth asking while broken text still
reports. `the_insertion_probe_…`, `the_expansion_probe_…` and
`the_accepted_text_probe_still_reports_text_that_does_not_parse` are those.
**32.7, measurement 1 — `parse_tolerant` cost on the largest corpus file.**
Measured properly rather than across binaries built on different days: the
parser crate was extracted at both revisions into a throwaway harness
(scratchpad only, nothing in the repo) that times `parse` and `parse_tolerant`
over the same tokens, so the *strict* path — which this round provably does not
touch — is the control.
| `corpus/picorv32/picorv32.v` (94 657 B, 16 559 tokens) | `parse` | `parse_tolerant` |
|---|---|---|
| before (§32 absent) | 2.455 / 2.175 / 2.161 ms | 2.302 / 2.101 / 2.141 ms |
| after (this branch) | 2.214 / 2.190 / 2.170 ms | 2.172 / 2.167 / 2.166 ms |
Three runs each, mean of 40 parses per run, clone included. Run-to-run spread
is ~2 % **on the untouched strict path too**, and the tolerant/strict ratio is
≤ 1 on both builds — so the new bookkeeping (`let at = self.pos`, a diagnostic
mark per header, one extra branch per element) is below the noise floor. The
same holds on `ibex_core.sv` (1.298 → 1.216 ms tolerant, with strict moving
1.473 → 1.233 ms between the two builds, which is the point). The in-repo
`perf.rs` harness, run read-only, prints `parse_tolerant` 1.34 ms at 1 k lines
and 15.5 ms at 10 k against `docs/perf/README.md`'s 1.16 / 14.3 ms — but
`tokenize` (untouched) reads 1.39 ms against a recorded 1.14 ms in the same
run, so that table was taken on a faster day and is not a before/after.
**32.7, measurement 2 — the truncated-corpus census.** Every corpus file cut at
its midpoint (char-boundary), parsed tolerantly, by both revisions of the
parser:
| | error nodes | diagnostics |
|---|---|---|
| before | 622 | 1 702 |
| after | **555** (−11 %) | **1 826** (+7 %) |
Error nodes fell, as predicted. **Diagnostics rose, which the plan did not
predict**, and the breakdown says why: `expected \`endmodule\`` goes 333 → 424
(+91) and `expected \`)\`` 118 → 147 (+29), while `expected identifier` falls
77 → 63. A module whose header is cut in half now *survives* and reaches its
body loop, where a truncated file has no `endmodule` — so it says so. Before,
that module was swallowed into one error node and said nothing about its
closer. The rise is 91 modules-worth of "you have not closed this yet", not new
noise: the new `expected \`,\`` message does not even reach the top eight. An
LSP shows the same count of *squiggles per real problem*, on constructs that
now exist in the tree.
**Gates, all through `tools/guard.sh`.**
- `cargo fmt -p` for each of the six touched crates — clean (it reflowed three
lines of mine).
- `cargo clippy --all-targets --workspace` — **0 warnings**.
- `cargo test --workspace` — **3 259 passed, 0 failed, 42 ignored**. That is
0.35.0's 3 244 plus exactly the 15 pins this round adds (9 in
`error_recovery.rs`, 6 in the server). The branch is based on 6a15594, so it
does *not* carry 0.36.0's §33 linter tests; the 3 393 / 48 the lead quoted is
master's number, and the comparison to make at merge is 3 393 + 15.
- `cargo build --release -p lucisv` + `scripts/corpus_gate.sh corpus` —
**814/820 (99.3 %)**, the same six failures by category
(`invalid-or-fragment` 2, `directive-split` 1, `macro-items` 1,
`not-verilog` 1, `other` 1).
- `--stdout` over all **820** corpus files against
`~/.cache/lucisv-baselines/lucisv-0.36.0`: **0 differing**. The strict path is
untouched, byte for byte.
- OpenTitan, read-only (`--check` only): identical to the baseline binary's
sweep — **3 896 would reformat, 72 unchanged, 11 failed**, and the failure
*set* and would-reformat *set* diff empty against the baseline, which is
byte-level evidence over 3 979 files. `git -C …/opentitan status --porcelain`
before and after shows the same three files
(`hw/ip/aes/dv/tb/tb.sv`, `hw/top_darjeeling/ip/ast/rtl/ast.sv`,
`hw/top_earlgrey/ip/ast/rtl/ast.sv`) and nothing else.
**For the merge.** This branch is based on 6a15594, before 0.36.0. The three
`vlog_linter` arms named in Handshakes (`visit.rs::walk_param_ports`, the two
connection loops in `signals.rs`) are carried here against the *pre*-§33
linter; master's linter has since grown 36 rules, `Severity` on `Rule` and new
files, so those three arms need re-applying to master's versions of the two
files at merge. Nothing else in this branch touches `crates/vlog_linter`.
## QA log
### 2026-09-04 — QA agent
Read CLAUDE.md, TODO §32, this README, `docs/features/error-recovery/README.md`,
and the code in `crates/vlog_parser/src/parser/{recover.rs, recover_list.rs,
module.rs, tf.rs, instance.rs, stmt.rs, keyword_stmt.rs}`,
`crates/vlog_parser/tests/error_recovery.rs`,
`crates/lucisv_server/src/{diagnostics.rs, symbols.rs, completion/tiers.rs}`
before testing. All commands ran through `tools/guard.sh` per CLAUDE.md.
Scratch work in `/private/tmp/.../scratchpad/qa-32/`, including two throwaway
worktrees (`before_4d70de1` at the pre-§32 commit, `throwaway` at f1d44a2 with
the dev's uncommitted diff applied) — neither touched by any tracked-file
edit; both removed after use. Never touched `git checkout/stash/reset/clean`
in the dev worktree; the only edit here is this entry.
**1. Gates — all reproduced exactly, independently.**
- `cargo fmt --all -- --check`: clean.
- `cargo clippy --all-targets --workspace`: 0 warnings. `git diff 4d70de1 --
-- '*.rs'` has zero added `#[allow(` lines.
- `tools/guard.sh -m 8 -t 1800 -- cargo test --workspace --no-fail-fast`:
summed every `test result:` line myself (not trusting the dev's tally) —
**3 259 passed, 0 failed, 42 ignored.** Matches exactly.
- `git diff --stat f1d44a2 -- crates/vlog_formatter/src/verify.rs`: empty.
- Changed-file set: `git diff --stat 4d70de1 -- .` (58 files) is the four
list-type crates + the two disclosed `vlog_linter` arms (`visit.rs`,
`signals.rs`) named in Handshakes, **plus `crates/vlog_refactor/src/{
instantiate.rs, ports/*.rs}` (7 files)**, which is *also* disclosed in
Handshakes ("`vlog_refactor` ... both had to decide") but was not named in
TODO §32's original "Files:" list written 2026-09-02 (written before the
dev found refactor's exhaustive matches also needed arms). Not a violation
— it's transparently documented — but flagging so the lead's merge review
knows the file-ownership list undersold the true footprint. LOW.
- `cargo build --release -p lucisv` + `--stdout` over all **820** corpus
files (`~/.cache/lucisv-corpus`) against `~/.cache/lucisv-baselines/
lucisv-0.36.0`: **0 differing.** `tools/corpus_check.sh`: **814/820
(99.3 %)**, same six failure categories as claimed.
- Opentitan, read-only, sampled: `--check` exit codes over the 118 `.sv`/`.v`
files under `hw/ip/aes` — dev binary vs the 0.36.0 baseline binary — **0
differing.** `git -C .../opentitan status --porcelain` before and after:
unchanged (the same three pre-existing modified files).
**2. The advance guarantee, adversarially, then fuzzed.**
Read `list_ends`/`element_or_recover`/`skip_inside_brackets` end to end. The
guarantee is structural, not argued: every one of the five list loops (ANSI
ports, non-ANSI ports, param ports, tf-args, connections) calls
`list_ends(start, ...)` at the top of its check, and `list_ends`'s *first*
condition in tolerant mode is `self.pos == start` — an iteration that made no
progress ends the list unconditionally, before any of the comma/bracket/
directive logic runs. This holds regardless of what `element_or_recover`,
`recover_element` or `skip_inside_brackets` do internally, including the edge
case where `recover_element`'s own forced-bump is skipped (already at a sync
stop) — the outer check still catches it. I could not construct a case where
this loop iterates without the cursor moving. Confirmed sound.
Fuzzed 30 corpus files of deliberately varied shape (ANSI/non-ANSI ports,
param lists, instantiations, functions, `for`/`if`, macros, `` `ifdef ``
splits, classes, covergroups, header files) under `tools/guard.sh -m 4 -t
900`, running (a) truncate-at-every-byte, (b) delete-every-character, (c)
delete-every-token, (d) insert a stray `,`/`)`/`;`/`(` at every token
boundary, via a standalone harness linked directly against `vlog_parser`
(faster and more precise than shelling out to the CLI per mutation; built in
`scratchpad/qa-32/fuzzharness`, never inside the dev worktree). List of files
and the harness source are in the scratchpad.
**First run hit the guard, and it was my own harness's bug, not the
parser's.** Computing `format!("{tree:?}")` on every one of ~94 658
mutations of `picorv32.v` (94 657 B) to count error nodes, plus (worse)
eagerly collecting the delete-char/insert-stray categories into one
`Vec<String>` of near-full-length variants *before* iterating (up to ~132 000
strings × ~95 KB each for insert-stray alone), pushed the harness itself past
4 GB and `tools/guard.sh` correctly killed it. I isolated the cause with a
second, minimal harness (`leancheck`) that parses every truncation of
`picorv32.v` with no debug-formatting at all: **94 658 parses, 283.6 s total,
max single parse 115.02 ms, RSS flat at ~20 MB** — proving the parser itself
was never the problem. Fixed the harness (lazy iterators throughout instead of eager `Vec<String>`
collection; error-node counting sampled every 20th variant) and reran under
the same `-m 4 -t 900` guard: RSS stayed flat at 20–32 MB through the first
~4.5 minutes (truncate + well into delete-char/delete-token), a small
fraction of the 4 GB cap, with no growth trend — conclusively confirming the
fix. The other 29 files completed cleanly (0 panics) well before that, with
a max single-parse time of **95.73 ms**. Diagnostics and error-node counts
scale with how broken each mutation is (up to ~195 diagnostics on the most
heavily-mutated UVM sequence file) but never explode disproportionately to
input size. No finding against the feature here — the guard kill was mine to
fix, and I did; the corrected full run on all four categories of
`picorv32.v` was still finishing (large file, ~250k total mutations across
the four categories) as this report was written, with memory behavior
already dispositive.
**3. Strict-mode parity, extended to the full corpus.** Wrote a second
standalone harness (`scratchpad/qa-32/fuzzharness/src/bin/parity.rs`) that
walks every `.v`/`.sv` file under `~/.cache/lucisv-corpus`, keeps the ones
`parse_source` accepts, and asserts `Debug` equality against
`parse_source_tolerant` plus an empty diagnostic list. Result: **814
strict-parseable files, 0 mismatches, 0 diagnostics-on-strict-ok.** 814 is
exactly `tools/corpus_check.sh`'s "parsed & formattable" count, which is the
right cross-check. PASS — extends the 550-fixture guarantee to the full
corpus with zero exceptions.
**4. Shapes (a)–(g) and three of my own.** Built a small `shapes` probe
(prints diagnostics + a summary of the tree) against the dev worktree's
`vlog_parser`, in the throwaway harness — equivalent to, and more precise
than, `lucisv --check` for this purpose.
- QA source `module m #(parameter W = , parameter X = 4) (input a); wire
ok; endmodule` → **1 diagnostic**, one `Module m`, `param_ports` = [error,
ok `X`], one ansi port `a`, one body item (the `wire ok;`). Exactly as
pinned.
- (b) `module m (input logic a, inp⏎ output b);` → **1 diagnostic**
(`expected \`,\``), ports `a`, `inp`, `b`, no error element. Exactly as
claimed.
- (e) `sub u (.a(x), .b(⏎ wire w;` → **1 diagnostic**, module body has 2
items (the instantiation with one error connection element, and `wire w;`
as a sibling item). Exactly as claimed.
- (c), (d), (f), (g) I did not re-probe by hand — they are asserted exactly
by the dev's own pins in `tests/error_recovery.rs`, which passed under my
own from-scratch `cargo test --workspace` run (item 1), so I trust them at
the same level as every other passing test in that suite.
**My three added shapes:**
- **A mid-typed interface port list**
(`module m (bus_if.mp bus, input logic clk, input logic\nendmodule\n`):
**1 diagnostic** (`expected identifier`), 3 ansi ports — `bus`, `clk`, and
one error element for the truncated last port. Recovers cleanly; matches
the feature's promise.
- **A broken `case (` header**
(`case (a ==\n endcase\n`, inside a module/initial/begin): **1
diagnostic** (`unexpected keyword \`endcase\` in expression`), the `case`
statement survives with an `Error` condition and correctly consumes
`endcase`. Recovers cleanly.
- **A half-typed `#(` override in an instantiation** — **MEDIUM finding**,
see below.
**MEDIUM: a half-typed parameter override whose broken value can be extended
into a call swallows the whole instantiation, not just the element.**
Source:
```
module m;
sub #(.WIDTH(8), .DEPTH(
u0 (.a(x), .b(y));
endmodule
```
Result: **2 diagnostics**, and the module's one body item is an **item-level
`Error` node covering the entire instantiation** — `.WIDTH(8)`, which parsed
fine, is lost along with everything else. This is the *pre-§32* failure mode
("garbage tree... whole construct destroyed"), not the improved one, despite
this being exactly the shape §32.5 asks to be tested (a half-typed `#(`
override in an instantiation).
Root cause, traced through `recover_element`/`skip_inside_brackets`: `.DEPTH(`
opens a paren the user never closes. `parse_expr_or_type` on the value is
*greedy* and this grammar supports named-argument call syntax
(`f(.a(1), .b(2))`, IEEE 1800 §13.5.3) — so when the very next real construct
happens to look exactly like `identifier(...)` (which an instance name plus
its own connection list always does), the value expression successfully
parses `u0(.a(x), .b(y))` as a **call expression**, consuming the real next
instance's name and connections *before* any error is ever raised. The
`expect_sym(")")` for `.DEPTH(`'s own closing paren then fails on the real
`;` — a clean, single failure — and `element_or_recover` correctly turns
*that* into one list element error. But the instance name it needed
(`u0`) is already gone: `parse_instantiation`'s `instances` loop (which has
no `element_or_recover` of its own — it isn't one of the five covered list
types) calls `expect_name()` on the `;` and fails, and *that* Err has no
recovery closer than the outer item-level `item_or_recover`, which swallows
the whole instantiation, discarding the good `.WIDTH(8)` progress along with
it.
Control test confirming the mechanism (not the bug): the same shape with a
value that *cannot* extend into a call —
`.DEPTH(4\n u0 (.a(x), .b(y));` (a bare number instead of an identifier) —
recovers correctly: **1 diagnostic**, `.DEPTH(` becomes an error element, the
instantiation survives with 1 item. The difference is entirely that `u0(...)`
is syntactically valid as a *continuation* of the broken expression, so the
failure never reaches the list boundary where `element_or_recover` could
catch it before the damage is done.
This is a real, if narrow, gap in the "headers keep their node" promise: it
is not covered by any of the 9 parser pins, and the error-recovery README's
existing "greedy expression" Assumption describes a much milder consequence
(a for-loop's *next statement* is lost, but the loop survives) — here the
*entire enclosing construct* is lost, which is the outcome §32 exists to
prevent. Recommend: either note it explicitly as a known limitation in
Assumptions (the parenthetical, named-argument-call ambiguity is subtle
enough to be worth writing down), or — better — extend the "declines on a
line change" style protection so a connection/param value's own greedy call
parse can also be interrupted by a sync-stop condition, though that is a
larger design question for the dev, not something I should redesign in QA.
File/line: `crates/vlog_parser/src/parser/instance.rs` (`parse_connection`,
`parse_instantiation`'s `instances` loop), `parser/recover_list.rs`
(`element_or_recover`, `skip_inside_brackets`). Reproduction is the source
block above.
**5. Server behavior, over the wire.** Built `cargo build -p lucisv_server`
(already built by item 1's workspace test run) and drove the real
`lucisv-server` binary with hand-rolled LSP framing (same technique as
`tests/e2e.rs`), from a standalone probe binary
(`scratchpad/qa-32/fuzzharness/src/bin/e2e_probe.rs`).
- **Probe A** (the dev's own `diagnostics.rs` pin source, byte for byte:
`module m (input a, , input b);\n wire ok;\nendmodule\n`): documentSymbol
lists module `m` with children port `a`, port `b`, net `ok`. Exactly **1**
`publishDiagnostics` push, **1** diagnostic in it. Matches the unit-test pin
exactly, now confirmed over the real wire protocol too.
- **Probe A2** (the completion-scope pin source, `top #(parameter W = ,
parameter DEPTH = 4) (...)`): completion at the cursor after `output logic
DE` offers `DEPTH` first — `TIER_SCOPE`, as pinned. 1 push, 2 diagnostics
(the 1 parse diagnostic + 1 pre-existing, unrelated lint finding —
`explicit-parameter-storage-type` on the untyped `DEPTH` parameter, which
predates §32 and is not part of the header-recovery diagnostic count; the
dev's own unit test isolates parse-only diagnostics via `diagnostics(doc)`,
which is why it says "1" — the wire-level push legitimately aggregates
parse + lint). Not a discrepancy, just worth stating precisely.
- **Probe B** (real `opentitan/hw/ip/aes/rtl/aes_core.sv`, ~600 lines, one
port line half-deleted **in the buffer sent over `didOpen` only** —
`input logic rst_shadowed_ni,` truncated to
`input logic rst_sh`, no trailing comma):
documentSymbol still lists the whole module — every parameter, `clk_i`,
`rst_ni` *before* the truncation, the truncated port itself (read as a
legitimately-shaped, if oddly-named, ANSI port — no error element needed,
because syntactically `input logic rst_sh` is complete), and every port
*after* it (`entropy_clearing_req_o`, `entropy_clearing_ack_i`, …) through
to the end of the 600+ line body. **Exactly 1** `publishDiagnostics` push
with **1** diagnostic (`expected \`,\`` on the following port line).
Completion at the truncation cursor offers the real identifier
(`rst_shadowed_ni`) alongside the partial token. `git -C
/Users/guoliangchen/repo/opentitan status --porcelain`: unchanged (still
only `hw/ip/aes/dv/tb/tb.sv`, `hw/top_darjeeling/ip/ast/rtl/ast.sv`,
`hw/top_earlgrey/ip/ast/rtl/ast.sv` — the file itself was never written).
- The three validity probes: confirmed present and asserting the claimed
direction — `templates.rs::the_expansion_probe_still_reports_text_that_
does_not_parse`, `inline.rs::the_accepted_text_probe_still_reports_text_
that_does_not_parse`, `completion/tiers.rs::the_insertion_probe_still_
reports_text_that_does_not_parse` all assert `!parse_source_tolerant(probe)
.1.is_empty()` on genuinely-broken generated text. All green under item 1's
test run.
PASS on the whole item — the user-visible contract holds, including on a
real 600-line file from the wild, not just a hand-crafted fixture.
**6. The census, re-derived independently.** Built two more standalone
harnesses linking `vlog_parser` at two revisions: `before_4d70de1` (the
commit immediately before any §32 work) and the dev worktree as-is. Both cut
every corpus file at its own midpoint (char-boundary-safe) and parse
tolerantly. My numbers, from scratch, matching the dev's exactly:
| | error nodes | diagnostics |
|---|---|---|
| before | 622 | 1 702 |
| after | 555 | 1 826 |
Top-message deltas also match exactly: `expected \`endmodule\`` 333 → 424
(**+91**), `expected \`)\`` 118 → 147 (**+29**), `expected identifier` 77 →
63. Read all 10 files where the diagnostic count rose the most
(`prim_diff_to_alert.sv`, `push_pull_driver_lib.sv`, `synth_gates.v`,
`synth_area_top.v` ×2, `axicheck2.v`, `uart_bind.sv`, `uart_nf_if.sv`,
`prim_flop_en.sv`, `prim_flop.sv`) with both binaries side by side. Every
single one holds the dev's explanation without exception: before, the
header failure swallowed the whole construct into one error node that said
nothing past its own header (1–2 diagnostics, no closer message, because the
body-parsing loop was never reached); after, the same construct survives its
header and reaches the body loop, which then hits EOF without its
`endmodule`/`endclass`/`endinterface`/`)` and reports exactly that. The
"rise is 91 modules-worth of you-have-not-closed-this-yet, not new noise"
claim holds — confirmed, not just plausible.
**7. Docs.** `docs/features/header-recovery/README.md`: all seven sections
present and current. `docs/features/error-recovery/README.md`: the header
sentence is in Assumptions, the "Not done" line is inverted into a "Done,
2026-09-03" entry with the mechanism named, the "known shapes" amendment note
is present. `docs/coverage_gaps.md`: M10 struck through and closed with the
measured numbers. The §33-linter handshake (three arms to re-apply on
master's files at merge) is named precisely (`visit.rs::walk_param_ports`,
two loops in `signals.rs`). The (undisclosed-in-the-original-plan but
disclosed-in-Handshakes) `vlog_refactor` footprint is noted above under
Gates.
**LOW: `TODO.md` §32's "Gates" checkbox is unticked** despite the Gates line
in this very README's Status/TODO being `[x]` and every gate genuinely
passing (independently re-verified in item 1). `TODO.md:3474-3476`. Easy fix
at merge — tick it; the "QA" line below it is correctly left unticked since
QA (this pass) is what resolves it.
**CLAUDE.md compliance:** no `unwrap()`/`expect()`/`panic!` introduced outside
`#[cfg(test)]` (spot-checked the diff's non-test hunks). No `unsafe`. File
sizes: `recover_list.rs` at 322 production lines, comfortably under 600;
nothing in the diff pushes a file over threshold. Runaway guard: every
`cargo test`, fuzz sweep, corpus/opentitan sweep and server run in this QA
pass went through `tools/guard.sh` — including, notably, the one that caught
my own harness's memory bug (item 2), which is exactly what the guard is
for.
**Verdict: PASS.**
No CRITICAL (opentitan confirmed untouched, twice — the aes-subtree sweep and
the e2e probe). No HIGH (no guard kill, panic or slow parse attributable to
the feature itself — the one guard kill in this pass was my own harness,
isolated and fixed; strict-mode parity holds over the full corpus, not just
the 550 fixtures; every pinned shape's exact counts reproduce). One MEDIUM
(item 4: a half-typed `#(...)` override whose value can extend into a call
swallows the whole instantiation rather than just the element — real, not
forcing, worth a follow-up pin) and two LOW (the `vlog_refactor` footprint
undersold in TODO §32's original file list, though disclosed in Handshakes;
the unticked `TODO.md` Gates checkbox). Recommend the lead tick the Gates
checkbox at merge and decide whether the MEDIUM finding gets a follow-up pin
now or is filed for later — it does not block this round, since it is no
worse than pre-§32 behavior on that specific shape, just not yet improved by
it.
## Review
**2026-09-04 — lead.** Accepted. This round earned its structural rule
the hard way: the first cut's list loop could iterate without consuming
a token, and under the delete-any-character fuzzer it allocated
diagnostics until the machine died. The fix — `list_ends` ends a list
whose iteration left the cursor where it started — is a guarantee a
reader can check in one line, QA read it adversarially and then fuzzed
four mutation classes over thirty files without a stall, and the guard
that now wraps every suite exists because of this lane. The second
finding, strict parity broken by recovery swallowing the failure that
`split.rs` needs to see, is fixed at the one place the two mechanisms
meet. The census is reported honestly: fewer error nodes, more
diagnostics, because a module whose header was cut now survives to
report its missing `endmodule` — the right trade. QA's MEDIUM (a
half-typed `#(` override whose value reads as a call swallows the next
instance's name, so that instantiation still collapses to an item-level
error) is filed as `docs/topo.md` §2.9-24, not a rework: the shape is
outside the plan's list and the fix is a lookahead in the override
grammar, its own small item. TODO's Gates line ticked at review; the
`vlog_refactor` touch (two exhaustive-match arms) accepted. The three
`vlog_linter` arms are re-applied at merge against §33's files. Ships
in 0.37.0.