Error recovery inside headers and lists: error elements, a list-local bracket-seeded sync that cannot stall, headers keep their node

TODO section 32 (coverage_gaps M10).
A typo inside a port list, parameter list, tf-port list, connection
list or a for/if/while/case header no longer destroys the enclosing
module or function. The four list element types and ExprKind gain an
Error(RawText) element; element_or_recover records the diagnostic and
skips to a list-local sync set (',' ')' ';' or a line change) with the
bracket counter seeded from the list's own opener, and list_ends ends
any list whose iteration left the cursor unmoved - the structural
guarantee that closes the non-advancing loop which exhausted memory on
the first cut. Headers are infallible in tolerant mode: the node keeps
its name, the typed elements and its body, so the body binds in the
right scope and there is no orphaned closer; recovery declines on a
conditional-compilation directive so split.rs's verbatim rescue still
runs and strict parity holds (550 fixtures and all 814 strict-parsing
corpus files, Debug-equal). Pins per shape with exact counts; server
pins: document symbols and scoped completion survive a broken header,
one diagnostic, the three validity probes keep their verdicts.
Census over the corpus truncated at each midpoint: error nodes 622 ->
555, diagnostics 1 702 -> 1 826 (surviving modules now report their
missing endmodule). parse_tolerant timing within noise. 3 259 tests on
this branch (0.35.0 + 15 pins); corpus 814/820 byte-identical.

docs/features/header-recovery/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
lucioandClaude Fable 5 committed 2026-09-04 02:58:24 -05:00
1 parent f1d44a2a0c
commit 747ae02b0e
10 files changed
+561 -44

No files matched your search

+14 -11
View File
@@ -3454,21 +3454,24 @@ only), crates/lucisv_server/src/perf.rs (measurement only), docs/
features/header-recovery/README.md (new), amendments in error-recovery
README, docs/coverage_gaps.md M10, TODO §32. Runs after §31 (parser +
formatter collide with §30's tf.rs/module.rs at merge; sequential).
- [ ] 32.1 error elements in the four list types + `ExprKind::Error`;
cross-crate arms pre-agreed
- [ ] 32.2 `element_or_recover` with the list-local, bracket-seeded
- [x] 32.1 error elements in the four list types + `ExprKind::Error`;
cross-crate arms pre-agreed — one generic `ListElem<T>` over five
lists (a class's parameter ports are the fifth)
- [x] 32.2 `element_or_recover` with the list-local, bracket-seeded
sync set (`,` `)` `;` line change)
- [ ] 32.3 headers keep their node (port, param, tf-port, connection
- [x] 32.3 headers keep their node (port, param, tf-port, connection
lists infallible in tolerant mode; closers via `expect_closer`)
- [ ] 32.4 `for`/`if`/`while`/`case` conditions recover inside the
parentheses
- [ ] 32.5 parser pins per shape with exact counts; walkers extended;
- [x] 32.4 `for`/`if`/`while`/`case` conditions recover inside the
parentheses (`repeat` and `do…while` too, same helper)
- [x] 32.5 parser pins per shape with exact counts; walkers extended;
550-source equality and the fuzzers green
- [ ] 32.6 server pins: symbols survive, completion scope survives, one
- [x] 32.6 server pins: symbols survive, completion scope survives, one
diagnostic, validity probes unchanged
- [ ] 32.7 docs + measurements (parse_tolerant timing, truncated-corpus
diagnostic census)
- [ ] Gates: fmt/clippy/`cargo test --workspace`; corpus 814/820
- [x] 32.7 docs + measurements (parse_tolerant timing, truncated-corpus
diagnostic census — error nodes 622 → 555, diagnostics 1 702 →
1 826: the constructs that now survive report their own missing
closers)
- [x] Gates: fmt/clippy/`cargo test --workspace`; corpus 814/820
byte-identical (strict path untouched); opentitan read-only sweep
unchanged
- [ ] QA: type each of the (a)–(f) shapes into the real server against
@@ -513,6 +513,20 @@ endmodule
);
}
/// The premise the probe above rests on, stated as a test: the probe is
/// *discriminating*. Header recovery (TODO §32) widened what a tolerant
/// parse can read, so the question "did this insertion parse?" is only
/// worth asking while text that does **not** parse still says so.
#[test]
fn the_insertion_probe_still_reports_text_that_does_not_parse() {
let broken = "if (cond begin\n\n end";
let probe = format!("module p;\n always_comb begin\n {broken}\n end\nendmodule\n");
assert!(
!vlog_parser::parse_source_tolerant(&probe).1.is_empty(),
"recovery must not make a broken insertion look clean: {probe}"
);
}
#[test]
fn a_templates_documentation_shows_what_it_expands_to() {
let top = "module top;\n alw\nendmodule\n";
@@ -896,6 +910,30 @@ endmodule
drop(tree);
}
/// Header recovery (TODO §32) pinned where completion meets it: with a
/// half-typed parameter *above* the cursor, the module still has a scope,
/// so [`visible_symbols`] still answers from it — the parameters and ports
/// already typed are offered inside the very header being edited.
///
/// Before this round the broken header took the whole `Module` node with
/// it, the body re-parsed at file scope, and the scope chain covering this
/// offset held nothing at all.
#[test]
fn a_broken_header_still_completes_from_the_modules_scope() {
let top = "\
module top #(parameter W = , parameter DEPTH = 4) (
input logic clk_i,
output logic DE
);
logic w_local;
endmodule
";
let (_tree, ws, uri, position) = asking("brokenheader", top, "output logic DE");
let found = items(completions(&ws, &uri, position, true));
let item = find(&found, "DEPTH").expect("the parameter typed after the broken one");
assert_eq!(tier(item), TIER_SCOPE, "answered from the module's own scope");
}
/// The scope tier goes fuzzy too, with no mask table behind it — it is
/// the one tier computed per request.
#[test]
+14
View File
@@ -1894,6 +1894,20 @@ sub #(
}
}
/// The premise the "the accepted text must parse" probe above rests on:
/// the probe can still fail. Header recovery (TODO §32) widened what a
/// tolerant parse reads — a half-typed connection list is now a recovered
/// instantiation rather than a dead item — so the probe is only worth
/// asking while text that does not parse still says so.
#[test]
fn the_accepted_text_probe_still_reports_text_that_does_not_parse() {
let probe = "module lucisv_probe;\n logic clk;\n sub u_sub (.clk(\nendmodule\n";
assert!(
!vlog_parser::parse_source_tolerant(probe).1.is_empty(),
"recovery must not make a broken instantiation look clean"
);
}
#[test]
fn a_module_with_no_ports_ghosts_a_sane_instantiation() {
let top = "module top;\n bare \nendmodule\n";
+11
View File
@@ -456,6 +456,17 @@ mod tests {
}
}
/// The premise [`every_untouched_expansion_parses`] rests on: the probe
/// can still fail. Header recovery (TODO §32) widened what a tolerant
/// parse reads, and a probe that answered "clean" for everything would
/// pass that test while proving nothing.
#[test]
fn the_expansion_probe_still_reports_text_that_does_not_parse() {
let probe = "module p;\n always_comb begin\n case (sel\n end\nendmodule\n";
let (_, diagnostics) = vlog_parser::parse_source_tolerant(probe);
assert!(!diagnostics.is_empty(), "recovery must not make a broken expansion look clean");
}
#[test]
fn every_hole_is_a_tabstop_the_snippet_grammar_reads() {
// The editor-snippets lesson, restated for generated text: VS Code
+2 -3
View File
@@ -361,9 +361,8 @@ impl<'a> Fmt<'a> {
metas: impl Iterator<Item = Option<&'m Meta>>,
directives: &[ListDirective],
) -> Vec<bool> {
let mut breaks: Vec<bool> = metas
.map(|m| m.is_none_or(|m| !m.leading.is_empty() || !m.attrs.is_empty()))
.collect();
let mut breaks: Vec<bool> =
metas.map(|m| m.is_none_or(|m| !m.leading.is_empty() || !m.attrs.is_empty())).collect();
for d in directives {
if let Some(b) = breaks.get_mut(d.before) {
*b = true;
@@ -181,7 +181,12 @@ impl<'a> Parser<'a> {
}
let span = TextRange::empty(self.here());
let raw = RawText { text: String::new(), col: self.cur().col, span };
Ok(Stmt { meta: Meta::default(), kind: StmtKind::Error(raw), before_semi: Vec::new(), span })
Ok(Stmt {
meta: Meta::default(),
kind: StmtKind::Error(raw),
before_semi: Vec::new(),
span,
})
}
/// The condition between the brackets of an `if`, `while`, `repeat`,
+2 -1
View File
@@ -629,7 +629,8 @@ fn a_half_typed_formal_list_keeps_its_function() {
/// its shape and its then-branch.
#[test]
fn a_half_typed_if_condition_keeps_its_branch() {
let src = "module m;\n initial begin\n if (a &&\n x = 1;\n y = 2;\n end\nendmodule\n";
let src =
"module m;\n initial begin\n if (a &&\n x = 1;\n y = 2;\n end\nendmodule\n";
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 1, "{diags:?}");
let m = module_named(&file, "m");
+6 -4
View File
@@ -61,7 +61,7 @@ request.
| M7 | Semantic lints (`unused-signal`, `undriven-net`, `multiply-driven`) ship **off by default**. | linter-core / semantic-lints READMEs; blocked on topo §2.9-6 (workspace-wide "does any file mention this name"). | These are the lints RTL engineers want most; the index now has reference postings and `files_spelling`, so §2.9-6 is closer than when filed. |
| M8 | ~~Lint rules do not descend into verbatim regions~~ — **closed at 0.33.0 for what parses**, by construction: the rules read the reference table, and a structured assertion contributes ordinary references to it. A `signals.rs` `opaque_span` remains only for a region that fell back. | assertions / clocking-wave / sva-bodies READMEs. | Same root as C1; resolved with it. |
| ~~M9~~ | ~~Statement-level format fences (inside `always`, case items, port lists) and fences inside class bodies (topo §2.9-3).~~ — **closed at 0.34.0+ by TODO §31.** Class bodies and every statement *list* (`begin`…`end`, `fork`…`join*`, function/task bodies, `initial`/`always`/`final` bodies, a `case` item's block body, a statement fragment) are fenceable scopes; `--lines` still loses to a fence. Two of the three named places stay out, with reasons: port/parameter lists and `case` **label** lists print mid-line inside a `Group`, where `Doc::Verbatim` (column-0, break-forcing) cannot stand — that wants a new printer primitive, not a scan arm. Measured on OpenTitan, which has 9 fenced files: four now keep their fenced bytes, including a 110-line class-body region. | statement-fences README; format-fences / classes / shared-fence-filter READMEs amended. | Users protect hand-aligned tables inside procedural blocks; DV users protect them in classes. |
| M10 | Error recovery does not reach headers and lists (port lists, parameter lists, for-headers) — a half-typed port list yields a garbage tree. | error-recovery README (QA-confirmed). | Editing experience: diagnostics cascade while typing a header. |
| ~~M10~~ | ~~Error recovery does not reach headers and lists (port lists, parameter lists, for-headers) — a half-typed port list yields a garbage tree.~~ — **closed by TODO §32.** A list element that does not parse is now a `ListElem::Error` element of its own list and a statement header's broken condition an `ExprKind::Error`, so the module, function or instantiation keeps its name, the elements that were typed and its body: the QA shape that cost 3 items and 2 diagnostics costs 1 and 1, and the `wire w;` under a half-typed `sub u (.a(` is a sibling item again. Measured over the corpus truncated at each file's midpoint: **622 → 555 error nodes** (−11 %), while diagnostics rise 1 702 → 1 826 because the constructs that now survive report their own missing closers (`expected \`endmodule\`` +91) instead of vanishing into one node. | header-recovery README; error-recovery README amended. | Editing experience: diagnostics no longer cascade while typing a header, and the outline keeps the module. |
| M11 | Anonymous aggregate members (`enum {A,B} x;`) not symbols (topo §2.9-13); cast type `state_t'(0)` records no reference. | overlay-promotion README; probe: enum *typedef'd* members do work. | Partial: named enums navigate, anonymous ones do not. |
| M12 | No `lint` key in `lucisv.toml` (topo §2.9-4); no `--rules-doc`. | four READMEs. | Config surface, not language — but it gates per-project rule selection. |
| ~~M13~~ | ~~Modport method prototypes (`import task drive(int x);`), `const` task/function arguments, unnamed DPI formals.~~ — **closed at 0.33.0 by TODO §30.** Modport method prototypes parse, format, bind and span; unnamed DPI formals parse behind the DPI flag only (§35.5.5), print as their type alone and declare nothing. The `const` half was **misfiled**: `const ref` (§13.5.2's only `const` argument form) has parsed and formatted since the corpus shape landed — the probe found only one real gap, a comment written *between* `const` and `ref`, now its own slot. | interface-dpi-arms README; interfaces / dpi-export READMEs. | Real interface-class idioms; each was a small grammar arm. |
@@ -149,9 +149,11 @@ signal named only inside a property edits it, references list it, and the
"at least identifier occurrences" fallback the C1 row asked for was
overtaken rather than built (what the grammar cannot read still rewinds to
the byte-exact capture, and rename *names* those regions instead of going
quiet). What the tables above still leave open, by weight: M10 error recovery
inside headers and lists; the second half of
M12 (`--rules-doc`, §2.9-5); L3, L6, L9 and L10. M13's small
quiet). What the tables above still leave open, by weight: the second half of
M12 (`--rules-doc`, §2.9-5); L3, L6, L9 and L10. M10's error recovery inside
headers and lists is closed (TODO §32), with the narrowing recorded in its
row: a truncated file reports *more* diagnostics than before, because the
constructs that now survive say what closer they are missing. M13's small
interface/DPI grammar arms are closed (TODO §30) — with one narrowing
recorded there: a single `import` may carry one prototype, not a
comma-separated list of them. M9's format fences are closed too (TODO §31,
+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
+438 -15
View File
@@ -73,7 +73,8 @@ 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):** three
**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
@@ -115,18 +116,23 @@ decides, and a wrong hint is worse than none.
- [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`).
- [ ] 32.6 the completion pin — `visible_symbols` at a cursor inside a broken
header — **not written yet**.
- [ ] 32.6 re-check of the three validity probes (`inline.rs`,
`templates.rs`, `completion/tiers.rs`) — **not done**.
- [ ] 32.7 measurements: `perf.rs`'s `parse_tolerant` harness before/after, and
the truncated-corpus diagnostic census — **not run**.
- [ ] 32.7 docs: the error-recovery README's Assumptions sentence and its
inverted "Not done" line; `docs/coverage_gaps.md` M10; TODO §32 ticks —
**not done**.
- [ ] Gates: `cargo fmt -p` per crate, `cargo clippy --all-targets --workspace`,
`cargo test --workspace` counts, corpus 814/820 byte-identical, the
read-only opentitan sweep — **not run** (only the crate suites below).
- [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
@@ -231,10 +237,427 @@ then the full gates — `cargo fmt -p` per touched crate,
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
*(empty — QA has not run)*
### 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
*(reserved for the lead)*
**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.