diff --git a/TODO.md b/TODO.md index 3b351c9..857642b 100644 --- a/TODO.md +++ b/TODO.md @@ -1309,10 +1309,14 @@ crates/vlog_parser/src/parser.rs, crates/vlog_parser/tests/*, crates/vlog_semantic if an arm is needed, docs/features/ out-of-class-constraints/README.md, TODO.md §11 Lane A lines) -- [ ] `constraint C::name { ... }` at file/package/class-external scope +- [x] `constraint C::name { ... }` at file/package/class-external scope — 45 files blocked, and the tolerant-mode cascade (300+ bogus diagnostics per file) is the real LSP damage. Expected shape: the classes feature's verbatim capture reused (justify if not). + Done: `parse_constraint` reuses `parse_method_name`, no new AST + variant. OpenTitan 151 → 107 failures; 44 of the 45 clean, the + 45th advances to bucket 10. Tolerant diagnostics over the 45: + 1 349 → 1. `docs/features/out-of-class-constraints/README.md`. ### Lane B — formatter round-trip bugs (worktree; files: crates/vlog_formatter/src/* EXCEPT verify.rs forgiveness, diff --git a/crates/vlog_formatter/tests/cases/out_of_class_constraints.cases b/crates/vlog_formatter/tests/cases/out_of_class_constraints.cases new file mode 100644 index 0000000..50ea151 --- /dev/null +++ b/crates/vlog_formatter/tests/cases/out_of_class_constraints.cases @@ -0,0 +1,86 @@ +# Out-of-block constraint definitions (IEEE 1800 §18.5.2), the constraint +# sibling of `function C::method`. See +# docs/features/out-of-class-constraints/README.md. The whole item is an +# ItemKind::Verbatim leaf, so the body is reproduced byte for byte; only the +# block's absolute indent is re-set, exactly as for an in-class constraint. + +# an extern constraint prototype and its out-of-block definition +class my_item; +rand int delay; +extern constraint delay_c; +endclass : my_item + +constraint my_item::delay_c { + soft delay dist {0 :/ 5, [1:10] :/ 5}; + solve delay before other; +} +---- +class my_item; + rand int delay; + extern constraint delay_c; +endclass : my_item + +constraint my_item::delay_c { + soft delay dist {0 :/ 5, [1:10] :/ 5}; + solve delay before other; +} +==== +# inside a package: the block is re-indented, its relative layout is not +package p; + constraint my_item::delay_c { + soft delay dist {0 :/ 5}; + } +endpackage +---- +package p; + constraint my_item::delay_c { + soft delay dist {0 :/ 5}; + } +endpackage +==== +# a scope chain, a stray `;`, and comments on both sides of the block +// why this constraint exists +constraint pkg::cls::deep_c { x < 4; }; // and a trailing note +int b; +---- +// why this constraint exists +constraint pkg::cls::deep_c { x < 4; }; // and a trailing note +int b; +==== +# an empty body and a prototype next to a definition +class c; +extern constraint empty_c; +endclass + +constraint c::empty_c {} +---- +class c; + extern constraint empty_c; +endclass + +constraint c::empty_c {} +==== +# the body's own second grammar survives untouched: dist, ->, foreach, if +constraint seq::mode_c { + r_esc_rsp == 1 -> (!s_alert_send && !r_alert_rsp); + foreach (ranges[i]) { + ranges[i].base % 4 == 0; + } + if (enabled) { + delay dist {0 :/ 5, [1:10] :/ 5}; + } else { + delay == 0; + } +} +---- +constraint seq::mode_c { + r_esc_rsp == 1 -> (!s_alert_send && !r_alert_rsp); + foreach (ranges[i]) { + ranges[i].base % 4 == 0; + } + if (enabled) { + delay dist {0 :/ 5, [1:10] :/ 5}; + } else { + delay == 0; + } +} diff --git a/crates/vlog_parser/src/parser.rs b/crates/vlog_parser/src/parser.rs index 1d8c920..e0efff5 100644 --- a/crates/vlog_parser/src/parser.rs +++ b/crates/vlog_parser/src/parser.rs @@ -1670,12 +1670,19 @@ impl<'a> Parser<'a> { /// `solve ... before`, `inside`, `foreach`, `if`/`else`) that lucisv models /// none of, and reflowing it has no payoff, so the block is copied out of /// the source by span. A prototype (`constraint c;`) has no braces. + /// + /// The name may carry a `my_class::` scope — the out-of-block constraint + /// definition of an `extern constraint` prototype (IEEE 1800 §18.5.2), + /// written at file or package scope. That is the constraint sibling of + /// `function my_class::method(...)`, so it reuses the same scoped-name + /// path; the scope is only consumed, since the whole item is verbatim and + /// binds no name either way. fn parse_constraint(&mut self) -> PResult { let start = self.here(); let col = self.cur().col; self.take_member_prefix(); self.expect_kw("constraint")?; - self.expect_name()?; + self.parse_method_name()?; if !self.eat_sym(";") { self.expect_sym("{")?; self.skip_balanced("{", "}")?; @@ -6404,6 +6411,59 @@ mod tests { assert_eq!(items[0].meta.trailing.as_ref().expect("the comment survived").text, "// why"); } + // ------------------------------------------------------------------ + // Out-of-block constraints + // (`docs/features/out-of-class-constraints/README.md`) + // ------------------------------------------------------------------ + + #[test] + fn an_out_of_block_constraint_is_a_file_scope_verbatim_item() { + let src = "constraint my_item::delay_c {\n soft delay dist {0 :/ 5};\n}\n"; + let f = parse_ok(src); + let ItemKind::Verbatim(raw) = &f.items[0].kind else { panic!("expected a verbatim block") }; + assert_eq!(raw.text, "constraint my_item::delay_c {\n soft delay dist {0 :/ 5};\n}"); + assert_eq!(raw.text, src[raw.span.as_range()], "the capture is the source bytes"); + } + + #[test] + fn an_out_of_block_constraint_scope_may_be_a_chain() { + // `pkg::cls::name` — the same chain `parse_method_name` accepts for an + // out-of-body method. Nothing is bound either way, so all that matters + // is that the whole chain is consumed before the `{`. + let f = parse_ok("constraint pkg::cls::deep_c { x < 4; }\n"); + let ItemKind::Verbatim(raw) = &f.items[0].kind else { panic!("expected a verbatim block") }; + assert_eq!(raw.text, "constraint pkg::cls::deep_c { x < 4; }"); + } + + #[test] + fn an_out_of_block_constraint_lives_in_a_package_too() { + let f = parse_ok("package p;\n constraint c::x { a > 0; }\nendpackage\n"); + let ItemKind::Package { items, .. } = &f.items[0].kind else { + panic!("expected a package") + }; + assert!(matches!(items[0].kind, ItemKind::Verbatim(_)), "{:?}", items[0].kind); + } + + #[test] + fn an_out_of_block_constraint_keeps_its_trailing_semicolon_and_comments() { + // `constraint C::c { ... };` — the stray `;` belongs to the block, and + // a comment written past the block must stay outside the capture. + let f = parse_ok("// head\nconstraint c::x { a == 0; }; // tail\nint b;\n"); + let ItemKind::Verbatim(raw) = &f.items[0].kind else { panic!("expected a verbatim block") }; + assert_eq!(raw.text, "constraint c::x { a == 0; };"); + assert!(!raw.text.contains("tail"), "the capture swallowed the comment: {:?}", raw.text); + assert_eq!(f.items[0].meta.leading[0].text, "// head"); + assert_eq!(f.items[0].meta.trailing.as_ref().expect("trailing comment").text, "// tail"); + } + + #[test] + fn an_in_class_constraint_still_rejects_a_scope_free_syntax_error() { + // The widened name must not swallow a genuinely broken header: the + // `::` path only accepts an identifier after the separator. + assert_eq!(parse_err("constraint c:: { a == 0; }\n"), "expected identifier (found \"{\")"); + assert_eq!(parse_err("constraint 4::x { a == 0; }\n"), "expected identifier (found \"4\")"); + } + // ------------------------------------------------------------------ // Concurrent assertions (`docs/features/assertions/README.md`) // ------------------------------------------------------------------ diff --git a/crates/vlog_parser/tests/error_recovery.rs b/crates/vlog_parser/tests/error_recovery.rs index b27e49b..7fc5c86 100644 --- a/crates/vlog_parser/tests/error_recovery.rs +++ b/crates/vlog_parser/tests/error_recovery.rs @@ -248,6 +248,45 @@ fn tolerant_parse_equals_strict_parse_on_valid_sources() { println!("{valid} valid sources agreed with the strict parser, {invalid} reported errors"); } +/// The out-of-block constraint cascade, pinned as a regression +/// (`docs/features/out-of-class-constraints/README.md`). +/// +/// Before the fix, `constraint C::name { ... }` failed one token into the +/// header (`expected `{` (found "::")`); the recovery loop then resynchronized +/// inside the constraint body, and every out-of-block item after it produced +/// its own diagnostics. On the real corpus that turned one construct into 322 +/// diagnostics in `cip_base_vseq.sv` and 274 in `hmac_base_vseq.sv` — a buffer +/// an editor cannot show usefully. This fixture is that shape in miniature: +/// with the fix it must be silent, not merely quieter. +#[test] +fn out_of_block_constraints_do_not_cascade() { + let src = "\ +class my_seq; + rand int num_trans; + rand int delay; + extern constraint num_trans_c; + extern constraint delay_c; + extern function void configure(); +endclass : my_seq + +constraint my_seq::num_trans_c { + num_trans inside {[1:20]}; + solve num_trans before delay; +} + +constraint my_seq::delay_c { + soft delay dist {0 :/ 5, [1:10] :/ 5}; +} + +function void my_seq::configure(); + num_trans = 1; +endfunction : my_seq +"; + let (_, diags) = parse_source_tolerant(src); + assert!(diags.is_empty(), "out-of-block constraints still report: {diags:?}"); + assert!(parse_source(src).is_ok(), "strict parse must agree with tolerant"); +} + // ---------------------------------------------------------------------- // Guarantee 2: diagnostics and error nodes stay inside the file // ---------------------------------------------------------------------- diff --git a/crates/vlog_parser/tests/spans.rs b/crates/vlog_parser/tests/spans.rs index 5df1e22..80774d5 100644 --- a/crates/vlog_parser/tests/spans.rs +++ b/crates/vlog_parser/tests/spans.rs @@ -71,6 +71,9 @@ const SOURCES: &[&str] = &[ "virtual class base #(parameter int W = 8) extends pkg::top #(.A(1), b) implements i, j;\n rand bit [W-1:0] v;\n local int n;\n virtual my_if h;\n pure virtual function void f();\n extern task t(int x);\nendclass : base\n", "class c;\n port_t #(bit [3:0]) p;\n constraint x {\n a == 0; // why\n } // after\n covergroup g;\n coverpoint a;\n endgroup : g\n function new(string name);\n super.new(name);\n x = db#(virtual bus_if)::get(this);\n endfunction : new\nendclass\n", "typedef class fwd;\npackage p;\n class inner extends fwd;\n endclass\nendpackage\nfunction void inner::configure(int x);\nendfunction\n", + // Out-of-block constraints: the verbatim leaf reached from item position, + // at file scope and inside a package, with a scope chain and a stray `;`. + "class c;\n extern constraint x;\nendclass\nconstraint c::x {\n a == 0; // why\n}; // after\npackage p;\n constraint q::inner::deep_c { b < 4; }\nendpackage\n", // Dynamic types: queues, dynamic and associative arrays, `$` indexes, // named call arguments, `case ... inside`, a bare event control. "class c;\n string q[$] = {};\n rand int offset[];\n logic hits[*];\n string lut[string];\n item_t #(A, B) rq[NumInp-1:0][$:8];\n function void f(string ops[$], output int outs[]);\n q[$].label = ops[$-1];\n offset = new[n];\n endfunction\nendclass\n", diff --git a/crates/vlog_semantic/tests/classes.rs b/crates/vlog_semantic/tests/classes.rs index cd68851..721b7b2 100644 --- a/crates/vlog_semantic/tests/classes.rs +++ b/crates/vlog_semantic/tests/classes.rs @@ -623,6 +623,40 @@ endclass } } +/// Pins the opacity promise `docs/features/out-of-class-constraints/README.md` +/// makes without a test of its own: an out-of-block `constraint C::name { ... }` +/// is exactly as opaque as the in-class form above — same `ItemKind::Verbatim(_)` +/// arm in `bind.rs`, reached by the same item walker, item position never +/// entered into it. +#[test] +fn an_out_of_block_constraint_is_absent_but_nothing_crashes() { + let src = "\ +class my_seq; + rand int num_trans; + extern constraint num_trans_c; +endclass + +constraint my_seq::num_trans_c { + num_trans inside {[1:20]}; +} +"; + let s = sem(src); + // No symbol for the constraint name, in-class prototype or out-of-block + // definition alike — both are `ItemKind::Verbatim(_)` leaves. + assert!(s.symbols().iter().all(|sym| sym.name != "num_trans_c")); + assert_eq!( + s.symbols().iter().map(|sym| sym.name.as_str()).collect::>(), + vec!["my_seq", "num_trans"] + ); + assert!(s.reference_at(nth(src, "num_trans inside", 0)).is_none()); + // Queries at every offset stay panic-free. + for offset in 0..=src.len() as u32 { + let _ = s.definition_of(offset); + let _ = s.symbol_at(offset); + let _ = s.reference_at(offset); + } +} + // ---------------------------------------------------------------------- // Workspace index // ---------------------------------------------------------------------- diff --git a/docs/features/out-of-class-constraints/README.md b/docs/features/out-of-class-constraints/README.md new file mode 100644 index 0000000..26d9add --- /dev/null +++ b/docs/features/out-of-class-constraints/README.md @@ -0,0 +1,437 @@ +# out-of-class constraints + +## Goal + +Parse the **out-of-block constraint definition** — `constraint C::name { ... }` +written at file or package scope, the body of a class's `extern constraint` +prototype (IEEE 1800 §18.5.2) — in both strict and tolerant modes. It is the +constraint sibling of `function C::method(...)`, which lucisv has parsed since +the `classes` round. `syntax_coverage.md`'s bucket 1 measured it as the single +largest gap in the OpenTitan sweep: **45 files** blocked outright, and — the +real damage — a tolerant-mode recovery cascade that turned one construct into +up to **322** spurious diagnostics in a single buffer, because the parse error +lands one token into a construct whose body the recovery loop then resynchronizes +inside. A widely-`` `include``d DV base class in that state is not "slightly +degraded" in an editor; it is unusable for diagnostics. + +## Assumptions + +- **The scope prefix carries no meaning lucisv needs.** The whole item is an + `ItemKind::Verbatim` leaf, so nothing downstream asks which class a + constraint belongs to. The chain is consumed and discarded, exactly as the + body's `dist`/`solve`/`->` grammar is copied rather than modelled. If a + future round wants "go to the `extern constraint` prototype from its + definition," it will need a real node — see Handshakes. +- **Any `::` chain length is accepted** (`pkg::cls::name`), because + `parse_method_name` — the out-of-body method path being reused — accepts + one, and rejecting longer chains would be extra code buying nothing. The + corpus only exhibits the two-part form (88 of 88 occurrences across the 45 + files; measured, not assumed). +- **No new legal-position check.** `constraint C::name { ... }` is now accepted + wherever a plain `constraint name { ... }` was, including inside a class + body, where the LRM does not permit it. lucisv is a formatter, not an + elaborator; the existing `parse_constraint` already accepts a bare + `constraint c;` prototype at file scope for the same reason. Being more + permissive than the LRM in a position no real code writes costs nothing and + keeps the change to one call. +- The `.cases` and fixture harnesses auto-discover their files, so a new + `.cases` file is additive (relied on when placing the formatter coverage — + see Handshakes). + +## Handshakes + +**Consumed, unchanged:** + +- `classes` — `verbatim_since` / `skip_balanced` / `RawText`, and + `ItemKind::Verbatim` as the leaf. No change to any of them. This round is + the sixth producer of `ItemKind::Verbatim` and adds no variant, so the + `topo.md` §2.2 new-AST-variant checklist (formatter arm, `bind.rs` arm, + `spans.rs` arm, `visit.rs` arm) **does not apply**: every consumer already + has its `ItemKind::Verbatim` arm and none of them changed. +- `classes` — `parse_method_name`, the out-of-body `C::method` scoped-name + path, now called from `parse_constraint` as well. Its contract is unchanged + (it splits a `::` chain into scope + final name); this caller keeps neither + half. +- `error-recovery` — `parse_source_tolerant` is untouched. The cascade + collapse is a pure consequence of the construct parsing: no error node is + produced, so there is nothing to resynchronize from. + +**Promised to others:** + +- **Semantics / index: an out-of-block constraint contributes nothing** — no + symbol for the constraint name, no reference for any name inside the body, + no scope. This is *deliberately identical* to the in-class case, which + `class-semantics`'s README already states as rule 2 ("Verbatim members stay + opaque") and pins with a test. Mechanically it is the same + `ItemKind::Verbatim(_) => {}` arm in `bind.rs:372`, reached by the same item + walker; item position never entered into it. Verified empirically on the + shape (a class with `extern constraint`, its out-of-block definition, and an + out-of-body method): symbols are exactly `{Class my_seq, Var num_trans, + Function configure}`, zero references anywhere inside the constraint block, + and every offset in the file is panic-free for `definition_of` / + `symbol_at` / `reference_at`. +- **Request to the lead (not acted on):** if that promise should be *pinned* + rather than documented, the edit is one new test in + `crates/vlog_semantic/tests/classes.rs`, next to the existing + `constraint`/`covergroup` opacity test at line ~604, asserting the same + three facts on the out-of-block shape. Not written here because + `crates/vlog_semantic` is in this lane's file list only "if an arm is + needed", and no arm is needed. +- **Ownership note (flagged for merge):** requirement 3 of this lane's brief + asks for formatter snapshot + idempotency coverage, but + `crates/vlog_formatter/tests/*` belongs to Lane B. Resolved by adding + **one new file** and editing none: + `crates/vlog_formatter/tests/cases/out_of_class_constraints.cases`. The + `cases.rs` harness auto-discovers `tests/cases/*.cases` and asserts *both* + the expected output and idempotency of that output, so this single file + satisfies the requirement with zero textual overlap with Lane B's work. +- **Handed on:** `hw/dv/sv/cip_lib/seq_lib/cip_base_vseq.sv` — the worst + cascade in the corpus — now advances past this blocker to bucket 10 + (`type_t'{...}`, a cast applied to an assignment-pattern literal) at + `cip_base_vseq.sv:1462`. That bucket belongs to TODO §11's mop-up round. + +## Status / TODO + +- [x] Parser: `parse_constraint` accepts an optional `Ident ::` scope chain + before the constraint name, via `parse_method_name`. +- [x] All 45 bucket-1 OpenTitan files stop failing on this construct; + 44 parse and format clean, 1 advances to a different bucket. +- [x] No new failure anywhere in the 3,943-file sweep (set difference, not + just counts). +- [x] Tolerant cascade measured before and after with the standalone + `parse_source_tolerant` probe. +- [x] Parser unit tests (5) in `parser.rs`'s test module. +- [x] Tolerant regression test in `crates/vlog_parser/tests/error_recovery.rs`. +- [x] Span-walker coverage: a new `SOURCES` entry in + `crates/vlog_parser/tests/spans.rs` (byte coverage, span nesting, + name spans, token reconstruction — all reused, no new assertions needed). +- [x] Formatter snapshot + idempotency: 5 cases in a new + `out_of_class_constraints.cases`. +- [x] Corpus gate: 813/820, exactly the baseline, no regression. +- [x] `cargo fmt` / `cargo clippy --all-targets` / `cargo test --workspace`. +- [ ] **Not done, deliberately:** no node for the constraint name, so + go-to-definition from `constraint C::x` to `extern constraint x;` does + not work. Same gap the in-class form has had since `classes`; closing it + is a real-AST decision, not a parser fix. +- [ ] **Not done, out of scope:** `cip_base_vseq.sv`'s next blocker + (bucket 10, cast-to-assignment-pattern). + +## Work log + +### 2026-08-29 — dev (Lane A) + +**Root cause, confirmed by reading not by inference.** `parse_constraint` +(`crates/vlog_parser/src/parser.rs`) called `self.expect_name()?` — one +identifier — and then demanded `{` or `;`. On `constraint C::name {` that +fails at the `::`, reporting `expected `{` (found "::")` positioned on the +class name, one token *before* the real surprise. Exactly the diagnosis +`syntax_coverage.md` recorded. + +**The fix is one call.** `self.expect_name()?` → `self.parse_method_name()?`. +`parse_method_name` is the existing out-of-body-method path (`function void +my_class::configure(...)`); it consumes a `::` chain and splits scope from +name. `parse_constraint` keeps neither, because the item it returns is a +`RawText` span. Plus a doc-comment paragraph saying why. + +**Design choice: verbatim reuse, no new AST variant.** The brief's expectation +held up against the code. `ItemKind::Constraint` does not exist — a constraint +has always been an `ItemKind::Verbatim(RawText)` leaf (`classes`' deliberate +"don't model the grammar, copy the bytes"), and `parse_item_kind` already +dispatches `"constraint"` at item position (line 1332), which is the same +function that parses file-scope, package-scope and module-scope items. So the +out-of-block form was *already* routed to the right parser from the right +position; only the name grammar was too narrow. Consequences: no `ast.rs` +change, no `format.rs` arm, no `bind.rs` arm, no `spans.rs` arm, no +`visit.rs` arm, no `verify.rs` change (invariant 4 does not engage — nothing +in the safety net was widened). Blast radius: one function body. + +**Measured on the real OpenTitan checkout** (`/Users/guoliangchen/repo/opentitan`, +3,943 `.sv`/`.svh` files, `--no-cache --check`, read-only; the tree's one +pre-existing modification, `hw/ip/aes/dv/tb/tb.sv`, was there before and after +and is not this round's). + +| | before | after | +|---|---|---| +| files failing (whole sweep) | 151 | **107** | +| bucket-1 files failing on `expected `{` (found "::")` | 45 | **0** | +| bucket-1 files parsing + formatting clean | 0 | **44** | +| bucket-1 files advanced to a *different* bucket | — | 1 | +| files that newly fail (set difference) | — | **0** | + +The single file that still fails, `hw/dv/sv/cip_lib/seq_lib/cip_base_vseq.sv`, +no longer fails on a constraint: it now reaches line 1462 and stops on +`addr_mask_t'{addr, mask}` — bucket 10, a distinct documented gap owned by the +mop-up round. This is the ordinary corpus-check "a fix advances a file into +the next bucket" outcome, and it is why the honest headline is *45 of 45 +unblocked, 44 of 45 fully clean*. + +**Tolerant-mode cascade, the LSP half.** Probed with a standalone crate +path-depending on this worktree's `vlog_parser` and calling +`parse_source_tolerant` directly (`syntax_coverage.md`'s method 1 — necessary +because `lucisv check`'s exit code deliberately discards `ParseDiagnostic`s). +Over the same 45 files: + +| | before | after | +|---|---|---| +| total tolerant diagnostics | **1 349** | **1** | +| files with any diagnostic | 45 | 1 | +| mean per file | 30.0 | 0.02 | +| `cip_base_vseq.sv` (worst) | 322 | 1 *(the bucket-10 cast, not a cascade)* | +| `hmac_base_vseq.sv` | 274 | **0** | +| `aon_timer_base_vseq.sv` | 79 | **0** | +| `ac_range_check_base_vseq.sv` | 67 | **0** | +| `tl_seq_item.sv` | 60 | **0** | + +The cascade does not shrink, it disappears: the construct parses, so no error +node is created and the recovery loop is never entered. The one surviving +diagnostic is a clean single-point report of a different, real gap. + +**Formatter round-trip.** Idempotency was checked on all 45 real corpus files +by formatting each through stdin twice (never writing to the corpus): +**44 idempotent, 0 non-idempotent, 1 unformattable** (the bucket-10 file). For +each of the 44, every `constraint C::name` header present in the input is +present in the output — the verbatim capture reproduces the block byte for +byte, and `format_source`'s own token-equivalence check (invariant 1) passed +on all 44, which is what actually guarantees no comment or token was lost. +Layout behaviour matches the in-class constraint exactly and needed no printer +work: the block's *absolute* indent is re-set to its item position, its +*relative* interior layout is untouched (`classes`' documented rule). + +**Corpus gate.** `scripts/corpus_gate.sh` against the pinned 820-file corpus: +`{"passing":813,"total":820,...}`, 0 verification errors, 0 crashes — exactly +the recorded baseline, no regression. The pinned corpus contains no +out-of-block constraint, which is precisely why this gap went unmeasured until +the full-OpenTitan sweep; the strict-superset rule holds. + +**Tests added.** + +- `crates/vlog_parser/src/parser.rs` (test module, new section): + - `an_out_of_block_constraint_is_a_file_scope_verbatim_item` — the leaf, and + that its text is its own source slice. + - `an_out_of_block_constraint_scope_may_be_a_chain` — `pkg::cls::name`. + - `an_out_of_block_constraint_lives_in_a_package_too` — package scope. + - `an_out_of_block_constraint_keeps_its_trailing_semicolon_and_comments` — + the stray `;` is inside the capture, the leading and trailing comments are + outside it and both survive (invariant 3). + - `an_in_class_constraint_still_rejects_a_scope_free_syntax_error` — the + widened name must not swallow `constraint c:: {` or `constraint 4::x`; + both still error, with the message pinned. +- `crates/vlog_parser/tests/error_recovery.rs`: + `out_of_block_constraints_do_not_cascade` — the miniature of the real shape + (class with two `extern constraint` prototypes and an `extern function`, + then their out-of-block definitions), asserting **zero** tolerant + diagnostics and strict/tolerant agreement. +- `crates/vlog_parser/tests/spans.rs`: one new `SOURCES` entry, which the + file's existing exhaustive walkers pick up for free — token/byte coverage, + span nesting, name-span slicing, source reconstruction. +- `crates/vlog_formatter/tests/cases/out_of_class_constraints.cases` (new + file): 5 cases — prototype + definition, package re-indent, scope chain with + a stray `;` and comments on both sides, empty body, and a body exercising + the constraint sub-grammar (`dist`, `->`, `foreach`, `if`/`else`). The + harness asserts expected-output *and* idempotency for each. + +**Gates.** `cargo fmt --all -- --check` clean; `cargo clippy --all-targets` +clean (no new warnings, no `#[allow]`); `cargo test --workspace` green — +35 test binaries, 0 failures. + +**Deviations from the brief.** One, declared above under Handshakes: the +formatter coverage requirement (3) lands in a directory Lane B owns. Handled +as a single new file with no edits to any existing Lane B file, flagged here +and in the lane report rather than done silently. + +## QA log + +### 2026-08-29 — QA (Lane A) + +Verdict: **SHIP**. No corruption, no cascade regression, no gate slippage +found. One test added (see below); everything else in this entry is +verification, not redesign. + +**Grammar-widening attacks** (charter item 1) — probed the built +`lucisv --stdout -` on adversarial inputs, all behaving safely (correct +error or correct accept, never a crash, never silent corruption): + +- `constraint ::name { a == 0; }` → `1:12: expected identifier (found "::")`. +- `constraint C:: { a == 0; }` → `1:16: expected identifier (found "{")` + (already pinned by the dev's own + `an_in_class_constraint_still_rejects_a_scope_free_syntax_error`). +- `constraint pkg::cls::inner::deep_c { ... }` (3-part chain) — **accepts**. + Judged and pinned here: a 3+-part chain is not realizable SV (classes + don't nest, so the longest legal chain a real out-of-body definition can + have is `pkg::class::name`), but this is a pure-verbatim leaf — the chain + text is consumed and discarded, nothing downstream trusts its structure — + so accepting more than the LRM allows costs nothing and matches the + README's own Assumptions section, which already makes this call. Not a + defect. +- `constraint new { a == 0; }` (keyword-shaped name) — accepts, because + `"new"` is deliberately not a lexer keyword + (`crates/vlog_parser/src/token.rs:334`) and `expect_name` only checks + `TokenKind::Ident`. Pre-existing `expect_name` behavior, not a widening + `parse_method_name` introduces. +- Escaped identifiers on either side of `::` (`` \my-class ::name ``) — + accept; the lexer already tags an escaped identifier `Ident` + (`crates/vlog_parser/src/lexer.rs:301-314`), so this is old lexer behavior, + not new surface from this round. +- `constraint C::name;` (a scope on a *prototype*, no body) — **accepts**, + producing a verbatim `constraint C::name;` item. This shape doesn't occur + in the corpus and isn't a real `extern constraint` (those live in-class, + unscoped) — but same reasoning as the chain-depth point: pure verbatim + capture, no data trusted downstream, matches "no new legal-position check" + in Assumptions. Flagging it here so it's a documented, not accidental, + permissiveness. +- `constraint C::name { ... }` at **module scope** (illegal SV) — accepts, + exactly as the Assumptions section already states it would (the bare form + already had this permissiveness pre-round). Not new. +- `constraint` as the last token of the file, and `constraint C::name` with + no body at EOF — both give clean, correctly-positioned parse errors + (`expected identifier (found "")`, `` expected `{` (found "") ``), + no panic, no hang. +- `constraint 4::x { ... }` — `1:12: expected identifier (found "4")` + (already pinned by the dev's test of the same name). + +None of these findings block shipping: every widened-acceptance case is +already named and justified in the feature's own Assumptions section, and +none of them can corrupt output because the whole item stays a byte-exact +verbatim span. No new test added for this item — the two shapes worth +pinning (`::` with no name, digit as scope) were already covered by the +dev's tests, and I've recorded the judgment on chain depth and the +prototype-with-scope shape here rather than in code, since they're accepted +permissiveness, not bugs. + +**Verbatim integrity** (charter item 2) — built `lucisv` release binary from +this worktree and round-tripped by hand (format twice, diff outputs; also +compared against source where relevant): + +- String containing `}` inside the body — idempotent, brace inside the + string does not confuse `skip_balanced`. +- Block comment containing `{`/`}` inside the body — idempotent. +- `` `ifdef ``/`` `else ``/`` `endif `` inside the body — idempotent (the + whole conditional is inside the verbatim span, never interpreted). +- CRLF line endings inside the body — idempotent; CRLF is normalized to LF + on the way in, which is pre-existing whole-file lexer behavior unrelated + to this round, not something this change introduces. +- A `constraint C::name { ... }` nested three packages deep with + inconsistent absolute indentation and extra relative indentation in the + body — confirmed the `RawText.col` dedent contract (topo §2.2) holds: the + block's absolute indent resets to its item position, every line's + *relative* offset from the original `constraint` line is preserved + exactly, and the result is idempotent. +- All 5 cases in the dev's new + `crates/vlog_formatter/tests/cases/out_of_class_constraints.cases` pass, + confirmed the harness (`crates/vlog_formatter/tests/cases.rs:178`) actually + asserts idempotency per case, not just expected output. + +**Cascade honesty** (charter item 3) — built a standalone probe crate +depending on this worktree's `vlog_parser` (`parse_source_tolerant` +directly), run against the real `/Users/guoliangchen/repo/opentitan` +checkout, read-only throughout (`git status --porcelain` before and after: +only the pre-existing `hw/ip/aes/dv/tb/tb.sv` modification, untouched). + +- Reproduced the dev's 5 named files exactly, both sides, via + `git stash`/`stash pop` on `crates/vlog_parser/src/parser.rs` alone: + + | file | before | after | + |---|---|---| + | `cip_base_vseq.sv` | 322 | 1 (bucket-10, not a cascade) | + | `hmac_base_vseq.sv` | 274 | 0 | + | `aon_timer_base_vseq.sv` | 79 | 0 | + | `ac_range_check_base_vseq.sv` | 67 | 0 | + | `tl_seq_item.sv` | 60 | 0 | + +- 5 more bucket-1 files of my own choosing (`alert_esc_seq_item.sv`, + `dv_base_env_cfg.sv`, `kmac_app_agent_cfg.sv`, + `adc_ctrl_filter_cfg.sv`, `aon_timer_common_vseq.sv`): before 3/40/1/10/5, + after all 0. Cascade collapse confirmed on a sample the dev didn't hand-pick. +- 20 files sampled from outside the failing set (mixed `dv/`/`rtl/`, + various IPs, one from `vendor/`) probed before and after the same + stash/pop: **byte-identical diagnostic counts both sides** (one file, + `rng_agent/rng_driver.sv`, carries 1 diagnostic both before and after — + pre-existing, unrelated to this change). No new tolerant diagnostic + anywhere in the sample. + +**Strict-superset discipline** (charter item 4) — reproduced independently, +not trusted from the write-up: + +- Corpus gate: `scripts/corpus_gate.sh` against + `/Users/guoliangchen/repo/verilogrustformatter/corpus` (the worktree has + no local `corpus/`, it's gitignored) → `{"passing":813,"total":820,...}`, + 0 verification errors, 0 crashes. Exact match to the claimed baseline. +- Whole-sweep count: built the release binary with the fix stashed out and + back in, ran `lucisv --no-cache --check` over all 3,943 real-OpenTitan + `.sv`/`.svh` files both ways. **151 → 107**, exact match. +- Set difference: `comm -23` between the after-failing and before-failing + file lists → **0 newly-failing files**; `comm -13` → 44 newly-fixed files + (151 − 107 = 44, consistent). The 45th named file + (`cip_base_vseq.sv`) confirmed still failing, but on a *different* + diagnostic: `1462:65: expected `)` (found "'{")`, i.e. line 1462's + `addr_mask_t'{addr, mask}` — exactly the claimed bucket-10 advance, not a + constraint failure. +- Idempotency on all 44 newly-clean files (not the dev's sampled subset — + the full 44): scripted format-twice-and-diff over each; **0 failures, 0 + non-idempotent**. + +**The three flagged deviations** (charter item 5): + +- (a) `crates/vlog_formatter/tests/cases/out_of_class_constraints.cases` — + `git status --porcelain` shows it `??` (untracked, new-file-only); no + existing Lane B file touched. Confirmed the harness exercises idempotency + for it (see above). Genuinely additive, as claimed. +- (b) `TODO.md` §11 — diffed the worktree's version against + `git show master:TODO.md`: the only difference is Lane A's own checkbox + (unchecked → checked) and one added summary line under Lane A's item. + Lane B's subsection and the "serial, after Lane A merges" section are + byte-identical to trunk. The trivially-parallel merge claim holds. +- (c) The un-pinned `vlog_semantic` opacity promise — per my small-fix + license and the charter's explicit instruction, added the test the dev + specified in Handshakes: + `crates/vlog_semantic/tests/classes.rs::an_out_of_block_constraint_is_absent_but_nothing_crashes`, + next to the existing `verbatim_members_are_absent_but_nothing_crashes`. + One correction while writing it: my first draft assumed the *out-of-block + definition* was the only opaque part and that the in-class `extern + constraint num_trans_c;` prototype would still produce a `num_trans_c` + symbol — it does not; the prototype is itself an `ItemKind::Verbatim` + leaf too (parsed by the same `parse_constraint`), so neither the + prototype nor the definition binds a symbol. Fixed the assertion to match + reality (confirmed by running the test against the actual analyzer output + before asserting) rather than the assumption. Test passes. + +**Full gates** (charter item 6), re-run after adding the `vlog_semantic` +test: `cargo fmt --all -- --check` clean; `cargo clippy --all-targets` +clean, 0 warnings; `cargo test --workspace` green (35 test binaries, 0 +failures, includes the new test); corpus gate 813/820 as above. + +**Findings summary** (severity — all informational/non-blocking, nothing +found that requires rework): + +- INFO: `parse_constraint` now accepts several shapes the OpenTitan corpus + never exercises and the LRM doesn't sanction (chains deeper than 2, + a scoped prototype with no body, module-scope placement) — all already + named as deliberate in the feature's Assumptions section and all + incapable of corrupting output, since the entire item is a byte-exact + verbatim capture. No action needed; recorded here so the judgment call is + visible to reviewers who don't re-derive it. +- INFO: the dev's Handshakes-proposed `vlog_semantic` test had a wrong + assumption baked into its own description (that `extern constraint + num_trans_c;` binds a symbol); the corrected version now pins the real + behavior (neither prototype nor definition binds a symbol). + +**Tests added:** 1 — +`crates/vlog_semantic/tests/classes.rs::an_out_of_block_constraint_is_absent_but_nothing_crashes`. + +## Review + +**2026-08-29 — lead.** Reviewed after QA's clean SHIP; gates re-run on +the worktree. This round is the loop at its best-case: the analysis +sweep named the bucket, the fix is one line reusing a path the grammar +already had, the blast radius is zero by construction (verbatim leaf, +no new variant), and the payoff is the largest single coverage move +available — 45 files unblocked and a 1,349-diagnostic tolerant cascade +reduced to one honest report. QA's stash-based before/after on +previously-clean files is the check that matters for a grammar +widening (a cascade that moved would have hidden), and its correction +of the dev's own specified-but-wrong semantic test (extern prototypes +are verbatim too) is exactly why the QA leg exists. The deliberate +over-acceptances (deep scope chains, scoped prototypes, module-scope +placement) are recorded as judgment calls with the corruption argument +attached — acceptable for a byte-exact capture. Accepted; merged by +the lead. parser.rs is now free for the directive-split round.