diff --git a/docs/features/ansi-first-port/README.md b/docs/features/ansi-first-port/README.md index 2678149..cd9a3e6 100644 --- a/docs/features/ansi-first-port/README.md +++ b/docs/features/ansi-first-port/README.md @@ -105,10 +105,15 @@ its name, so it reports `iface_bus.mst` as the type with no change either. itself. It is a different production, none of the three filed shapes needs it, and it wants a `DataType` that can say "any interface", which is a modelling question this round should not answer in passing. -- [ ] **Not done, deliberately: `virtual bus_if.mp v;`** — a modport-qualified - virtual interface in a *declaration* (§25.9). Reaching it means teaching - `parse_opt_data_type` about the dot, which changes how an identifier is - read in every position; it needs its own round and its own attack tests. +- [x] ~~**Not done, deliberately: `virtual bus_if.mp v;`**~~ — delivered by + the testbench-mopup round (2026-08-29): `at_modport_port` — this + feature's own gate — is reused at the two `virtual` positions, so the + dot is read only where a modport can legally follow, exactly the + narrow reading this item said a broad `parse_opt_data_type` change + would violate. The pinning test here was amended in the same round + (`the_two_shapes_left_open_by_ansi_first_port_still_refuse` still + pins what genuinely remains open). See + `docs/features/testbench-mopup/README.md`. - [ ] **Not done, pre-existing: `module m (a[3], b);`** — a non-ANSI port with a bit-select. It failed before this round and fails identically after (pinned by `a_broken_header_still_reports_its_own_token`), and it is not diff --git a/editors/vscode/CHANGELOG.md b/editors/vscode/CHANGELOG.md index d6fb27a..e898758 100644 --- a/editors/vscode/CHANGELOG.md +++ b/editors/vscode/CHANGELOG.md @@ -5,26 +5,6 @@ for you. The extension and its bundled language server share one version number; the full engineering notes live in the [project changelog](https://git.luci.ooo/lucio/lucisv/src/branch/master/CHANGELOG.md). -## Unreleased - -- Added a dedicated **lucisv Hierarchy** Activity Bar view with a persistent - fuzzy search field for module and instance names, alphabetical instance - paths, exact source navigation, full-path copy, definition/instance actions, - yellow workspace bookmarks, and split-right definition opening. -- Every level of the hierarchy starts collapsed; nothing expands on its own, - and what you open stays open across a refresh or a rescan. -- Searching the hierarchy runs entirely in memory over a prebuilt name index: - it never asks the server per keystroke and never rebuilds the tree. Results - are ranked and capped, with a count of the matches not shown. -- The workspace index now retains each individual instance name and source - span while preserving the existing statement-level call-hierarchy and code- - lens counts, and it records the editor positions of every module declaration - and instance — so the hierarchy snapshot reads no files at all. On a - 4 000-file workspace the snapshot went from ~300 ms and 11.6 MB to ~40 ms - and 2.3 MB, and a go-to-definition sent behind one no longer waits a - quarter of a second. The index cache rebuilds once because its facts format - changed. - ## 0.16.0 — 2026-08-29 The testbench-syntax release. @@ -50,9 +30,11 @@ The interactive-latency release. per keystroke, and occurrence highlighting actually works on cross-file names. - **A new design-hierarchy sidebar** (contributed by codex): modules - and their instances in the Activity Bar, instant search over the - whole design, bookmarks, click-to-jump. Collapsed by default; your - expansion survives refreshes. + and their instances in the Activity Bar, instant in-memory search + over the whole design (ranked, capped, never per-keystroke to the + server), workspace bookmarks, full-path copy, and split-right + definition opening. Collapsed by default; your expansion survives + refreshes. - **Out-of-box answers:** `lucisv.index.scopeDepth` now defaults to 2, so opening a file indexes its whole block — cross-file hover, definition and references work immediately. Set it to 0 for the old diff --git a/syntax_coverage.md b/syntax_coverage.md new file mode 100644 index 0000000..65ccea4 --- /dev/null +++ b/syntax_coverage.md @@ -0,0 +1,645 @@ +# lucisv syntax coverage over real OpenTitan — 2026-08-29 + +One round of analysis, no fixes. Measures what SystemVerilog syntax lucisv +does not yet support against the **real** OpenTitan checkout at +`/Users/guoliangchen/repo/opentitan` (HEAD `0098135`, 2026-08-28), not the +sparse `hw/ip/uart`+`hw/ip/gpio` slice `docs/features/corpus-check/README.md` +uses, and not the 820-file pinned corpus `scripts/score.sh` scores. lucisv +built from this repo's HEAD (`34b766c`, `cargo build --release`). + +## Summary + +**3,943 `.sv`/`.svh` files. 3,792 parse and format cleanly (96.2%). 151 +fail** — 139 genuine parse/lex errors, 12 formatter round-trip bugs +(verification errors — the safety net correctly refused all 12, no +corruption reached disk). 114 of the 151 (75%) are under +`dv/`/`tb/`/`test/`/`sim/`/`fpv/`/`uvm/`/`pre_dv/`. Zero crashes across all +3,943 files. + +| # | Bucket | Files | LSP impact | Difficulty | +|---|---|---|---|---| +| 1 | Out-of-class `constraint C::name { ... }` | **45** | Severe — cascades to 60–320+ tolerant diagnostics per file; a widely-`` `include``d base class is hit | **Trivial** — 2-line parser fix, verbatim capture already exists | +| 2 | Formatter round-trip bugs (comment/`else if` corruption family) | 12 | **None** — all 12 parse perfectly, 0 tolerant diagnostics | Bug-fix, not new syntax; needs `format.rs`/printer investigation | +| 3 | `default clocking` / clocking-item `= expr` | 12 | Low — isolated, 1–2 diagnostics/file | Medium — documented non-goal from `interfaces` round | +| 4 | Local (block-scoped) `typedef` statement | 10 | Low | Small — new `StmtKind::Typedef`, reuses item-typedef parsing | +| 5 | Macro-bracketed / macro-as-statement long tail (`` `CREATE_TPM_CASE_STMT``, macro-in-`for`, `program`/`endprogram`) | 13 | Low–Medium | Needs macro-expansion awareness in places; `program` is trivial | +| 6 | Unsupported cast base (`weak0/weak1/pull0/pull1'()`) | 9 | Low | Small — extend cast-base grammar | +| 7 | `` `ifdef``/`` `else``/`` `endif`` splitting an **expression/statement** (anchor B's bucket) | 5 (floor) | **High** — hits the two flagship top-level chip RTL files | Medium — new recovery shape, not covered by existing directive machinery | +| 8 | Enum member range (`Name[hi:lo]`, `Name[N]`) | 6 | Low | Small — grammar + printer addition | +| 9 | `expression chain too long` (256-term generated OR-reduction) | 7 | Low | Policy call — raise/soften `MAX_CHAIN_LENGTH`, all in autogen `reg_top.sv` | +| 10 | Cast to assignment pattern `type_t'{...}` | 5 | Low | Small — extend cast grammar to accept `'{` | +| 11 | Gate-instantiation delay list `#(rise, fall[, off])` | 5 | Low | Trivial — `parse_delay_value` → comma list | +| 12 | `virtual iface.modport name;` | 5 | Low | Small — type-name parser accepts a dotted suffix | +| 13 | Alternate instantiation heads behind `` `ifdef``, shared connection list | 2 | **High** — the two `top_{earlgrey,darjeeling}/dv/tb/tb.sv` files (the DUT top testbenches) | Medium-hard — extends `directive-split` to instantiations | +| 14 | `rand`/`randc` on a plain (non-class) struct member | 3 | Low | Small — grammar-only qualifier | +| 15 | `foreach` with an omitted index dimension (`arr[, j]`) | 2 | Low | Small | +| 16 | `bind` with a hierarchical path in `: instance_list` | 1 | Low | Small (see Anchor A) | +| — | Malformed source in the corpus itself (missing `end`) | 1 | N/A — not a lucisv gap | N/A | +| — | Vendor template / `` `include``-fragment files (not standalone compilable) | 2 | N/A — not a lucisv gap | N/A | + +Counts are **first-blocking-construct** counts (one vote per file, corpus-check's +convention) — a floor, not a ceiling, for constructs that co-occur with an +earlier blocker in the same file. Rows 1–16 plus the two "not a lucisv gap" +rows sum to 145 of the 151 failures; the remaining 6 are an unbucketed long +tail of one-off shapes not written up individually (each read and confirmed +to be a distinct minor gap, not a repeat of the above). + +**The two owner anchors land at rows 16 (bind) and 7/13 (chip_if/tb.sv +directive splits)** — see the deep dives below. Anchor A's exact file +(`aes_bind.sv`) turned out to be a **stale anchor**: it already parses and +formats cleanly on this build. + +## Per-bucket detail + +### 1. Out-of-class `constraint C::name { ... }` — 45 files, top blocker + +IEEE 1800 §13.2's out-of-body constraint definition, the constraint +sibling of the already-supported `function C::method(...)` shape: + +```systemverilog +class ac_range_check_smoke_racl_vseq; + extern constraint range_attr_c; +endclass + +constraint ac_range_check_smoke_racl_vseq::range_attr_c { // <- fails here + foreach (dut_cfg.range_base[i]) { ... } +} +``` + +`hw/dv/sv/alert_esc_agent/alert_esc_seq_item.sv:74`, +`hw/top_darjeeling/ip_autogen/ac_range_check/dv/env/seq_lib/ac_range_check_base_vseq.sv:47`. + +Root cause, read directly in `crates/vlog_parser/src/parser.rs:1673` +(`fn parse_constraint`): `self.expect_name()` after the `constraint` +keyword consumes a single identifier and then requires `{` or `;` — +`ClassName::` after the name is not anticipated, so it fails with +`expected `{` (found "::")` on the class name, one token before the actual +constraint name. `function C::method` already parses `C::method` as a +scoped name elsewhere in the parser; `parse_constraint` never reuses that +path. + +**Why this is the #1 recommendation, not just by file count.** Because +`ItemKind::Constraint` is already a verbatim capture (the body is `dist`, +`->`, `solve...before` — a second grammar lucisv deliberately does not +model, per the existing doc comment on `parse_constraint`), fixing this +needs **no new AST variant and no printer work at all** — only teaching +`parse_constraint` to accept an optional `Ident "::" ` prefix before the +constraint name, exactly mirroring the out-of-body function/task path. +Zero blast radius in `format.rs`/`bind.rs`/`spans.rs` (an `ItemKind::Verbatim` +consumer already exists everywhere). This is as close to a pure win as this +corpus offers. + +**Why it also matters for the LSP, disproportionately to its file count.** +Probed with a standalone `parse_source_tolerant` harness (see Methodology): +the tolerant parser does not fail gracefully here — because the parse error +happens one token into a *class-scoped* construct, the recovery loop +resynchronizes badly and produces long cascades of spurious downstream +diagnostics: `hw/dv/sv/cip_lib/seq_lib/cip_base_vseq.sv` (widely +`` `include``d by other DV testbenches) produces **322** tolerant +diagnostics from this one construct, `hw/ip/hmac/dv/env/seq_lib/hmac_base_vseq.sv` +produces **274**. A file an editor opens in this state is not "slightly +degraded" — it is effectively unusable for diagnostics, though +`documentSymbol` for the class itself still resolves (confirmed live, see +Anchor B's LSP probe methodology, same recovery machinery). + +### 2. Formatter round-trip bugs — 12 files, all pre-existing, all invisible to the LSP + +These are `verification failed: token stream diverges...` — `format_source` +parsed the file with **zero errors**, produced output, and its own +equivalence/convergence check caught the output disagreeing with the input. +Per `CLAUDE.md` invariant #1 the safety net did its job: every file was +left byte-for-byte on disk (confirmed for all 12: `md5` before/after +matches). This is not "unsupported syntax" — it is a formatter bug, and +the `docs/features/corpus-check/README.md` methodology is right to call +these out separately. + +Root cause (read directly, all 12): a **comment written immediately before +an `else`/`else if`** gets its text extended with tokens from the branch +that follows, e.g. `hw/ip/keymgr/dv/env/keymgr_scoreboard.sv:643`: + +```systemverilog +// addr_phase_write +else if (addr_phase_read) begin +``` + +comes back as one comment reading `// addr_phase_write else if (addr_phase_read) begin`. +Four of the twelve show this exact shape +(`keymgr_scoreboard.sv`, `spi_cmdparse.sv`, `spi_passthrough.sv`, +`aon_timer_scoreboard.sv`); the other eight are comment-drop variants of +the same family (`i2c_monitor.sv`, `i2c_base_vseq.sv`, +`spi_host_status_stall_vseq.sv`, `usb_fs_tx.sv`) plus two unrelated ones +(`hmac_core.sv` — a label/`;` confusion; `otp_ctrl_dai.sv`, hit **three +times** because the same generated file is vendored into +`hw/ip_templates/otp_ctrl` and both `hw/top_{darjeeling,earlgrey}/ip_autogen/otp_ctrl` +— one bug, three file paths). + +**LSP impact: none.** Probed all 12 with the tolerant parser directly — +every one produces **0 diagnostics** (confirmed: the 12 zero-diagnostic +files in the tolerant sweep are exactly, and only, these 12 +verification-error files). A user editing any of these in an LSP-backed +editor sees a perfectly clean file with full navigation; only +`lucisv format`/`lucisv --check` on the command line refuses it. This is +the sharpest illustration in the whole corpus of the strict/tolerant +divergence the brief asked to characterize. + +### 3. `default clocking` / clocking-item `= expr` — 12 files + +Both shapes are **already documented non-goals** from +`docs/features/interfaces/README.md`'s Assumptions ("A clocking item's +optional `= expression`... is not supported. 0 corpus uses." and +`default clocking` is absent from that round's scope). This is simply the +first time either has real corpus evidence: `default clocking @(posedge +clk_aon_i); endclocking` (`hw/ip/adc_ctrl/dv/sva/adc_ctrl_fsm_sva_if.sv:30`, +7 files) and `output req_valid = req_valid_driven;` inside a `clocking` +block (`hw/dv/sv/kmac_app_agent/kmac_app_if.sv:92`, 5 files). Not a new +finding — folding it in here because it now has a real file count. + +### 4. Local (block-scoped) `typedef` statement — 10 files + +`typedef` used as a **statement** inside a function/task body (IEEE 1800 +§6.18, scoping a type to the block), not as a module/package item: + +```systemverilog +task access_data_fifo(...); + typedef enum bit {WRITE = 1'b1, READ = 1'b0} rdwr_e; // <- fails + rdwr_e rw = ...; +``` + +`hw/ip/spi_host/dv/env/seq_lib/spi_host_base_vseq.sv:577`, +`hw/dv/sv/usb20_agent/usb20_item.sv:246` (`typedef bit data_result[];`, +a dynamic-array local typedef). lucisv models `typedef` only at item +position (`ItemKind`, not `StmtKind`); confirmed no `StmtKind::Typedef` +exists in `crates/vlog_parser/src/ast.rs`. The fix reuses the existing +item-level typedef parse function from statement position and adds one +`StmtKind` variant — which means exhaustive-match arms in `format.rs` +(layout is identical to the item form), `spans.rs`, and `visit.rs` +(lint's AST walker) each need one arm; `bind.rs` does not descend into +statement bodies today for typedefs regardless. + +### 5. Macro-bracketed / macro-as-statement long tail — 13 files + +A grab-bag that all needs the same missing capability — knowing what a +macro's *body* contains, which lucisv deliberately does not track +(`docs/features/lexer-cleanup/README.md`'s "macro glue... stays parked"): + +- **A macro used as a `case` label**: `` `CREATE_TPM_CASE_STMT(TPM_INT_VECTOR, tpm_int_vector) `` sitting where a case item is expected (`hw/ip/spi_device/dv/env/spi_device_scoreboard.sv:643`). +- **A macro invocation containing a `for` loop** between `` `uvm_object_utils_begin``/`` `_end`` (`hw/ip/edn/dv/env/edn_env_cfg.sv:14`) — the macro-bracketed body walker (same one `constraint`/`covergroup` use to find their closer) doesn't expect a nested control-flow statement. +- `` `include``d fragment cut mid-declaration (`hw/dv/sv/cip_lib/seq_lib/cip_base_vseq__tl_errors.svh:9`) — genuinely not a standalone compilation unit; only fails standalone because this sweep checks every `.svh` independently, which is a sweep-methodology artifact, not a real gap (a real toolchain always `` `include``s it into a file first). +- **`program`/`endprogram`** (3 files, `hw/ip/spi_device/pre_dv/program/*.sv`) — `docs/features/interfaces/README.md` already named this "a one-line addition" they left out for lack of corpus evidence ("0 of 820"); it now has 3. + +### 6. Unsupported cast base (drive strengths) — 9 files + +`weak0'(...)`/`weak1'(...)`/`pull0'(...)`/`pull1'(...)` as a cast base — +already on the old 820-corpus's top-10 list (#9, "casts with a non-simple +base"), now with 8 files hitting `unsupported cast base expression` plus +one `unexpected keyword `weak1` in expression` (`hw/ip/spi_host/dv/tb.sv:101`). +Same construct, not previously counted this large because the small +corpus only had 4. + +### 7. `` `ifdef``/`` `else``/`` `endif`` splitting an expression or statement — 5 files (floor) + +**This is Anchor B's bucket.** See the deep dive below; folding the count +in here because it is genuinely a top-8-by-value bucket even though the +raw file count (5) looks small — two of the five are the actual top-level +synthesizable chip RTL (`chip_earlgrey_asic.sv`, `chip_earlgrey_cw340.sv`), +and the other three include both `top_{earlgrey,darjeeling}/dv/env/chip_if.sv` +(the design's central DV bind/probe interface — anchor B's named file). + +### 8. Enum member range — 6 files + +IEEE 1800 §6.19's enum name range: `Name[hi:lo]` or `Name[N]` auto-expands +to a run of sequential enum values. + +```systemverilog +typedef enum logic [ResetWidths-1:0] { + ReqPeriResetIdx[0:1], // <- fails + ReqMainPwrResetIdx, + ... +``` + +`hw/top_darjeeling/ip_autogen/rstmgr/rtl/rstmgr_pkg.sv:72`, +`hw/top_earlgrey/dv/env/chip_env_pkg.sv:88` (`OtbnDmem[16]`, the count +form). `EnumMember` has no dimension field today; needs one plus printer +support (print the bracket verbatim after the name — no re-layout +decision to make, since the value is data, not something lucisv computes). + +### 9. `expression chain too long (limit 256)` — 7 files, all autogenerated + +Not a missing grammar feature — a **safety budget** (`MAX_CHAIN_LENGTH = +256`, `crates/vlog_parser/src/parser.rs:214`, from +`docs/features/recursion-limit/README.md`, added to stop a maliciously +deep expression from blowing the native stack) tripping on **legitimate** +generated RTL: every hit is `reggen`-generated `*_reg_top.sv`, a +flattened `|`-chain of `(addr_hit[N] & ...)` OR-reduction terms, one per +register, in files that can have 250+ registers +(`hw/ip/rv_dm/rtl/rv_dm_mem_reg_top.sv:9156`, a 10,649-line file; also +both top-level `alert_handler_reg_top.sv` and all three `pinmux_reg_top.sv` +variants). The `docs/features/recursion-limit/README.md`'s own caveat — +"hand-written RTL does not nest expressions ~150 deep; absence of crashes +here is not evidence the bug is gone" — is exactly right, and this is the +counter-evidence: **generated** RTL does hit it, at scale, in exactly the +kind of register-block file every OpenTitan IP has one of. This is a +policy question (raise the constant, or special-case flat commutative +chains) more than an implementation one; recommend routing to whoever +owns `recursion-limit` rather than bucketing it as "new syntax." + +### 10. Cast to assignment pattern `type_t'{...}` — 5 files + +`docs/features/expressions-2/README.md` shipped "casts over any constant +primary" and `'{N{0}}` replication **without** a type prefix. Neither +covers a **cast applied to an assignment-pattern literal** +(`type_t'{...}`, IEEE 1800 §10.9.1) — confirmed by direct construction +that `bar_t y = '{a: 1};` (no cast) and `bar_t y = bar_t'(...)` (cast, +non-pattern) both work, but `bar_t y = bar_t'{a: 1};` fails uniformly for +keyed, positional, and replication forms alike, always at the `'{` token: + +```systemverilog +exp_alert_q[alert_name].push_back(expected_alert_t'{1, is_fatal, max_delay}); +``` + +`hw/dv/sv/cip_lib/cip_base_scoreboard.sv:442`, +`hw/top_earlgrey/ip/ast/rtl/ast.sv:293` (`ram_1p_cfg_req_t'{req: spram_rm.cfg}`, +inside a replication — genuine RTL, not just DV). A `grep` for the +textual pattern across the whole tree finds 7 files total (5 as +first-blocker), so this is not significantly masked. + +### 11. Gate-instantiation delay list — 5 files + +`buf #(rise, fall) b0 (out, in);` — a primitive gate instance with a +2-or-3-value delay specification (IEEE 1800 §28.14). Confirmed by +isolation: `buf b0 (a, b);` (no delay) parses fine; `sub #(5, 0) u0 (a, b);` +(a **module** instantiation with a positional two-value parameter +override) parses fine; only the gate-with-delay-list combination fails. +Root cause, read directly: +`crates/vlog_parser/src/parser.rs:2941` (`fn parse_delay_value`) accepts a +single expression or a `min:typ:max` triple in parens — never a +comma-separated *list* of delay values. All 5 hits are AST oscillator +gate-level models (`hw/top_{darjeeling,earlgrey}/ip/ast/rtl/{aon,io,sys,usb}_osc.sv`, +e.g. `buf #(ast_bhv_pkg::AON_EN_RDLY, 0) b0 (...)` +at `hw/top_darjeeling/ip/ast/rtl/aon_osc.sv:40`). + +### 12. `virtual iface.modport name;` — 5 files + +`docs/features/interfaces/README.md` shipped "virtual interface types in +every type position," but the base type name it parses is a plain +identifier — a **modport-qualified** virtual interface type +(`virtual spi_if.tb tb_sif;`) fails at the `.`, confirmed even with no +initializer and inside a class body: + +```systemverilog +virtual spi_if.tb tb_sif = sif.tb; +``` + +`hw/ip/spi_device/pre_dv/tb/spid_jedec_tb.sv:32`. A `grep` for the +textual pattern finds 6 files total in the whole tree, so this bucket is +essentially fully counted, not masked — genuinely small. + +### 13. Alternate instantiation heads behind `` `ifdef``, shared connection list — 2 files, outsized value + +**Closely related to Anchor B** (same underlying gap: a directive +appearing somewhere none of the three directive features anticipated), +but a structurally distinct shape and worth its own row because of *who* +it blocks: `hw/top_earlgrey/dv/tb/tb.sv` and +`hw/top_darjeeling/dv/tb/tb.sv` — **the top-level DUT testbench for each +chip**, the file every DV engineer opens first. + +```systemverilog +`ifdef DISABLE_ROM_INTEGRITY_CHECK + chip_earlgrey_asic #( + .SecRomCtrlDisableScrambling(1'b1) + ) dut ( +`else + chip_earlgrey_asic dut ( +`endif + .POR_N(...), ... + ); +``` + +Two full instantiation *heads* (module name + optional `#(...)` + instance +name) behind an `` `ifdef``, sharing one connection list. Traced the exact +failure: the parser accepts the **first** arm's head, opens the shared +connection list, and inside it hits the `` `else`` — but +`take_list_directives` (from `directives-in-instances`) treats *any* +directive found while inside a connection list's brackets as +conditioning *list elements*, not as "the rest of this file belongs to a +different arm of an outer conditional." It then tries to parse +`chip_earlgrey_asic` (the second arm's module name) as a positional +connection *expression* — which succeeds syntactically as a bare +identifier — and only fails two tokens later when `dut` appears where a +`,` or `)` was expected: `expected `)` (found "dut")` at +`hw/top_earlgrey/dv/tb/tb.sv:114:22`. So the diagnostic position is +misleading — the real defect is at the `` `else`` on line 113, three +lines earlier, which `directives-in-instances`'s harvest logic silently +accepted as valid without checking whether the item it's inside is +itself mid-conditional-split. `directive-split` (which does understand +item-level conditional splits) never gets a chance to run, because the +failure surfaces deep inside `parse_connections`, not at `parse_item_kind`'s +top level. + +### 14–16 (brief) + +- **`rand`/`randc` on a plain struct member** (3 files, + `hw/ip/spi_host/dv/env/spi_host_env_pkg.sv:64`: `rand bit cpol;` inside + a bare `typedef struct`, not a class). Not standard IEEE 1800 — `rand` + is only legal on class properties per the LRM — but real, vendor-tool-accepted + code the corpus actually contains; a grammar-only qualifier addition + with no semantic meaning needed (lucisv doesn't model randomization + semantics regardless). +- **`foreach` with a skipped dimension** (2 files, + `hw/ip_templates/flash_ctrl/dv/env/flash_ctrl_env.sv:43`: + `foreach (cfg.mem_bkdr_util_h[, bank])`, skipping the first array + dimension's index per IEEE 1800 §12.7.3). +- **`bind` with a hierarchical path in `: instance_list`** (1 file, + `hw/ip/entropy_src/dv/tb/tb.sv:94`: `bind prim_packer_fifo : + dut.u_entropy_src_core.u_prim_packer_fifo_precon ...` — the instance + list expects bare names; a dotted hierarchical path there is + vendor-tool-accepted but not modeled). See Anchor A. + +### Not lucisv gaps (2 files) + +- `hw/ip/kmac/fpv/tb/keccak_2share_fpv.sv:108` — **the source file itself + is malformed**: the `StPhase1:` case-item's `begin` is never closed + (traced by hand: exactly one `begin`/`end` pair is missing between + lines 74 and 83). lucisv correctly refuses this with a parse error; + it is not a gap. +- `hw/vendor/lowrisc_ibex/.../riscv_core_setting.tpl.sv` (a `.tpl.sv` + Jinja-style template, not real SystemVerilog) and + `.../riscv_custom_instr_enum.sv` (an enum-body fragment meant to be + `` `include``d, not compiled standalone) — both vendored, both + correctly not real compilation units. + +## Anchor deep-dives + +### Anchor A — `hw/ip/aes/dv/sva/aes_bind.sv` (`bind` directive) + +**This anchor is stale: the file already parses, formats, and is +idempotent on this build.** + +``` +$ target/release/lucisv --no-cache --check hw/ip/aes/dv/sva/aes_bind.sv +would reformat: .../aes_bind.sv +$ (format twice, diff outputs) +IDEMPOTENT +``` + +Read the file: five `bind` directives, all the shape +`docs/features/bind/README.md` already delivered — module target, plain +`module_name inst_name (...)` instantiation, mixed positional/named/ +`.name` implicit connections, and hierarchical dotted references +inside a connection expression +(`.buffer_q (u_aes_core.u_aes_prng_clearing.gen_buffer.buffer_q)`), plus +one `bind` nested inside a plain `if (`EN_MASKING) begin : label ... end` +generate block (ordinary generate-if, unrelated to `bind` support). None +of these shapes needed anything beyond what the `bind` feature (delivered +2026-08-20/21, per that feature's README) and `directives-in-instances` +already ship. **What support needs:** nothing further for this exact file. + +Since the anchor itself doesn't reproduce, I searched the whole tree for +any remaining `bind`-shaped failure: there is exactly **one**, +`hw/ip/entropy_src/dv/tb/tb.sv:94` — bucket 16 above, a hierarchical +dotted path in the `: instance_list` position (`bind prim_packer_fifo : +dut.u_entropy_src_core.u_prim_packer_fifo_precon entropy_subsys_fifo_exception_if #(...)`). +The `bind` feature's own README already documents (Status/TODO) that +`instances: Vec` doesn't carry per-instance structure beyond a bare +name list; the fix is the same shape — accept a dotted path per instance +name, formatted verbatim. Grammatically, `bind` is still exactly "an +instantiation with a target prefix," as the task brief characterizes it; +that design point is *why* the feature landed as cleanly as it did, and +why this one remaining gap is a small, bounded extension rather than new +grammar. + +### Anchor B — `hw/top_earlgrey/dv/env/chip_if.sv:1192` (`` `ifdef`` inside a statement) + +**Confirmed, reproduces exactly as described.** The code at issue +(`hw/top_earlgrey/dv/env/chip_if.sv:1189-1194`, quoted verbatim): + +```systemverilog + // Signal probe function for `rnd_ctr` of AES_CIPHER_CTRL + wire [3:0] aes_ctrl_rnd_ctr; + assign aes_ctrl_rnd_ctr = +`ifdef GATE_LEVEL + `AES_HIER.u_aes_core.u_aes_cipher_core.u_aes_cipher_control.mr_rnd_ctr[3:0]; +`else + `AES_HIER.u_aes_core.u_aes_cipher_core.u_aes_cipher_control.rnd_ctr; +`endif +``` + +`lucisv --check` on the real file: `parse error: 1192:1: expected +expression (found "`ifdef GATE_LEVEL")`. A live `lucisv-server` probe +(stdio, `didOpen` on this exact file, no writes) confirms the LSP sees +**2** diagnostics — `1192:1` (the same one) and `1195:7: expected +declaration or instantiation (found "`AES_HIER")` (the recovery resyncs +at the `` `else`` arm's own body and immediately re-fails on the bare +directive-prefixed identifier there) — but `documentSymbol` still returns +the file's top-level `chip_if` interface cleanly. This is the file-can't- +format-but-still-navigates story the brief asked to characterize, shown +live rather than inferred. + +**Why does this fail when directive support already exists in three +places?** Three existing features handle directives, and none of their +trigger conditions fire here: + +1. **`directives-in-lists`/`directives-in-instances`** accept a directive + *between the elements of a bracketed list* (port lists, parameter + lists, enum members, instantiation `#()`/connection lists). An + `assign`'s right-hand side is not a list — it's a single expression — + so there is no list-element boundary for `take_list_directives` to sit + at. +2. **`directive-split`** accepts a directive that closes a region + **already open when the failing item started**, provided the item left + a bracket open at the failure point (`Parser::at_split_conditional`'s + four conditions, `docs/features/directive-split/README.md`). Here the + failure is not at the *closing* `` `else``/`` `endif`` with a bracket + open — it is **at the opening `` `ifdef`` itself**, one token into + parsing the assign's expression. `parse_expr`/`parse_primary` has no + rule that treats a directive token as a valid expression start (unlike + an item or statement list, an expression parse has no "this might be a + pass-through directive" branch at all), so it fails immediately, + before any bracket is opened and before `directive-split`'s trigger + ever gets evaluated. +3. Directives are pass-through only at **item-list and statement-list** + boundaries (`error-recovery`'s recovery points) and inside the four + bracketed-list sites `directives-in-lists`/`directives-in-instances` + cover. An expression's right-hand side, mid-statement, is none of + these — it is new surface, not a gap in an existing rule's coverage. + +**How large is this gap class?** Searching the whole tree for the exact +first-blocker shape (`expected expression (found "` `` `if...")`, i.e. a +directive appearing where an expression was expected) finds **5 files**: +both `chip_if.sv` (earlgrey and darjeeling — bucket 7), plus +`hw/dv/sv/jtag_agent/jtag_dtm_reg_block.sv:173`, and — importantly — +**`hw/top_earlgrey/rtl/autogen/chip_earlgrey_asic.sv:621`** and +**`chip_earlgrey_cw340.sv:502`**, the actual top-level *synthesizable* +chip RTL, not DV code. This is a measured floor: any file that hits an +earlier, unrelated blocker first would mask an occurrence of this same +shape without it ever surfacing as a first error, exactly as +`corpus-check`'s own methodology warns. The closely-related instantiation-head +variant (bucket 13) adds the two `top_{earlgrey,darjeeling}/dv/tb/tb.sv` +files — meaning this general fault line (a directive somewhere the +existing machinery's four preconditions don't cover) touches **7 files +total that are disproportionately central**: both chips' top-level +synthesizable RTL, both chips' DV probe interfaces, and both chips' DUT +top testbenches. + +## Implementation notes for the top buckets + +| Bucket | New AST surface | `format.rs`/`bind.rs`/`spans.rs` arms needed | LSP-relevant | +|---|---|---|---| +| 1. extern constraint | none (reuses `ItemKind::Verbatim`) | none | Yes — cascades in tolerant mode | +| 4. local `typedef` stmt | `StmtKind::Typedef` (new variant) | `format.rs`, `spans.rs`, `visit.rs` — 1 arm each | Low | +| 7/13. directive-splits-an-expression / -instantiation-head | new recovery paths (statement/expression-level, and instantiation-level) — no new AST leaf, reuses `ItemKind::Error`-style verbatim capture pattern | none if verbatim | **Yes — 2 flagship testbenches + 2 flagship top RTL files** | +| 8. enum range | new field on `EnumMember` | `format.rs` (print verbatim), `spans.rs` | Low | +| 10. cast-to-pattern | none if reusing existing `'{...}` pattern-literal parse under the cast production | `format.rs` layout reuse | Low | +| 11. gate delay list | `GateInstantiation::delay` becomes `Vec` or similar (was `Option`) | any exhaustive match on that field | Low — RTL only, no DV/LSP-heavy files | +| 12. virtual+modport | extend the type-name parse after `virtual` to accept `Ident "." Ident` | `format.rs` print, `spans.rs` | Low | + +**Verbatim-capture candidates** (cheapest, matches the `classes`/`constraint` +pattern of "don't model the grammar, copy the bytes"): buckets 1 +(already verbatim), 5 (macro long tail — inherently verbatim already), +7/13 (the directive-split extensions — the existing `ItemKind::Verbatim` +pattern extends naturally to "capture from the failed statement/instantiation +through the shared terminator", exactly as `directive-split` already does +for item-level declarations). + +**Real grammar work** (new AST + printer layout, not just a wider +verbatim net): buckets 4 (local typedef — needs a real `StmtKind` since +its layout should match the item form), 8 (enum range — needs a printed +dimension), 11 (gate delay list — small but a real field-type change). + +## Ranked recommendation + +1. **Fix out-of-class `constraint C::name` (bucket 1, 45 files).** Highest + files-per-unit-of-work in this entire sweep: a ~10-line parser change + (mirror the existing `C::method` scoped-name path into + `parse_constraint`), zero new AST surface, zero printer work, and it + also removes the worst tolerant-mode diagnostic cascades in the corpus + (up to 322 spurious diagnostics from one file). Do this first. +2. **Extend `directive-split`'s reach to expression/statement RHS and to + instantiation heads (buckets 7 + 13, 7 files).** Small file count, but + this is the one place in the whole sweep where the *specific files* + blocked are disproportionately important — both chips' top-level + synthesizable RTL and both chips' DUT top testbenches. This is + Anchor B's bucket, and it is a natural sequel to the existing + `directive-split`/`directives-in-instances` work (same team of + concepts, one more shape each). Recommend doing this as one round + covering both variants together, since they share the diagnosis + (directives showing up in a position none of the three existing + directive features anticipated). +3. **Sweep the small, well-scoped grammar gaps as one "mop-up" round** + (buckets 8, 10, 11, 12, 14, 15 — enum ranges, cast-to-pattern, gate + delay lists, virtual+modport, rand-on-struct, foreach-skip-dim; ~26 + files combined). Each is independently small, each is fully + characterized above with an exact repro, and doing them together + amortizes the "read CLAUDE.md, build, run corpus, write README" + overhead the way `mop-up-2` already did for a similar grab-bag. + +Lower priority, flagged but not recommended for the next round: bucket 2 +(formatter round-trip bugs — real bugs, but zero LSP impact and each +needs individual root-causing in `format.rs`'s comment-attachment logic, +not a coverage win); bucket 9 (`expression chain too long` — a policy +call on `MAX_CHAIN_LENGTH`, not new syntax, belongs with whoever owns +`recursion-limit`); bucket 5's macro-expansion-dependent shapes (need a +capability lucisv deliberately doesn't have yet, per +`docs/features/lexer-cleanup/README.md`). + +## Methodology + +**Commands** (read-only; `--check`/`check` only, `--no-cache` throughout so +results reflect this exact build, not a stale cache): + +```bash +cargo build --release -p lucisv # 34b766c +cargo build --release -p lucisv_server # same commit, for the LSP probe + +find /Users/guoliangchen/repo/opentitan -type f \( -name '*.sv' -o -name '*.svh' \) \ + -not -path '*/.git/*' | sort | xargs -P8 -I{} bash -c ' + lucisv --no-cache --check "$1" # strict formatter parse + lucisv check --no-cache "$1" # tolerant linter parse + ' _ {} +``` + +3,943 files swept in 20.5s wall time (8-way parallel). Bucketing reused +`scripts/score.sh`'s `classify()` heuristic as a first pass, then every +"other"-bucketed message pattern (91 of 151) was read at its exact +file:line in the real source and manually re-bucketed by hand — the +counts in the table above are the hand-verified ones, not the raw +`score.sh` output (which was tuned against the smaller 820-file corpus +and under-recognizes several of these constructs, notably the extern +constraint shape, which it doesn't have a rule for at all). + +**Tolerant-path characterization** used two methods: + +1. A standalone Rust probe (`vlog_parser = { path = ".../crates/vlog_parser" }`, + ~20 lines, built and run from the scratchpad, never touching the + lucisv repo) calling `vlog_parser::parse_source_tolerant` directly on + all 151 failing files — this is the same entry point both + `lucisv check` and `lucisv-server` use, and gives an exact diagnostic + count per file without the overhead of driving the LSP server 151 + times. Distribution: 12 files 0 diagnostics (all 12 are the + verification-error bucket), 43 files exactly 1 (clean single-point + recovery), the rest a long tail up to 475 (the worst extern-constraint + cascades). +2. A live `lucisv-server` stdio session (Python, `initialize` → + `didOpen` → capture `publishDiagnostics` → `documentSymbol`/`hover`) + against the `chip_if.sv` anchor specifically, to show real + editor-visible behavior rather than inferring it from the diagnostic + count alone. Confirmed the file's top-level `interface` symbol still + resolves via `documentSymbol` despite the internal statement-level + parse failures. + +Note on `lucisv check`'s exit code: it is **not** a reliable proxy for +"does the tolerant parser report anything," because +`crates/vlog_linter/src/context.rs` deliberately discards +`ParseDiagnostic`s ("no rule reads them... the one consumer that publishes +them is the language server, which holds its own") — `check`'s exit code +reflects lint-rule violations only. This is why method 1 above (calling +`parse_source_tolerant` directly) was necessary rather than relying on +`lucisv check`'s exit code as originally planned. + +**Counts.** Total files: 3,943 (3,896 `.sv` + 47 `.svh`). Parse-clean +(formatter accepts, `--check` exit 0 or 1): 3,792 (96.2%). Parse-error +(`--check` exit 2, `parse error:`/`lex error:`): 139. Verification-error +(`--check` exit 2, `verification failed:`): 12. Crashes (any exit status +outside {0,1,2}): **0**, confirmed across all 3,943 files. DV/TB slice +(`/dv/`,`/tb/`,`/test/`,`/sim/`,`/fpv/`,`/uvm/`,`/pre_dv/` in the path) of +the 151 failures: 114 (75.5%); RTL slice: 37. + +**Corpus state.** `git status --porcelain` in `/Users/guoliangchen/repo/opentitan` +shows one pre-existing modification, `hw/ip/aes/dv/tb/tb.sv`, from a prior +session's work (not touched by this analysis — confirmed by diffing +`git status` before and after this round; no command in this analysis +writes to the corpus). The lucisv repo itself is unmodified except for +this file. + +**Caveats.** + +- Bucket counts are first-blocking-construct counts; several buckets + (notably 7, and to a lesser extent 12) were cross-checked with a raw + `grep` for the textual pattern across the whole tree to see whether + masking was significant — it was not, for the buckets checked (5 vs. 5, + 6 vs. 6, 7 vs. 6). This was not done for every bucket; the long-tail + buckets (14-16) were not cross-checked this way and may be undercounted + if the same shape occurs in a file blocked by something else first. +- The unbucketed remainder (6 of 151 failures) was individually read and + confirmed to be a one-off shape distinct from every named bucket, but + was not written up with its own section — these are genuinely rare + (each a single file) and did not change the ranked recommendation. +- The LSP probe used `lucisv.index.scope`'s default (`"folder"`), not a + full-workspace scan of all 3,943 files — appropriate for characterizing + a single buffer's diagnostics/symbols, but this analysis did not + measure whole-workspace index quality (cross-file resolution rates) + against the real OpenTitan tree the way `docs/features/directives-in-lists/README.md` + did against the smaller pinned corpus. That would be a reasonable + follow-up if the workspace-index angle matters for the next round. + + +> **Correction (2026-08-29, mop-up round):** bucket 6 was mislabeled. +> The tree holds zero `weak0`/`pull1` drive-strength casts; the 8 files +> raising `unsupported cast base expression` are all system-function +> casting types — `$bits(x)'(...)`, `$clog2(N)'(...)` — a legal +> `constant_primary` cast base, fixed as such. The 9th file lumped in +> here is a gate drive strength (`pullup (weak1) ...`), a different +> production, documented as skipped in +> `docs/features/testbench-mopup/README.md`. Bucket 12 is 6 files, not +> 5 (`spid_common.sv:563`). Sweep counts after the wave live in the +> feature READMEs; this document remains the pre-wave snapshot.