Rename the tool to lucisv (Language Utility for Coding In SystemVerilog)

This commit is contained in:
lucio committed 2026-08-25 23:36:00 -07:00
1 parent a284e33110
commit eeaffafd56
188 files changed
+2825 -2802

No files matched your search

+68 -68
View File
@@ -2,11 +2,11 @@
## Goal
Make a repeat `vfmt` run over an unchanged tree do (almost) no work.
Make a repeat `lucisv` run over an unchanged tree do (almost) no work.
`TODO.md` §3's content-hash cache item: remember, per file, that *this
exact content, under these settings, on this vfmt version* was already
exact content, under these settings, on this lucisv version* was already
formatted, and skip the whole read-parse-format-verify pipeline on the
next run. Monorepo RTL trees are the case that matters — vfmt's per-file
next run. Monorepo RTL trees are the case that matters — lucisv's per-file
cost is dominated by parse + format + the two runtime safety checks
(equivalence and convergence), all of which are pure functions of
`(content, config)`, so a cache hit is exactly as trustworthy as the run
@@ -24,29 +24,29 @@ what they would have been anyway (modulo one extra summary segment).
true (a formatter that reads the file's *name*, or another file), this
cache silently goes wrong and the assumption must be revisited here.
- **`line-length` and `indent` are the whole config surface.** They are
the only two things `vfmt_core::config::FileConfig` can put into
the only two things `lucisv_core::config::FileConfig` can put into
`vlog_formatter::Config`. The key stores the *resolved values*, not the
config file's path or mtime — so moving a `vfmt.toml` around, or
config file's path or mtime — so moving a `lucisv.toml` around, or
switching from a file to an equivalent `--line-length` flag, correctly
does **not** invalidate anything, while a real value change does.
`exclude` is not part of the key: it changes *which* files are visited,
never how one is formatted.
- **The version string is the workspace version** (`env!("CARGO_PKG_VERSION")`
read inside `vfmt_core`, whose `version.workspace = true` makes it the
read inside `lucisv_core`, whose `version.workspace = true` makes it the
same string for every crate here). This is a coarse proxy for "the
formatter's behavior": two builds of the same version with different
code — a `cargo build` in the middle of development — share a version
and therefore share cache entries. **Developers of vfmt itself should
and therefore share cache entries. **Developers of lucisv itself should
use `--no-cache`** (the test suite does); released binaries are fine.
- **Paths are keys, byte-for-byte as processed.** No canonicalization, no
symlink resolution (config discovery is lexical for the same reason).
`vfmt .` and `vfmt /abs/path/to/tree` therefore do not share entries;
`lucisv .` and `lucisv /abs/path/to/tree` therefore do not share entries;
they just each build their own. A path that is not valid UTF-8, or that
contains a tab or a newline, is never cached (it cannot be written to
the line-based store) — those files are simply always re-formatted.
- **The cache is not a lock.** Two vfmt processes may write it
- **The cache is not a lock.** Two lucisv processes may write it
concurrently; see "Concurrency".
- **`vfmt check` (the linter) is not cached.** `--no-cache` /
- **`lucisv check` (the linter) is not cached.** `--no-cache` /
`--cache-dir` are accepted there and do nothing, so a wrapper script
can pass them unconditionally. Lint results depend on the rule
selection, the waiver comments and the fix mode; caching them is a
@@ -56,7 +56,7 @@ what they would have been anyway (modulo one extra summary segment).
### The key
Per file: **(content hash, line-length, indent, vfmt version)**, keyed on
Per file: **(content hash, line-length, indent, lucisv version)**, keyed on
the file path.
- **Content hash: hand-rolled FNV-1a, 64-bit**, over the file's bytes
@@ -69,12 +69,12 @@ the file path.
stable within one version. FNV-1a is ~15 lines, has no dependency, and
is byte-exactly specified. It is not cryptographic and does not need to
be (see collision posture).
- Hashing costs one pass over bytes vfmt has already read into memory;
- Hashing costs one pass over bytes lucisv has already read into memory;
it is noise next to parsing.
### Collision posture (stated honestly)
A 64-bit content hash means a collision could make vfmt skip a file that
A 64-bit content hash means a collision could make lucisv skip a file that
actually changed — a wrong "clean" verdict, the only way this feature can
produce a wrong result. Two things bound it:
@@ -90,9 +90,9 @@ produce a wrong result. Two things bound it:
It is *not* collision-resistant against an adversary who can choose the
file contents: FNV-1a is trivially invertible, so someone able to write
files in your tree can craft two files with the same hash and make vfmt
files in your tree can craft two files with the same hash and make lucisv
skip the second. That threat model (an attacker with write access to your
source tree, trying to get past a formatter) is not one vfmt defends
source tree, trying to get past a formatter) is not one lucisv defends
against; `--no-cache` removes the cache from the picture entirely if it
ever matters. This is documented rather than fixed because the fix (a
cryptographic hash) is a dependency or ~200 lines of SHA-256 for a threat
@@ -118,13 +118,13 @@ the hash of **the bytes that were written** goes in.
| Miss, in-place write failed (I/O) | — | **nothing** | error, exit 2 |
| Parse error / failed safety check / contained panic | — | **nothing** | error, exit 2 |
| `--stdout` | cache off for the run | nothing | printed |
| stdin (`vfmt -`) | never | never | as before |
| stdin (`lucisv -`) | never | never | as before |
Why "would reformat" and errors are never cached: the fix for both is
**external** to vfmt. A dirty file gets fixed by an editor or by
`vfmt` without `--check`; a parse error gets fixed by editing the source
**external** to lucisv. A dirty file gets fixed by an editor or by
`lucisv` without `--check`; a parse error gets fixed by editing the source
or by teaching the parser new syntax. If either verdict were cached, a CI
`vfmt --check` would keep reporting a stale complaint (or, worse, stop
`lucisv --check` would keep reporting a stale complaint (or, worse, stop
reporting a real one) until someone thought to clear the cache. Caching
only the fixed-point verdict also means the cache can never *invent* work
or *suppress* a diagnostic: the worst a stale, wrong or missing entry can
@@ -148,10 +148,10 @@ interesting characters. Lines are sorted by path, so the file is stable
and diffable and two runs over the same tree produce byte-identical
cache files.
**No serde, no TOML, no JSON.** `vfmt` and `vfmt_core` have exactly one
third-party dependency between them (`rayon`, in `vfmt`). `serde` exists
in the workspace only because `vfmt_server` needs it for LSP wire
messages — `vfmt`/`vfmt_core` do not depend on it, and taking it here
**No serde, no TOML, no JSON.** `lucisv` and `lucisv_core` have exactly one
third-party dependency between them (`rayon`, in `lucisv`). `serde` exists
in the workspace only because `lucisv_server` needs it for LSP wire
messages — `lucisv`/`lucisv_core` do not depend on it, and taking it here
would put a proc-macro build step into the CLI's dependency graph to
encode five fields. Five fields on a line need no schema; CLAUDE.md's
"standard library first" says so.
@@ -165,8 +165,8 @@ Loading, corruption and staleness:
starts empty. A file we cannot fully parse is not a file we can prove
we wrote; partial trust is not worth the branch.
- A well-formed line whose *version* is not this binary's is dropped
silently (that is not corruption, just another vfmt's entry). It is not
carried forward on write, so alternating between two vfmt versions
silently (that is not corruption, just another lucisv's entry). It is not
carried forward on write, so alternating between two lucisv versions
rebuilds the cache each time.
- **Writing is atomic**: the new text goes to `<cache-dir>/cache.<pid>.tmp`
and is `rename`d over `cache`. A reader therefore sees the old file or
@@ -183,7 +183,7 @@ Loading, corruption and staleness:
The cache directory gets a self-ignoring `.gitignore` containing `*`
written into it when it is created, the same trick cargo uses for
`target/`; `/.vfmt_cache` is also listed in this repo's root
`target/`; `/.lucisv_cache` is also listed in this repo's root
`.gitignore`.
### Flags
@@ -191,16 +191,16 @@ written into it when it is created, the same trick cargo uses for
| Flag | Meaning |
|---|---|
| `--no-cache` | do not read and do not write the cache. Nothing is created on disk |
| `--cache-dir <PATH>` | use this directory instead of `.vfmt_cache` |
| `--cache-dir <PATH>` | use this directory instead of `.lucisv_cache` |
**Where the default lives: the current directory.** `.vfmt_cache` is
**Where the default lives: the current directory.** `.lucisv_cache` is
resolved relative to the cwd, not to the input paths and not to the
config file's directory. This is wrong for the multi-project invocation
(`vfmt ~/a/rtl ~/b/rtl` from a third directory writes one cache in that
(`lucisv ~/a/rtl ~/b/rtl` from a third directory writes one cache in that
third directory, and running the same command from elsewhere starts a new
one), and it is what ruff did for years before growing a per-project
resolution. The honest v1 rule is "one cwd, one cache", which is exactly
right for the overwhelmingly common `cd repo && vfmt --check .` in CI and
right for the overwhelmingly common `cd repo && lucisv --check .` in CI and
in a pre-commit hook, and `--cache-dir` covers everything else. Making
the default follow the config-file root is the natural next step and is
deliberately not guessed at here.
@@ -230,7 +230,7 @@ is only mutated in the serial loop afterwards; the file is written once,
single-threaded, at the end of the run. There is no lock and no shared
mutable state.
Two vfmt processes running at once: last writer wins the `rename`, so one
Two lucisv processes running at once: last writer wins the `rename`, so one
process's entries can be lost. That is self-healing and safe:
- An entry only ever asserts *content that this process verified*, so a
@@ -255,18 +255,18 @@ the only writer of an entry is the code path that just observed
re-tested with the cache on.
- **Consumes `docs/features/config-discovery/README.md`'s promise** that
the cache key "must include the resolved per-file settings … not just
file content + vfmt version". Done, with the *values*
file content + lucisv version". Done, with the *values*
(`Config::max_width`, `Config::indent_width`) rather than the config
file's identity, so two trees governed by different `vfmt.toml` files
file's identity, so two trees governed by different `lucisv.toml` files
that happen to say the same thing share entries correctly.
- **Consumes `vlog_formatter::Config`** read-only, for its two fields.
Nothing in `vlog_parser` / `vlog_formatter` / `vlog_linter` was
touched.
- **Where the module lives: `vfmt_core::cache`,** next to `config` and
`walk`. `vfmt_core` is by its own doc comment "the parts of vfmt that
- **Where the module lives: `lucisv_core::cache`,** next to `config` and
`walk`. `lucisv_core` is by its own doc comment "the parts of lucisv that
decide *which* files are processed and *with what settings*", and "this
file is already formatted, skip it" is the third member of that family.
It also keeps the door open for `vfmt_server`: a language server that
It also keeps the door open for `lucisv_server`: a language server that
wanted to avoid re-formatting an unedited buffer on save would want the
same predicate, and would otherwise have to duplicate the file format.
Nothing in the module is CLI-specific — it takes paths, `u64`s and two
@@ -276,7 +276,7 @@ the only writer of an entry is the code path that just observed
or every user with a warm cache keeps their old formatting on files
that did not otherwise change. This is the same discipline ruff and
black need. Within-version development builds must use `--no-cache`.
- **Promises to `crates/vfmt/tests/cli.rs`:** the shared `run` helper
- **Promises to `crates/lucisv/tests/cli.rs`:** the shared `run` helper
appends `--no-cache`, so the pre-existing tests keep running with the
cache out of the picture (they share one cwd — the crate root — and
would otherwise share one cache directory *and* pollute the repo with
@@ -285,13 +285,13 @@ the only writer of an entry is the code path that just observed
## Status / TODO
- [x] `vfmt_core::cache`: FNV-1a `content_hash`, `Entry`, `Cache`
- [x] `lucisv_core::cache`: FNV-1a `content_hash`, `Entry`, `Cache`
(`load` / `disabled` / `is_clean` / `record` / `store`).
- [x] Hand-rolled tab-separated store, sorted by path, atomic
temp+rename write, self-ignoring `.gitignore` in the cache dir.
- [x] Corrupt / unreadable / wrong-version entries ignored, never fatal.
- [x] `--no-cache` and `--cache-dir <PATH>` in `args.rs` and `--help`,
accepted (and inert) for `vfmt check`.
accepted (and inert) for `lucisv check`.
- [x] Lookup at the top of `process_file`; entries collected through the
indexed `par_iter` results and recorded serially in input order.
- [x] Only clean verdicts recorded; `--check`/`--diff`/errors/`--stdout`
@@ -299,7 +299,7 @@ the only writer of an entry is the code path that just observed
- [x] `N files from cache` summary segment.
- [x] Unit tests in `cache.rs` (hash stability, round-trip, corruption,
version filtering, pruning, atomicity of the rename).
- [x] CLI tests in `crates/vfmt/tests/cli.rs` (warm run does no work,
- [x] CLI tests in `crates/lucisv/tests/cli.rs` (warm run does no work,
content change invalidates, indent change invalidates, wrong
version ignored, `--no-cache`, corrupt file tolerated, `--check`
exit codes, `--threads` determinism with a warm cache, default
@@ -315,18 +315,18 @@ the only writer of an entry is the code path that just observed
- Read CLAUDE.md, `TODO.md` §3, `docs/features/parallel-files/README.md`
(whose Handshakes section pre-specifies where the lookup goes) and
`docs/features/config-discovery/README.md` (whose Handshakes section
pre-specifies the key), then all of `crates/vfmt/src` and
`crates/vfmt_core/src`.
pre-specifies the key), then all of `crates/lucisv/src` and
`crates/lucisv_core/src`.
**Module placement.** `vfmt_core::cache`, reasoning in Handshakes. It
costs nothing today (`vfmt` is the only caller) and keeps `vfmt_core`
**Module placement.** `lucisv_core::cache`, reasoning in Handshakes. It
costs nothing today (`lucisv` is the only caller) and keeps `lucisv_core`
dependency-free — `Entry` carries two bare `usize`s rather than a
`vlog_formatter::Config`, so the crate still has an empty
`[dependencies]`.
**The store format.** Tab-separated, path last, sorted, one line per
entry. Rejected alternatives: (a) `serde`+`serde_json` — real dependency
for five fields, and `vfmt`/`vfmt_core` currently have one dependency
for five fields, and `lucisv`/`lucisv_core` currently have one dependency
total; (b) a binary format — unreadable when debugging exactly the kind
of "why did it skip that file?" question a cache creates; (c) one file
per cached path (ruff's older layout) — thousands of tiny files, and the
@@ -347,14 +347,14 @@ forever in a tree where files get renamed.
**Test isolation.** Integration tests run with cwd = the crate
directory, so a default-on cache would (a) create
`crates/vfmt/.vfmt_cache/` in the working tree and (b) make tests
`crates/lucisv/.lucisv_cache/` in the working tree and (b) make tests
interfere: `thread_count_changes_nothing_but_speed` runs the same tree
twice and compares stderr byte-for-byte, which a warm cache would change.
The `run` helper therefore appends `--no-cache`, and the cache tests use
a new `run_raw` with an explicit `--cache-dir` (or a set cwd for the
default-location test). Recorded as a handshake so nobody removes it.
**Measured.** Release build, 10 logical cores, `vfmt --check` over the
**Measured.** Release build, 10 logical cores, `lucisv --check` over the
corpus, best of 10 runs (mean in the work log's raw numbers was within
10 %). The corpus was formatted first, since a tree that is already
clean is exactly the case the cache exists for; the "612 files" column
@@ -394,7 +394,7 @@ correctness risk. Not taken.
**Attacked before handing over** (release binary, outside the test
suite; every one of these degrades quietly, none changes an exit code):
- **Eight vfmt processes at once** over the same 612-file tree and the
- **Eight lucisv processes at once** over the same 612-file tree and the
same cache directory: all eight exit 0, no leftover `*.tmp`, the
resulting file has 612 well-formed lines (`awk -F'\t' 'NF!=5'` finds
none), and the next run is `612 files from cache`. Last-writer-wins,
@@ -412,7 +412,7 @@ suite; every one of these degrades quietly, none changes an exit code):
as cached and exits 0, which is the proof that a hit skips the *whole*
pipeline rather than doing the work and agreeing. That is now the CLI
test `a_hit_skips_the_work_entirely`; the same trick with the wrong
version stamp is `an_entry_from_another_vfmt_version_is_ignored`.
version stamp is `an_entry_from_another_lucisv_version_is_ignored`.
**Blocked by the workspace, as parallel-files was.** A concurrent agent
is mid-landing alignment inference in `vlog_formatter` (`align.rs` plus
@@ -420,23 +420,23 @@ is mid-landing alignment inference in `vlog_formatter` (`align.rs` plus
gates were therefore run in a scratchpad copy of the workspace with
*only* their three crates reverted to `HEAD` (`git checkout --
crates/vlog_{formatter,parser,semantic}`); my own files were copied in
from the real tree. Nothing outside `crates/vfmt`, `crates/vfmt_core`,
from the real tree. Nothing outside `crates/lucisv`, `crates/lucisv_core`,
`docs/features/format-cache`, `README.md`, `TODO.md` and `.gitignore`
was edited, and `cargo fmt` was run scoped (`-p vfmt -p vfmt_core`) so
was edited, and `cargo fmt` was run scoped (`-p lucisv -p lucisv_core`) so
no file of theirs was touched. Re-run everything on the merged tree once
their work lands.
**Gates** (scratchpad tree, described above):
- `cargo test -p vfmt -p vfmt_core`: 28 unit (`vfmt`) + **63** CLI
(`vfmt`) + **45** unit (`vfmt_core`), all green. New: 15 CLI tests, 14
- `cargo test -p lucisv -p lucisv_core`: 28 unit (`lucisv`) + **63** CLI
(`lucisv`) + **45** unit (`lucisv_core`), all green. New: 15 CLI tests, 14
`cache.rs` unit tests, 1 `args.rs` test.
- `cargo test --workspace`: green, no churn in any other crate's tests —
this feature changes no formatter output.
- `cargo clippy --workspace --all-targets`: silent.
- `cargo fmt -p vfmt -p vfmt_core -- --check`: clean.
- `cargo fmt -p lucisv -p lucisv_core -- --check`: clean.
- No `Cargo.toml` / `Cargo.lock` change: no new dependency, and
`vfmt_core` still has an empty `[dependencies]`.
`lucisv_core` still has an empty `[dependencies]`.
## QA log
@@ -454,12 +454,12 @@ was reverted). All cargo commands below ran in that copy; the real tree
was touched only to append this entry. No commit/push.
**Gates, reproduced from scratch in the copy:**
- `cargo build -p vfmt -p vfmt_core --release` — clean.
- `cargo test -p vfmt -p vfmt_core`: 28 (`vfmt` unit) + 63 (`cli.rs`) + 45
(`vfmt_core` unit) = 136, all green, matching the claimed counts exactly.
- `cargo build -p lucisv -p lucisv_core --release` — clean.
- `cargo test -p lucisv -p lucisv_core`: 28 (`lucisv` unit) + 63 (`cli.rs`) + 45
(`lucisv_core` unit) = 136, all green, matching the claimed counts exactly.
- `cargo test --workspace`: every crate green, no churn elsewhere.
- `cargo clippy --workspace --all-targets`: silent.
- `cargo fmt -p vfmt -p vfmt_core -- --check`: clean.
- `cargo fmt -p lucisv -p lucisv_core -- --check`: clean.
- `git diff --stat HEAD -- Cargo.toml Cargo.lock crates/*/Cargo.toml`:
empty — no dependency added, confirmed.
@@ -476,7 +476,7 @@ the corrupt-file/version unit tests, all passing). Confirmed by hand:
- `--cache-dir` pointing at an existing plain file, and a `chmod 500`
cache directory: both exit 0, run output unaffected, nothing written —
matches "silent write failures."
- 8 parallel `vfmt --check` processes over a shared 200-file tree and
- 8 parallel `lucisv --check` processes over a shared 200-file tree and
cache dir: all exit 0, zero `*.tmp` leftovers, exactly 200 well-formed
lines afterward (`awk -F'\t' 'NF!=5'` empty), next run is a clean
200-file hit.
@@ -491,11 +491,11 @@ independent repro:
file gives `would reformat: ...`/exit 1 on three consecutive `--check`
runs, never "from cache" — the stale-CI-verdict failure mode does not
occur.
- `--stdout` never creates `.vfmt_cache` even with a warm entry present
- `--stdout` never creates `.lucisv_cache` even with a warm entry present
for the same file (prints every time, does not read or write the
cache) — matches `cache_enabled() == !no_cache && !stdout` in
`args.rs`.
- `vfmt check <file> --no-cache --cache-dir X`: exits normally (lint
- `lucisv check <file> --no-cache --cache-dir X`: exits normally (lint
verdict, unrelated to formatting), creates no cache artifact under
either name — accepted-but-inert confirmed.
- `run_stdin` in `main.rs` never references `Cache` at all — stdin mode
@@ -505,11 +505,11 @@ independent repro:
chmod-000-after-caching repro below) proves the lookup happens before
`format_contained` is ever called.
**Claim 3 (flags).** `--no-cache`: no `.vfmt_cache` appears for either a
`vfmt <file>` or `vfmt --stdout <file>` run — checked directly with `ls`.
**Claim 3 (flags).** `--no-cache`: no `.lucisv_cache` appears for either a
`lucisv <file>` or `lucisv --stdout <file>` run — checked directly with `ls`.
`--cache-dir`: exercised throughout. Default cwd-relative location and
self-ignoring `.gitignore`: reproduced outside the test suite too
(`vfmt --check .` from a fresh dir leaves exactly `.vfmt_cache/{cache,
(`lucisv --check .` from a fresh dir leaves exactly `.lucisv_cache/{cache,
.gitignore}`, the latter reading `*\n`). The README's own "Where the
default lives" paragraph states the multi-root limitation honestly.
@@ -568,10 +568,10 @@ strictly warm < cold < `--no-cache` on every run observed.
file that is actually dirty): the run trusts it and exits 0. This is
exactly the collision/tamper posture the README's "Collision posture"
section states outright — "an attacker with write access to your
source tree ... is not one vfmt defends against" — so this is
source tree ... is not one lucisv defends against" — so this is
documentation matching behavior, not an undisclosed hole.
- **Two directories with differently-formatted-but-equal-valued
`vfmt.toml`** (`indent = 2` vs `indent = 2 # comment`), same
`lucisv.toml`** (`indent = 2` vs `indent = 2 # comment`), same
file path: still a hit — confirms the key is the resolved *value*, not
the config file's text or identity.
- **CRLF file**: never reaches a clean fixed point (always "would
@@ -620,7 +620,7 @@ Points reviewed and accepted:
small touch, right instinct. The whole-file-discard-on-any-malformed-
line rule is the right paranoia for a value store.
4. **Value-keyed config** (not config-file identity) means two
differently-written-but-equal vfmt.tomls share hits — QA probed it.
differently-written-but-equal lucisv.tomls share hits — QA probed it.
The cwd-relative default cache location is the honest v1 limitation,
stated.
5. **Both agents' isolation discipline under the concurrent alignment