Closes TODO §71: eight owner-ordered features shipped as 0.65.2–0.65.11. No engine change since 0.65.11. - docs/topo.md refreshed through 0.65.11: contracts, server-lane edges, packaging rows, open handshakes 44–66, new modules, choke points; stale FACTS_FORMAT and state.rs references corrected. - CLAUDE.md: file sizes re-measured. - Feature READMEs: five stale facts corrected. - large.rs: the two linear-time tests re-measure up to three times before failing (0.65.11's Linux CI run read 24.9x against a 24x limit under load). Co-Authored-By: Claude Mythos 5.2 <[email protected]>
957 lines
56 KiB
Markdown
957 lines
56 KiB
Markdown
# format-styles
|
||
|
||
## Goal
|
||
|
||
Let a project pick a house layout by name instead of living with lucisv's
|
||
one: `[format] style = "<name>"` in `lucisv.toml`, `--style <name>` on the
|
||
command line, and a `lucisv.format.style` drop-down in VS Code. The owner
|
||
asked for the formatter to "adapt to the current file's way of handling when
|
||
to start newline / what to group / how to align the ports", with a drop-down
|
||
of common styles (ANSI, Google, Microsoft, NXP) as the fallback if adapting
|
||
is too ambiguous, and for the rules to be easy to read in the source. So
|
||
this ships both: six named presets, each one row of a table in
|
||
`crates/vlog_formatter/src/style.rs`, and `auto`, which lays each file out in
|
||
the preset it is already closest to. The default, `lucisv`, is byte-for-byte
|
||
the layout every earlier release produced — proven over the corpus and
|
||
OpenTitan, not asserted.
|
||
|
||
## Assumptions
|
||
|
||
- **A style only moves whitespace.** Every switch chooses between a space and
|
||
a line break in front of a token, a deeper or shallower indent, or padding.
|
||
The token stream is identical under every style, which is why `verify.rs`
|
||
is untouched (CLAUDE.md invariant 4: nothing was widened).
|
||
- **An explicit `indent`/`line-length` beats the preset's**, from whichever
|
||
rung it came. A preset is a starting point; a number someone wrote down is a
|
||
decision. `--style ansi` with a `lucisv.toml` that says `indent = 2` is ANSI
|
||
at 2 spaces.
|
||
- **`lucisv` and `auto` do not count as "a chosen style" for the editor's
|
||
`tabSize` rung.** VS Code sends `lucisv` when nobody touched the drop-down,
|
||
and `auto` picks a layout but no size, so both leave today's
|
||
`tabSize`-beats-default behaviour exactly as it was. Any other style
|
||
outranks `tabSize` (an editor default of 4 must not silently undo
|
||
`google`'s 2).
|
||
- **`case` items and `do` keep `begin` on their own line's end in every
|
||
style** — `0: begin`, `do begin`. clang-format's Microsoft style does the
|
||
same (`AfterCaseLabel: false`), and an Allman `0:` / `begin` reads as a
|
||
label with nothing under it.
|
||
- **The `else` switches govern `if`/`else` statements and generate `if`/`else`
|
||
only.** An immediate assertion's `else` (`assert (a) … else …`), a
|
||
constraint's `else` and `randsequence`'s keep the layout they always had.
|
||
`else_after_label` is the guides' one exception: after `end : label`,
|
||
`google` and `lowrisc` start `else` on a new line (Google "Eschatology",
|
||
lowRISC "Begin / End"); `lucisv` keeps `end : l1 else begin`, as it always
|
||
printed.
|
||
- **"One entry per line" governs module/interface/program headers (parameter
|
||
and port lists, whenever non-empty) and instances' *named* parameter and
|
||
connection lists.** A positional override `#(16)` and an ordered connection
|
||
list `(a, b)` keep fitting on one line, as both guides show. `(.*)` alone
|
||
is broken like any other named list.
|
||
- **`Wrap` (two-level list indent) applies to the same lists**, header and
|
||
instance; function/task port lists and expression lists are untouched.
|
||
- **`Alignment::Always` reuses the alignment planner unchanged** except for
|
||
one question it skips — "did the author pad this?". Every other refusal
|
||
(a group of one, nothing to pad, a group too wide for the line, a row with
|
||
a comment in it, a blank line or comment between tables) still applies.
|
||
Its connection spelling is Verible's (`.clk (clk)`, one space before the
|
||
widest row's `(`); lowRISC's guide writes the widest row tight
|
||
(`.req_ready_o(req_ready)`). Not modelled: one more axis for one guide's
|
||
one column. A second lowRISC deviation: a comment line inside a table ends
|
||
lucisv's alignment group (both layouts are fixed points only because the
|
||
groups are drawn the same on every pass), where lowRISC keeps aligning
|
||
across it.
|
||
- **Known limit — a declaration of several instances under `OnePerLine`.**
|
||
`p1 u8 (.a(a)), u9 (.a(b));` breaks into the hanging layout every style
|
||
has always used for several instances: under `google` the connections land
|
||
at 8, `u9` and each `)` at 4, the opening line at 2 (`microsoft`: 4/12/8).
|
||
The `)` of each instance is at its instance's column, not the opening
|
||
line's. Fixing it means a new multi-instance layout for every style, the
|
||
default included; not done here.
|
||
- **`auto` never guesses an indent or a width.** It competes the presets'
|
||
layout switches at the config's own indent and width. Guessing an indent
|
||
from a file whose formatted output has a different indent is exactly the
|
||
kind of detector whose second run disagrees with its first. Its measure is
|
||
the number of lines whose bytes change, indentation included — see
|
||
"auto" below for why the first round's indentation-blind measure was wrong.
|
||
- **Under `auto`, a buffer that does not parse and has no remembered preset
|
||
is laid out in the default (`lucisv`) layout** by range, selection and
|
||
on-type formatting — the formatter has nothing to resolve from. The
|
||
language server remembers the preset of each recently formatted document
|
||
(the 64 most recent), so this only happens before the first successful
|
||
resolve of a buffer. The CLI's `--lines` has no memory and refuses a file
|
||
that does not parse anyway.
|
||
|
||
## The axes
|
||
|
||
Surveyed against what `format/` actually decides today (2026-11-19):
|
||
|
||
| candidate | verdict | why |
|
||
|---|---|---|
|
||
| indent width | **kept** (`indent`) | already a `Config` field; a preset supplies the default |
|
||
| line length | **kept** (`line_length`) | same |
|
||
| `begin` same line / own line | **kept** (`begin`) | one choke point (`Fmt::body_after`, `Fmt::gen_block`): a space or a `HardLine` before `begin` |
|
||
| `else` after `end` | **kept** (`else_keyword`) | one condition in `if_stmt` and in `gen_if` |
|
||
| `else` after a labelled `end` | **kept** (`else_after_label`) | the same condition, asked of `end : label` — both guides' exception |
|
||
| header/connection lists: fit vs one per line | **kept** (`port_lists`) | the lists already had a `force_break` flag (`Fmt::style_breaks`) |
|
||
| list entries at 1 or 2 levels | **kept** (`list_indent`) | Google's guide and Verible's `wrap` both indent header lists 4; one `Indent` more in `delimited_at`, and the alignment budget follows (`Fmt::list_depth`) |
|
||
| alignment of ports, connections, `parameter`s | **kept** (`alignment`: `Infer` / `Always`) | one skipped question in `align::plan`; `Never` was dropped — no preset needed it |
|
||
| closing `);` hugging the last port | rejected | no guide wants it; every guide found puts `)` on its own line |
|
||
| space before `(` in instances / calls | rejected | every source agrees: space after the instance name, none after a function name — already lucisv's |
|
||
| spaces around `:` in ranges | rejected | both guides want `[7:0]` tight — already lucisv's |
|
||
| consecutive blank lines kept | rejected | the parser records `blank_before: bool`, not a count; would need a parser change outside this lane, and no guide asks for more than one |
|
||
| `case` item indentation | rejected | both guides indent items one level — already lucisv's |
|
||
| net/variable declaration alignment, assignment alignment | rejected | lucisv has no such alignment group today; building one is a feature of its own, not a style switch |
|
||
|
||
## The presets
|
||
|
||
The same table is the `PRESETS` constant in `style.rs`, one row per preset.
|
||
|
||
| style | indent | width | `begin` | `else` | `else` after `end : l` | lists | list indent | columns | modelled on | confidence |
|
||
|---|---|---|---|---|---|---|---|---|---|---|
|
||
| `lucisv` | 2 | 100 | same line | same line | same line | fit | block | infer | lucisv itself | exact (byte identity) |
|
||
| `google` | 2 | 100 | same line | same line | own line | one per line | wrap | infer | Google Verilog Style Guide | high |
|
||
| `lowrisc` | 2 | 100 | same line | same line | own line | one per line | block | always | lowRISC Verilog Coding Style Guide | high (two deviations, above) |
|
||
| `ansi` | 4 | 80 | own line | own line | own line | fit | block | infer | Artistic Style / iStyle `--style=ansi` (Allman) | medium for `begin`/`else`; width a guess |
|
||
| `microsoft` | 4 | 120 | own line | own line | own line | one per line | block | infer | clang-format `Microsoft` base style | guess |
|
||
| `nxp` | 2 | 80 | same line | own line | own line | one per line | block | always | a conservative RTL house style | guess |
|
||
|
||
Sources consulted (2026-11-19):
|
||
|
||
- **Google Verilog Style Guide** (google.github.io/styleguide/verilogguide.html,
|
||
read from the `google/styleguide` gh-pages `verilogguide.md`): "Line
|
||
Length" (100), "Indentation" (2, no tabs), "Eschatology" (`begin` on the
|
||
keyword's line, `end else begin`, but `else` on a new line after a labelled
|
||
`end`), "Line Wrapping" (4-space continuation),
|
||
"Module Header Definition Examples" and "Use named ports" (one entry per
|
||
line, entries at 4 spaces, closing paren at column zero), "Tabular
|
||
Alignment" (alignment *recommended* "where it is reasonable"; the guide's
|
||
own header examples are not name-aligned — hence `infer`).
|
||
- **lowRISC Verilog Coding Style Guide** (lowRISC/style-guides,
|
||
VerilogCodingStyle.md), whose summary says it defaults to "being consistent
|
||
with Google's C++ Style Guide": "Line Length" 100, "Indentation" 2,
|
||
"Begin / End" `end else begin` (and the same labelled-`end` exception),
|
||
"Module Declaration" one port per line, `);` at column zero, its examples
|
||
aligned in columns (shown, not required), "Module Instantiation"
|
||
connections *required* "aligned in tabular style", at 2 spaces. lucisv has
|
||
one alignment switch for ports, connections and parameters, so the row
|
||
says `always` for all three: the requirement for connections, the examples
|
||
for ports.
|
||
- **ANSI**: the iStyle Verilog formatter's README (a port of Artistic Style)
|
||
lists `--style=ansi` and describes its bracket-breaking mode as "ANSI C/C++
|
||
style", default indent 4. No Verilog guide by that name exists that we
|
||
found; 80 columns is our guess.
|
||
- **Microsoft**: no Microsoft Verilog/SystemVerilog guide found. clang-format's
|
||
`getMicrosoftStyle` (llvm-project `clang/lib/Format/Format.cpp`):
|
||
`ColumnLimit = 120`, `IndentWidth = 4`, braces after control statements and
|
||
before `else` on their own lines; LLVM's base sets
|
||
`VerilogBreakBetweenInstancePorts = true`. Whether clang-format's own
|
||
Verilog mode wraps `begin` like a brace was not verified.
|
||
- **NXP**: no public NXP Verilog style guide found (searched 2026-11-19).
|
||
The preset is lucisv's guess at a conservative ASIC house style, and the
|
||
source and the docs say so.
|
||
|
||
## Safety sweeps
|
||
|
||
Trees: the 860-file corpus (`~/.cache/lucisv-corpus`) and OpenTitan's `hw/`
|
||
(`~/.cache/lucisv-opentitan-full/hw`, 4 061 files with symlinks followed) —
|
||
4 921 `.v`/`.sv`/`.vh`/`.svh` files, copied to scratch (the trees are never
|
||
written). Commands: `tools/style_sweep.sh -b <lucisv> -w <scratch> <trees>`
|
||
(the CLI, in place, `--no-cache --no-config --no-gitignore`, every run under
|
||
`tools/guard.sh`) and `cargo run --release -p vlog_formatter --example
|
||
auto_sweep -- <trees>` (under `guard.sh`). 2026-11-19, final binaries.
|
||
|
||
**Default byte identity.** Both trees formatted with the 0.65.4 binary
|
||
(`d574969`, built before any edit) and with this lane's binary, no flag and
|
||
`--style lucisv`: `diff -r` is empty both ways (0 lines over 4 921 files;
|
||
identical summaries, 4 817 reformatted / 90 unchanged / 14 failed, the 14 the
|
||
same parse errors). The snapshot + idempotency suite is unchanged and green.
|
||
|
||
| style | files | parse errors | verification errors | crashes | not idempotent |
|
||
|---|---|---|---|---|---|
|
||
| `lucisv` | 4 921 | 14 | 0 | 0 | 0 |
|
||
| `google` | 4 921 | 14 | 0 | 0 | 0 |
|
||
| `lowrisc` | 4 921 | 14 | 0 | 0 | 0 |
|
||
| `ansi` | 4 921 | 14 | 0 | 0 | 0 |
|
||
| `microsoft` | 4 921 | 14 | 0 | 0 | 0 |
|
||
| `nxp` | 4 921 | 14 | 0 | 0 | 0 |
|
||
| `auto` | 4 921 | 14 | 0 | 0 | 0 |
|
||
|
||
"Not idempotent" is `--check` with the same style over the formatted copy
|
||
(files it would reformat). The 14 parse errors are the baseline's own, under
|
||
every style.
|
||
|
||
**`auto` proof sweep** (`auto_sweep`, fix-round binary): 4 921 files, 14
|
||
refused (the parse errors), 0 crashes, **0 files whose second or third auto
|
||
format changed a byte, 0 files whose second or third run named a different
|
||
preset**. Picked: `lucisv` 4 050, `lowrisc` 645, `google` 92, `microsoft` 92,
|
||
`nxp` 24, `ansi` 4. (First round, indentation-blind measure: `lucisv` 3 875,
|
||
`lowrisc` 484, `google` 465, `microsoft` 46, `nxp` 29, `ansi` 8; before
|
||
`canonical` existed that sweep showed 47 renames, all `lowrisc` → `lucisv`,
|
||
identical bytes.)
|
||
|
||
**Cost of `auto`**: see the latency table under "auto".
|
||
|
||
The tables above are from the fix-round binaries (2026-11-19): the per-style
|
||
table, the default byte identity and the cross-preset matrix below were all
|
||
re-run after the fix round and came out the same, except the `auto` row of
|
||
the matrix.
|
||
|
||
## auto
|
||
|
||
**The measure.** `auto` formats the file with every preset (at the
|
||
configured indent and width) and keeps the output with the fewest lines whose
|
||
bytes change — the multiset difference of lines, **indentation included** —
|
||
ties to the earlier preset. The first round compared lines with indentation
|
||
stripped and used indentation only to break ties; QA showed that lets a
|
||
preset that saves three layout lines beat one that keeps 741 lines'
|
||
indentation (F1). Counting every changed line is also simply what the docs
|
||
always said.
|
||
|
||
**`auto` picks a layout for the configured indent and width; it never infers them — set `indent` to match the file first.** Because every re-indented line counts as changed, a file written at another indent is closest to whichever preset changes the fewest of its lines once they are all re-indented: a 4-space Allman file (formatted with `--style ansi`) run through `--style auto` at the default indent 2 comes out in the cuddled `lucisv` layout, while with `indent = 4` it stays Allman (and with `line-length = 80` as well, byte for byte). (In VS Code the editor's `tabSize` rung supplies the
|
||
indent when nothing else does, which often matches the file; the CLI has no
|
||
such rung.) QA measured that 426 of the 4 921 files' auto output changed
|
||
between the two measures.
|
||
|
||
**F1 experiment** (QA's driver, `qa_auto edit`, rebuilt against this tree):
|
||
200 sampled files (198 with an `endmodule`), each formatted with auto, one
|
||
construct inserted before `endmodule`, formatted with auto again. "Flips":
|
||
the named preset changed; "rewritten": lines of the first output no longer
|
||
present in the second.
|
||
|
||
| inserted construct | flips before → after | files with rewritten lines before → after | worst rewrite before → after |
|
||
|---|---|---|---|
|
||
| `assign qa_x=qa_y ;` | 0 → 0 | 0 → 0 | 0 → 0 |
|
||
| cuddled `always_comb if … begin … end else begin … end` | 4 → 0 | 4 → 0 | 741 → 0 |
|
||
| Allman `begin`/`else` block | 81 → 1 | 21 → 1 | 140 → 3 |
|
||
| one-line instance `qa_mod qa_u (.a(qa_a), .b(qa_b));` | 14 → 0 | 14 → 0 | 37 → 0 |
|
||
|
||
The remaining flip rewrites 3 lines, so no stabiliser beyond the measure was
|
||
added. ("Before" is QA's run on the first-round binary; "after" re-runs the
|
||
same driver, so each column starts from its own binary's auto output.) Every
|
||
second format in both runs was idempotent.
|
||
|
||
**Naming costs a pass; formatting does not need it.** `format_source` under
|
||
auto and `format_auto` (the server's whole-document path) format once per
|
||
preset until one leaves the file unchanged, and return the winner.
|
||
`resolve_style`, which *names* the preset, additionally finds the earliest
|
||
preset that leaves the output as it is (`canonical`), so a second run names
|
||
the same one; only it pays that pass. Range and selection formatting resolve
|
||
through the internal `concrete`, which does not name.
|
||
|
||
**The server remembers each document's preset** (`lucisv_server/src/
|
||
auto_style.rs`, owned by the `Server` struct; the 64 most recent documents,
|
||
no `didClose` hook). Whole-document formatting and the save hook resolve and
|
||
remember. Range, multi-range and `;` on-type formatting use the remembered
|
||
preset; with none, they resolve once from the buffer when it parses and
|
||
remember that; with none and no parse, they use the default layout (F3's
|
||
case, now confined to a buffer that has never resolved). A typed newline
|
||
needs no preset and never searches.
|
||
|
||
The memory is invalidated (QA R2-1): a document's entry is **forgotten** on
|
||
`didOpen`, `didClose`, `didRenameFiles` (old and new name),
|
||
`didDeleteFiles`, and on any request or whole-document format under a named
|
||
style; **every** entry is forgotten when settings are applied (pushed or
|
||
pulled) and when a watched-file event names `lucisv.toml`/`.lucisv.toml`. A
|
||
`didChange` that replaces the whole buffer — rangeless, or one change from
|
||
the top whose text is the whole result — marks the entry *replaced*: the next
|
||
request resolves afresh when the buffer parses, and uses the old preset only
|
||
when it does not (the lead asked for "forget"; marking instead keeps QA's
|
||
case 8 — a full-sync client's every keystroke is a whole replacement, and
|
||
forgetting there would drop the preset of a half-typed buffer, the case the
|
||
memory exists for). QA's `memattack.py`, re-run against this tree's release
|
||
binaries: cases 1–9 and 11's eviction check OK; case 10 is a request the
|
||
server rejects as invalid params (`v x.sv`: a raw space is not a valid URI —
|
||
a driver issue, not the memory); case 11's last check expected the *old*
|
||
stale preset after a full-text change ("stale by design") and now gets the
|
||
re-resolved one, which is the R2-1 fix.
|
||
|
||
**Latency** on `pinmux_reg_top.sv` (42 192 lines; auto picks `lowrisc`),
|
||
release, `qa_auto time2`, two runs agreeing within 5 %:
|
||
|
||
| request | before (QA) | after |
|
||
|---|---|---|
|
||
| whole-document format, unformatted | 2.30 s | 2.40 s (unchanged: it must search) |
|
||
| selection / on-type `;` on the formatted buffer | 1.36 s | 0.07 s remembered; 1.24 s for the first request with no memory |
|
||
| selection / on-type `;` on the unformatted buffer | 3.0 s | 0.10 s remembered; 2.55 s for the first request with no memory |
|
||
| (selection under a named preset, for scale) | 0.094 s | 0.064 s |
|
||
|
||
## Cross-preset stability
|
||
|
||
Formatting with A, then B, then A again lands exactly where A alone did —
|
||
`A(B(A(x))) == A(x)` — **for every pair where A aligns by rule
|
||
(`lowrisc`, `nxp`)**. Where A *reads* alignment from the source (`Infer`:
|
||
`lucisv`, `google`, `ansi`, `microsoft`), the identity can fail, and for
|
||
one root cause: B changed which runs are aligned, and A then faithfully keeps
|
||
what it finds. B either *wrote* columns (B is `Always`) or *dropped* a table
|
||
whose padded width no longer fit B's narrower line or deeper indent (an
|
||
aligned group that overflows falls back to flush as a whole) — e.g. `lucisv`
|
||
via `ansi` (80 columns, 4 spaces), `microsoft` via `lucisv` (100 < 120). Every
|
||
other decision is a function of the AST and the config, so it comes back.
|
||
|
||
The differences are alignment **plus its knock-on**, not alignment alone.
|
||
QA classified every differing hunk in 20 files per pair (QA log, F5):
|
||
`microsoft` via `lucisv` and `ansi` via `nxp` are all padding or the list
|
||
breaks alignment forces; in `lucisv` via `lowrisc`, 261 of 265 hunks are, and
|
||
the other 4 (18 lines, e.g. `flash_phy_core.sv:230`, `kmac_entropy.sv:297`)
|
||
are a named parameter override `#(.Width(HashCntW))` that was broken in
|
||
`lucisv(x)` and comes back joined once its instance's connection list is
|
||
aligned — the existing coupling between an instance's head and its
|
||
connection list, set off by the alignment. This is the alignment feature's
|
||
design — "a file written without alignment never grows any" — not a style
|
||
bug.
|
||
|
||
Measured (files of 4 921 where `A(B(A(x))) != A(x)`; rows A, columns B):
|
||
|
||
| A \ B | lucisv | google | lowrisc | ansi | microsoft | nxp | auto |
|
||
|---|---|---|---|---|---|---|---|
|
||
| `lucisv` | — | 0 | 1 288 | 106 | 0 | 1 281 | 0 |
|
||
| `google` | 0 | — | 1 288 | 106 | 0 | 1 281 | 0 |
|
||
| `lowrisc` | 0 | 0 | — | 0 | 0 | 0 | 0 |
|
||
| `ansi` | 0 | 0 | 1 244 | — | 0 | 1 244 | 0 |
|
||
| `microsoft` | 20 | 20 | 1 296 | 119 | — | 1 290 | 20 |
|
||
| `nxp` | 0 | 0 | 0 | 0 | 0 | — | 0 |
|
||
| `auto` | 857 | 1 987 | 1 192 | 1 832 | 1 844 | 2 315 | — |
|
||
|
||
The `Always` rows are all zero; every non-zero `Infer` cell is in a column
|
||
that writes columns (`lowrisc`, `nxp`) or is narrower/deeper than the row
|
||
(`ansi` for the 100-column rows; 100-column `lucisv`/`google`/`auto` for
|
||
`microsoft`'s 120). The `auto` row is non-zero by definition: auto keeps the
|
||
layout it finds, and B just changed it — `auto(B(auto(x)))` is `B`'s layout
|
||
(or the nearest preset to it), which is the feature working. What holds for
|
||
auto is the idempotency above.
|
||
|
||
## Handshakes
|
||
|
||
- **Consumes `align::plan`** (own crate): gained a `mode: Alignment`
|
||
parameter. `Infer` is exactly the old function; the one call site passes
|
||
the style's mode.
|
||
- **Promises `vlog_formatter::Config`**: new fields `style: Style` and
|
||
`auto_style: bool`; `Config::styled(Style)`, `Config::named(&str)`,
|
||
`Config::style_name()`. `Config::default()` is `Config::styled(LUCISV)` and
|
||
lays out byte-identically to before. Every external `Config { .., ..Default }`
|
||
literal keeps compiling.
|
||
- **Promises `vlog_formatter::resolve_style(source, &Config) -> Config`**: the
|
||
preset `auto` *names* for a whole file (the canonical one — stable across
|
||
runs), and **`vlog_formatter::format_auto(source, &Config) ->
|
||
Result<(String, Style), FormatError>`**: auto's output and the preset that
|
||
produced it, for a caller that will format ranges of the same buffer
|
||
later (the server's memory).
|
||
- **`lucisv_core::config`**: `FileConfig::format_style: Option<&'static str>`,
|
||
`STYLE_NAMES` (the presets plus `auto`; pinned equal to the formatter's by
|
||
`args::tests::the_core_style_names_are_the_formatter_presets` in `lucisv`),
|
||
`parse_style` (the one error message, reused by `--style` and the server).
|
||
`lucisv_core` still depends on nothing.
|
||
- **`lucisv_core::cache::Entry`** gained `style: &'static str`; the store line
|
||
has seven fields (`…\tuvm\tstyle\tversion\tpath`). A six-field line (0.65.x)
|
||
and a line naming a style this build does not know are dropped
|
||
individually, like another version's entry. **One edit outside the new
|
||
test file:** `crates/lucisv/tests/cli.rs`'s `cache_line` helper (which
|
||
forges store lines) writes the new `lucisv` field — two existing cache
|
||
tests failed on the old six-field shape otherwise. The lead lifted the
|
||
ban on that file mid-lane; the edit is two lines.
|
||
- **Request to the `server-lint`/71.1 lane (`crates/lucisv_server/src/lint.rs`,
|
||
owned by lane 71.1, not edited here):** `lint.rs:307` resolves the
|
||
`line-length` rule's width as `file.line_length.or(client.line_length)
|
||
.unwrap_or(100)`. Under a style with another width (`ansi` 80, `microsoft`
|
||
120, `nxp` 80) the editor's `line-length` finding and the formatter now
|
||
disagree. Wanted: fall back to the chosen style's width —
|
||
`file.format_style.or(client.style).and_then(vlog_formatter::style::preset)
|
||
.map_or(100, |s| s.line_length)` — the same ladder `format::indent_width`
|
||
now walks (that one is fixed here, and lint's `tab_width` already calls it).
|
||
The CLI's `lucisv check` and the MCP `diagnostics` tool already use the
|
||
style's width.
|
||
- **Note for the alignment README (not in this lane's scope):** its rule is
|
||
now the `Infer` mode; `Always` is documented here.
|
||
- **`editors/vscode/package.json`**: `lucisv.format.style` (enum with one
|
||
description per entry, default `lucisv`). `extension.js` forwards the whole
|
||
`lucisv` section already, so it is unchanged.
|
||
|
||
- **`crates/lucisv_server/src/server/notification.rs` (lane 71.1's file;
|
||
allowed by the lead for these lines only, one call each into
|
||
`auto_style.rs`, nothing else touched):**
|
||
1. in `handle_notification`, after `let released = self.forget_port_entry(&method, ¬ification);`:
|
||
`self.auto_styles.notice(¬ification);`
|
||
2. in the `DidChangeTextDocument` arm, after the `let (text, end) = { … };` block:
|
||
`self.auto_styles.changed(&uri, &p.content_changes, &text);`
|
||
3. first line of `apply_settings`: `self.auto_styles.forget_all();`
|
||
- **`lucisv_core::config::NAMES`** is now `pub` (the two config file names),
|
||
so the memory recognises a `lucisv.toml` event without a second copy.
|
||
- **Server (this lane, formatting handlers only):** `auto_style.rs` (new),
|
||
a field on `Server` (`server/mod.rs`, constructed in `server/startup.rs`),
|
||
`server/formatting.rs` routing the five entries through it, and
|
||
`format::whole_document_edit`. Nothing in `state/` or
|
||
`server/{index,notification,diagnostics}.rs` (lane 71.1's) was touched.
|
||
|
||
## Status / TODO
|
||
|
||
- [x] Survey the axes; keep five layout switches plus indent and width
|
||
- [x] `style.rs`: one `Style` struct, six presets as `const` rows, sources in comments
|
||
- [x] Axes: `begin`, `else`, lists one-per-line, list indent, alignment
|
||
- [x] `lucisv` preset byte-identical to 0.65.4 over corpus + OpenTitan
|
||
- [x] `[format] style`, `--style`, `lucisv.format.style`, MCP; cache key
|
||
- [x] Per-preset sweeps: no verification errors, no crashes, idempotent
|
||
- [x] Cross-preset stability measured and explained
|
||
- [x] Phase 2: `auto`, proof sweep, range/selection use the whole file's style
|
||
- [x] Docs: root README (Configuration, Named styles), VS Code README
|
||
- [x] Fix round (QA F1–F8): auto measure counts indentation; server remembers
|
||
the preset per document; labelled-`end` `else` for google/lowrisc; presets
|
||
as one table; doc corrections
|
||
- [x] Lane 71.1: `lint.rs` line-length width from the style (Handshake request above)
|
||
— delivered by localized-reindex (lane 71.1, round 3) and released in
|
||
0.65.6: `crates/lucisv_server/src/lint.rs` falls back to the chosen style's
|
||
width (`file.format_style.or(client.style)` → `style::preset`), else 100
|
||
|
||
## Work log
|
||
|
||
**2026-11-19 — dev.**
|
||
|
||
- Baseline first: built 0.65.4 (`d574969`) before any edit and formatted
|
||
scratch copies of both trees with it; every "byte-identical" claim below is
|
||
a `diff -r` against that tree.
|
||
- `style.rs` holds the whole vocabulary: `Placement`, `PortLists`,
|
||
`ListIndent`, `Alignment`, the `Style` struct, the six `const` presets and
|
||
`PRESETS`. Each field's doc has its before/after; each preset's comment says
|
||
what it is modelled on and how sure.
|
||
- `format/branch.rs` (new): `if_stmt` moved out of `stmt.rs` and `gen_if` out
|
||
of `item.rs`, plus `before_keyword` (the space-or-break helper) and
|
||
`else_cuddles`. `stmt.rs` drops from 604 to 556 production lines, `item.rs`
|
||
from 472 to 449; the move changed no output (snapshot suite and both tree
|
||
identities green).
|
||
- `Fmt::stmt_as_body_from` now calls `body_after(prefix, s, skip, begin)`;
|
||
`case_item` passes `SameLine`. `gen_block` takes the placement, `gen_case`
|
||
passes `SameLine`.
|
||
- `list.rs`: `delimited_dangling` is `delimited_at(.., Block)`; `header_list`
|
||
uses the style's indent; `style_breaks` and `list_depth` are the two style
|
||
questions the header and instance code ask.
|
||
- `align::plan(.., mode)`: `Always` skips `wants_alignment` and nothing else.
|
||
- Plumbing follows `uvm-utils-indent` everywhere it flows. The CLI and MCP
|
||
resolve the style first and write explicit `indent`/`line-length` over it;
|
||
the server's ladder is documented on `format::settings_for`.
|
||
- **Phase 2.** A per-axis detector (vote on `begin`/`else` placement, port
|
||
list shape) was designed first and dropped before coding: the formatter
|
||
itself writes `begin`/`else` in places no switch governs (case items, `do`,
|
||
after comments, immediate assertions), so votes on the *output* are
|
||
contaminated by construction and "detect(output) == detect(input)" could
|
||
only ever be measured, not argued. `auto` instead formats once per preset
|
||
at the configured indent/width and keeps the output with the least
|
||
line-multiset difference from the input, indentation compared last; ties go
|
||
to `PRESETS` order. That is idempotent by construction (argument in
|
||
`auto.rs`), and naming the *earliest* preset that leaves the output as it is
|
||
(`canonical`) makes the second run name the same preset too. A first sweep
|
||
without `canonical` showed 0 byte violations and 47 files whose second run
|
||
named `lucisv` instead of `lowrisc` (identical bytes) — that is what
|
||
`canonical` removes.
|
||
- Cost: `auto` formats a file up to six times (stopping at the first preset
|
||
that leaves it unchanged, which on an already-formatted file is usually
|
||
the first); range/selection/on-type formatting under `auto` pay that over
|
||
the whole buffer to pick the style.
|
||
|
||
**2026-11-19 — dev, fix round (QA: PASS WITH FINDINGS).**
|
||
|
||
- **F1.** `auto.rs` `distance` is now `(lines whose bytes change, texts
|
||
differ)`, indentation included; `(0, 0)` still means equal, so the
|
||
idempotency argument is unchanged. QA's 200-file × 4-construct experiment
|
||
re-run with QA's own driver: flips 0/4/81/14 → 0/0/1/0, worst rewrite
|
||
741 → 3 lines (table under "auto"). No stabiliser added: the one remaining
|
||
flip changes 3 lines. The test that relied on indentation being ignored
|
||
(`auto_picks_a_layout_never_a_size`) now configures the indent, which is
|
||
the documented contract.
|
||
- **F3/F4.** `lucisv_server/src/auto_style.rs`: a 64-entry most-recent list
|
||
of (URI, preset), on the `Server`. Whole-document format and the save hook
|
||
resolve (`vlog_formatter::format_auto`) and remember; range, multi-range
|
||
and `;` on-type use the memory, resolve-and-remember when the buffer
|
||
parses, else fall back to the default layout (documented). A newline never
|
||
resolves. `resolve_style` keeps the naming pass; the formatter's own
|
||
range/selection path (`auto::concrete`) and `format_auto` drop it.
|
||
Five unit tests and three end-to-end tests (`server/tests/formatting.rs`).
|
||
- **F2.** New style column `else_after_label`: `OwnLine` for google and
|
||
lowrisc (and ansi/microsoft/nxp, where `else` is already on its own line),
|
||
`SameLine` for lucisv. One condition in `branch.rs` (`else_cuddles`), for
|
||
procedural and generate `if`. Test
|
||
`else_after_a_labelled_end_starts_its_own_line_in_the_guides`.
|
||
- **F5–F7.** Cross-preset text now says "alignment plus its knock-on" with
|
||
QA's 261/265 numbers; lowRISC's ports-required claim corrected (row
|
||
unchanged: the one alignment switch covers connections, which the guide
|
||
requires); the comment-line deviation listed; the multi-instance hanging
|
||
layout recorded as a known limit and the `list_indent` doc corrected.
|
||
- **F8.** `style.rs`: the presets are one `PRESETS` table, a `row(..)` per
|
||
preset, columns aligned by hand under `#[rustfmt::skip]` (reason in the
|
||
comment); the named constants are `PRESETS[i]` and carry the provenance.
|
||
`port_lists` names exactly the lists it governs; `begin` lists the headers
|
||
that move with it.
|
||
|
||
**2026-11-19 — dev, round 3 (QA round 2: PASS WITH FINDINGS).**
|
||
|
||
- **R2-1.** `auto_style.rs` forgets as listed under "auto" (open, close,
|
||
rename, delete, named-style requests and formats; everything on a settings
|
||
change or a seen `lucisv.toml` event) and marks an entry *replaced* on a
|
||
whole-buffer `didChange`, re-resolving on the next request when the buffer
|
||
parses. Deviation from the brief, reasoned under "auto": marked, not
|
||
forgotten, so a full-sync client's half-typed buffer keeps its preset.
|
||
The three one-line calls in `notification.rs` are listed under Handshakes.
|
||
Tests: four new unit tests (open/close/rename/delete; config file and
|
||
settings; whole-buffer replacement, partial edit and full-range-from-top;
|
||
named-style forgetting) and four new end-to-end tests (replaced buffer,
|
||
auto → named format → auto, close + reopen, rename). QA's `memattack.py`
|
||
run against this tree: see "auto".
|
||
- **R2-2.** "`auto` picks a layout for the configured indent and width; it
|
||
never infers them — set `indent` to match the file first", with the
|
||
4-space Allman example (checked on the CLI: indent 2 → lucisv layout;
|
||
`--indent 4 --line-length 80` → unchanged), in this README, the root
|
||
README, the extension README and the `lucisv.format.style` `auto`
|
||
description.
|
||
|
||
## Changelog paragraph (for the lead)
|
||
|
||
**Named formatting styles.** `[format] style = "<name>"` in `lucisv.toml`,
|
||
`--style <name>` on the command line, or the new `lucisv.format.style`
|
||
drop-down in VS Code picks a house layout: `lucisv` (the default, unchanged
|
||
byte for byte), `google` (the Google Verilog Style Guide: one port and
|
||
connection per line at a 4-space continuation indent), `lowrisc` (OpenTitan's
|
||
guide: the same with every port and connection table aligned), and `ansi`,
|
||
`microsoft` and `nxp` — lucisv's educated guesses at those names (Allman
|
||
`begin`/`else`, 4 spaces and 80 or 120 columns; a conservative aligned RTL
|
||
style), not rules those companies publish. `auto` keeps each file in the
|
||
preset it is already closest to, and the language server remembers each
|
||
document's preset so on-type and selection formatting stay fast. Every style only moves whitespace and runs
|
||
through the same safety check; each was swept over the 860-file corpus and
|
||
OpenTitan's `hw/` tree with no verification error, crash or idempotency
|
||
failure. An explicit `indent`/`line-length` still wins over a preset's.
|
||
|
||
## QA log
|
||
|
||
**2026-11-19 — QA (Opus 5.5).** Verdict: **PASS WITH FINDINGS.** None of the
|
||
four invariants broke anywhere I looked, and the default output is
|
||
byte-identical. The findings are about how `auto` behaves, how honest the
|
||
presets are and how accurate the docs are. Scratch:
|
||
`/private/tmp/claude-501/-Users-lucio-repo-lucisv/d043c274-11ff-4de2-ab0f-45daa8a877f0/scratchpad/qa715/`
|
||
(`bin/` holds my drivers). No source edits were made.
|
||
|
||
*Baseline.* `cargo fmt --all -- --check` clean. `cargo clippy --all-targets
|
||
-- -D warnings` clean; the one manifest warning (`workspace.package.authors`)
|
||
is already on the base. Every test run went through guard.sh: vlog_formatter
|
||
374/0, lucisv 151/0, lucisv_core 119/0, lucisv_server 1980/0, lucisv_mcp
|
||
384/0, node 37/0. `tools/gates.sh` was run on its own (no guard.sh wrapper)
|
||
and printed **PASS**, every step green. `git diff d574969 -- '**/verify.rs'`
|
||
is empty. No test was deleted: every test name in d574969 still exists. The
|
||
only `-assert` lines are the `align::plan` calls that gained
|
||
`Alignment::Infer`, and the two cache-format assertions that gained the
|
||
`lucisv` field. The `cli.rs` `cache_line` change is the two lines described,
|
||
and it weakens nothing. Production sizes: `stmt.rs` and `item.rs` shrank, and
|
||
every changed file stays under its threshold.
|
||
|
||
*Default byte identity, rebuilt independently.* Base built from `git archive
|
||
d574969` with its own target dir. 4 921 files (corpus + OpenTitan `hw`,
|
||
scratch copies) were formatted four ways: base vs new with no flag, new
|
||
`--style lucisv`, and base vs new with a `lucisv.toml` setting only
|
||
`line-length = 90` / `indent = 3`. `diff -r` gives **0 lines** for all three
|
||
comparisons, and stderr is identical too. Sanity check: the toml tree differs
|
||
from the default tree in 4 690 files.
|
||
|
||
*Invariants per style, using my own driver* (`bin/sweep.sh` plus
|
||
`bin/lexcmp.py`). lexcmp is an independent Python lexer: maximal-munch
|
||
words, strings and escaped identifiers kept whole, based numbers and `@*`
|
||
normalised as `verify.rs` already does, `` `define `` lines compared whole,
|
||
and comments compared by count and per-line-stripped text. I mutation-tested
|
||
it on five crafted corruptions and it caught all five. Run against the base
|
||
binary's output it reports zero problems. Each style was formatted three
|
||
times over the full tree.
|
||
|
||
| style | files | parse err | verif err | crash/guard kill | partial output on failure | token diffs | comment diffs | run2≠run1 | run3≠run2 |
|
||
|---|---|---|---|---|---|---|---|---|---|
|
||
| lucisv | 4 921 | 14 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||
| google | 4 921 | 14 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||
| lowrisc | 4 921 | 14 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||
| ansi | 4 921 | 14 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||
| microsoft | 4 921 | 14 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||
| nxp | 4 921 | 14 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||
| auto | 4 921 | 14 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||
|
||
*Hand attacks* (`hand/src`, 12 files) were run under all seven styles, at
|
||
the default size and at `--line-length 40` with `--indent 8` and with
|
||
`--indent 1`. The inputs covered:
|
||
|
||
- comments after a header, after `end`, between `end` and `else`, and
|
||
between `)` and `begin`
|
||
- labelled blocks, `else if` chains, generate `if`/`for`/`case`,
|
||
`fork…join_none`, `do…while`, `case` items, macros as statements,
|
||
`assert … else`, `@*`, nested `if` without `begin`
|
||
- an empty port list, a single port, unpacked dimensions and defaults,
|
||
`.*`, positional connections, `#(16)`
|
||
- `` `ifdef `` inside port and connection lists and inside an aligned group
|
||
- multi-instance declarations, `(* *)` on an instance
|
||
- 80- and 120-column expressions
|
||
- tabs plus CRLF, no trailing newline, non-ASCII text
|
||
- a fence, an empty file, a comment-only file, a parse error
|
||
|
||
Results: 0 token diffs, 0 comment diffs, every file idempotent, and the
|
||
parse-error file was refused with its bytes unchanged. Three inputs failed
|
||
identically on the d574969 binary, so they are bugs that predate this lane:
|
||
|
||
- a comment between a generate `end` and `else` gives a verification error;
|
||
the safety net caught it and nothing was written
|
||
- `` `ifdef `` between `end` and `else` is a parse error
|
||
- `(* keep *)` on an ANSI port is a parse error
|
||
|
||
Each layout matched its row, with the exception in F2.
|
||
|
||
*Plumbing.* All checked by hand, all as documented:
|
||
|
||
- toml with a valid style; unknown, wrong-case, empty and trailing-space
|
||
names, each giving exit 2 with `file:line` and the list of names
|
||
- wrong types (`1`, `true`, an array), giving "expected a quoted string"
|
||
- `style` outside `[format]`
|
||
- `--style` with `--indent`/`--line-length`, flag over toml, and a toml
|
||
`indent` over the flag's preset
|
||
- nested configs: the nearest one wins with no merging
|
||
- `check --select line-length` under each style (80, 100 and 120 columns,
|
||
auto 100)
|
||
- MCP `format` live over stdio, ansi + `indent = 3`, byte-equal to the CLI
|
||
- the cache: A → B → A is never served stale; a corrupt 7th field, a
|
||
6-field line and a garbage line are each dropped without error; the base
|
||
binary reading the new store re-checks the file and rewrites it
|
||
- the `lucisv.format.style` drop-down matches `STYLE_NAMES` (a test pins
|
||
this)
|
||
|
||
*auto.*
|
||
|
||
- **Determinism:** `--threads 1` vs the default thread count over all
|
||
4 921 files: 0 diff lines.
|
||
- **Ties:** I built a file where `lucisv` and `nxp` tie exactly at 15/16.
|
||
It went to `lucisv`, the earlier preset, three runs gave the same bytes,
|
||
and the result is idempotent.
|
||
- **Edge cases:** an empty file, a comment-only file, a fence region and a
|
||
parse error all behave as under a fixed preset.
|
||
- **Range:** `--lines` under auto changed nothing outside the range, and the
|
||
result was stable.
|
||
- **Stability and cost:** findings F1, F3 and F4.
|
||
|
||
**Findings.**
|
||
|
||
- **F1 — medium-high (user-visible, not an invariant): under `auto`, a
|
||
one-line edit can rewrite most of a file.** `auto.rs` `distance` compares
|
||
layout lines first and indentation only to break ties. A preset that saves
|
||
3 layout lines therefore beats one that keeps 741 lines' indentation.
|
||
Repro (`qa_auto/` probe, scratch):
|
||
1. Take `hw/top_earlgrey/rtl/autogen/chip_earlgrey_asic.sv`.
|
||
2. Auto picks `microsoft`, at distance (626, …) against `google` (626, …).
|
||
3. Insert `always_comb if(qa) begin qa_x=1; end else begin qa_x=0; end`
|
||
before `endmodule` and run auto again.
|
||
4. It now picks `google`, and `ListIndent::Wrap` re-indents **741 of 1 314
|
||
lines**.
|
||
|
||
Measured on 200 random files with `endmodule`, comparing the auto output
|
||
before and after one inserted construct. The `--style auto` column counts
|
||
files whose pre-existing lines changed.
|
||
|
||
| inserted construct | preset changed | pre-existing lines changed | >20 lines changed |
|
||
|---|---|---|---|
|
||
| `assign qa_x=qa_y ;` | 0 | 0 | 0 |
|
||
| the cuddled if/else line above | 4 | 4 | 2 (741, 194 lines) |
|
||
| an Allman if/else block | 81 | 21 | 2 (140 lines max) |
|
||
| a one-line instance `qa_mod qa_u (.a(qa_a), .b(qa_b));` | 14 | 14 | 2 (37 lines max) |
|
||
|
||
In the last row, typing one ordinary instance into a google-style file
|
||
flips it to `lucisv` and un-breaks every short header. Idempotency still
|
||
holds in every case. Possible cheap mitigations, for the lead to decide:
|
||
- compare total changed lines instead of lexicographically
|
||
- add hysteresis: keep the preset the input is already a fixed point of
|
||
unless another wins by a margin
|
||
- in the editor, pin the preset per document
|
||
- **F2 — medium (preset honesty): `google` and `lowrisc` cuddle `else`
|
||
after a labelled `end`.** Both cited guides make an exception: after a
|
||
labelled `end`, the `else` goes on a new line (Google "Eschatology";
|
||
lowRISC "Begin / End"). Repro: `if (a) begin : l1 … end : l1` / `else
|
||
begin` with `--style google` or `--style lowrisc` prints `end : l1 else
|
||
begin`. The preset comments in `style.rs` (GOOGLE, LOWRISC) leave this
|
||
exception out.
|
||
- **F3 — medium (functional): under `auto`, range, selection and on-type
|
||
formatting fall back to `lucisv` whenever the buffer has a parse error
|
||
anywhere.** `auto.rs` `resolve_style` does this in its `Err(_) =>
|
||
PRESETS[0]` arm. A half-typed buffer is exactly when on-type runs, and
|
||
selection formatting otherwise works around parse errors. Repro: take the
|
||
google-formatted `common_cells/src/stream_throttle.sv`, insert an
|
||
unindented 4-line broken instance at line 48, and run `format_selection`
|
||
lines 48–51 with auto:
|
||
- with no parse error elsewhere, it lays the instance out google-style
|
||
(one connection per line)
|
||
- with ` assign qa = ;` added near the end, it joins the instance onto
|
||
one line, lucisv-style
|
||
|
||
This is documented in a code comment, but not in either README.
|
||
- **F4 — medium (cost; the README is optimistic).** Release build, on a
|
||
busy machine, 10 largest files:
|
||
|
||
| file | auto, unformatted | lucisv, unformatted | auto selection, formatted file | lucisv selection | auto selection, unformatted file |
|
||
|---|---|---|---|---|---|
|
||
| `pinmux_reg_top.sv`, 42 192 lines | 2.30 s | 0.37 s | 1.36 s | 0.094 s | 3.0 s |
|
||
| `rv_plic_reg_top.sv`, 20 021 lines | 0.45 s | — | 0.25 s | — | — |
|
||
| `ac_range_check_reg_top.sv`, 14 418 lines | 0.32 s | — | 0.28 s | — | — |
|
||
|
||
The README says an already-formatted file costs "0.41 s vs 0.40 s (the
|
||
first preset leaves it unchanged)". That holds only when the file's preset
|
||
is `lucisv`. pinmux's auto output resolves to `google`, so every selection
|
||
pays three whole-file formats: `lucisv`, then `google`, then `canonical`'s
|
||
`lucisv` again. Selection does not need `canonical`, which only names the
|
||
preset. Caching the resolved preset per document version would remove the
|
||
whole cost from on-type. Whether 1–3 s per on-type keystroke on 20k–42k
|
||
line files is acceptable is the lead's call.
|
||
- **F5 — low (docs): the cross-preset claim "every other decision … comes
|
||
back" is slightly overstated.** I reproduced the counts for lucisv via
|
||
lowrisc (1 288), microsoft via lucisv (20) and ansi via nxp (1 244). I then
|
||
classified every differing hunk in 20 files per pair (`bin/classify.py`):
|
||
- microsoft via lucisv and ansi via nxp: all padding, or lists broken by
|
||
alignment
|
||
- lucisv via lowrisc: 261 of 265 hunks are padding or alignment-forced
|
||
breaks; 4 hunks (18 lines) are something else. Examples:
|
||
`flash_phy_core.sv:230` and `kmac_entropy.sv:297`. A named parameter
|
||
override `#(.Width(HashCntW))`, broken in `lucisv(x)`, comes back
|
||
joined in `lucisv(lowrisc(lucisv(x)))` once its connection list is
|
||
aligned.
|
||
|
||
This is the pre-existing coupling between the head and the connection
|
||
list, and it is a knock-on effect of alignment rather than a new bug. The
|
||
README should say so instead of "only alignment".
|
||
- **F6 — low (docs):**
|
||
- `style.rs` LOWRISC says the guide's "Module Declaration" section
|
||
*requires* aligned ports. The guide requires alignment only for
|
||
instantiation port expressions; for declarations it is just shown in
|
||
the examples. The feature README's "aligned in columns" has the same
|
||
issue.
|
||
- lowRISC keeps a comment line without a blank line before it inside the
|
||
same alignment block. lucisv breaks the group at the comment. This
|
||
deviation is not listed beside the widest-row-tight one in Assumptions.
|
||
- **F7 — low (cosmetic; the layout predates the lane but is now common):**
|
||
`OnePerLine` breaks every multi-instance declaration (`p1 u8 (.a(a)), u9
|
||
(.a(b));`) into the old hanging layout. Under `google`, entries land at
|
||
8, `)` and `u9` at 4, and the opening line is at 2. Same under
|
||
`microsoft` at 4/12/8. `style.rs` `list_indent` says the closing `)`
|
||
stays at the opening line's column, which is false here.
|
||
- **F8 — low (readability, concrete gaps in `style.rs`):**
|
||
- The module doc says "every preset is a table row in this file", but the
|
||
presets are six separate 9-line struct literals. Only the README has the
|
||
side-by-side table.
|
||
- `port_lists`' doc does not say which lists it governs (not positional
|
||
connections, not function/task ports, not `#(16)`). That is in the
|
||
README's Assumptions only.
|
||
- `begin`'s doc does not say it also moves `always_comb`/`initial`/`for`
|
||
`begin` (ansi prints `always_comb` / `begin`).
|
||
|
||
Confirmed honest: in every user-facing place `ansi`, `microsoft` and `nxp`
|
||
appear (root README, extension README, package.json `enumDescriptions` and
|
||
`markdownDescription`, `style.rs` comments), they are labelled as lucisv's
|
||
guesses, and no citation is made up. Both guides were fetched
|
||
(google/styleguide `verilogguide.md` up to character 100 000;
|
||
lowRISC/style-guides `VerilogCodingStyle.md`). Indent 2, width 100,
|
||
`begin` on the keyword's line, `end else begin`, one entry per line, Google's
|
||
4-space list indent, lowRISC's 2-space list indent, and Google's
|
||
recommended-only alignment all match the text, apart from F2 and F6.
|
||
|
||
Not verified:
|
||
- a live VS Code or LSP session (the server's style ladder is covered only
|
||
by unit tests, which I read against the README)
|
||
- the dev's per-preset pick counts (lucisv 3 875, …)
|
||
- the rest of Google's guide beyond character 100 000
|
||
- lint.rs line-length under ansi/microsoft/nxp in the server (owned by
|
||
lane 71.1; the Handshake request stands)
|
||
|
||
**2026-11-19 — QA round 2 (Opus 5.5), on the fix round.** Verdict:
|
||
**PASS WITH FINDINGS.** No invariant violation, and the default output is
|
||
still byte-identical. F1, F2, F4 and F8 are fixed. F3 is fixed for the case
|
||
it named, but the new per-document memory can serve a stale preset (R2-1).
|
||
Binaries were rebuilt from the worktree (`bins/new2`, `bins/server2`).
|
||
Drivers are in scratch `bin/`: `sweep2.sh`, `identity2.sh`, `lexcmp.py`,
|
||
`lsp.py`, `memattack.py`, plus the `qa_auto` probe's `edit2` mode.
|
||
|
||
*Baseline.*
|
||
- `cargo fmt --check` clean; `clippy --all-targets -D warnings` clean.
|
||
- node tests 37/0.
|
||
- `tools/gates.sh` **PASS**, with every suite run through guard.sh:
|
||
vlog_formatter 376/0, lucisv 151/0, lucisv_core 119/0, lucisv_server
|
||
1988/0, lucisv_mcp 384/0; corpus step 814/6, the same as round 1.
|
||
- `git diff d574969 -- '**/verify.rs'` is empty.
|
||
- No test name from d574969 is missing.
|
||
- The one rewritten test, `auto_picks_a_layout_never_a_size`, now
|
||
configures indent 4 and asserts Allman output. It does not hide a
|
||
regression, but it reflects a behaviour change (R2-2).
|
||
- Sizes: unchanged hot spots. `auto_style.rs` is 184 lines with its tests;
|
||
no production file grew past a threshold.
|
||
|
||
*Default byte identity* against the d574969 build, over all 4 921 files: no
|
||
flag, `--style lucisv`, and a toml with only `line-length`/`indent` each
|
||
give **0 diff lines** in output and in stderr.
|
||
|
||
*Invariants, independent lexer, three runs per style, all 4 921 files.* For
|
||
every one of the seven styles: 14 parse errors (the base's own), 0
|
||
verification errors, 0 crashes or guard kills, 0 partial outputs, 0 token
|
||
diffs, 0 comment diffs, and 0 files changed by the 2nd or the 3rd run.
|
||
|
||
*a. Edits under auto.*
|
||
|
||
On the numbers that need reconciling: both are right; they are different
|
||
columns of my round-1 table. For the own-line block, 81 is "preset
|
||
changed" and 21 is "pre-existing lines changed".
|
||
|
||
Round 2, same 200 files, same four constructs, measured as preset changes
|
||
(and maximum lines rewritten):
|
||
|
||
| inserted construct | round 1 | round 2 |
|
||
|---|---|---|
|
||
| `assign` | 0 | 0 |
|
||
| cuddled if/else line | 4 | 0 |
|
||
| own-line block | 81 | 1 (3 lines) |
|
||
| one-line instance | 14 | 0 |
|
||
|
||
This matches the dev's figures.
|
||
|
||
Wider set: 500 new random files with `endmodule`. "Rewritten" counts
|
||
original lines changed outside the edit; for `delete_block` the deleted
|
||
lines are taken out of the baseline first.
|
||
|
||
| edit | n | preset changed | 0 lines | 1–3 | 4–20 | >20 | max |
|
||
|---|---|---|---|---|---|---|---|
|
||
| `assign` line | 499 | 0 | 499 | 0 | 0 | 0 | 0 |
|
||
| cuddled if/else line | 499 | 3 | 496 | 3 | 0 | 0 | 2 |
|
||
| Allman if/else block | 499 | 6 | 493 | 6 | 0 | 0 | 2 |
|
||
| one-line instance | 499 | 1 | 498 | 1 | 0 | 0 | 2 |
|
||
| new port in the header | 419 | 20 | 399 | 16 | 4 | 0 | 6 |
|
||
| instance, 3 connections one per line | 499 | 25 | 474 | 25 | 0 | 0 | 3 |
|
||
| `always_ff`, cuddled | 499 | 6 | 493 | 6 | 0 | 0 | 2 |
|
||
| `always_ff`, Allman | 499 | 6 | 493 | 6 | 0 | 0 | 2 |
|
||
| `always_ff`, nxp layout | 499 | 6 | 493 | 6 | 0 | 0 | 2 |
|
||
| delete the last `always … begin` block | 185 | 0 | 85 | 100 | 0 | 0 | 1 |
|
||
| paste a 37–42-line module in another preset | 499 | 161 | 339 | 29 | 131 | 0 | 12 |
|
||
| paste a module in the same preset | 499 | 12 | 487 | 4 | 8 | 0 | 6 |
|
||
|
||
- No edit rewrote more than 12 unrelated lines, so none crossed the
|
||
~20-line flag, and every result was idempotent.
|
||
- The `delete_block` 1-line cases are the blank line left behind,
|
||
collapsed. Example: `spid_fifo2sram_adapter.sv`.
|
||
- Pasting a whole google-formatted module into a lucisv file flips the file
|
||
in 101 of 298 cases and re-lays up to 12 of its own header lines. Majority
|
||
rule by line count is a defensible outcome.
|
||
|
||
*c. The per-document memory, live over stdio against `lucisv-server`.*
|
||
Setup: auto via `didChangeConfiguration`. "Google file" means a
|
||
google-formatted module; the range format target is one unindented
|
||
one-line instance. Ground truth is the CLI's auto on the same buffer.
|
||
|
||
| case | expected | got | result |
|
||
|---|---|---|---|
|
||
| 1. First range on a google file | resolves google | google; edits confined to the range; second range returns no edits | OK |
|
||
| 2. Buffer replaced by a lucisv-layout text (external reformat / reload) | lucisv | **google** | FAIL, R2-1 |
|
||
| 3. Whole-document format with a remembered preset | searches afresh | equals CLI auto | OK |
|
||
| 4. Range after that format | lucisv | lucisv | OK |
|
||
| 5. Named `lucisv` / `google` while a preset is remembered | memory ignored | memory ignored | OK |
|
||
| 6. auto → whole-document format under `lucisv` → auto, then a range | lucisv | **google** | FAIL, R2-1 |
|
||
| 7. Close, then reopen the same URI with lucisv content | lucisv | **google** | FAIL, R2-1 |
|
||
| 8. Buffer stops parsing after a preset is remembered | remembered google | google, for range and for `;` on-type | OK |
|
||
| 9. Buffer never parsed | default layout (documented) | default layout | OK |
|
||
| 10. Same file under `c%6Dx.sv`, `cmx.sv`, `CMX.sv` | independent entries, none inherits | independent | OK |
|
||
| 11. 70 documents | oldest evicted and resolved afresh, newest kept, list bounded at 64 | as expected | OK |
|
||
|
||
- Range locality held in every case, stale ones included. So R2-1 is
|
||
layout-only and safe.
|
||
- Latency, 42 192-line pinmux file, live: the first range costs 1.49 s
|
||
formatted and 2.90 s unformatted (one search). Each later range costs
|
||
0.06 s, and a named-style range costs 0.067 s. F4 is fixed after the
|
||
first request per document.
|
||
- didRename was not run live. By the code, the new URI has no entry
|
||
(it searches), and the old URI keeps its entry, which is case 7 again if
|
||
a file reappears under the old URI.
|
||
|
||
*d. `else_after_label`.* I wrote new inputs (`hand2/`):
|
||
- procedural `end : l` followed by `else`, `else if`, `else begin : l`, a
|
||
trailing `//`, a `/* */` between, a plain `else` statement, and
|
||
`` `ifdef `` inside the block;
|
||
- an unlabelled `end` before a labelled `else` block;
|
||
- `unique if`;
|
||
- generate `if`/`else if`/`else` chains with labels, including inside a
|
||
labelled `for`.
|
||
|
||
Under all seven styles: token-equal, comments intact, idempotent.
|
||
|
||
The cited sections, re-fetched today:
|
||
- Google "Eschatology": "if `end` has a label, a following `else` must be
|
||
on a new line".
|
||
- lowRISC "Begin / End": the same rule, with an `end : a` / `else begin : b`
|
||
example at the same column.
|
||
|
||
google and lowrisc now print exactly that, and `end else begin : t9` (no
|
||
end label) stays cuddled. lucisv still cuddles, and its byte identity
|
||
holds. One older bug, already present in d574969, showed up here: a
|
||
trailing `// c` after a generate `end : g4` followed by `else` is a
|
||
verification error under every style. The safety net catches it. It is the
|
||
round-1 generate-comment-before-else bug again.
|
||
|
||
*e. Table attributes.* `#[allow(clippy::too_many_arguments)]` at
|
||
`style.rs:102` and `#[rustfmt::skip]` at `style.rs:138` each carry a reason.
|
||
The table is column-aligned with a header comment and reads side by side.
|
||
`cargo fmt --check` passes.
|
||
|
||
**Findings, round 2.**
|
||
- **R2-1 — medium (wrong preset served; layout only, safe).**
|
||
`crates/lucisv_server/src/auto_style.rs`, `concrete` → `recall`: the
|
||
memory is keyed by URI alone and never invalidated. Nothing clears it:
|
||
not `didChange`, `didOpen`, `didClose`, a settings change, nor a whole
|
||
document format under a named style. Repro: cases 2, 6 and 7 above
|
||
(`bin/memattack.py`).
|
||
- In case 6, the user formats the whole file under `lucisv`, switches
|
||
back to auto, and the next selection or on-type `;` is laid out
|
||
google-style in a file that is entirely lucisv.
|
||
- It stays that way until the next whole-document format or save.
|
||
- Cheap fixes: drop the entry on `didOpen`/`didClose` and on any
|
||
settings change, and on a whole-document format under a named style;
|
||
or key the entry by the document version it was resolved on, and
|
||
re-resolve only on a full-text replacement.
|
||
- **R2-2 — low-medium (behaviour change from F1, undocumented in the
|
||
README).** Now that indentation counts in full, a file whose indent
|
||
differs from the configured one loses its layout under auto. Repro:
|
||
`lucisv --style auto` with default indent 2 on a 4-space Allman file
|
||
(`hand/src/a01` formatted `--style ansi`) prints cuddled lucisv layout;
|
||
round 1 kept it Allman. The dev's test documents this as "indent is the
|
||
config's". In VS Code the editor `tabSize` rung softens it; on the CLI it
|
||
does not. Between rounds, 426 of 4 921 files' auto output changed.
|
||
Worth a sentence in the README's `auto` paragraph.
|
||
- Round-1 F5–F7 doc fixes were read and are accurate. F7's hanging
|
||
multi-instance layout is recorded as a known limit.
|
||
|
||
Not verified in round 2:
|
||
- a real VS Code session
|
||
- `didRename` live
|
||
- a lucisv.toml style change while a preset is remembered: by the code it
|
||
behaves like case 6, since `concrete` checks only `config.auto_style`
|
||
- the dev's pick counts
|
||
- Google's guide past character 100 000
|
||
|
||
## Review
|
||
|
||
**Lead, 2026-11-19.** Accepted for 0.65.5, after two QA rounds and three dev rounds.
|
||
|
||
- The owner asked for adaptation to the file, with named styles as the
|
||
fallback if that was too ambiguous. Both shipped, and the order they were
|
||
built in was the right one: presets first, each proven on 4 921 files, then
|
||
`auto` as a search over them rather than a detector — the dev dropped the
|
||
voting detector before writing it because its stability could only be
|
||
measured, never argued. `auto`'s idempotency is argued (a preset's own
|
||
output is its fixed point) and then measured.
|
||
- QA earned its keep twice. Round 1 found that `auto` could re-indent 741
|
||
lines after a one-line edit; round 2 found the fix's per-document memory
|
||
could go stale. Both are fixed and both are the kind of thing only an
|
||
adversarial run finds. The invariant table (seven styles, three runs,
|
||
independent lexer, mutation-tested) is the evidence I am accepting this on.
|
||
- I allowed three one-line calls in `server/notification.rs`, another lane's
|
||
file, for the memory's invalidation; they are listed under Handshakes and I
|
||
resolve that merge.
|
||
- The dev departed from my wording on whole-buffer replacement (re-resolve,
|
||
not forget) and was right: a full-sync client would otherwise lose the
|
||
preset of every half-typed buffer.
|
||
- Not done, recorded: the server's `line-length` lint still falls back to 100
|
||
under the 80- and 120-column styles (`lint.rs`, lane 71.1's file — I take
|
||
it at that merge); multi-instance declarations under one-per-line styles;
|
||
the three pre-existing bugs QA met on the way (comment between a generate
|
||
`end` and `else`: verification error; `` `ifdef `` between `end` and `else`
|
||
and an attribute on an ANSI port: parse errors) go to the backlog.
|
||
- Owed to a human: the drop-down in a running VS Code. `ansi`, `microsoft`
|
||
and `nxp` are guesses and say so wherever a user meets them.
|