# Round 6 — Formatter Alignment Completeness, `lowrisc` Fidelity, Selective `[format]` Overrides, and Full Cache Keying > [!NOTE] > Live working note. Final gate and OpenTitan sweep results are recorded under **QA log** after the last verification pass. ## Goal Close four remaining formatter/configuration gaps in Round 6 without touching parser/linter semantics, without weakening safety-net invariants (`CLAUDE.md` #1, #2, #4), and keeping every modified production `.rs` file within `<= 600` non-blank non-comment production lines: 1. **Alignment completeness for `#(...)` module/interface parameter ports and `#(...)` named parameter overrides:** align `Module::param_ports` (`PARAM_PORT_COLS`) and `Instantiation::params` (`connection_cols`) cleanly under both `Alignment::Infer` and `Alignment::Always`, preserving single-row / comment / directive / attribute / continuation / no-default / budget-overflow splits and leaving `class` parameter headers (`classes.cases`) untouched. 2. **`lowrisc` fidelity (`connection_align_min = 0`):** add `connection_align_min: usize` to `vlog_formatter::Style` (`0` for `lowrisc`, `1` for `lucisv`, `google`, `ansi`, `microsoft`, `nxp`), aligning the widest named connection / parameter override tight (`.long_port(sig)`), while still padding narrower entries to the aligned `(` column cleanly and keeping fixed-point convergence under both `Always` and `Infer`. 3. **Selective `[format]` overrides on top of named presets (Owner Decision #5):** allow explicit per-knob overrides (`begin`, `else`, `else-after-label`, `port-lists`, `list-indent`, `alignment`, `connection-align-min`) in `lucisv.toml` `[format]`, VS Code settings (`editors/vscode/package.json` `lucisv.format.*`), `lucisv_server`, `lucisv_mcp`, and `lucisv` CLI — layering over any active named preset *and* over every competing preset under `style = "auto"`. 4. **Full `lucisv_core::cache::Entry` serialization:** record every effective formatting knob (`content`, `line_length`, `indent`, `uvm_utils_indent`, `style`, `begin`, `else_keyword`, `else_after_label`, `port_lists`, `list_indent`, `alignment`, `connection_align_min`) in `.lucisv_cache/cache` (14-field format), invalidating in both directions on any `[format]` toggle (including un-overridden vs explicitly overridden `auto`) and dropping older 5-/6-/7-field cache lines individually as stale. ## Exact Preset Table | style | indent | width | `begin` | `else` | `else_after_label` | `port_lists` | `list_indent` | `alignment` | `connection_align_min` | |---|---:|---:|---|---|---|---|---|---|---:| | `lucisv` (default) | 2 | 100 | `same-line` | `same-line` | `same-line` | `fit` | `block` | `infer` | 1 | | `google` | 2 | 100 | `same-line` | `same-line` | `own-line` | `one-per-line` | `wrap` | `infer` | 1 | | `lowrisc` | 2 | 100 | `same-line` | `same-line` | `own-line` | `one-per-line` | `block` | `always` | 0 | | `ansi` | 4 | 80 | `own-line` | `own-line` | `own-line` | `fit` | `block` | `infer` | 1 | | `microsoft` | 4 | 120 | `own-line` | `own-line` | `own-line` | `one-per-line` | `block` | `infer` | 1 | | `nxp` | 2 | 80 | `same-line` | `own-line` | `own-line` | `one-per-line` | `block` | `always` | 1 | ## Assumptions - `lucisv_core` remains zero-dependency (`Cargo.toml`); enum string tables (`PLACEMENT_NAMES`, `PORT_LISTS_NAMES`, `LIST_INDENT_NAMES`, `ALIGNMENT_NAMES`, `CONNECTION_ALIGN_MIN_{MIN,MAX}`) live in `lucisv_core::config` and are cross-checked against `vlog_formatter` in `lucisv::args::tests` and against `editors/vscode/package.json` in `lucisv_server::settings::tests`. - `ClassDecl::param_ports` and `extends #(...)` stay unaligned (`class.rs`), preserving existing `cases/classes.cases` expectations. - `ParamPort` alignment uses 2 columns `[ColSpec { flush: 1, min: 1 }, ColSpec { flush: 1, min: 1 }]` (type/kw prefix, parameter name + unpacked dims, `= default`) matching `PARAM_DECL_COLS`, and falls back to 1 unaligned cell when `kw`/`is_type`/`ty` are all empty, `default` is `None`, or inline gap comments / attributes exist. - Under `style = "auto"`, un-overridden per-knob cache fields serialize as `"auto"` (`None` for `connection_align_min`) so toggling e.g. `[format] begin = "same-line"` on top of `style = "auto"` still misses cached entries recorded under plain `style = "auto"`. - `connection-align-min` allows integer bounds `0..=8` in both `lucisv.toml` and VS Code settings. ## Handshakes - `vlog_formatter::style::{Style, StyleOverrides, Placement, PortLists, ListIndent, Alignment}` <-> `lucisv_core::config::FileConfig`: string spelling lockstep verified in `lucisv::args::tests::the_core_format_override_choices_match_the_formatter`. - `vlog_formatter::auto::{format_auto, resolve_style, resolve_concrete}` <-> `lucisv_server::auto_style::AutoStyles`: `fixed(...)` applies `config.overrides` onto candidate presets, and `AutoStyles::concrete` resolves the base preset by `preset.name` before re-applying current `config.overrides`. - `lucisv_core::cache::Entry` (14 fields) <-> `lucisv::main::entry_for`: all 12 formatting keys + `VERSION` + `path` written/parsed strictly, older 5-/6-/7-field lines discarded individually. - `editors/vscode/package.json` (`lucisv.format.*`) <-> `lucisv_server::settings::ClientSettings` <-> `lucisv_server::format::config_from`: `lucisv.toml` outranks pushed `ClientSettings`, which outranks editor tab options and preset defaults. ## Status / TODO - [x] `Module::param_ports` and `Instantiation::params` alignment (`Infer` & `Always`) - [x] `Style::connection_align_min` (`lowrisc` = `0`, others = `1`) and `tests/styles.rs` alignment - [x] `StyleOverrides` + `Config::{apply_overrides, with_overrides, effective}` + `auto` layering - [x] `lucisv_core::config` strict `[format]` override keys & validation - [x] `lucisv_core::cache::Entry` full 14-field keying & legacy 5/6/7-field staleness handling - [x] `lucisv` CLI, `lucisv_mcp`, `lucisv_server`, and `editors/vscode/package.json` wiring - [x] Final verification gates (`fmt`, `stamp_author`, `clippy`, workspace tests, `gates.sh`, OpenTitan sweeps) ## Work log - Added `StyleOverrides`, `Placement`/`PortLists`/`ListIndent`/`Alignment` parse & string helpers, and `Style::connection_align_min` (`0` for `LOWRISC`, `1` for others) in `crates/vlog_formatter/src/style.rs`. - Wired `Config::overrides` and `effective()` through `crates/vlog_formatter/src/{lib.rs, auto.rs, format/mod.rs}` so concrete presets, `auto`, `--lines`, and selection formatting all honor overrides cleanly. - Implemented `#(...)` header parameter port alignment (`PARAM_PORT_COLS`, reusing `decl::eq_offset`) in `crates/vlog_formatter/src/format/module.rs` and `#(...)` named parameter override alignment + `connection_cols` (`min = connection_align_min`) in `crates/vlog_formatter/src/format/instance.rs`. - Extended `lucisv_core::config::FileConfig` (`begin`, `else`, `else-after-label`, `port-lists`, `list-indent`, `alignment`, `connection-align-min`) and `lucisv_core::cache::Entry` (14 tab-separated fields, 5/6/7-field legacy lines individually dropped as stale). - Wired override layering into `crates/lucisv/src/{args.rs, main.rs}`, `crates/lucisv_mcp/src/tools/format.rs`, `crates/lucisv_server/src/{settings.rs, format.rs, auto_style.rs}`, and `editors/vscode/package.json`. - Updated `README.md` named-styles note for `lowrisc` tight `.clk(clk)`. ## QA log - **Round 6 QA Verdict: PASS** (adversarial audit of uncommitted changes on `4cf50a0`). - **Invariants & code hygiene:** - Production LOC before `#[cfg(test)]` / `mod tests` across all touched `.rs` files (`<= 574`, ceiling `600`; `crates/lucisv/src/main.rs` = 574, `crates/vlog_formatter/src/format/stmt.rs` untouched = 570, `crates/vlog_formatter/src/format/module.rs` = 467, `crates/lucisv/src/args.rs` = 456, `crates/vlog_formatter/src/format/instance.rs` = 388, `crates/vlog_formatter/src/format/decl.rs` = 381, `crates/lucisv_core/src/config.rs` = 352, `crates/lucisv_server/src/settings.rs` = 295, `crates/vlog_formatter/src/format/mod.rs` = 293, `crates/vlog_formatter/src/style.rs` = 223, `crates/lucisv_core/src/cache.rs` = 221, `crates/lucisv_mcp/src/tools/format.rs` = 168, `crates/lucisv_server/src/format.rs` = 139, `crates/vlog_formatter/src/auto.rs` = 128, `crates/lucisv_server/src/auto_style.rs` = 57, `crates/vlog_formatter/src/lib.rs` = 16). - Zero `.unwrap()`, `.expect()`, `panic!`, or `unsafe` in non-test production code across `lucisv_core`, `lucisv`, `lucisv_server`, `lucisv_mcp`, and `vlog_formatter`. - Non-blocking observations: `FileConfig -> StyleOverrides` conversion is repeated in `lucisv/src/args.rs`, `lucisv_mcp/src/tools/format.rs`, and `lucisv_server/src/format.rs` (alongside `overrides_from_client`) due to `lucisv_core`'s zero-dependency boundary; `--help` (`args.rs`) and root `README.md` Config/Cache sections only name `style` and `uvm-utils-indent`. - **Adversarial technical checks:** - Alignment (`#(...)` param ports/overrides, `connection_align_min: 0` vs `1`, `Infer` vs `Always`, single-item `.p(v)`/`#(.P(v))`, `.P` implicit params, positional `#(1)`, escaped identifiers, inline gap comments, `` `ifdef `` splits, multi-instance `#47` under `lowrisc`, unpacked dims + `type` params + continuation params): verified fixed-point idempotency and exact behavior. - Selective `[format]` & editor overrides (`editors/vscode/package.json` <-> `ClientSettings` <-> `lucisv_server` <-> `lucisv_mcp` <-> `lucisv`): schema, enum/null/range validation (`0..=8`), `lucisv.toml > ClientSettings > tabSize > preset`, `auto` + overrides + `AutoStyles` cache invalidation/reapplication verified. - Cache keying (`lucisv_core::cache::Entry` 14-field format & `main.rs::entry_for`): verified bidirectional invalidation across `connection-align-min` (`0 <-> 1` under `lowrisc`), `else-after-label` (`own-line <-> same-line` under `google`), `style = "auto"` un-overridden vs overridden, individual drop of legacy 5/6/7-field rows, and wholesale discard on corrupt lines. - `python3 tools/stamp_author.py --check`: pass (`249 untouched`, `0` missing stamps). - `./tools/gates.sh` (all 17 steps, log `target/gates/20261126-145646`): **PASS** - `stamp`, `fmt`, `clippy`, `build`, `cross`: pass (`0` warnings/errors). - `suite:vlog_parser` (`527/0`), `suite:vlog_semantic` (`438/0`), `suite:vlog_refactor` (`769/0`), `suite:vlog_formatter` (`383/0`), `suite:vlog_linter` (`672/0`), `suite:lucisv_core` (`123/0`), `suite:lucisv` (`162/0`), `suite:lucisv_server` (`2195/0`), `suite:lucisv_mcp` (`399/0`), `docs` (`1/0`): all pass. - `corpus`: pass (`814/820`, `99.3%`, `0` verification errors). - `node`: pass (`37/0`). - Release `target/release/lucisv` (`/Users/lucio/repo/opentitan/hw`, tested in `/tmp` scratch copies; `/Users/lucio/repo/opentitan` verified clean via `git status --porcelain`): - Default (`--no-config`): `3967 reformatted, 72 left unchanged, 7 failed` (**4,039/4,046**, `0` verification errors); pass 2 `--check`: `4039 unchanged`, `0` would reformat. - `--style lowrisc` (`--no-config`): `3976 reformatted, 63 left unchanged, 7 failed` (**4,039/4,046**, `0` verification errors); pass 2 `--check`: `4039 unchanged`, `0` would reformat. - `--style auto` (`--no-config`): `3967 reformatted, 72 left unchanged, 7 failed` (**4,039/4,046**, `0` verification errors); pass 2 `--check`: `4039 unchanged`, `0` would reformat. - Selective `[format]` overrides (`style = "google"`, `begin = "own-line"`, `else = "own-line"`, `else-after-label = "same-line"`, `port-lists = "one-per-line"`, `list-indent = "block"`, `alignment = "always"`, `connection-align-min = 0`): `3985 reformatted, 54 left unchanged, 7 failed` (**4,039/4,046**, `0` verification errors); pass 2 `--check`: `4039 unchanged`, `0` would reformat. ## Review **Lead Self-Inspect (2026-11-26): APPROVED for trunk commit.** - Production LOC invariant verified across all modified `.rs` files (`<= 574` prod LOC before `#[cfg(test)]`, ceiling `600`; `format/stmt.rs` untouched at 570). - Zero `.unwrap()`, `.expect()`, `panic!`, or `unsafe` in non-test production code across modified files. - Verified Round 6 QA PASS across all 17 `./tools/gates.sh` steps (`5,668` Rust tests passed, `1` doc, `814/6` corpus, `37/0` node, `cross`, `stamp`) and all 4 OpenTitan `hw/` sweeps (default, `lowrisc`, `auto`, selective overrides — each `4,039/4,046` with `0` verification errors and 100% pass-2 idempotency). - OpenTitan repository `/Users/lucio/repo/opentitan` verified clean (`git status --porcelain` empty).