Files
lucisv/docs/features/semantic-lints/README.md
T

896 lines
52 KiB
Markdown

# semantic-lints
## Goal
The first three lint rules lucisv writes against the *symbol table* rather than
the syntax tree (TODO.md §8, M12): `unused-signal`, `undriven-net` and
`multiply-driven`. TODO.md §7's non-goal — "no semantic claims in v1 lint
rules; semantic rules only after `vlog_semantic` exists" — is crossed here,
which is the whole point: these are the rules Verible structurally cannot
write, because each one needs to know which declaration a name refers to. The
round also wires the analysis into `LintContext` so `lucisv check` and the
language server both reach it through the existing one-parse path, and pays
for it only when a semantic rule actually runs.
The bar the round was built to is **not crying wolf**. A style rule that
misfires is an annoyance; a semantic rule that tells an engineer their signal
is undriven when it is not costs them a debugging session and their trust in
the tool. Every design decision below leans to silence, and each one is
listed as a decision rather than left implicit.
## Assumptions
- **A use with no direction on it must be classified from context.**
`vlog_semantic::Reference` records *that* a name was used, never whether it
was read or written. `crates/vlog_linter/src/signals.rs` derives that from
the AST position the use is written in: an assignment's left-hand side is a
write, an instance connection or a call argument is *unknown*, and
everything else that resolved to a declaration is a read.
- **Unknown means silent.** An instance connection's direction is not looked
up in the instantiated module — not even when that module is in the same
file. `.port(sig)` may be an output, so `sig` is never called undriven. The
same goes for a gate connection, a task or function call argument, a
`clocking` block's signals, and the implicit `.name` connection form.
- **A name a macro, a compiler directive, an attribute, a verbatim block
(`constraint`/`covergroup`/concurrent assertion) or an unparsed region
mentions is dropped from every judgement.** lucisv does not expand macros and
does not evaluate directives, so what those regions do to a signal is
unknowable. This is measured, not theoretical: it is what keeps
`` `ASSERT_KNOWN(FooKnown_A, foo) `` from making `foo` look unused.
- **A module that hides code is not judged at all.** Two ways to hide it: an
instance connected with `.*` (which reads and drives same-named signals
without writing any of their names down) and an `` `include`` written
*inside* the module body (arbitrary code lucisv does not follow — this is
exactly how `prim_rom.sv` loads its memory array). A file-level
`` `include`` does not blind anything: it brings in macro definitions, and
any macro *use* is already guarded above.
- **Ports are the module's interface, not its business.** No rule reports a
port. An input is driven by the instantiating file, an `inout` from either
side, and an unused port is the caller's problem. Only item-level `wire`/
`logic`/`reg`/... declarations inside a `module` are candidates.
- **Interfaces, packages, classes, and block-local variables are out of
scope.** An interface's signals are driven by whoever uses the interface; a
variable declared inside an `always` block is a different (and smaller)
question. Both are honest gaps, not oversights.
- **Single file, single elaboration.** These rules see one file. A signal
read or driven from *another* file through a hierarchical path
(`tb.dut.internal_sig`) is invisible to them — the one false-positive mode
that survives every guard above, and the reason all three ship **off by
default** (see "The on/off ruling" below).
- **The intentionally-unused convention is Verilator's, not Verible's.**
Verible has no unused-signal rule to be compatible with, so there is no
Verible spelling to match. Verilator's `--unused-regexp` defaults to
`*unused*`; lucisv exempts a name containing `unused` (case-insensitive) or
starting with `_`. It is not configurable this round — that waits on the
`lint` key in `lucisv.toml`, like every other rule setting.
- **`analyze` is exact enough to lint on.** The `vlog-semantic` corpus test
asserts every one of its 95 193 name spans slices back to the name it
claims; these rules trust `references_of` for "is this used" and the
reference table for "what does this name mean here".
## Handshakes
**Consumed**
- `vlog_semantic` — **new dependency of `vlog_linter`**, justified here and in
`Cargo.toml`. It is a workspace crate depending on `vlog_parser` alone, so
the linter's external dependency surface is unchanged (still zero:
`cargo tree -p vlog_linter -e normal` is `vlog_parser` + `vlog_semantic`,
both path crates). Used API: `analyze`, `Semantics::{symbols, references,
references_of}`, `Reference::resolved`, `Symbol::{name, name_span}`,
`SymbolId`. Nothing in `vlog_semantic` was modified — the lead's
pre-authorization for a minimal read/write classification **went unused**,
because the classification wants AST context (which statement, which item,
which generate arm) that the binder does not keep and the linter has for
free. Recorded so the authorization is not read as taken.
- `vlog_parser::ast` — the item, statement and expression shapes
`signals.rs` walks, plus `token::TokenKind` for the whole-word mention
scan. Two token facts are load-bearing: a macro invocation is a single
`Ident` token whose text starts with a backtick and carries its arguments
verbatim, and a line directive is a single `Directive` token carrying the
whole line. Both are scanned for words, so a name only a macro mentions is
still seen.
**Promised**
- Three new stable rule names: `unused-signal`, `undriven-net`,
`multiply-driven`. All three are diagnose-only — `Rule::fix()` is `None`
and no violation carries a `Fix`. There is no safe automatic repair for any
of them: deleting a declaration, inventing a driver or removing one all
change what the code means.
- `LintContext` gains two public methods, both additive:
`semantics() -> &Semantics` (analyzes on first use) and
`with_semantics(&Semantics)` (lends a caller's). `from_parse`'s signature
is **unchanged**, so no existing caller had to move.
- The analysis is lazy: a `LintContext` on which no semantic rule ever runs
never calls `analyze`. Measured — a default `lucisv check` over the corpus is
byte-identical and time-identical to the one before this round.
- The signal table is built once per context and shared by all three rules,
so enabling three costs what enabling one costs. Also measured.
**Requested of others (not done here)**
- *whoever owns the workspace index*: the single false-positive mode left in
`unused-signal`/`undriven-net` is cross-file hierarchical use
(`tb.dut.sig`). `WorkspaceIndex` already scans every file in the project;
a "does any file in the workspace mention this name" query would close it,
and is the precondition for these rules defaulting on. Filed here rather
than attempted: it changes a rule from single-file to project-wide, which
is a design decision, not a patch.
- *config-discovery's owner*: the intentionally-unused convention wants to be
a `lucisv.toml` setting (`[lint.unused-signal] ignore = "..."`), for the same
reason the naming styles do. Restated, unchanged.
## The three rules
### `unused-signal`
Flags a `wire`/`logic`/`reg`/... declared at item level in a `module` that
1. bound a symbol (a redeclaration binds none and is never judged),
2. has **zero** references in `vlog_semantic`'s table, and
3. is not mentioned anywhere else in the file's tokens.
Rule 3 is the insurance. The mention scan walks the whole token stream —
comments and string literals excluded, macro invocations, directive lines,
attributes and unparsed regions *included* — and subtracts every position
that is a declared name. If anything is left, the signal is not reported.
Being name-based rather than scope-based, it costs false negatives (an unused
`count` in one module is shielded by a used `count` in the next); that is the
harmless direction, and it is what makes the rule safe in a file full of
macros.
### `undriven-net`
Flags a signal that is **read** somewhere and written nowhere. Silent about:
ports, anything connected to an instance, a gate, a clocking block or a call
argument, anything declared with an initializer, anything a macro or an
unparsed region mentions, anything in a `.*` or `` `include``-bearing module,
and anything nothing reads (that is `unused-signal`'s subject). A drive is any
of: a continuous `assign`, a procedural assignment in an `always*`, `initial`
or `final` block, an assignment in a function or task body, a declarator
initializer, a loop-variable assignment, `x++`, `-> ev` for a named event, or
a **`force`** — a simulation-only override, but one that does put a value on
the signal. **`release` and `deassign` are not drives**: they take an
override *away*, so a signal whose only write is a release is still driven by
nothing, and this rule says so. Whole-signal and part-select writes both
count.
### `multiply-driven`
Flags a **variable** (never a net — a multiply-driven `wire` is what a `tri`
bus is made of) with more than one driver, counting only continuous `assign`s
and `always*` blocks. Two `always` blocks, an `assign` plus an `always`, or
two `assign`s all report. It steps aside entirely when the signal has any
driver that is:
- a **part-select** write (`a[0]` here, `a[1]` there). Still illegal for
`always_comb`/`always_ff`, but proving it needs the bit ranges resolved,
and a conservative rule does not guess. This was the explicitly-flagged
false-positive risk and it is answered by silence.
- inside a **`generate`** construct, where only one arm of an `if`/`case` is
ever elaborated;
- an **`initial`/`final`** block or a **function/task body**, neither of
which says which process runs it;
- a **declarator initializer**, which is an initial value;
- an **event trigger**;
- a **`force`/`release`/`deassign`** override. These are simulation-only
directives with no synthesis meaning: a `force` replaces whatever drives a
signal for as long as it holds, so it is never a *second* driver, and a
`release` establishes nothing at all. Excluding them is deliberately wider
than "do not count them" — like `initial` and a task body, one anywhere on
a signal takes that signal out of the rule, because a forced signal is
verification-harness territory this rule stays out of.
It also steps aside when a conditional-compilation directive
(`` `ifdef``/`` `else``/`` `endif``) is written between the first and last
driver — the preprocessor's spelling of the same exclusivity `generate` has.
lucisv parses both arms of an `` `ifdef`` as ordinary items, so without this
guard the `` `ifdef FAST / `else `` pattern would report every time.
## The corpus measurement, and the on/off ruling
Release build, `lucisv check corpus --select <rule> --output-format json`, over
the 860 `.v`/`.sv`/`.svh` files in `corpus/` (Ibex, OpenTitan, PULP
common_cells, picorv32), 2026-08-25:
| rule | violations | files | wrong answers found on inspection |
|---|---:|---:|---|
| `unused-signal` | 52 | 10 | 0 |
| `undriven-net` | 3 | 2 | 0 |
| `multiply-driven` | 0 | 0 | 0 |
Every finding was read against its source. All 55 are *true statements about
the code*; none is a signal the file actually uses or drives.
**`unused-signal`, all 52, judged:**
| finding | verdict |
|---|---|
| `picorv32.v:221-252` `dbg_reg_x0` … `dbg_reg_x31` (32 of them) | real — debug taps under `` `ifdef DEBUGREGS``, declared to be watched in a waveform viewer, never read by the RTL |
| `picorv32.v:375 mem_busy` | real — dead declaration |
| `ibex_if_stage.sv:768-772` `predicted_branch_nt_pc_d`, `awaiting_instr_after_mispredict_q/_d`, `mispredicted` | real — four dead declarations in shipping ibex RTL, each named once in the whole file |
| `ibex_register_file_fpga.sv:46 mem_o_a`, `mem_o_b` | real — dead declarations, one line, no other mention |
| `alt_lsu.sv:59-77` (6) | real — a formal-verification stub of the LSU with most logic removed; the declarations stayed |
| `cdc_fifo_gray.sv:251 rptr_bin_d`, `rr_arb_tree.sv:195 lower_empty`, `clock_divider_counter.sv:67,70` (2), two `common_cells` testbench signals | real — dead declarations, one of them next to the commented-out code that used it |
| `prim_alert_tb.sv:56 default_spinwait_timeout_ns` | real — assigned at declaration, read by nothing |
**`undriven-net`, all 3, judged:** `unread.sv:21 x` (a module whose *purpose*
is to consume a signal: `logic x; assign d_i = x;` inside
`` `ifdef TARGET_VIVADO``, with `x` deliberately undriven — the file even
carries `/* verilator lint_on UNUSED */`), and `alt_lsu.sv:65,66`
`data_be`/`data_wdata` (the same stripped formal stub: declared, wired to an
output port, assigned nowhere).
**`multiply-driven`: zero.** The rule said nothing about 860 files of good
RTL, which is the strongest quietness evidence available and the same score
`always-comb-blocking` posts.
**Ruling: all three ship `default_on() == false`.** Not because the corpus
was noisy — it was not, 0 wrong answers out of 55 — but because of what the
corpus *findings* are. The largest single cluster (32 of 52 `unused-signal`
hits) is picorv32's debug taps: signals declared precisely so that something
*outside the file* can look at them. That is the one false-positive mode no
guard in this round can close, because closing it means leaving the file. A
first-of-its-kind rule that would put 33 warnings on picorv32's main source
file is not one to switch on for everybody by default.
Two consequences recorded honestly:
- `multiply-driven` is the closest to a default-on rule — it reports a
violation of IEEE 1800 §6.5, it scored 0/860, and cross-file use cannot
create a second *driver*. It is off for now for cost symmetry (enabling any
semantic rule costs the analysis, below) and because a rule with no
demonstrated find has not earned a default.
**How much weight 0/860 carries, honestly (QA finding, 2026-08-25):** less
than it looks. QA reproduced a false positive this corpus could never have
shown — an `assign` plus a `force`/`release` override block, where
`force`/`release` were inheriting the enclosing block's driver kind. Only 2
of the 860 files use either keyword at all, and both write through a
hierarchical path the rule ignores for other reasons, so the score was
silent about the whole surface. The bug is fixed (see the work log below,
and the `.lint` cases that now pin both directions), but the lesson stands:
0/860 measures this corpus's shapes, not the rule's full false-positive
surface. Verification-flavoured RTL — `force`/`release`, hierarchical
drives, `bind`-ed overrides — is thin in this corpus, and that is exactly
the code `multiply-driven` would meet first if it were switched on.
- The path to defaulting the other two on is the workspace index handshake
above, not more guards.
### What the analysis costs
Same corpus, best of five runs, this machine:
| run | 1 thread | 10 cores |
|---|---:|---:|
| `lucisv check` before this round | 0.21 s | 0.07 s |
| `lucisv check` after (semantic rules off) | 0.22 s | 0.07 s |
| `lucisv check --select <defaults>,unused-signal` | 0.26 s | 0.07 s |
| `lucisv check --select <defaults>` + all three | 0.26 s | 0.07 s |
Reading it: the default run is unchanged — proven byte-for-byte, not
inferred, by diffing the whole-corpus JSON and stderr of this build against a
`git worktree` build of `HEAD` (identical, including the 359 parse-error
lines). Turning on a semantic rule costs about **45 ms over 860 files, ~50 µs
per file, +20 % of a single-threaded check** — that is `analyze` plus one
AST-and-token walk. Turning on all three costs the same as turning on one,
which is the shared table doing its job. In parallel the whole thing
disappears into the worker pool.
## Status / TODO
- [x] `LintContext::semantics()` (lazy) + `LintContext::with_semantics()`
(lent); `from_parse` unchanged.
- [x] `crates/vlog_linter/src/signals.rs`: declarations, read/write/unknown
classification, driver kinds and blocks, the opaque-name guard, the
whole-word mention scan, the `.*` / `` `include`` blindness rule.
- [x] `unused-signal`, `undriven-net`, `multiply-driven` — registered,
documented, diagnose-only, off by default.
- [x] Server wiring: `lucisv_server` lends the document's own `Semantics`, so
a keystroke never analyzes twice.
- [x] `force`/`release`/`deassign` classified as their own driver kinds, out
of `multiply-driven` entirely and half-out of `undriven-net` (QA
finding, fixed 2026-08-25).
- [x] 69 new unit tests: 23 in `signals.rs` (the classification), 43 across
the three rule modules, 2 in `context.rs` (lazy vs lent analysis), 1 in
`lucisv_server::lint` (the server reads the document's own table).
- [x] 52 `.lint` cases across three new case files — 16 + 20 + 16 —
covering violating / clean / waived / unused-waiver and every guard.
- [x] Corpus measurement, per-finding judgement, and the on/off ruling above.
- [x] `rules_markdown` golden test pins the three new rows;
`linter-core`'s rule table updated.
- [ ] Cross-file use through the workspace index — the handshake above, and
the precondition for defaulting any of these on.
- [ ] Block-local variables (`logic tmp;` inside an `always` block) and
interfaces as `unused-signal` subjects.
- [ ] Direction-aware instance connections: when the instantiated module is
in the same file, its port directions *are* knowable, which would let
`undriven-net` see an output connection as a driver instead of an
unknown. Deliberately not done — it is a second resolution mechanism
and wants the workspace index behind it anyway.
- [ ] Per-rule configuration of the intentionally-unused convention — needs
the `lucisv.toml` `lint` key.
## Work log
### 2026-08-25 — dev
- **Read first**: `linter-core`, `lint-rules-2`, `vlog-semantic`,
`one-parse`, `lint-harness`, plus `vlog_linter/src/` and
`vlog_semantic/src/model.rs`. Confirmed the premise of the task:
`Reference` carries no read/write kind, so the rules had to classify uses
themselves.
- **Where the classification lives — decision.** The lead pre-authorized a
minimal read/write extension inside `vlog_semantic`. I did not take it.
Classification needs *AST context the binder does not keep*: which item
owns a write (two writes in one `always` block are one driver, two blocks
are two), whether that item sits in a `generate` arm, whether an
`` `ifdef`` separates two drivers, whether a use is an instance connection.
`bind.rs` throws all of that away by design, and adding it would push
driver semantics — a lint concept — into the crate the language server
shares. The linter has the tree already, so the whole classification is
one 658-line module (`signals.rs`, plus 275 lines of its own tests) and
`vlog_semantic` is untouched.
- **Lazy analysis — decision.** Making `from_parse` take a `Semantics`
would have forced every caller to build one, i.e. made `lucisv check` pay for
an analysis nobody reads on a default run. Instead `LintContext` holds a
`OnceCell<Semantics>` filled on first use, plus `with_semantics` for the
server, which analyzes every buffer anyway. `from_parse`'s signature never
moved. Same treatment for the signal table itself
(`OnceCell<Signals>`), which is why three semantic rules cost what one
costs.
- **Three corpus rounds, two of which changed the design.** The first run
scored 56 `unused-signal` and **42** `undriven-net`. Reading the 42 found
two false-positive families, both now closed:
1. **The implicit `.name` connection** (`prim_subreg.sv`'s `.wr_en,`,
`uart.sv`'s `.reg2hw,`, 13 of ibex_top_tracing's `rvfi_ext_*`). The
reference recorded at `.wr_en` resolves to the *instantiated module's
port*, in another file's scope, so the local signal was never marked
connected. Now the connection's name marks the local signal connected
directly. 34 of the 42 were this.
2. **`` `include`` inside a module body** (`prim_rom.sv`, `prim_xilinx_rom.sv`:
`mem` is loaded by `` `include "prim_util_memload.svh" ``). A module
with an in-body include now judges nothing.
A third run, after `-> ev` became a drive, cleared picorv32's two
`ser_sample` findings (`event ser_sample;` triggered with `-> ser_sample`
was being read as "read, never driven"). Final: 52 / 3 / 0, zero wrong.
- **Guards that came from thinking, not from the corpus** (each has a test):
`.*` blinds a module; a name inside a macro, a directive, an attribute, a
verbatim block or an `Error` leaf is dropped; a clocking block's signals are
dropped (`vlog_semantic` records no reference inside one, so the *token*
guard is what catches them — found while testing, and the reason the
clocking case is a `judgeable` test and not a `connected` one); an
expression statement that is not `x++` is a call whose arguments may be
`output` arguments.
- **The `` `ifdef`` guard for `multiply-driven`** exists because lucisv parses
both arms of a conditional as ordinary items — the same property that makes
`unused-signal` see through an `` `ifdef``. Two `always_comb` blocks in
opposite arms would otherwise report every time. Implemented as "is a
conditional directive written between the first and last driver", which is
narrow: a directive elsewhere in the file excuses nothing.
- **Part-selects: silence.** The task named this as the judgement call.
`a[0]` in one block and `a[1]` in another *is* illegal in `always_comb`, but
it is also the everyday shape of legacy `always` code, and lucisv does not
resolve bit ranges. Any partial driver takes the signal out of the rule.
- **On/off**: measured, judged per finding, ruled off for all three, with the
reasoning and the dissent for `multiply-driven` written above rather than
buried.
- **Scope**: `crates/vlog_linter/{Cargo.toml,src/context.rs,src/lib.rs,
src/signals.rs,src/rule_docs.rs,src/registry.rs,src/rules/**,tests/cases/**}`,
`crates/lucisv_server/src/lint.rs` (the two-line lend + one test, which the
task authorized), this README, `docs/features/linter-core/README.md`'s rule
table, and the top-level `README.md`'s Linting section (the three rules and
their off-by-default footnote — changed because that section called the
rule set "syntactic", which this round made false; the bullet originally
omitted it, QA's nit). `Cargo.lock` gains the workspace-internal
`vlog_linter → vlog_semantic` edge. **`TODO.md` deliberately not touched**
(lead's instruction for this round, overriding CLAUDE.md's default).
- **Gates**: `cargo fmt --all --check` clean; `cargo clippy --all-targets
--workspace` silent; `cargo test --workspace` 1535 passed / 0 failed across
34 suites (baseline at `HEAD` a96c908, measured in a throwaway
`git worktree`: 1474 — the delta is exactly this pass's 61 new tests);
`cargo test -p vlog_linter` 182 unit (was 122) + 14 case-harness + 1 doc. CLI smoke:
all three rules fire on a crafted module, the `_ignored` name is exempt, a
`// lucisv: waive unused-signal` suppresses its finding, the default run on
the same file is clean, and JSON carries `"fix":null`.
### 2026-08-25 — dev (QA follow-up: the `force`/`release` ruling)
QA's should-fix, and the lead's ruling on it, implemented in full.
- **`force`/`release`/`deassign` now carry their own `DriverKind`.**
`signals.rs`'s `body()` used to fold `StmtKind::ForceRelease` into the same
arm as `StmtKind::Assign`, so an override inherited the enclosing block's
kind — `Always` inside an `always`, `Initial` inside an `initial`. Two new
variants: `Force` (`force x = ...;`) and `Release` (`release x;` /
`deassign x;`), told apart by the statement's own keyword, which the parser
stores verbatim and only ever sets to one of those three
(`parser.rs:3609-3622`, read to confirm — procedural `assign`/`deassign`
statements are *not* routed here; QA established they become `Error` leaves
and are already opaque). Two predicates carry the meaning where the rules
need it: `DriverKind::is_override()` and `Driver::establishes_a_value()`.
- **`multiply-driven` excludes the family exactly like `Initial`/`Routine`/
`Trigger`**: one override anywhere on a signal takes the signal out of the
rule. QA's repro (`assign a = clk;` plus `force`/`release` inside an
`always` block) reports nothing now — verified through the CLI, not only in
a unit test.
- **`undriven-net` splits the family**: a `force` counts as a drive (it does
put a value on the signal), a `release`/`deassign` does not (it removes an
override — it cannot be the only thing driving a signal). QA's second repro
now reports `` `a` is read but never driven``, which is the correct answer
and closes the undocumented false negative.
- **Attack tests in both directions**, per hard-invariant 4's mindset, and
every one checked non-vacuous by sabotage:
- `an_override_block_is_not_a_second_driver` — QA's exact repro.
- `an_override_anywhere_takes_the_signal_out_of_the_rule` — two *real*
drivers plus a `force` is silence. Deleting `is_override()` from
`unclassifiable()` turns this one red on its own; the other override
tests do not, because giving the family its own kind already keeps it out
of the `Always`/`Continuous` driver count. Recorded because it means the
wider exclusion is a *second*, independent decision, and it needed its
own test to be real.
- `an_override_does_not_hide_a_real_conflict_it_did_not_create` — the same
two drivers without the override still report, so the exclusion cannot be
reached by accident.
- `a_force_is_a_drive_but_a_release_is_not` and
`a_released_signal_that_something_really_drives_is_quiet` — both
directions of the `undriven-net` split. Reverting the rule to
`!usage.drivers.is_empty()` turns the first one red.
- `the_override_family_keeps_its_own_kind_inside_any_block` and
`only_a_release_establishes_no_value` in `signals.rs` — the
classification itself, for all three keywords in `always`, `initial` and
a task body.
- Six new `.lint` cases: four in `undriven_net.lint` (force-drives,
release-only *violating* with its marker, deassign-only violating,
release-next-to-a-real-driver clean) and two in `multiply_driven.lint`
(QA's repro, and the override-anywhere case). A deliberate wrong column
in the release-only marker produces the harness's two-direction report,
so the new cases are not vacuous either.
- **Corpus unchanged**, checked rather than assumed: 52 / 3 / 0, and the
three JSON outputs are byte-identical to the pre-fix run — the corpus's two
`force`/`release` files write through hierarchical paths these rules do not
track, which is exactly why the corpus never showed the bug. Default
`lucisv check` over the corpus is still byte-identical (stdout **and**
stderr) to a `git worktree` build of `HEAD` a96c908.
- **README**: the `undriven-net` driver list now names `force` and states
that `release`/`deassign` are not drives; `multiply-driven`'s exclusion
list gained the override bullet with the "deliberately wider" note; and the
"closest to default-on" argument now carries QA's caveat that 0/860 does
not cover the `force`/`release` surface at all.
- **Gates after the fix**: `cargo fmt --all --check` clean, `cargo clippy
--all-targets --workspace` silent, `cargo test --workspace` **1543 passed /
0 failed** across 34 suites (1535 before this pass; the delta is the 8 new
unit tests). `cargo test -p vlog_linter` 190 unit + 14 case-harness + 1
doc. No version bump, `TODO.md` still untouched.
## QA log
### 2026-08-25 — QA
Verdict: **ship-after-fixes**. No hard-invariant break, no corruption risk
(all three rules are diagnose-only — `Rule::fix()` is `None`, confirmed by
grep and by every rule's `it_points_at_the_declared_name` test asserting
`fix.is_none()`), and the byte-identical/corpus-count claims all reproduce
exactly. One should-fix correctness finding below (`force`/`release`
misclassification), plus two low-severity notes. Nothing was corrupted or
made worse; the should-fix is a real gap in the rule that this round itself
flags as "closest to default-on."
**Gates.** `cargo fmt --all --check` clean. `cargo clippy --all-targets
--workspace` silent (forced rebuild by touching `lib.rs` first, per the
house discipline). `cargo test --workspace`: **1535 passed**, 0 failed,
summed from every `test result:` line — matches the claim exactly.
`node editors/vscode/smoke.js target/debug/lucisv-server`: `OK`. No `unsafe`;
the only `.unwrap()`/`.expect()`/`panic!` in the five touched files
(`signals.rs:675-676`, `context.rs:355`) are inside `#[cfg(test)]` modules.
No `#[allow]` anywhere in the new code. `cargo tree -p vlog_linter -e
normal`: `vlog_parser` + `vlog_semantic`, both path crates — matches the
Handshakes claim and the justification comment in `Cargo.toml`. Crate
version stayed `0.4.2` (no bump), `TODO.md` untouched, confirmed by
`git status`.
**Byte-identical claim — verified myself, not re-trusted.** Built HEAD
(`a96c908`) in a `git worktree`, release profile, alongside the working
tree's release build. `lucisv check corpus --output-format json` from both
binaries: stdout **byte-identical**, stderr **byte-identical** (same
single lex-error line and the same "found 7932 violations, 1 file could
not be checked" summary — the corpus grew a naming-rule finding since the
lint-rules-2 round, but the two builds under test agree with each other,
which is the claim). Exit code 2 both. The default corpus run **contains
no semantic-rule finding** — confirms "the default run adds nothing."
**Corpus counts — reproduced exactly.** `--select unused-signal`: 52
violations / 10 files. `--select undriven-net`: 3 / 2. `--select
multiply-driven`: 0 / 0. Per-file breakdown matches the README's table
verbatim (33 picorv32.v, 6 alt_lsu.sv, 4 ibex_if_stage.sv, 2
ibex_register_file_fpga.sv, 2 clock_divider_counter.sv, and 1 each for the
rest). Independently spot-read three hits against source, not just trusted
the dev's table:
- `picorv32.v:375 mem_busy` — declared with an initializer, `grep -n
mem_busy` finds only the declaration line. Real.
- `ibex_if_stage.sv:768 predicted_branch_nt_pc_d` — declared alongside
`predicted_branch_nt_pc_q`; grep finds only the one declaration line for
the `_d` name. Real.
- `common_cells/src/unread.sv:21 x` — read the whole 24-line file: `x` is
declared and assigned to the input port `d_i` only inside `` `ifdef
TARGET_VIVADO``, bracketed by `/* verilator lint_off/on UNUSED */`,
exactly the "deliberately undriven, module exists to consume a signal"
shape the README describes. Real.
All three agree with the dev's judgement. **0 wrong answers confirmed.**
**The cross-file false-positive mode — reproduced on purpose.** Built a
two-file fixture (`dut.sv` declaring `logic dbg_probe;` with no local
driver or read, `tb.sv` instantiating it and reading `d.dbg_probe`
hierarchically). Linting `dut.sv` alone: `unused-signal` fires on
`dbg_probe` — exactly the documented blind spot, and exactly the
picorv32 `dbg_reg_x0..x31` shape. Note for the record: the **same-file**
version of this test (both modules in one file) does **not** reproduce
the false positive, because the whole-token mention scan
(`mentioned_outside_declarations`) sees the literal identifier text
`dbg_probe` in the hierarchical reference `d.dbg_probe` and treats it as
"mentioned," even though `vlog_semantic` never resolves a reference to it.
This is a second, independent guard accidentally covering part of the
same blind spot — worth knowing, not worth changing: it only helps when
the hierarchical reader happens to sit in the same file, which is not the
case that matters (waveform viewers, VPI, and other-file testbenches carry
no source text at all).
**Attack results.** Per rule, in the order of the QA brief:
*`unused-signal`* — all silent as documented: macro-argument-only use
(`` `ASSERT_KNOWN(FooKnown_A, foo)``), assertion/property-only use
(`assert property (...)`), different `` `ifdef`` arms (declare in `A`, use
in `B` — silent because the token scan doesn't respect `` `ifdef``
boundaries, the documented false-negative direction), unpacked-struct
member read, genvar (never a candidate — `ItemKind::Genvar` isn't scanned
into `Decl`s at all, confirmed by reading `signals.rs`'s `item()` match,
which only handles `ItemKind::DataDecl`). Whole-word matching confirmed
live: `clk` unused next to a used `clk_en` **is** flagged (no substring
shielding).
*`undriven-net`* — input port read: silent (unit-tested, re-confirmed
live). Force-only-driven signal: silent (confirmed live —
`force a = 1'b1;` inside `initial` satisfies the drive). Task
output-argument: silent (`compute(result)` with `result` never assigned
elsewhere — confirmed live, `unknown.push` covers the whole call-statement
span). `readmemh`-loaded memory: silent (confirmed live — `$readmemh(...)`
is an `ExprStmt` whose whole span is pushed to `unknown`, same mechanism
as a task call). The closed implicit-`.name` FP family: reproduced the
pre-fix shape directly (`prim_subreg`-style `.reg2hw,` connection, no
local driver, signal read elsewhere) — silent, confirming the fix holds.
*`multiply-driven`* — two `always_comb`: flagged. `always_ff` + `assign`:
flagged. Two `initial` blocks: silent (`Initial` is `unclassifiable`).
Different struct fields written from two blocks: silent (member writes
are `whole: false`, disqualifying). Latch-inference shape
(`always_comb` with no `else`): silent, correctly out of this rule's
business. Implicit (keyword-less) generate-if: silent, confirmed the
`in_generate` flag is set for `GenIf` reached without an explicit
`generate`/`endgenerate` wrapper, not just the explicit-keyword shape the
unit tests use.
**Should-fix — `force`/`release`/`deassign` collapse into the enclosing
block's ordinary `DriverKind`, and `release`/`deassign` are untested.**
`crates/vlog_linter/src/signals.rs:383-420`, the `body()` walk:
```rust
StmtKind::Assign { lhs, .. } | StmtKind::ForceRelease { lhs, .. } => {
self.write(lhs, kind, block, in_generate)
}
```
`kind` here is whatever `DriverKind` the caller passed for the *whole
enclosing block* (`Always` for any `always*`, `Initial` for
`initial`/`final`, `Routine` for a function/task body) — `force`, `release`
and `deassign` are not told apart from an ordinary procedural assignment,
and not told apart from each other. Two consequences, reproduced live:
1. **False positive for `multiply-driven`.** A signal driven by one
continuous `assign` and overridden by `force`/`release` inside an
`always` block (a verification-harness pattern — bypass/override logic
guarded by a control signal) is reported as "driven both by a
continuous assignment and by a procedural block," even though
`force`/`release` are simulation-only directives with no synthesis
meaning and are not what the rule's own doc says it counts ("only
continuous `assign`s and `always*` blocks" — true assignments, not
overrides). Repro:
```systemverilog
module m (input logic clk, input logic bypass, output logic q);
logic a;
assign a = clk;
always @(posedge clk) begin
if (bypass) force a = 1'b1;
else release a;
end
assign q = a;
endmodule
```
`lucisv check --select multiply-driven` on this file: 1 violation,
`` `a` is driven both by a continuous assignment and by a procedural
block``. This is exactly the kind of finding CLAUDE.md and this
feature's own "not crying wolf" bar exist to prevent — a real,
non-synthetic RTL/verification shape producing a wrong accusation. Low
corpus incidence today (`grep` for bare `force `/`release ` statements
finds only 2 of 860 files, and both write through a hierarchical path
that this rule doesn't track anyway, which is why the corpus scored
0/860 despite the bug), but the README specifically argues
`multiply-driven` is "the closest to a default-on rule" on the strength
of that 0/860 score — this finding means the 0/860 score under-reports
the rule's real false-positive surface, and should be weighed before
that argument is acted on.
2. **Undocumented behavior, false negative, for `undriven-net`.** The
README's driver list names `force` explicitly ("A drive is any of: ...
`force`, ...") but never mentions `release`/`deassign`. The code
nonetheless treats a signal driven *only* by `release`/`deassign` (no
actual assignment anywhere) as driven, so `undriven-net` stays silent
on it. Repro:
```systemverilog
module m (output logic q);
logic a;
initial begin
release a;
end
assign q = a;
endmodule
```
`lucisv check --select undriven-net`: 0 violations, even though `a` is
never actually assigned a value anywhere in the file. This is the
silent/harmless direction (no false accusation), so it is not a
blocking bug, but it is a real behavior gap the doc doesn't own, and it
has **zero test coverage**: `grep -n
"force\|release\|deassign\|ForceRelease"` across `signals.rs` and all
three rule files finds exactly one hit
(`undriven_net.rs`'s `every_shape_of_drive_silences_it`, which covers
`force` only). No test exercises `release`, `deassign`, or the
`force`/`release`-inside-`always` shape at all — the multiply-driven
false positive above was not caught by the 61 unit tests or the 46
`.lint` cases because none of them tries it.
Recommend, for the dev's next pass (not attempted here — this is a design
decision, adding a `DriverKind::Override` or similar and excluding it from
`multiply-driven`'s and `undriven-net`'s reasoning the same deliberate way
`Initial`/`Routine`/`Trigger` already are, not a typo fix): give
`force`/`release`/`deassign` their own `DriverKind` distinct from the
block they sit in, with masked-corruption-style attack tests for both
directions (force/release must not manufacture a `multiply-driven` finding
out of an override pattern; force must still count as a drive for
`undriven-net`). This doesn't block shipping the three rules off-by-default
as this round proposes — the off-by-default posture already absorbs it —
but it should be fixed before `multiply-driven`'s default is ever
reconsidered, per the README's own reasoning about that rule.
**Separately verified, not a parser bug introduced by this round:**
procedural continuous assignment (`assign a = b;` written as a *statement*
inside a procedural block, as opposed to the item-level continuous
`assign`) is not a recognized statement form in `vlog_parser` — it falls
through `parse_keyword_stmt`'s final `_ =>` arm into `StmtKind::Error`.
Confirmed live: a file using this form produces zero findings for any of
the three rules on the affected signal, because `signals.rs` already
treats an `Error` leaf as opaque (`item()`/`body()`'s `StmtKind::Error(_)
=> self.opaque_spans.push(...)`), which is the safe default this round's
"when uncertain, say nothing" policy calls for. No action needed; noted
because the QA brief asked about "procedural continuous assign/deassign"
by name and the honest answer is "silently and safely out of scope," not
"handled."
**Waivers.** Spot-ran `// lucisv: waive <rule>` on the declaration/violation
line for all three rules live (not just the `.lint` harness, which was
also re-run: `cargo test -p vlog_linter --test lint_cases` — 14/14 green,
including the three new case files' own suites). Every waiver suppressed
its rule's finding as expected.
**Server parity.** `crates/lucisv_server/src/lint.rs`'s `context()` now
calls `.with_semantics(&doc.semantics)`, and the round's own test
(`a_semantic_rule_reads_the_documents_own_analysis`) proves both that a
semantic rule fires correctly through the server's `LintContext` and that
`context(doc).semantics()` is pointer-identical to `&doc.semantics` (the
lent table, not a second analysis) — read and re-run, passes. **Caveat
worth recording**: `lucisv_server::lint::violations`/`diagnostics` call
`lint(&context(doc), &default_rules())` only (`crates/lucisv_server/src/
lint.rs:35-36`) — there is no server-side rule-selection surface yet, so
none of the three semantic rules can actually be *reached* through the
live LSP path today; the parity claim is true at the plumbing level (verified
above) but not yet observable end-to-end through a real `initialize`/
`didOpen`/`publishDiagnostics` exchange, because there is nothing to
select them with. Not a defect — the README doesn't claim otherwise — but
worth flagging so "server parity" isn't read as "reachable from the
editor today."
**Test-count reconciliation — exact, not approximate.** `grep -c
"#\[test\]"`: `signals.rs` 21, `rules/{unused_signal,undriven_net,
multiply_driven}.rs` 12+13+12=37, `context.rs` 9 total (2 new — the other
7 predate this round), `lucisv_server/src/lint.rs` 11 total (1 new). New
total: 21+37+2+1 = **61**, matching the claim exactly. `.lint` case
files: 15/15/13 `====` separators → 16/16/14 cases (one more case than
separators, per the format) = **46**, matching exactly. This precision
across every count claimed in the work log is itself evidence the rest of
the narrative is trustworthy.
**Minor, cosmetic finding.** The Work log's "Scope" bullet
(`docs/features/semantic-lints/README.md`, the "2026-08-25 — dev" entry)
lists the touched files as `crates/vlog_linter/{...}`,
`crates/lucisv_server/src/lint.rs`, "this README, and
`docs/features/linter-core/README.md`'s rule table" — it does not mention
the top-level `README.md`, which `git diff HEAD -- README.md` shows *was*
changed (a "Linting" section update adding the three new rules and the
off-by-default footnote). The change itself is accurate and welcome; the
Scope bullet is just incomplete. Left unfixed — it's the dev's Work log
entry, not mine to edit.
**On the off-by-default ruling (task item 5).** Agree with shipping all
three off by default. The corpus evidence is real (I re-derived it
independently) and the cross-file blind spot is the correct reason — I
reproduced it directly rather than taking the argument on faith. I
partially disagree with how strongly the README stakes `multiply-driven`'s
"closest to default-on" case on the 0/860 corpus score: that score is
real but, per the finding above, doesn't cover the `force`/`release`
shape at all (only 2 corpus files use either keyword, and both write
through a hierarchical path this rule already ignores for other reasons).
The rule's true false-positive surface is not fully measured by this
corpus. This doesn't change my agreement with the off-by-default
*decision* — it changes how much weight I'd put on "0/860" as an argument
for flipping the default later, until the `force`/`release` classification
is fixed.
**Fixes applied by me:** none — every finding above needs a design
decision (a new `DriverKind` variant and its threading through two rules)
or is a documentation/logging nit outside QA-log-only scope, not a typo or
missing assertion.
### 2026-08-25 — QA, round 2 (force/release rework)
Verdict: **ship**. The should-fix from round 1 is closed at the mechanism
level, correctly and more thoroughly than the minimum fix would have been.
Every claim in the dev's round-2 message reproduced exactly; the two
sabotage checks behaved exactly as predicted, including the mechanistic
detail (blocks-filtering vs. the wider unclassifiable() exclusion) that the
dev's own explanation rests on. No new findings.
**Mechanism, verified by reading `signals.rs` and `parser.rs` before
running anything.** `parser.rs:3609-3622` — confirmed `"force"` and
`"release" | "deassign"` are the only two arms producing
`StmtKind::ForceRelease`; nothing else in `parse_keyword_stmt` does.
`DriverKind` gained `Force` and `Release` (`signals.rs:47-53`); the
`body()` walk's `StmtKind::ForceRelease { kw, lhs, .. }` arm now sets
`kind` from `kw` directly (`"force"` → `Force`, else → `Release`) instead
of inheriting the caller's block-level `kind` — and it does this
**unconditionally**, so `force`/`release` keep their own kind regardless
of which block they sit in (`always`, `initial`, or a task/function body).
`DriverKind::is_override()` (`Force | Release`) and
`Driver::establishes_a_value()` (`self.kind != DriverKind::Release`) are
the two new predicates; `multiply-driven`'s `unclassifiable()` gained
`|| driver.kind.is_override()`, and `undriven-net`'s `check()` now gates
on `usage.drivers.iter().any(Driver::establishes_a_value)` instead of
`!usage.drivers.is_empty()`.
**Confirmed the dev's mechanistic claim independently, not just read it.**
The claim: separating `Force`/`Release` from `Always` already closes my
round-1 `multiply-driven` false positive through `blocks()`'s exact-kind
filter alone, before `unclassifiable()` is even touched — because
`blocks(&usage.drivers, DriverKind::Always)` only counts drivers whose
`kind == Always`, and a `force`/`release` inside an `always` block no
longer has that kind. I verified this by tracing it rather than trusting
the sentence: my round-1 repro (`assign a = clk;` plus `force`/`release`
inside an `always` block) has one `Continuous` driver and zero `Always`
drivers under the new scheme, so `always.len() + continuous.len()` is
`0 + 1 = 1 < 2` regardless of `unclassifiable()`. That means
`driver.kind.is_override()` in `unclassifiable()` is doing separate,
*additional* work: taking a signal out of the rule entirely whenever an
override touches it anywhere, even when two genuine drivers already exist
independent of the override. I confirmed this is exactly what
`an_override_anywhere_takes_the_signal_out_of_the_rule` tests (two real
`always_comb` drivers plus an unrelated `initial force`) and exactly what
the sabotage below isolates.
**Sabotage-checked both named predicates myself, in the actual tree, not
by reasoning alone:**
1. Deleted `|| driver.kind.is_override()` from `unclassifiable()`
(`multiply_driven.rs`). `cargo test -p vlog_linter` (full crate, 190
tests): **exactly one** test went red —
`an_override_anywhere_takes_the_signal_out_of_the_rule` — with the
failure showing the two-`always_comb` conflict now reporting again
(`` `a` is driven from 2 always blocks``), which is precisely the
mechanism above: without the wider exclusion, `blocks()`'s kind
filtering alone isn't enough to silence a genuine conflict that merely
*also* has a force nearby. `an_override_block_is_not_a_second_driver`
(my original round-1 repro, now a named test) stayed green under this
sabotage, confirming the dev's claim that `blocks()` filtering alone
already covers that specific case. Reverted; `md5` of the file matched
before and after.
2. Changed `establishes_a_value()` to `true` unconditionally
(`signals.rs`). Two tests went red:
`rules::undriven_net::tests::a_force_is_a_drive_but_a_release_is_not`
(the one the coordinator named) and
`signals::tests::only_a_release_establishes_no_value` (the classifier's
own unit test, which exercises the same predicate directly and would be
a strange thing to leave silently passing). Both failures are the
expected shape: a `release`-only signal stopped being flagged undriven.
Reverted; `md5` matched before and after both files.
**Round-2 attacks (coordinator's list), all live against the release
binary:**
| attack | result | verdict |
|---|---|---|
| `force` targeting a part-select (`force a[0] = ...`) alongside `assign a = ...` | `multiply-driven` silent | correct — a part-select write already disqualifies via `!driver.whole`, independent of the override fix; no resurrection |
| `force` targeting the whole signal (control, same shape without part-select) | `multiply-driven` silent | correct, matches round-1 fix |
| `force` inside a **task body** (`task drive_it; force a = 1'b1; endtask`) | `undriven-net` silent | sane — `Force` is set unconditionally from the statement keyword and wins over `Routine`; a force is a force regardless of what calls it |
| `deassign` alone, no other driver | `undriven-net` **flagged** (`` `a` is read but never driven``) | correct — `deassign` maps to `Release`, which does not establish a value, exactly as the coordinator expected |
| `force` then `release` of the **same** signal in one `initial` block | both rules silent | correct — `undriven-net` sees the `Force` driver (`establishes_a_value() == true`) and stops there; `multiply-driven` excludes the whole signal via `is_override()` on either driver |
| hierarchical `force` (`force u.y = 1'b1;`, `u` an instance) | all three rules silent | unchanged from round 1 — `lvalue_targets` still resolves a `Member` write down to its base identifier, which is the instance symbol, not a tracked `Decl`; the override-kind change doesn't touch this path at all |
No new false positives or false negatives found in this pass.
**Gates, re-run clean.** `cargo fmt --all --check` clean. `cargo clippy
--all-targets --workspace` silent (forced rebuild). `cargo test
--workspace`: **1543 passed**, 0 failed — exactly the claimed 1535 + 8.
`node editors/vscode/smoke.js` OK. No `#[allow]` added anywhere in
`signals.rs`/`multiply_driven.rs`/`undriven_net.rs`; no `.unwrap()`/
`.expect()`/`panic!` outside `#[cfg(test)]` in those files.
**Test-count and case-count reconciliation, exact again.** `#[test]`
counts: `signals.rs` 23 (+2), `unused_signal.rs`/`undriven_net.rs`/
`multiply_driven.rs` 12+15+16=43 (+6), `context.rs` 9 (unchanged),
`lucisv_server/src/lint.rs` 11 (unchanged) → **8 new unit tests**, matching
the claim exactly. `.lint` `====` separators: `unused_signal` 15
(unchanged, 16 cases), `undriven_net` 19 (+4, 20 cases), `multiply_driven`
15 (+2, 16 cases) → **6 new cases**, totalling **52** (16+20+16), matching
both the round-2 claim and the arithmetic in `Status/TODO`.
**Byte-identical claim, re-verified with a fresh worktree build.** Built
HEAD (`a96c908`) in a new `git worktree`, release profile. `lucisv check
corpus --output-format json`: stdout and stderr byte-identical to the
working tree's release build (same exit 2, same single lex-error line,
same summary line). Also diffed the new `--select <rule>` corpus outputs
against my own round-1 saved copies: **byte-identical** for all three
rules, confirming the 52/10, 3/2, 0/0 counts didn't just come out the same
by coincidence — the actual finding sets didn't move at all, as expected
since the fix only reclassifies `force`/`release` drivers, which the
corpus barely contains and which write through paths these rules already
ignore.
**Docs.** The `undriven-net` section now names `force` as a drive and
states `release`/`deassign` are not, matching the code. The
`multiply-driven` section's bullet list gained the override exclusion with
the "deliberately wider than not-counting" framing that matches
`an_override_anywhere_takes_the_signal_out_of_the_rule`'s actual behavior,
not a narrower claim the code wouldn't back up. The on/off ruling now
carries the "how much weight 0/860 carries, honestly" paragraph I asked
for in round 1 — read it, and it states the finding accurately (2 corpus
files, both hierarchical, score doesn't cover the surface) without
overclaiming that the bug fix now makes 0/860 fully trustworthy — it
doesn't, since the corpus still can't exercise the shape either way; the
paragraph is honest about that limit rather than declaring victory.
**Verdict: ship.** The should-fix is closed correctly, at the mechanism
level, with tests that fail for the right reason when sabotaged (verified,
not assumed) and documentation that matches the code rather than
overclaiming it. No blocking or should-fix findings remain from either
round.
## Review
**2026-08-25 — lead.** Reviewed after QA round 2's ship verdict; gates
run independently (1543 tests, 0 failures). This milestone crossed the
"no semantic claims" line the right way: measurement first (55 corpus
hits, every one read against source, two false-positive families found
and closed by measuring), defaults decided from the data (all three off,
with the honest reason — the cross-file-read blind spot — not modesty),
and the classification's unknown-direction taxonomy doing the
load-bearing honesty. The dev declining my pre-authorized vlog_semantic
extension was the correct call for the right reason: driver semantics is
a lint concept, and the binder discards the context it would need by
design. QA's force/release find was real — the fix's two independent
layers (own DriverKind; override-excludes-entirely) each carry their own
only-test-that-goes-red, verified by sabotage twice over. Default `lucisv
check` output stays byte-identical to HEAD, worktree-diffed by three
different people now. Accepted; M12 checked off in the umbrella plan and
TODO §8. The path to default-on runs through the workspace-index
handshake filed in this README — a future round's decision, made on a
future round's measurements.
*(reserved for the lead)*