Files
lucisv/docs/features/linter-hardening-r7
Guoliang ChenandClaude Mythos 5.2 e229ff9668 Round 7: linter hardening — missing-port-direction, nested incomplete-assignment, option/regex safety (#41)
New Error-class rule missing-port-direction (75 rules) closes topo #41.
incomplete-assignment walks every path and accepts an enumerated case only
when the selector width is proven. suspicious-semicolon exempts the
while-drain idiom; mismatched-labels reads statement labels and gains an
Unsafe footer fix. Quote-aware option list splitter; regex nesting cap.
The uvm-macro-semicolon autofix was withdrawn after three QA failures and
the instance-shadowing exemption reverted. Files topo #67 (lucisv.toml
array splitting).

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-26 16:32:41 -08:00
..

vlog_linter hardening (Round 7)

Goal

Close docs/topo.md §2.9 row 41 (MCP-13) with a new Error-class rule, missing-port-direction, that reports a non-ANSI header port with no body direction declaration; cut OpenTitan false-positive noise in module-port, instance-shadowing and suspicious-semicolon where — and only where — the hits are demonstrably false, keeping every real-bug detection; make the [ ... ] option-list splitter quote-aware; give the naming-pattern regex engine a nesting cap and reusable match buffers so a pathological pattern is refused cleanly instead of overflowing the stack; fix the nested incomplete-assignment miss; and add a small number of unambiguous, round-trip-verified autofixes to existing rules. A bug-fix round: no new features beyond the row-41 rule.

Assumptions

  • A non-ANSI header port is declared by an ItemKind::PortDecl among the module's own items; port declarations inside generate blocks are not legal, so they are not searched. Both arms of an `ifdef are present as items, so a declaration in either arm counts.
  • A body holding an unexpanded macro item, an `include directive, a verbatim item or an error item may declare ports lucisv cannot see; the new rule is silent for such a module (Error-class discipline).
  • while (<call with ≥1 argument>); — the whole condition, parentheses aside, one call that hands back through an argument — is the mailbox-drain idiom, not a typo. All five opentitan suspicious-semicolon hits were that.
  • (Withdrawn in fix round 1, lead ruling: a nested loop reusing its outer loop's index is the shadowing bug; the exemption was reverted.)
  • A body declaration of a header port with a user-defined, unqualified type (my_if bus;) is a non-ANSI interface port declaration — unless it is certainly data: it carries any qualifier (var, const, static, virtual; an interface port declaration has none), or its type name is a typedef among the module's own items or the file's top-level items. A typedef in another module or inside a function is not in scope and proves nothing (fix round 2).
  • A plain case whose labels are sized literals of one width w <= 8 with no x/z/? and all 2^w distinct values takes an arm on every path only when its selector is proven to be w bits wide (fix round 2): a plain name or a concatenation of plain names, each resolved by vlog_semantic to a port, net or variable of this file, every declaration of which spells a scalar or one [literal:literal] range of a logic/bit/reg/implicit type. An ANSI port that inherits its type from the port before it, a parameterized range, a typedef'd/enum/integer type, an array, and a name the file does not declare are all "unknown", and unknown is not complete. An x/z selector value matching no arm is still not counted as a path (synthesis view, as since fix round 1).
  • incomplete-assignment counts a partial write as coverage, in either order: if (x) y = a; y[1] = b; is silent although every bit but y[1] latches. Telling which bits are covered needs ranges resolved; the rule stays quiet rather than guess (QA R2-3, documented, not changed).
  • Option values come into RuleOptions::set_raw raw (lucisv_core stores the text after = untouched), so the TOML rule \" escapes a quote is the right one for the splitter; unquote still refuses any " in a value.

Handshakes

  • Consumed: vlog_parser::ast::{PortList::NonAnsi, ItemKind::PortDecl, StmtKind::{For, Foreach, While}, ExprKind::Call}, vlog_semantic scopes (unchanged), vlog_formatter::format_source (test-only, round-trip check).
  • Promised (changed): the rule registry gains missing-port-direction (Error, on by default, no fix) — every consumer of all_rules() / rules_markdown() / vscode_lint_settings() sees 75 rules. editors/vscode/package.json regenerated from cargo run -p vlog_linter --example vscode_lint_settings (one new entry, later order values shift by one). mismatched-labels now declares fix() == Some(Unsafe) (uvm-macro-semicolon did too until fix round 3 withdrew its fix; it is None again, as on trunk). The CLI --unsafe-fixes and --rules-doc pick that up with no change on their side. The LSP and MCP do not offer it: both apply Safe fixes only (lucisv_server/src/code_action.rs:81, MCP tools/format.rs:178) — an earlier version of this sentence wrongly said the LSP code actions pick Unsafe fixes up.
  • Request → server lane (not done, out of lane): crates/lucisv_server/src/code_action.rs:8 still says "No rule ships an Unsafe fix today"; mismatched-labels now ships one. The behaviour (Safe only) is right; the comment is stale.
  • Doc sync outside the crate: docs/site/src/content/docs/reference/rules.md (new row + section, one Fix cell — mismatched-labels —, rule notes) and the "74 rules" count in index.mdx, guides/linter.md, reference/architecture.md.
  • Fix round 1: no handshake changed; vlog_parser::token::is_keyword and crate::literal::parse are newly consumed. No workspace helper for escaped-identifier normalization exists, so missing-port-direction has a three-line local one (same_identifier).
  • Fix round 2: no promised handshake changed (rule count, fix classes, package.json are as fix round 1 left them). Newly consumed: vlog_semantic::Semantics::{reference_at, symbol, references_of} and SymbolKind::{Port, Net, Var} (incomplete-assignment selector width — the rule now builds the file's semantics when, and only when, it meets a default-less fully enumerated case); ast::{AnsiPort, Dim, DimKind, DataDecl::qualifiers, DataType::virt, ItemKind::Typedef}.
  • Request → lucisv_core (not done, out of lane): crates/lucisv_core/src/config.rs:375 parse_array has the same naive inner.split(','), so a lucisv.toml array value of its own (e.g. a files/exclude glob "**/{a,b}/*") is split inside its quotes. Rule options are not affected (they are stored raw and go through the fixed splitter). Reuse the quote-aware split there.

Status / TODO

  • #41 missing-port-direction rule in rules/missing_port_direction.rs, registered, unit tests + .lint cases
  • Sync editors/vscode/package.json, site rule reference and rule counts
  • OpenTitan BEFORE counts captured; module-port, instance-shadowing, suspicious-semicolon audited
  • suspicious-semicolon: while (<call>); drain idiom exempted (+ true-positive tests)
  • instance-shadowing: nested-loop index exemption — reverted in fix round 1 (lead ruling); unchanged from trunk
  • module-port: audited, all 165 hits legitimate — unchanged
  • Quote-aware option-list splitter in new options/list.rs
  • Regex nesting cap (64), iterative alternation emit and state follow, reusable scratch in new regex/pike.rs
  • Nested incomplete-assignment miss: failing test first, then must-assign walk
  • Unsafe fix for mismatched-labels, round-trip tests in tests/fix_round_trip.rs
  • Unsafe fix for uvm-macro-semicolon — withdrawn in fix round 3 (lead ruling); the rule file is identical to trunk and a test pins "no fix"
  • Gates: fmt, clippy, guarded tests (vlog_linter, lucisv, lucisv_server, lucisv_mcp), node tests, stamp check
  • Fix round 1: QA findings 1–8 addressed (see work log)
  • Fix round 2: R2-2 (selector width), R2-4 (var / typedef'd declarations), R2-3 documented; its R2-1 rewrite of the uvm-macro-semicolon fix failed QA and was withdrawn in fix round 3
  • Fix round 3: uvm-macro-semicolon autofix withdrawn
  • Not in this round — a future uvm-macro-semicolon autofix must prove, with attack tests for each: (1) the re-parse of the edited text is clean — no parse diagnostics at all, not merely "no Error node" (the tolerant parser closes a body at EOF silently); (2) the edited text's token stream equals the original's apart from the one ; — same kinds and texts, so `uvm_x;end → `uvm_xend is refused; (3) no fix for a direct child of fork — each statement there, a null one included, is its own process, and deleting it changes join_any/join_none timing; (4) the proofs compose across a pass — every fix offered must stay valid when the others of the same pass (and of later passes, however a budget cuts them) are applied, including the "follows another macro" refusal

Work log

2026-11-26 — dev (Round 7)

OpenTitan baseline (target/release/lucisv check /Users/lucio/repo/opentitan/hw, HEAD 9437966, guarded): 1,182 findings, 1 file not checked (a .tpl.sv lex error). Per audited rule: module-port 165, instance-shadowing 128, suspicious-semicolon 5, incomplete-assignment 0.

After (same command): 1,148 findings, same 1 file not checked.

Rule Before After Change
module-port 165 165 none — all legitimate
instance-shadowing 128 98 −30 nested-loop index reuse
suspicious-semicolon 5 0 −5 while (q.try_get(x)); drains
incomplete-assignment 0 1 +1 true latch (nested-miss fix)
missing-port-direction (new) — 0 opentitan compiles; no FP
every other rule identical

Audit notes.

  • module-port: every one of the 165 hits is tl_if <name>(clk, rst_n); in top_*/dv/autogen/tb__xbar_connect.sv — an interface instance connected by position. Two same-width 1-bit ports swapped by hand is exactly the bug the rule exists for (Verible's rule flags it identically), so nothing was tightened. A project that does not want it on generated TB code excludes the directory.
  • instance-shadowing: sampled i (37 hits), hart, fw_ov_insert, u_prim_*, msg, csr. Demonstrably false (by the rule's own genvar reasoning): an inner for (int i…) / foreach (…[i]) reusing the index name of the loop around it (cip_base_vseq.sv:678, rv_timer_scoreboard.sv:306, …) — 30 hits. Kept as real: a loop index hiding a function local (lc_ctrl_jtag_access_vseq.sv:112 hides int i = 0; at :87 — the int i; for (int i…) … use i bug), a class property (riscv_asm_program_gen.sv:73 hart), block locals hiding function locals (entropy_src_scoreboard.sv), and generate-block instances hiding a module instance (prim_sdc_example.sv, the doc's stated policy).
  • suspicious-semicolon: all five were while (fifo.try_get(item)); (aes_scoreboard.sv:882/883, ibex_mem_intf_monitor.sv:59, ibex_mem_intf_response_driver.sv:43, ibex_icache_mem_driver.sv:36). Exempted only a while whose whole condition is an ExprKind::Call; while (busy);, while (a && q.try_get(x));, while (!q.try_get(x));, if (q.try_get(x)); and repeat (count(q)); are pinned as still reported.
  • incomplete-assignment new hit: ip/rom_ctrl/dv/tb/tb.sv:158 if (!rst_n) h = 0; else if (rsp_valid) h = 1; in an always_comb — a genuine latch (deliberate in a TB, but exactly what the rule reports).

#41 missing-port-direction (rules/missing_port_direction.rs, 92 production lines). Error class, on by default, no fix (the direction is the design's answer). Silent for an unclean parse, an error element in the header, and a body with a macro item / `include / verbatim / error item. Compares names as written. 9 unit tests (row-41 shape, data declaration is not a direction, ANSI/empty headers, `ifdef arms, macro / include bodies, unclean parse, interface/program, another module's declaration) + 2 .lint cases in tests/cases/declarations.lint. CLI check of the exact MCP-13 text module k (a, b);\n output b; reports 1:11 error: port a …. The nested-module case was dropped from the tests: the parser does not accept a module declared inside a module, so the file is unclean and the rule (correctly) says nothing.

Quote-aware splitter (options/list.rs, 30 lines; options.rs 282 production lines). split_items splits at commas outside "…"; inside a quoted item \ escapes the next character. An unclosed string is refused with "<key> expects a list whose every string is closed". Behaviour change on one edge only: ["a\"] (a value ending in a lone backslash) was accepted as a\ and is now refused as unclosed — the same reading TOML gives it.

Regex (regex.rs 320 production lines, new regex/pike.rs 84). MAX_DEPTH = 64 nested groups, counted in the parser, refused with "groups nested more than 64 deep are unsupported in lucisv patterns". That bounds every recursion over the tree (parse, emit, drop). emit_alt is now a loop (the program is identical), and the matcher's ε-closure (add) uses an explicit stack, so a 100,000-way alternation compiles and matches on a 256 KB thread. The working memory (two state lists, the follow stack, visited marks) lives in a RefCell<Scratch> on the Regex and is reused across is_match calls; visited marks are generation stamps (one increment per character instead of clearing a flag per instruction), with a wrap that clears them once. A re-entrant borrow (none exists) falls back to a fresh scratch instead of panicking.

Nested incomplete-assignment (rules/incomplete_assignment.rs). The concrete miss: if (en) begin if (x) y = a; end else y = b; was silent (pinned as silent by the old a_nested_conditional_is_left_to_the_top_level_one test) because the outer if/else counted every name each arm wrote anywhere as covered; same for an open if in a case default arm and a default-less case in an else. Wrote the failing tests first (2 failed as expected), then replaced the top-level loop with a must-assign walk (Walk::covered_after): a block threads coverage, an if/else or defaulted case covers the intersection of its arms, and an open if / default-less case reports names its taken branch writes on every path that were not covered on the way to it. A nested open branch is reported once, at the innermost header. Loops are still not descended into. The old test is replaced by three (a_nested_conditional_without_an_else_is_a_latch_too, …_that_covers_every_path_is_quiet, a_doubly_open_branch_is_one_finding).

Autofixes — deliberately two, both Unsafe:

Rule Fix Class Why
mismatched-labels rewrite a footer that names another block to the header's name Unsafe the footer is inert and the header's name is the one the hierarchy uses, so this cannot rebind a reference; Unsafe because the author may have meant the other name. Not offered for a footer on an unlabelled block or an escaped header name.
uvm-macro-semicolon delete the ; after a `uvm_* invocation Unsafe the UVM macros end their own statement; lucisv does not expand macros, so a project macro named uvm_* that expands to an expression would lose its ;. Not offered where the invocation is visibly an operand (previous token =, (, ,, return, another operator).

Round-trip tests in tests/fix_round_trip.rs (4): exact fixed text, parsed_cleanly(), rule silent on re-lint, format_source accepts the output (its verifier runs) and converges on a second pass, and neither fix applies without --unsafe-fixes. On opentitan: the one mismatched-labels finding (otbn_mask_accelerator_sca_wrapper_prolead.sv:69) fixed on a scratch copy through the CLI to the header name, then clean; --select uvm-macro-semicolon gives 215 findings, all with a fix; applying all 215 on scratch copies of the 95 files leaves the rule silent and the formatter result unchanged (94 would reformat, the same 1 pre-existing format failure before and after).

Skipped on purpose: explicit-function-lifetime / explicit-task-lifetime (static vs automatic changes meaning, and a module automatic flips the default); legacy-generate-region (whole-region re-indent is the formatter's job); case-missing-default, incomplete-assignment, generate-label, missing-port-direction (the content is a design decision); suspicious-semicolon (deleting the ; changes behaviour); module-port / module-parameter (need the other file's port list); instance-shadowing (rename reaches every use). Every rule doc that said "no automatic fix" for these still says so.

2026-11-26 — dev, fix round 1 (QA FAIL → lead rulings 1–8)

Each item got its failing test first (run red, then fixed).

  1. uvm-macro-semicolon fix corrupted code (HIGH). starts_a_statement is now a whitelist: a fix only after ;, a block keyword (begin, end, fork, join*, else, do, forever, initial, final, always*, endcase), a begin : name / fork : name label, or a ) whose matching ( follows if/while/for/foreach/repeat (else if (…) is covered by the if). No fix after : (ternary arm, case label), after #(…) / #1 delays, after @(…) — decided: no fix after an event control, since x = @(e) m;is intra-assignment and indistinguishable by tokens — after an operator,return, another macro, or a directive / attribute. Attack tests pin 14 no-fix and 10 fix positions. Opentitan: 215 findings, **204** with a fix (was 215; the 11 lost are invocations right after another `` uvm_* `` macro with no ;). Re-applied on fresh scratch copies of the 95 files: rule then reports only the 11 unfixed, format results identical before/after (94 would reformat, the same 1 pre-existing failure).
  2. Fully enumerated case (MEDIUM). New rules/incomplete_assignment/full_case.rs: a plain case (not casez/casex, not inside) whose labels are all sized literals (via crate::literal::parse) of one width w <= 8, every digit known, values fitting w, listing all 2^w distinct values covers every path — at every depth. unique/priority: before the rewrite the rule never looked at the qualifier (a default-less unique case at top level was reported), so they are judged exactly like a plain case at every depth. Corpus (~/.cache/lucisv-corpus, --select): pre-round 3, QA-measured 22 after the first round, now 4: the pre-round 3 (common_cells/src/deprecated/clock_divider.sv:131, a case without default whose arms leave s_clk_div_valid/s_clock_enable/state_next open — real) plus 1 new, common_cells/src/serial_deglitch.sv:46 (if … else if … with no final else — a real latch on q_o). generic_fifo*.sv are silent. rules.md and the rule doc now say 4.
  3. Assignment after a nested open if (MEDIUM). The walk is now two pure parts: always_written(stmt) (a block writes the union of what its statements write on every path, in any order; if/else and a covering case the intersection of their arms) and Walk::judge, which judges each statement of a block against what the other statements of the block (plus the enclosing context) write on every path. Applies at top level too: a_default_assignment_before_the_if_is_the_repair pinned if (en) y = a; y = 1'b0; as a finding — that was a false positive (the last write wins on every path) and the test now asserts silence.
  4. missing-port-direction interface ports (MEDIUM). A body DataDecl with no net keyword whose type name is a plain identifier, not a keyword (vlog_parser::token::is_keyword), and not an inline aggregate declares its names as ports. my_pkg::t_s a;, logic a;, wire a;, reg [3:0] a;, int a;, wire my_t a; stay reported (pinned).
  5. Escaped names (LOW). Header and body names compare through same_identifier (drop the \ and the terminating whitespace); module a7b (\c , d); input c; input \d ; is silent.
  6. Drain exemption narrowed (LOW). Only a call with at least one non-empty argument, with redundant parentheses looked through: while (q.size());, while (busy());, while ((q.size())); reported; while ((q.try_get(x))); exempt like the bare form. Opentitan stays 0.
  7. instance-shadowing exemption reverted (git checkout of the file: code, tests, doc note gone; site note removed). The 30 nested-loop hits were audited and are kept as legitimate shadowing reports — foreach (a[i]) foreach (b[i]) x += a[i]*b[i]; is the bug the rule exists for, and the genvar analogy was wrong (IEEE 1800 §27.4). Opentitan back to 128.
  8. initial lbl : begin … end : lbl (pre-existing). Small and contained, so fixed: mismatched-labels first collects each StmtKind::Labeled prefix keyed by its inner statement's start, then compares a begin/fork with no own label against it. Pinned for begin/fork, and a wrong footer still reports "closes lbl" (and gets the Unsafe fix to lbl).

Opentitan after fix round 1 (guarded release lucisv check hw): 1,178 findings (1,182 baseline), 1 file not checked; module-port 165, instance-shadowing 128, suspicious-semicolon 0, incomplete-assignment 1 (rom_ctrl/dv/tb/tb.sv:158, real), missing-port-direction 0, mismatched-labels 1; every other rule identical to baseline. The before/after table in the first entry is superseded by these numbers.

Production sizes: incomplete_assignment.rs 221, full_case.rs 31, uvm_macro_semicolon.rs 136, missing_port_direction.rs 112, mismatched_labels.rs 203, suspicious_semicolon.rs 96.

2026-11-26 — dev, fix round 2 (QA re-check FAIL → lead rulings 1–4; escalated)

Failing tests first for each item (run red, then fixed).

  1. R2-1 uvm-macro-semicolon — the fix no longer looks at the previous token at all. Two rounds of token-predecessor rules each left a hole because "what stands before the invocation" cannot say what the ; is; only the grammar position can, and the parser already knows it. starts_a_statement, closes_a_control_header, follows_a_block_label and both keyword tables are deleted. A fix now needs three independent things, each with attack tests, and each shown load-bearing by disabling it and watching its tests fail:
    • Role (uvm_macro_semicolon/whole.rs): in a cleanly parsed file the invocation is a MacroStmt/MacroItem node with semi == true — the parser consumed this ; as the invocation's own optional terminator (parse_macro_call: eat_sym(";")) — standing in a whitelisted slot: an item of an item list (file, module/interface/program, class, package, generate region/block/if/for/case); a statement of a begin/fork block or a function/task body or a statement fragment; the whole body of initial/final/always, if/else, a loop, or an immediate assertion's action. An invocation in an expression, a for header, a constraint, a covergroup, a randomize … with block, a struct body, a property/sequence, a concurrent assertion's action or any verbatim capture is not such a node, so no token before it can make it one: the R2-1 inputs (for (i = 0; uvm_line; i++), constraint c { a > 0; uvm_cond; }) fall out of the construction, as does every other "inside an unclosed bracket" shape. By choice (the lead's list), the arm after a case/statement label and the body a delay, event control or wait guards are not slots, although the tree has them as MacroStmt (their inner begin … end statements are). An attribute before the invocation (span.start != raw.span.start) is refused too.
    • Nothing unread before it: the previous token is not a compiler directive or another macro invocation — text the parser passes through, after which "a statement begins here" is the parser's guess.
    • Re-parse proof (uvm_macro_semicolon/reparse.rs): the file with that one ; removed is parsed again; every item and statement (kind + start offset, in walk order, via the shared walks), the fragment shape and every whole-invocation's semi flag must equal the original's with only this invocation's flag cleared. This is what catches the parser's own look-ahead: at_macro_item decides where an invocation ends from the tokens after it, so `uvm_x; y = 1; on one line re-reads as a declaration `uvm_x y = 1; and `uvm_info(…); @(posedge clk); as one expression — both now "no fix" because the comparison fails, not because a rule predicted it. Dangling shapes checked: if (c) m;, else m;, if (c) m; else …, for (;;) m;, do m; while (x);— the invocation is the body, the;its optional terminator, fix offered and round-tripped. A;that terminates something else —assign x = m;, wire w = m;, int v = m;, x = y ⏎ m;, wire w ⏎ m;, sub u (.a(a)) ⏎ m;, return ⏎ m;, module m uvm_hdr;, function void f uvm_args; and 20 more probed through the CLI — no fix (either not a whole-statement node or the file is unclean). Tests: rules/uvm_macro_semicolon/tests.rs (moved out of the rule file; 15 tests; 50 refused inputs across 6 attack tests, 31 accepted inputs applied and re-parsed, 1 budget test) and tests/fix_round_trip.rs (+2: 22 accepted contexts round the whole loop including the formatter; 23 refused inputs asserted byte-unchanged under --fix --unsafe-fixes). Behaviour change versus fix round 1, besides the holes: an immediate assert (x) [else] m; action now gets the fix (it is a body slot); a finding in a file with a parse error anywhere gets none. **Opentitan** (--select uvm-macro-semicolon, guarded): 215 findings in 95 files; **203** with a fix (204 in fix round 1). The 12 without: the same 11 that follow another macro invocation, plus 1 in ip/spi_device/dv/env/spi_device_scoreboard.sv, which does not parse cleanly. Applied on fresh scratch copies of the 95 files: 203 lines changed, each only losing its trailing ;; rule then reports the 12; lucisv --checkoutput byte-identical before/after (94 would reformat, the same 1 pre-existing failure); default-rulelucisv check` output byte-identical before/after (88 findings).
  2. R2-2 full-case trusts the selector, not the labels. full_case::enumerated_width returns the labels' width; covers_every_path accepts it only when incomplete_assignment/widths.rs proves the selector that wide (see Assumptions). The linter had no width facility — decls.rs walks types but resolves nothing — so widths.rs (97 lines) reads the declared width off the AST declarator and takes which declaration a name means from vlog_semantic (reference_at → symbol → references_of, which is how a non-ANSI port's body declarations are found). Deliberate reading of the ruling: a concatenation of plain declared names is accepted as well as one plain name (its width is the sum, equally proven) — without it generic_fifo.sv:156 (case ({valid_i, grant_i})) would be reported again. The R2-2 shape (3-bit s3, nested or top level), an undeclared selector, s[1:0], s + 1, f(s), parameterized/typedef/enum/int/array declarations, an inherited ANSI port type, a block-local shadow of another width and another module's s are all pinned as findings. Corpus (~/.cache/lucisv-corpus, guarded, --select incomplete-assignment,missing-port-direction,suspicious-semicolon): 4, unchanged — clock_divider.sv:131 ×3 and serial_deglitch.sv:46; generic_fifo*.sv stay silent (their selectors are input logic ANSI ports). The "4" in the rule doc and rules.md is the measured number.
  3. R2-4 missing-port-direction. A DataDecl counts as an interface port declaration only with no net keyword, no qualifier at all and no virtual, and a type name that is not a typedef of the module's own items or of the file's top level. var my_t a;, const/static declarations, virtual my_if a;, and t a; with typedef … t; before or after it (alias, enum, struct, forward class; module or file scope) are reported; another module's or a function's typedef does not count.
  4. R2-3 documented only — Assumptions above, the rule doc and rules.md now say if (x) y = a; y[1] = b; is silent and why.

Opentitan after fix round 2 (guarded release lucisv check hw): 1,178 findings, 1 file not checked; module-port 165, instance-shadowing 128, suspicious-semicolon 0, incomplete-assignment 1 (rom_ctrl/dv/tb/tb.sv:158), missing-port-direction 0, mismatched-labels 1 — identical to fix round 1. instance_shadowing.rs is still identical to trunk.

Production sizes: uvm_macro_semicolon.rs 128, …/whole.rs 62, …/reparse.rs 57, incomplete_assignment.rs 237, …/full_case.rs 31, …/widths.rs 97, missing_port_direction.rs 136.

2026-11-26 — dev, fix round 3 — autofix withdrawn (escalated QA FAIL → lead ruling)

The uvm-macro-semicolon autofix is withdrawn from Round 7. Escalated QA found a third corruption in it — R3-1: `uvm_new_func;endclass became `uvm_new_funcendclass, because the re-parse was not required to be clean (the tolerant parser closes a body at EOF without an Error node) and the comparison ignored the invocation's raw text — plus a behaviour change inside fork (R3-2: each ; there is a process of its own, so deleting it changes join_any timing) and a pass-order dependence (R3-3). Three failed rounds on an optional fix in a bug-fix round: the lead's ruling is to stop, not to patch a fourth time. Nothing was repaired.

  • rules/uvm_macro_semicolon.rs restored with git checkout HEAD -- (diff against trunk empty: no fix(), findings carry no fix, trunk's inline tests are back); rules/uvm_macro_semicolon/ (whole.rs, reparse.rs, tests.rs) deleted.
  • tests/fix_round_trip.rs: every uvm-macro-semicolon case removed; the two mismatched-labels round trips kept; the "not without --unsafe-fixes" test now covers mismatched-labels alone; new uvm_macro_semicolon_offers_no_fix pins fix() == None and no edit with or without unsafe fixes on a plain `uvm_info(…); statement.
  • docs/site/…/reference/rules.md: the rule's table row (Fix —) and note are trunk's again. Table re-compared with lucisv check --rules-doc on severity / default / fix for all 75 rules: equal (the only textual differences are trunk's on&nbsp;(project) spelling on six rows). editors/vscode/package.json equals the vscode_lint_settings generator output on all 78 keys — no edit needed (the settings carry no fix class).
  • This README: the three Assumptions that existed only for the fix are removed; Handshakes corrected (LSP/MCP offer Safe fixes only; stale comment at code_action.rs:8 filed as a request); Status records what a future attempt must prove.
  • The work-log entries above that describe the fix (first entry's autofix table, fix round 1 item 1, fix round 2 item 1 and its sizes) are history; the "215 findings, 203 with a fix" numbers no longer describe the tree.

Everything else in the round is untouched (fix round 2's items 2–4 stand). Opentitan (guarded release lucisv check hw): 1,178 findings, 1 file not checked; module-port 165, instance-shadowing 128, suspicious-semicolon 0, incomplete-assignment 1, missing-port-direction 0, mismatched-labels 1 — unchanged. Guarded tests: vlog_linter 711, lucisv 162, lucisv_server 2,195, lucisv_mcp 399, all passed; node 37/37.

QA log

2026-11-26 — QA (Round 7) — verdict: FAIL

Gates re-run (all green): cargo fmt --all --check clean; cargo clippy --workspace --all-targets clean; guarded (tools/guard.sh -m 8 -t 600) cargo test -p vlog_linter / lucisv / lucisv_server / lucisv_mcp — 28 test binaries, 0 failed, no guard kill; node --test editors/vscode/*_test.js 37/37; stamp_author.py --check 0 to stamp. Release lucisv check opentitan/hw (guarded) reproduces the work log exactly: 1,148 findings, 1 file not checked; module-port 165, instance-shadowing 98, suspicious-semicolon 0, incomplete-assignment 1, missing-port-direction 0. rom_ctrl/dv/tb/tb.sv:158 confirmed a real latch. opentitan git status --porcelain empty afterwards.

Sync / hygiene verified: package.json equals the vscode_lint_settings generator output for all 78 keys (75 rules, unique orders); site rules.md table equals lucisv check --rules-doc on severity, default and Fix for all 75 rules; no live "74 rules" left (only dated snapshots in docs/coverage_gaps.md:20, docs/repository-analysis.md:89). No unwrap/expect/panic!/unsafe in changed production code; largest changed production file regex.rs 320 lines. Regex (now !Sync via RefCell) is compiled per check call and never shared across threads; the borrow uses try_borrow_mut with a fresh-scratch fallback, so no panic path. Regex probes via lucisv.toml: depth 64 compiles, 65 refused by name; (|a)b, a||b|, (a*)*b, ((a|)*)*b, (a+)+b, a 20,001-way alternation all behave. Splitter: ["[a,b]b", "x",] two items; ["a\"] refused as unclosed; no shipped config/test/doc uses a backslash-ending list item.

Findings (scratch inputs under the session scratchpad, not in the repo):

  1. HIGH — uvm-macro-semicolon Unsafe fix corrupts code, contrary to its own doc (rules/uvm_macro_semicolon.rs:96, starts_a_statement: : and ) count as statement starts). UVM's `uvm_line / `uvm_file are expressions. Input: line = c ? 0 : uvm_line;andx <= #(1) uvm_line; with check --select uvm-macro-semicolon --fix --unsafe-fixes. Expected: no fix (the macro is an operand). Actual: ; deleted → line = c ? 0 : uvm_line(does not compile). The rule doc promises no fix "after=, (, ,, returnor another operator". (The finding itself on ``uvm_line; `` is a pre-existing false positive.)
  2. MEDIUM — incomplete-assignment rewrite: 19 new findings on the lucisv corpus, 18 of them fully-enumerated nested cases without default. ~/.cache/lucisv-corpus: 22 findings (rules.md and the rule doc still say "3 on lucisv's corpus"). common_cells/src/deprecated/generic_fifo.sv:132 (case (valid_i) 1'b0: … 1'b1: … endcase nested in a defaulted outer case), :156 (case ({valid_i,grant_i}) with all four 2-bit values), :222, and the same three shapes in generic_fifo_adv.sv — no latch in synthesis. Same shape: if (en) begin unique case (s) <all 4 values> endcase end else y = c; now reported (silent before). The full-case FP was top-level only before; the walk carries it to every depth. New true positive: common_cells/src/serial_deglitch.sv:46 (if … else if … without else).
  3. MEDIUM — incomplete-assignment: an assignment after a nested open if is not coverage. always_comb begin if (en) begin if (x) y = a; y = b; end else y = c; end → reported at if (x); y is written on every path. Silent before the rewrite (the ordering rule existed at top level only, and a_default_assignment_before_the_if_is_the_repair pins that top-level FP).
  4. MEDIUM — missing-port-direction (Error class) false positive: non-ANSI interface port. module a12 (bus, a); my_if bus; input a; endmodule → port bus … has no direction declaration. my_if bus; is a legal non-ANSI interface port declaration (IEEE 1800 §23.2.2.1 interface_port_declaration); a user-type declaration of a header port can only be that (a data declaration alone would be an error anyway), so it should count, or the rule should stay silent. (my_if.master bus; is already silent; my_pkg::t_s a; correctly reported.)
  5. LOW — missing-port-direction: escaped vs plain spelling. module a7b (\c , d); input c; input \d ; endmodule → reports \c and d; \c and c are the same identifier (IEEE 1800 §5.6.1). Documented ("names as written") but an Error-class FP.
  6. LOW — suspicious-semicolon drain exemption hides the typo the rule exists for. while (q.size()); begin void'(q.pop_front()); end → silent; it hangs. Any call is exempted, including argument-less pure methods. Suggest restricting to calls with ≥1 argument (the try_get(x) output arg) or to try_* names. (while ((q.try_get(x))); is still reported — inconsistent, harmless.)
  7. LOW / lead's call — instance-shadowing nested-loop exemption. foreach (a[i]) foreach (b[i]) x += a[i] * b[i]; → silent; the inner i silently replaces the outer in a[i], a real copy-paste bug. The genvar justification in the doc is inaccurate: nested generate loops may not reuse one genvar (IEEE 1800 §27.4). The opentitan hits sampled (cip_base_vseq.sv:678) are benign, so the exemption is a noise-vs-recall policy choice; the doc should say so rather than claim each loop "owns" the name harmlessly.
  8. INFO (pre-existing, not this round): initial lbl : begin … end : lbl → mismatched-labels error "closes a block with no label" (statement-label form, IEEE 1800 §9.3.5); no fix is offered there, so no corruption.

Mismatched-labels fix probed clean: comment between : and label, escaped footer \b2 → a2, endmodule : wrong → : m, escaped header gets no fix, unlabelled-block footer gets no fix. uvm fix probed clean for if (x) … ; else, case-item label, trailing // and /* */ comments. Neither fix applies without --unsafe-fixes (CLI checked). Not verified: LSP code-action path for the two new fixes; MCP surface beyond its test suite.

2026-11-26 — QA re-check of fix round 1 — verdict: FAIL (one narrow HIGH)

Gates re-run (all green): fmt clean; clippy --workspace --all-targets clean; guarded cargo test -p vlog_linter / lucisv / lucisv_server / lucisv_mcp — 28 binaries, 3,468 passed, 0 failed, no guard kill; node 37/37; stamp 0 to stamp. Production sizes as logged (largest changed 221), no unwrap/expect/panic!/unsafe. Site rules.md table equals --rules-doc on severity/default/fix for all 75 rules; package.json equals the generator. instance_shadowing.rs diff against trunk is empty and no exemption note is left in rules.md. Opentitan guarded sweep reproduces the dev exactly: 1,178, 1 not checked; module-port 165, instance-shadowing 128, suspicious-semicolon 0, incomplete-assignment 1, missing-port-direction 0, mismatched-labels 1. --select uvm-macro-semicolon: 215 findings in 95 files; on scratch copies --fix --unsafe-fixes applied 204, 11 left; lucisv --check result before and after identical (94 would reformat, the same 1 failure), and every other rule's findings on the 95 files identical before/after (no parse change). Lucisv corpus --select incomplete-assignment,missing-port-direction,suspicious-semicolon: 4 findings, exactly the dev's (clock_divider.sv:131 ×3, serial_deglitch.sv:46). Opentitan git status --porcelain empty.

Earlier findings: 1 fixed for every position the lead listed (ternary :, #(…), @(…), operators, return, after another macro, directives — all now no fix) — but see R2-1. 2 fixed (generic_fifo* silent). 3 fixed (if (x) y = a; y = b; silent, top level and nested). 4 and 5 fixed; wire/reg [3:0]/logic/int/my_pkg::t/wire my_t/inline struct/ an instance named like the port are still reported. 6 fixed (q.size(), busy(), (q.size()), f( ), f(,) reported; try_get(x), (q.try_get(x)), $fgets(line, fd) exempt). 7 reverted. 8 fixed: lbl : begin … end : lbl and fork quiet; l2 : begin … end : wrong2 → "closes l2", Unsafe fix rewrites to l2; l6 : if (a) begin … end : l6 still reported (correct — the begin has no name).

New findings:

  • R2-1 HIGH (from Round 7's new fix, not a fix-round regression) — uvm-macro-semicolon still deletes a ; that is not a null statement after a ; that is not a statement end. rules/uvm_macro_semicolon.rs starts_a_statement: TokenKind::Symbol if prev.text == ";" => true. Input for (i = 0; uvm_line; i++) n++;→ fixed tofor (i = 0; uvm_line i++) n++; (does not compile). Same in a constraint block: constraint c { a > 0; uvm_cond; }→{ a > 0; uvm_cond } (a constraint item needs its ;). Needs a uvm_* macro used as an expression, so rare (none in opentitan), but it is exactly the class the whitelist was meant to close. Repair: reject when the ; is inside an unclosed ( (scan back as closes_a_control_header does) or inside a constraint … { block.
  • R2-2 LOW (new in fix round 1, a miss) — full-case ignores the selector's width. if (en) case (s3) 2'b00: … 2'b01: … 2'b10: … 2'b11: … endcase else y = 2; with a 3-bit s3 → silent; s3 = 3'b100 matches no arm (a latch). Trunk reported this shape at top level. Conservative direction; the rule doc could say the labels' width is trusted.
  • R2-3 LOW (new with order-independent coverage, a miss) — if (x) y = a; y[1] = b; → silent; every bit but y[1] latches. Follows from "a partial write counts as coverage", now in either order; defensible as documented, noted.
  • R2-4 LOW (miss, conservative) — missing-port-direction treats any plain user type as a possible interface: typedef logic [3:0] t; t b; and var my_t b; (both data, never interface ports) → silent.
  • INFO (pre-existing): initial l3 : begin : inner3 … end : inner3 (both a statement label and a block name — illegal, IEEE 1800 §9.3.5) is not reported; no wrong fix offered. while (f(.a())); is exempted (named argument with empty value) — harmless. Fixing /* d */ ; leaves a trailing space (no-trailing-whitespace then cleans it).

uvm fix positions probed and correct: first token of file, class item, sole statement of a function, for (…), foreach, repeat, while, if (f(n)), else, do … while, fork … join_any, fork : fk, begin : b1, comments around the ;, if … ; else. No fix (correct): case label 0:, wait (n), assert (n), after another macro, x = (…), return, n + .

2026-11-26 — escalated QA of fix round 2 — verdict: FAIL (one HIGH, same fix)

Gates (all green): cargo fmt --all -- --check clean; cargo clippy --workspace --all-targets clean; guarded (tools/guard.sh -m 8 -t 600) cargo test -p vlog_linter 724 / lucisv 162 / lucisv_server 2,195 / lucisv_mcp 399 passed, 0 failed, no guard kill; node 37/37; stamp 0 to stamp. Changed production files: largest regex.rs 320 lines; no unwrap/expect/panic!/unsafe/#[allow]. rules.md table equals --rules-doc for all 75 rules; package.json equals the generator (78 keys); README has the seven sections. vlog_linter → vlog_semantic is an existing dependency (Cargo.toml / Cargo.lock untouched). Opentitan check hw: 1,178, 1 not checked; module-port 165, instance-shadowing 128, suspicious-semicolon 0, incomplete-assignment 1, missing-port-direction 0, mismatched-labels 1; against a trunk build (temp worktree, removed) the only per-rule differences are suspicious-semicolon 5→0 and incomplete-assignment 0→1. Lint time on opentitan/hw: 0.47–0.48 s for both trunk and this tree (5 runs each). Corpus: incomplete-assignment 4. uvm-macro-semicolon --fix --unsafe-fixes on scratch copies: opentitan 215 findings / 95 files, 203 fixed, 12 left; corpus 22 / 14 files, 22 fixed; in both, only ; bytes were deleted (byte-aligned check), and lucisv --check, default check and check --select error,warning,style --ignore uvm-macro-semicolon outputs are byte-identical before/after. Opentitan git status --porcelain empty.

Findings:

  • R3-1 HIGH (this round's fix) — deleting the ; glues the macro name to the next token. rules/uvm_macro_semicolon/reparse.rs:58-78. Input class c;\n uvm_new_func;endclass(also ``uvm_object_utils_end;endclass after a `;`, uvm_x;end ``, ;endmodule, ;endfunction, ;endtask, ;endgenerate, ;endpackage, ;join) with --fix --unsafe-fixes→ ``uvm_new_funcendclass : an undefined macro and a missing `endclass`; `lucisv --check` on the result: "parse error: expected `endclass`". Expected: no fix. Why the proof passes: (1) `ParsedSource::parse` drops the re-parse's diagnostics and the tolerant parser closes a body at EOF without an `Error` node, so the re-parse is never required to be clean (and `parsed_cleanly()` — "no Error node" — is true for the corrupted text, so the tests' own `after.parsed_cleanly()` assertion cannot see it either); (2) the comparison is kind + start offset only — the invocation's `raw` text is not compared, so uvm_x `` → `` uvm_xend `` at the same offset is "the same node". Needs an argument-less macro with no space after the ;; none in opentitan or the corpus.
  • R3-2 MEDIUM (lead's call) — in a fork the ; is a process. whole.rs:70 lists ForkJoin statements as slots. fork uvm_do(a); uvm_do(b); join_any → both ; deleted. Per IEEE 1800 §9.3.2 a par block is {statement_or_null}, each its own process: before the fix the two null statements end at once and join_any returns immediately; after it, join_any waits for a sequence. That is a behaviour change with UVM's own macros, which the rule doc says cannot happen ("exactly the repair"). No such site among the opentitan/corpus fixes.
  • R3-3 LOW — the result depends on where a pass ends. Condition two refuses an invocation that follows another macro, but one pass deletes both ; of `uvm_a; ⏎ `uvm_b;. With the 32 MiB budget cutting a pass short, the first finding of every later round follows a just-fixed macro and is refused for good: a 1.9 MB file of 20,000 consecutive `uvm_info(…); gets 170 fixed per CLI run (17 per round × 10 rounds), 9 of the first 179 lines permanently skipped. "A second --fix run reaches them" (Assumptions) holds only for small files.
  • INFO — the LSP offers no Unsafe fix at all (lucisv_server/src/code_action.rs:81, fix_all passes false), nor does MCP format (tools/format.rs:178): correct, but Handshakes says the LSP code actions "pick that up", and the comment at code_action.rs:8 ("No rule ships an Unsafe fix today") is now stale (three do). missing-port-direction: parameter type t = logic; t a; is silent (conservative miss).

Probed and correct. uvm fix refused: case arm, statement label, @/#/ wait bodies, ;;, same-line y = 1; / $display / if / begin after the ;, constraint, randomize with, covergroup, property/sequence, concurrent-assertion action, clocking, specify, modport, struct body, UDP table, config, any `ifdef arm's first statement, a file with a parse error, without --unsafe-fixes, inside a // lucisv: off fence, in a `define body. Fixed and judged sound under the stated macro assumption: dangling if (a) if (b) m; else, assert (x) m; else n;, do m; while, generate if/for/case items, CRLF, EOF without newline, ; on the next line, comments and non-ASCII text before the ;, two modules per file, a same-pass explicit-begin fix. Selector width: ascending and non-zero-based ranges, signed, block/generate/other-module shadows, non-ANSI double declarations (agreeing and not), packed 2-D, unpacked, parameter, genvar, `ifdef-alternative declarations, replication/literal/nested concatenations, inherited ANSI type — all as the Assumptions say. missing-port-direction: 31 shapes incl. every round-1/2 pin. Round-1 fixes: drain exemption, instance_shadowing.rs identical to trunk, statement-label handling and its fix, splitter, regex depth 64/65 — intact.

Not verified: behaviour in a real simulator (none installed; R3-2 is from the LRM grammar); interplay of the deletion with every other rule's fix in one pass beyond explicit-begin and the default set on one probe.

2026-11-26 — escalated QA, final check after fix round 3 — verdict: PASS

Withdrawal confirmed. git diff HEAD -- rules/uvm_macro_semicolon.rs is empty; rules/uvm_macro_semicolon/ is gone; no whole.rs / reparse.rs / survives_deleting / whole_invocations / REPARSE_BUDGET / mod reparse / mod whole reference left under crates, docs/site or editors. Under check --select uvm-macro-semicolon --fix --unsafe-fixes every earlier corruption input is byte-unchanged with its finding still reported: R3-1 (`uvm_new_func;endclass, `uvm_object_utils_end;endclass, `uvm_x;end, `uvm_x;endmodule), R3-2 (fork … join_any, 2 findings), R1 (ternary : uvm_line;, <= #(1) uvm_line;), R2-1 (for header, constraint item), and a plain `uvm_info(…);. tests/fix_round_trip.rs round-trips mismatched-labels (two cases), pins uvm-macro-semicolon to fix() == None and no edit with or without unsafe fixes, and keeps the "not without --unsafe-fixes" test on mismatched-labels.

Sync. rules.md table equals --rules-doc for all 75 rules (uvm-macro-semicolon Fix —); package.json equals the generator (78 keys). Handshakes, Status and the fix-round-3 work-log entry describe the tree as it is (LSP/MCP Safe-only stated; stale code_action.rs:8 comment filed as a request).

Gates. fmt clean; clippy --workspace --all-targets clean; guarded cargo test -p vlog_linter 711 passed, -p lucisv 162 passed, 0 failed, no guard kill; stamp 0 to stamp. Guarded release opentitan check hw: 1,178, 1 file not checked; module-port 165, instance-shadowing 128, suspicious-semicolon 0, incomplete-assignment 1, missing-port-direction 0, mismatched-labels 1. Opentitan git status --porcelain empty.

INFO (not this round's to fix): docs/site/…/guides/linter.md:28 names only the always-comb rewrite under --unsafe-fixes; mismatched-labels now has an Unsafe fix too (the sentence does point to the rule reference for per-rule applicability). Not re-run in this check: lucisv_server / lucisv_mcp tests and the node tests (no file of theirs changed since the previous entry, where they were green).

Review

2026-11-26 — lead: accepted after four QA passes; one item withdrawn.

  • Delivered: missing-port-direction (§2.9 #41, closed in docs/topo.md), the nested incomplete-assignment walk with proven-width enumerated cases, the narrowed suspicious-semicolon drain exemption, statement-label handling and the Unsafe footer fix in mismatched-labels, the quote-aware option list splitter, and the regex nesting cap with reused buffers.
  • Withdrawn by lead ruling: the uvm-macro-semicolon autofix. It corrupted code in three successive QA passes (operand positions, for headers and constraints, then token gluing in `uvm_x;endclass) and changes process structure inside fork. The rule is byte-identical to trunk and a test pins that it offers no fix. A future attempt must meet the four conditions in Status / TODO.
  • Reverted by lead ruling: the instance-shadowing nested-loop exemption. It silenced foreach (a[i]) foreach (b[i]), the bug the rule exists for; the 30 OpenTitan hits stay as legitimate reports. module-port was audited and left alone.
  • Escalation per CLAUDE.md: fix round 1 was Opus 5.5; after the second QA failure fix rounds 2–3 and QA passes 3–4 were Fable 5.2.
  • Handshakes ruled: the lucisv.toml parse_array comma split is filed as §2.9 #67 (lucisv_core). The stale Unsafe-fix comment in lucisv_server/src/code_action.rs and the --unsafe-fixes sentence in the site linter guide were corrected by the lead at merge (comment and prose only).
  • OpenTitan lucisv check hw: 1,182 → 1,178 findings (suspicious-semicolon 5 → 0, incomplete-assignment 0 → 1 real latch); lint time unchanged against a trunk build.