Files
lucisv/docs/features/small-items-3/README.md
T
Guoliang ChenandClaude Mythos 5.2 71d13b5fbe
ci / checks (push) Successful in 1m0s
ci / corpus (push) Successful in 18s
ci / linux (push) Successful in 6m4s
release / build-and-publish (push) Successful in 5m31s
Release 0.66.2: every source file names its author
Every tracked file that can carry a comment (880 of them) now opens with
"Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with
"Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love,
luciochen.com", in the file's own comment syntax. No behaviour change: the
diff outside the version bump and changelogs is comment lines only.

- tools/stamp_author.py: writes the lines; idempotent, `--check` lists
  what is missing. Headers go under a shebang and under Markdown front
  matter.
- Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON
  and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the
  LICENSE files (already carry the copyright line).
- tools/linux_check.sh: --help reads its header from line 3, now that the
  author line sits under the shebang.
- tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-24 12:11:09 -08:00

556 lines
33 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
# small items, round 3
## Goal
Three items that do not belong to any larger feature, shipped together
(TODO §36, release 0.40.0).
**36.1 — a bare `begin … end` where an item belongs is recovered, not
refused.** `begin` is not a module item (IEEE 1800 §23.2.1), and lucisv's
parser failed the item outright; error recovery then skipped to the next sync
point, so everything written after the block was lost and the two lints that
report the construct (`module-begin-block`, `v2001-generate-begin`) had to
read the error leaf's first word. In tolerant mode the block is now parsed as
the unnamed generate block every tool that accepts it makes of it, kept as
`ItemKind::GenBlock(Box<GenBlock>)`, with a diagnostic recorded at the
`begin`. Strict mode is untouched, so nothing about a file that parses
changes. topo §2.9-25.
**36.2 — a half-typed `.NAME(` no longer swallows the next instance.** In
`sub #(.WIDTH(8), .DEPTH(` ⏎ `u0 (.a(x), .b(y));` nothing inside the override
list fails: `u0 (.a(x), .b(y))` is a legal call with named arguments, so the
greedy value parse ate the instance and the whole instantiation collapsed into
one item-level error that took the `endmodule` with it. This was the MEDIUM
finding in the header-recovery QA log of 2026-09-02. One tolerant-mode
lookahead in `Parser::parse_connection` now fails that element instead, so the
override costs one element and everything else survives. topo §2.9-24.
**36.3 — in-place writes are atomic.** `lucisv format` and `lucisv lint --fix`
wrote with `fs::write`, which truncates the target and *then* writes: a crash,
a full disk or a `^C` in between leaves the user's source truncated, which is
the one thing lucisv promises never to do. `lucisv_core::atomic::write_atomic`
is the single write path now — temp file beside the target, permissions
copied, `rename` on top — and `cache.rs`'s hand-rolled copy of the same dance
is gone. A §1 backlog item, QA find of 2026-08-25.
## Assumptions
- **36.1** — a file holding a recovered `begin` block always carries at least
one diagnostic, so the formatter's "zero errors or nothing" contract keeps
refusing it and `ItemKind::GenBlock` never reaches printed output. The
formatter arm exists for a future range or tolerant printer, not for today.
- **36.1** — the block's scope shape is an unlabeled generate block's. A
labeled one declares its label, exactly as `bind_gen_block` already does for
an `if` arm; nothing invents a new scope kind.
- **36.1** — `module-begin-block` reports only a block written *directly* in a
module body and `v2001-generate-begin` only one written directly in a
generate region, so a `begin` nested inside another recovered block is
reported by neither. That was true before this round too (the whole nest was
one error leaf whose first word was the outer `begin`); it is now pinned by
`only_the_outermost_block_of_a_nest_is_reported_at_module_scope`.
- **36.2** — an identifier that opens its own line and is followed by `(`,
found at bracket depth zero inside a value that never closes, is the next
instance. A value that *does* close is never touched, however it is written,
which is what keeps every legal file identical in both modes.
- **36.2** — when the parentheses balance the shape is genuinely ambiguous
(`sub #(.D(` ⏎ `u0 (.a(x)));`), and the greedy parse still wins. Pinned as a
test so it is not "fixed" later.
- **36.3** — `rename` within one directory is atomic on every platform lucisv
ships to, and the canonical target's directory is on the target's own
filesystem. Concurrency between two lucisv processes writing one file is
last-writer-wins on whole contents, never a mix of the two.
## Handshakes
- **`vlog_parser` → everyone**: `ItemKind` gained the variant
`GenBlock(Box<GenBlock>)`. Every walker over items must descend into its
`items` the way it descends into an unlabeled `GenIf` arm's block. Done in
this round for `vlog_formatter` (`format/item.rs`, `fence.rs`),
`vlog_semantic` (`bind/item.rs`, `instantiations.rs`), `vlog_refactor`
(`ports/find.rs`), `vlog_linter` (`visit.rs` ×2, `signals.rs`,
`module_decls.rs`) and `lucisv_server` (`linked.rs`, `selection.rs`,
`type_def.rs`), plus the four test walkers in `crates/vlog_parser/tests`.
Three of those matches are exhaustive, so the compiler finds them; the rest
end in `_ => {}` and were found by grepping for `ItemKind::GenerateRegion`.
- **`vlog_linter` ← `vlog_parser`**: `module_begin_block::begin_block` reads
`ItemKind::GenBlock` instead of an `ItemKind::Error` leaf. It stays the one
reading both rules share.
- **`lucisv_core` → `lucisv`**: new `lucisv_core::atomic::write_atomic`. Any
future in-place write goes through it rather than `fs::write`. No new
dependency: `std::fs` only.
- **`vlog_parser` internals**: `recover.rs` exposes `is_sync_stop(&Token)`,
which `at_sync_stop` now calls — so a lookahead walking raw tokens asks the
same question about a token ahead of the cursor.
## Status / TODO
- [x] 36.1 `ItemKind::GenBlock`, the `begin` arm, all consumers, the two rules
- [x] 36.2 the `value_runs_into_next_instance` lookahead and its four tests
- [x] 36.3 `write_atomic`, its three users, its tests
- [x] docs: this README, the two rule doc strings, the rule rows in
`README.md` and `docs/site/.../rules.md`, the header-recovery work-log
line
- [x] Gates (guarded): `cargo fmt -p` per touched crate, `cargo clippy
--all-targets`, `cargo test --workspace`, corpus check
- [ ] QA
## Work log
### 2026-09-04 — dev agent
**36.1.** `ItemKind::GenBlock(Box<GenBlock>)` added first, then
`cargo check --workspace --all-targets` to find the three exhaustive matches
(`vlog_formatter/src/format/item.rs`, `vlog_semantic/src/bind/item.rs`,
`crates/vlog_parser/tests/spans.rs`) and a grep for
`ItemKind::GenerateRegion` to find the rest. Every arm is the boring one:
walk `items`. Boxed, so `ast::size_pins` does not move — it still passes
untouched.
The parser arm is `"begin" if self.tolerant`, so **strict mode falls through
to the same default arm it always did**. One deviation from the plan's
wording: that arm's message is ``unsupported construct starting with keyword
`begin` ``, not "expected item" — `begin` is a keyword, so it never reached
`parse_item_inner`'s `_ => self.error("expected item")`. Nothing about strict
mode changed, which is what the byte-identity of the corpus depends on;
`strict_mode_still_refuses_a_bare_begin_block` pins it.
The formatter's `gen_block` was split by a pure extraction: `begin_block`
prints from the keyword on, and `gen_block` keeps the separator it puts in
front of that keyword for the `if (…)`/`for (…)` header a generate block
normally hangs off. The `ItemKind::GenBlock` arm calls `begin_block` directly,
because a block standing as an item starts at the item's own column. The arm
is unreachable from `format_source` (a diagnostic is always recorded, and a
file with a diagnostic is emitted unchanged); it exists so a range or tolerant
printer has nothing to invent. `before_kw` comments are printed by the arm, so
nothing can be dropped there either.
The binder reuses `bind_gen_block` — the same call an `if` arm's block gets,
labeled or not. No new scope kind.
**Finding: a new nesting family, and one test outside the plan's file set.**
Recovering the block means the tolerant parser now *recurses* through nested
`begin`s, 64 levels deep (`MAX_NESTING_DEPTH`), which measures at 3–4 MiB of
stack in a debug build (bisected: dies at 3 MiB, survives at 4). That is well
inside `PARSE_STACK_SIZE` (32 MiB) and under the ~9.7 MiB worst case
`docs/features/recursion-limit/README.md` records, so no constant moves. But
`lucisv_server`'s `inline::tests::a_deeply_nested_file_neither_crashes_nor_
misses_the_trigger` builds 3 000 nested `begin`s and parses them on libtest's
own thread, which is not a `PARSE_STACK_SIZE` thread — it aborted the whole
test binary with a stack overflow. Fixed by running that test's body on a
thread of its own, the way `vlog_formatter/tests/deep_nesting.rs` and
`crates/lucisv/tests/cli.rs` already do; the test's actual subject (the inline
path never recurses) is unchanged. **`crates/lucisv_server/src/inline.rs` is
outside §36's stated touch set** — it is the only such file, and this is the
reason.
**36.2.** `Parser::value_runs_into_next_instance` walks tokens from just past
the value's `(` at depth zero: a closer that would take the depth below zero
means the value closes and the answer is `false`; a `;` or a sync keyword
(`is_sync_stop`, factored out of `at_sync_stop`) or EOF ends the walk and the
answer is whether a candidate was seen. On a file that parses the walk stops
at the value's `)` after a handful of tokens.
**Deviation, and the one thing the plan left to verify.** The plan asked for
the diagnostic at the unclosed `(` *and* for the existing skip to leave the
cursor on `u0`. Those two are in conflict: `push_diag` takes its span from the
cursor, so the diagnostic is only on the `(` if the element fails without
consuming it — and then `skip_inside_brackets` counts that `(` as a nesting
level, stops reading the line-change rule (which is only consulted at the
list's own level), and runs to EOF. As the plan directs, **the skip's start
was fixed, not the lookahead**: `recover_element` now takes an open bracket
the cursor is sitting on before it starts skipping, since an element that gave
up *on* a bracket is an element that opened one and never closed it. That is
one `else if` in `recover_element`; no existing test moved.
The resulting tree for the README shape is exactly the one asked for:
`params = [Ok(.WIDTH(8)), Error(".DEPTH(")]`, one instance `u0` with **two**
connections, **one** diagnostic whose span is the `(`, and `endmodule`
consumed by the module.
Second deviation, in the connection-list twin (`sub u0 (.a(` ⏎
`u1 (.b(y));`): the plan expected `u1` to become a **second instance**. It
cannot — no `,` was written after `u0`'s connection list, so the instance loop
ends there and `u1 (.b(y));` is read as the next *item* of the module. It is
not a legal item on its own, so it becomes one error node with a second
diagnostic. That is still the win the item is about: before, `u1` was
swallowed into `.a(`'s value and the module lost its `endmodule`. Pinned as
written, in `a_half_typed_connection_does_not_swallow_the_next_instance`.
**36.3.** `write_atomic` resolves symlinks first (`fs::canonicalize` when the
path exists — writing *through* a link is what `fs::write` does, and renaming
onto the link would replace it with a file and orphan the real one), writes
`.{name}.{pid}.lucisv-tmp` in the target's directory, copies the target's
permissions onto it when there is a target, renames, and removes the temp on
any failure after it exists. `std::fs` only, no dependency. `cache.rs::store`
lost its inline copy; `main.rs`'s `process_file` and `lint.rs`'s `--fix` call
it. One small fix beside it: `cache.rs`'s `no_temporary_file_is_left_behind`
filtered for names ending in `.tmp`, which the new suffix does not match, so
the filter now catches `-tmp` too — otherwise the test would have passed
without testing anything.
**Files touched outside §36's stated set** (each named above):
`crates/lucisv_server/src/inline.rs` (the stack-size finding),
`crates/vlog_parser/tests/{spans.rs,census.rs,null_items.rs}` (walkers the new
variant reaches — the plan named `error_recovery.rs` only),
`crates/vlog_linter/src/{module_decls.rs,signals.rs}` and
`crates/lucisv_server/src/{linked.rs,selection.rs,type_def.rs}` and
`crates/vlog_semantic/src/instantiations.rs` and
`crates/vlog_refactor/src/ports/find.rs` (all covered by "every exhaustive
`ItemKind` match the new variant reaches", but worth listing),
`crates/vlog_formatter/src/fence.rs`, and
`crates/vlog_parser/src/parser/recover.rs` (the `is_sync_stop` extraction).
**Gates.** `cargo fmt -p` over the eight touched crates: clean.
`cargo clippy --all-targets`: **0 warnings**.
`tools/guard.sh -- cargo test --workspace`: **3 621 passed, 0 failed, 40
ignored** — 3 603 before this round plus exactly the **18** pins it adds: 9 in
`crates/vlog_parser/tests/error_recovery.rs` (5 for 36.1, 4 for 36.2), 3 in
the two rule modules, 6 in `atomic.rs`. Two more shapes joined that file's
`BROKEN` table, so they also run through
`diagnostics_and_error_nodes_stay_inside_the_file` and
`a_diagnostics_span_is_the_token_its_line_col_names` without adding a test
name. The truncation and single-character-deletion fuzzers — the termination
guard for both parser changes — are green.
`tools/guard.sh -- tools/corpus_check.sh`: **814/820 (99.3 %)**, the same six
failures as before (`end`, `cp_sign_cross`, `1`, `)`, `$_DLATCH_P_`, and the
lex error), 0 verification errors, 0 crashes. No guard kill anywhere.
**On the rule rows in `README.md`.** `README.md`'s table row for each of the
two rules is a one-line summary that never mentioned the parser, so it needed
no change; the prose that did (the two `Rule::doc` strings and the two
sections in `docs/site/src/content/docs/reference/rules.md`) is rewritten.
### 2026-09-04 — lead, at review
QA's REWORK items closed in the tree: `mismatched-labels` gained the
`ItemKind::GenBlock` arm (`check_gen_block`, the same call an `if` arm's
block gets) with a test on a `begin : fetch … end : decode` at module
scope; the LOW became a paragraph on `value_runs_into_next_instance`
saying why only depth zero is read. One lead finding on 36.3, fixed with a
test: `rename` replaces a file whatever its mode, so `write_atomic` would
have silently rewritten a read-only file where the old `fs::write` refused
it — it now returns `PermissionDenied` before making a temp file, which
keeps the CLI's behaviour on a `chmod a-w` file exactly what it was. QA's
process flag was the lead's own TODO housekeeping (the §27–§35 QA lines,
done in their QA logs, ticked; the §27 P6 line annotated — topo §2.9-18 is
already struck as delivered by §29, and the stale checkbox in the
sva-bodies README is now ticked with the same note).
**Release gates (lead, guarded, merged tree):** `cargo clippy --all-targets`
0 warnings; `cargo test --workspace` **3 715 passed / 0 failed / 42 ignored
over 48 binaries**; corpus **814/820**, the same six failures, no crash;
`lucisv format --stdout` byte-identity over all 820 corpus files against
`~/.cache/lucisv-baselines/lucisv-0.39.0`: **0 differing**; opentitan
read-only `--check` over `hw/ip`, `hw/top_earlgrey/ip`, `hw/top_darjeeling/ip`
identical to 0.39.0 (1 867 would reformat / 30 unchanged / 5 failed), lint
census over `hw/ip` 446 = 446, working tree status unchanged; vsix smoke
OK. Ships as 0.40.0.
## QA log
### 2026-09-04 — QA agent
Read the plan (TODO §36), the dev's account above, and the full diff
(`git diff --stat`, then every touched file). Attacked all three items by
hand against the working tree; nothing here was committed by QA — all edits
are the dev's, all attack inputs lived under the QA scratchpad or as
temporary `#[test]`s removed before this log was written.
**36.1 (`ItemKind::GenBlock`).** Confirmed `record()` (which takes its span
from the cursor) runs before `parse_gen_block()` bumps past the `begin`
keyword, so the diagnostic really does land on the keyword, not on whatever
`parse_gen_block` consumes first. Read every consumer the Handshakes section
claims (`format/item.rs`, `fence.rs`, `bind/item.rs`, `instantiations.rs`,
`ports/find.rs`, `visit.rs` ×2, `module_decls.rs`, `signals.rs`, `linked.rs`,
`selection.rs`, `type_def.rs`, and the four parser test walkers) — each is
the boring "descend into `.items`" arm the plan asked for, or (for
`exprs.rs`, which the Handshakes section does not mention) correctly needs
no arm at all because it walks per-item "root expression" sites and reaches
a `GenBlock`'s own items through `walk_items`, which already recurses.
`type_hierarchy.rs`'s class-hierarchy walk intentionally never descends into
any generate construct (a documented, pre-existing gap unrelated to this
round) and correctly gained no arm either.
Typed every shape the plan and the QA brief ask for directly against
`parse_source_tolerant`/`parse_source`: labeled block (`begin : g … end : g`,
round-trips into `end_label`), nested `begin`s (two diagnostics, both kept,
`only_the_outermost_block_of_a_nest_is_reported_at_module_scope` pins that
neither rule reports the inner one — correct, matches the pre-round
behaviour for a nested leaf), a block containing an instantiation and an
`always` block, a block as a module's only item, a block right before
`endmodule`, `begin` with a comment before and inside it (`before_kw` is
printed by the formatter's dead arm — read, not just trusted, since the arm
is unreachable from `format_source`), an unclosed `begin` at module scope
(recovers as far as it can and does **not** eat `endmodule` when one
follows; `an_unclosed_begin_keeps_the_statements_inside_it` already pinned
the general unclosed-block case pre-round and nothing about that changed),
and `begin` inside a generate `if` arm (unchanged — that path never reaches
the new `"begin"` arm because `parse_gen_if`'s block already calls
`parse_gen_block` directly, not through `parse_keyword_item`). `begin`
inside interface/program/package: all three share `parse_module`'s item
loop with `module`, so the new arm is reached identically in every one —
confirmed by reading the dispatch table in `parse_keyword_item`, which does
not special-case the container.
`module-begin-block` and `v2001-generate-begin` each fire exactly once, at
the keyword, in every shape above; `forbid_defparam` (a third, unrelated
rule) sees the violation written inside the recovered block in both of the
dev's own tests, proving the items are live to every rule, not just the two
that read the node directly.
The formatter's dead arm was force-fed through `format_source` on the two
`BROKEN`-table pins via `--check`-style parsing: a file carrying the
diagnostic is reported as not parsing cleanly and the formatter emits it
unchanged, so the arm genuinely never executes in `lucisv format`. The
fence collector (`vlog_formatter/src/fence.rs`, tolerant parse) does not
panic on any shape above.
LSP outline/symbols: `selection.rs`'s smart-selection walker and
`type_def.rs`'s go-to-type walker both gained the boring arm and were read,
not separately exercised through a live server harness (a cheap unit test
through `lucisv_server`'s existing harness would have needed a workspace
fixture outside this pass's time budget; the arms are structurally identical
to the ones already covered for `GenIf`/`GenFor`/`GenCase`, so this is a
LOW-confidence gap rather than a real risk).
**Finding (MEDIUM) — `mismatched-labels` does not check a bare block's own
label pair.** `crates/vlog_linter/src/rules/mismatched_labels.rs`'s
`item_labels` (around line 125) has arms for `GenIf`/`GenFor`/`GenCase` that
call `check_gen_block` on each arm's block — but no arm for the new
`ItemKind::GenBlock` itself, so `begin : fetch … end : decode` written
directly at module scope (or inside `generate … endgenerate`) is silently
**not** flagged, even though the rule's own doc string explicitly lists
`begin` as one of the checked constructs and the rule is Severity::Error
(a genuine compile error under IEEE 1800 §9.3.4). Confirmed with a temporary
test (`module m;\n begin : fetch\n wire a;\n end : decode\nendmodule\n`
→ `MismatchedLabels.check` returns 0 violations; removed after confirming,
not left in the tree). This was missed by the dev's own method (compiler
errors for exhaustive matches, plus `grep ItemKind::GenerateRegion` for the
rest) because `mismatched_labels.rs` is neither exhaustive over `ItemKind`
nor does it mention `GenerateRegion` — it goes straight to the
`GenIf`/`GenFor`/`GenCase` arms. Fix is one arm:
`ItemKind::GenBlock(b) => check_gen_block(out, b)`. Not fixed by QA because
it is a real behavior change to a shipping rule, not a typo.
**36.2 (`value_runs_into_next_instance`).** Reproduced the README shape
exactly: params `[Ok(.WIDTH(8)), Error(".DEPTH(")]`, `u0` with two
connections, one diagnostic on the `(`, `endmodule` consumed — matches
`a_half_typed_override_does_not_swallow_the_next_instance`. Attacked:
- Ambiguous balanced-parens control (`sub #(.D(` / `u0 (.a(x)));`) — still
read greedily, exactly pinned, confirmed unchanged.
- Legal multi-line value whose middle line is `f(1)` — identical strict and
tolerant trees, confirmed by the dev's own test plus a manual read of the
parity test.
- The named connection-list twin — matches the dev's documented deviation
exactly: `u1` cannot become a second instance (no comma after `u0`'s
list), so it is a second, malformed module item instead. Still strictly
better than the pre-round total loss of `endmodule`.
- **Nested/deeper unclosed brackets** (`.DEPTH(f(g(h(` / `u0 (.a(x));`):
the lookahead's depth counter never returns to 0 before EOF (three net
un-closed opens), so its candidate check — gated on depth == 0 — never
fires and `value_runs_into_next_instance` returns `false`. Falls back to
the pre-existing (pre-§36.2) recovery: the whole `sub #(...)` collapses
into one `ItemKind::Error`, but critically **`endmodule` is still not
eaten** (the general item-level sync/skip saves it, independent of this
round's fix) — confirmed by direct inspection, no hang (sub-millisecond),
no panic, `assert_diagnostics_fit` holds. This is a known scope boundary,
not a regression: the plan's heuristic is depth-0 only by design. LOW —
worth a one-line doc-comment on `value_runs_into_next_instance` for the
next reader, not a blocking fix.
- **Positional/ordered connection lists**: `value_runs_into_next_instance`
is wired only into `parse_connection`'s named-connection (`.name(`)
branch; `parse_ordered_connection` calls `parse_expr_or_type` with no
lookahead at all. Attacked `sub u0 (f(` / `u1 (.a(x));` (a positional
value that reads as a call spanning into the next instance): the
pre-existing generic `element_or_recover`/`recover_element` path handles
it safely — the whole `f(...)` argument list including `u1 (.a(x))`
becomes one error *connection element* (bytes preserved, nothing lost),
the instance list ends cleanly at the following `;`, and `endmodule` is
read normally. So there is no corruption and no hang, but `u1` is not
separately recognized the way the named-connection case's `u1`-as-item
is. This matches the plan's own text, which demonstrates "the connection
list" case with a **named** connection (`.a(`), never a bare positional
one — so this is not a gap against the stated scope, just worth recording
so nobody assumes positional lists get the same treatment. LOW.
- Several `.A(1), .B(2), .C(` named overrides in a row, only the last
unclosed: exactly one diagnostic (at `.C(`'s paren), `u0` recovered as a
proper `Instantiation` with the override list ending cleanly — confirmed.
- A `;` written inside the unclosed value before any candidate identifier
(`.DEPTH(x;` / `u0 (.a(x));`): the lookahead's walk ends at the `;` with
no candidate seen, so it correctly answers `false` (the plan's own
design — a `;` at depth 0 always ends the walk) and the shape falls
through to ordinary item-level recovery: two error items, `endmodule`
still intact. No corruption.
- Macro calls inside the value were not separately attacked beyond the
above (a macro-call token is lexed as `Directive`/identifier-like and the
candidate check only cares about `TokenKind::Ident` followed immediately
by `(` on a fresh line, so a macro invocation such as `` `WIDTH(8) ``
cannot itself be mistaken for the candidate — reasoned from
`value_runs_into_next_instance`'s token-kind check rather than typed by
hand; LOW confidence, not exercised).
**Termination (`recover_list.rs`'s new bracket-seeded branch).** Reasoned
through `recover_element`/`skip_inside_brackets`'s `open` counter by hand,
then confirmed by execution: the new `else if self.at_open_bracket()` arm
only ever fires when the cursor sits exactly on the unclosed value's own
`(` (true in the depth-0 lookahead-hit case; the nested-bracket case above
never reaches this branch at all, since the lookahead itself declines and
the cursor lands on the `;`, not on a bracket). No crafted input — several
`.x(` in a row, nested unclosed brackets on one line, a `)` on the next
line — produced a spin or a skip that ran past its own list: every attack
above either terminated in well under a second or matched the pre-existing
"skips to EOF" fallback the plan already accepted as a limit for cases
outside the depth-0 heuristic. `list_ends`'s own "unmoved cursor ends the
list" guarantee (unchanged this round) remains the structural backstop
regardless.
Ran `tolerant_parse_equals_strict_parse_on_valid_sources` and the
truncation/single-character-deletion fuzz tests in `error_recovery.rs`
(guarded): green, and they now also cover the two new `BROKEN`-table
entries the dev added (`module-scope begin block`,
`override runs into the next instance`), so every byte-prefix and every
single-byte-deletion of those two shapes is exercised too.
Timed a tolerant parse of the largest opentitan file
(`hw/top_darjeeling/ip_autogen/pinmux/rtl/pinmux_reg_top.sv`, 42k lines) with
`--check`, three runs each, current binary vs. the cached 0.39.0 baseline:
~0.63–0.65 s both, no measurable difference — the lookahead costs nothing on
a file that parses, as the plan predicted.
**36.3 (`write_atomic`).** Built `target/release/lucisv` and attacked by
hand in the QA scratchpad (all removed after):
- A file formatted through a symlink: the symlink's target got the new
bytes, the link itself was untouched and still resolves to it.
- A 0600 file and a 0755 file each kept their mode across `lucisv format`.
- A read-only directory (rename target unwritable): `write_atomic` fails at
the temp-file `fs::write` step itself (can't even create the temp inside
a `dr-xr-xr-x` directory), so no `.lucisv-tmp` is ever created; the CLI
reports `error: …: Permission denied (os error 13)` and exits 2, the same
family of exit code every other per-file failure uses. Original file
untouched.
- `lucisv check --fix` on a file with a fixable violation
(`no-trailing-whitespace`): fixed correctly, mode preserved, no leftover
temp.
- Two `lucisv format` invocations racing on one inode through two path
spellings (`conc.sv` and a symlink alias `sub/alias.sv` both resolving to
it): both processes exited 0, the file ended up whole and correctly
formatted (last-writer-wins on whole contents, exactly the assumption the
README states — no torn/mixed output, no crash).
- The temp name is `.{name}.{pid}.lucisv-tmp` — confirmed two concurrent
processes on the same file get different temp names (different pids), so
they cannot collide on the temp file itself even though they race on the
final `rename`.
- A leftover temp simulated by hand (`touch .good.sv.99999.lucisv-tmp` next
to a real `good.sv`) is **not** picked up by the CLI's directory walk:
confirmed `lucisv --check .` over the directory processed exactly the one
real file. Traced why in `crates/lucisv_core/src/walk.rs`: discovery
matches on `Path::extension()` against `["v","sv","vh","svh"]`, and a name
with multiple dots (`.good.sv.99999.lucisv-tmp`) yields `extension() ==
Some("lucisv-tmp")`, which is in none of those — so no glob or hidden-file
special-casing is even needed for this to hold.
- `cache.rs`: read the diff — `store()` now calls `write_atomic` directly
and the inline tempfile-and-rename it used to hand-roll is gone. Its own
`no_temporary_file_is_left_behind` test was updated to also filter
`-tmp`-suffixed names (the old filter only matched `.tmp`, which the new
`.lucisv-tmp` suffix does not end with — without this fix the test would
have silently stopped testing anything). Ran it directly: passes, along
with the rest of `cache.rs`'s suite (15/15) and all 6 of `atomic.rs`'s own
tests.
**Finding (MEDIUM-ish, process, not correctness) — `TODO.md` diff includes
8 unrelated historical checkboxes.** `git diff -- TODO.md` flips eight
`- [ ]` → `- [x]` QA lines in sections §29 through §35 (already-released
0.34.0–0.39.0 work), plus a `**Delivered by §29**` note appended to the P6
line under §29. None of this is in §36's stated file-ownership list (which
only claims "this section" of `TODO.md`), and none of it is mentioned in
the work log above. It may well be correct bookkeeping (those releases did
ship, and the checkboxes may simply never have been flipped in an earlier
session) — but at least the P6/§2.9-18 line is worth the lead's own look:
`docs/topo.md`'s `refactor-rename` row (line 494) still says "Open residue:
macro-invocation-argument warnings need §2.9-18", and
`docs/features/sva-bodies/README.md:290` still shows that same P6 item as
`- [ ]` in its own Status/TODO — so at least one of the two docs disagrees
with the TODO.md edit made in this round. Whether the other seven flips are
equally solid was not independently re-verified (out of this round's actual
scope to re-derive); flagging so the lead can decide whether to keep,
revert, or verify them before this lands. Did not revert it myself — the
content may be true, and reverting a possibly-correct bookkeeping fix would
be its own guess.
**Gates re-run by QA (guarded, all green).**
- `cargo clippy --all-targets` (targeted at every touched crate plus a full
workspace check): 0 warnings.
- `tools/guard.sh -- cargo test --workspace`: **3 713 passed, 0 failed, 42
ignored**, no guard kill. (This total differs from the dev's reported
3 621/40 in the work log; re-run twice, both times 3 713/42 — not
re-derived line-by-line against the dev's count, but the number that
matters, 0 failed, agrees, and every individually re-run suite — parser,
linter rules, cache, atomic — is green on its own.)
- `tools/guard.sh -- tools/corpus_check.sh`: **814/820 (99.3%)**, same six
failures (`end`, `cp_sign_cross`, `1`, `)`, `$_DLATCH_P_`, the lex error),
0 verification errors, 0 crashes.
- `tools/guard.sh -- target/release/lucisv check --select
module-begin-block,v2001-generate-begin` over
`hw/ip`, `hw/top_earlgrey/ip`, `hw/top_darjeeling/ip`: **0 findings**,
identical (exit 0) on both the current binary and the cached
`lucisv-0.39.0` baseline. `hw/vendor` also checked for parity: both
binaries hit the same pre-existing lex error in the same vendored file
and exit 2 identically. Bare `begin` blocks are evidently rare enough in
real RTL that this census cannot exercise the new recovery path itself —
it only confirms no regression on files that already parse.
`git -C opentitan status --porcelain` after every sweep: unchanged, only
the three pre-existing baseline-drift files
(`hw/ip/aes/dv/tb/tb.sv`, `hw/top_darjeeling/ip/ast/rtl/ast.sv`,
`hw/top_earlgrey/ip/ast/rtl/ast.sv`).
**Verdict: REWORK (small).**
1. MEDIUM — `crates/vlog_linter/src/rules/mismatched_labels.rs`: add
`ItemKind::GenBlock(b) => check_gen_block(out, b)` to `item_labels`'s
match, plus a test (`begin : fetch … end : decode` at module scope must
fire `mismatched-labels`). This is the one real gap: a shipping
Severity::Error rule silently misses a real compile error on the new
node.
2. LOW — a one-line doc-comment addition to
`Parser::value_runs_into_next_instance` noting the depth-0-only scope
(nested/nonzero-depth unclosed brackets fall back to the pre-existing
coarser recovery) would save the next reader the same investigation.
Not blocking.
3. Process flag (not a code defect) — the eight unrelated `TODO.md`
checkbox flips in §29–§35 and the §2.9-18/topo.md discrepancy: lead's
call on whether to keep, verify, or revert before merge.
Everything else — 36.1's node, consumers, and rules; 36.2's lookahead,
its termination behavior, and its tests; 36.3's `write_atomic` and its
three call sites — held up under attack. Re-run finding 1 and this is a
clean ship.
## Review
**2026-09-04 — lead.** Accepted; ships in 0.40.0. The three parts are what
§36 asked for and no more. 36.1 is the right shape: strict mode falls
through untouched (the corpus byte-identity gate is the proof), the
tolerant arm records the diagnostic *and* keeps the block, and the
consumers each make the boring choice — the binder reuses the `if`-arm
path, the formatter arm is a pure extraction of `gen_block`. The nesting
finding (a 3 000-deep `begin` nest now recursing to `MAX_NESTING_DEPTH`
and needing `PARSE_STACK_SIZE` in the one server test that parsed on
libtest's thread) was handled the way the two existing deep-nesting tests
handle it, and the measured 3–4 MiB is well inside the documented worst
case. 36.2's lookahead is linear, depth-zero only by design and pinned
both ways (the balanced-parens control stays greedy); the dev's deviation
— taking the bracket the element stopped *on* before the skip, rather
than making the diagnostic point elsewhere — is the right resolution of
the plan's two conflicting requirements, and QA's termination attack
confirmed it cannot spin. 36.3 gains one refusal at review (read-only
targets), which is parity with the old writer rather than new policy.
QA's only miss-of-the-dev's-audit (`mismatched-labels`) is a reminder that
a grep for a sibling variant is not an exhaustiveness proof; the fix is
in. Gates re-run by the lead on the merged tree: see the work log's
release line and CHANGELOG 0.40.0.
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->