Every tracked file that can carry a comment (880 of them) now opens with "Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with "Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com", in the file's own comment syntax. No behaviour change: the diff outside the version bump and changelogs is comment lines only. - tools/stamp_author.py: writes the lines; idempotent, `--check` lists what is missing. Headers go under a shebang and under Markdown front matter. - Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the LICENSE files (already carry the copyright line). - tools/linux_check.sh: --help reads its header from line 3, now that the author line sits under the shebang. - tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
662 lines
38 KiB
Markdown
662 lines
38 KiB
Markdown
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
||
|
||
# expand-wildcard
|
||
|
||
TODO §50 — the first of the §8 refactoring backlog to ship. One engine
|
||
function, one code action, one command.
|
||
|
||
## Goal
|
||
|
||
`sub u_x (.clk(clk), .*);` binds every remaining port of `sub` to the
|
||
same-named signal in the scope the instantiation is written in (IEEE 1800
|
||
§23.3.2.4). **Expanding** the wildcard writes those bindings out: the
|
||
refactoring an RTL engineer reaches for the moment a port list is about to
|
||
diverge from the wrapper around it, and the one the ports engine already
|
||
refuses to edit around — `add_port` and `remove_port` warn and leave a `.*`
|
||
site alone, and `propagate_ports` declines a wildcard outright, because none of
|
||
them can rewrite a connection nobody wrote. After this round the user can turn
|
||
the wildcard into text first and then use all three.
|
||
|
||
The engine is `vlog_refactor::expand_wildcard`, so Vim, VS Code and any future
|
||
CLI get identical behavior; `lucisv_server` maps the protocol and decides
|
||
nothing. Whole-edit-or-nothing, through the ports engine's lexical splice and
|
||
its "the file still parses" verifier: an `Ok` is safe to apply, an `Err` is a
|
||
sentence for the user and no edits at all.
|
||
|
||
## API as built
|
||
|
||
```rust
|
||
// crates/vlog_refactor/src/lib.rs
|
||
pub fn expand_wildcard(files: &[(PathBuf, String)], file: &Path, offset: u32)
|
||
-> Result<RefactorEdit, String>;
|
||
// new beside `sites_phrase`, for the server's title arithmetic:
|
||
pub fn is_sites_phrase(phrase: &str) -> bool;
|
||
```
|
||
|
||
`files`, `RefactorEdit`, `TextEdit` and the `Err(String)`-is-a-sentence
|
||
convention are M2's, unchanged. `port_actions` gained a third offer, so the
|
||
code-action path needed no new entry point at all.
|
||
|
||
## The rule, exactly as implemented
|
||
|
||
At the cursor's instantiation — the instance whose span covers the offset, or
|
||
the only instance of the statement whose module name it covers, which is
|
||
`propagate_ports`'s own rule:
|
||
|
||
1. The connection list must be **named** and hold exactly **one** `.*`.
|
||
2. Every port the instantiated module declares that the list does **not**
|
||
name explicitly is what the wildcard stands for, in the module's
|
||
**declaration order**. `.clk`, `.clk()` and `.clk(x)` all count as
|
||
explicit — they are connections the source wrote, so `.*` never bound
|
||
those ports.
|
||
3. For each of them, lucisv asks `vlog_semantic` what the name means in the
|
||
scope the *instance name* sits in — the generate block's, then its
|
||
parents', up to the module's:
|
||
- **a net, a variable, or a port** of that name → `.name(name)`;
|
||
- **anything else, or nothing** → `.name()`, and a warning naming every
|
||
port left that way.
|
||
|
||
"A signal" is read strictly, and that is the whole of the LRM rule that
|
||
matters here: a **parameter**, a **localparam**, a **genvar**, a **type**,
|
||
an **instance** or a **task/function argument** of the same name is *not* a
|
||
net or a variable, so `.*` does not bind it. This is a narrower set than
|
||
the one `add_port`/`propagate_ports` use when they *write* a connection
|
||
(`find::visible_in`, which happily writes `.p(p)` for a parameter, because
|
||
there the user asked for a connection and a parameter is a legal
|
||
expression). Here the question is not "what could be connected" but "what
|
||
*was* connected", and connecting an output port to a constant because a
|
||
`localparam` happened to share its name would be a legal-looking, silent,
|
||
wrong expansion. The two readers share one scope walk
|
||
(`find::kind_visible_in`) so they cannot come to disagree about *which*
|
||
declaration a name means, only about whether that kind counts.
|
||
4. A port with nothing to bind to is one the wildcard never bound either —
|
||
the compiler would have rejected the instantiation — so `.name()` plus the
|
||
warning is the honest answer, and saying it out loud is half the point of
|
||
the expansion. (It found two real ones in OpenTitan; see Acceptance.)
|
||
|
||
### Escaped identifiers
|
||
|
||
A port named `\my-port` is written `.\my-port (\my-port )`, with the space an
|
||
escaped identifier needs after it: an escaped identifier runs from its `\` to
|
||
the next **whitespace** and to nothing else (IEEE 1800 §5.6.1), so
|
||
`.\my-port(\my-port)` would be one enormous token swallowing the parens, the
|
||
comma and the rest of the line. `instantiate.rs` learned this from a QA
|
||
finding on the skeleton renderer; `ends_escaped` is now `pub(crate)` and the
|
||
expansion asks the same question rather than spelling the rule a second time.
|
||
Two behavior tests pin it, bound and unbound.
|
||
|
||
### Layout
|
||
|
||
The `.*` element is **replaced**, in place, by the generated connections. The
|
||
list's own layout is copied the way `append_to_list` copies it: the gap before
|
||
the wildcard (from the previous element, or from the list's `(`) decides
|
||
**one connection per line** — at the wildcard's own indentation — from
|
||
**inline**, `, `-separated. Refactored output is *edited source*, not
|
||
reformatted source (umbrella Handshakes); the user runs the formatter
|
||
afterwards if they want more, and the acceptance tests below prove the
|
||
formatter is happy with what is written.
|
||
|
||
### Comments
|
||
|
||
- A comment written **before** the `.*` is outside the replaced span and stays
|
||
exactly where it is, which puts it before the first generated connection.
|
||
- A comment written **after** it on the same line (`.* // and the rest`) gets
|
||
the `append_to_list` treatment, for the same reason: the comma is written
|
||
*before* the comment and the remaining connections after it, so the comment
|
||
stays with the **first** generated connection instead of drifting onto the
|
||
last, and no `,` is ever written inside a `//`.
|
||
- A comment written **inside** the element (`. /* here */ *`) is inside the
|
||
span the expansion replaces, so the verifier's comment rule refuses the
|
||
whole refactoring. Comments are never dropped (invariant 3), and lucisv will
|
||
not decide where that one should move.
|
||
|
||
## The refusal list — exact
|
||
|
||
`expand_wildcard` refuses when:
|
||
|
||
1. **The position is not an instantiation** — *"there is no module
|
||
instantiation at this position."*
|
||
2. **The statement declares several instances** — *"this statement declares 2
|
||
instances of `sub`; put the cursor on the one to expand."*
|
||
3. **The instance is a `bind` directive's** — *"`u_x` is instantiated by a
|
||
`bind` directive, where `.*` binds in the target's scope rather than in
|
||
this one; lucisv does not expand it there."* §23.3.2.4 resolves a bound
|
||
instance's wildcard in the *target's* scope, which lucisv would have to
|
||
elaborate a hierarchy to know. Out of scope for this round, and said so.
|
||
(This is the majority of real `.*` sites in OpenTitan — see Acceptance.)
|
||
4. **The list connects positionally** — *"`u_x` connects `sub`'s ports by
|
||
position; there is no `.*` to expand."*
|
||
5. **There is no `.*`** — *"`u_x` writes no `.*` to expand."*
|
||
6. **There is more than one** — *"`u_x` writes `.*` 2 times, which is illegal;
|
||
lucisv will not guess what it means."*
|
||
7. **Either file carries a parse diagnostic** — *"top.sv does not parse (… at
|
||
line N), so lucisv will not expand a `.*` in it."* Stricter than the
|
||
verifier's "no *new* diagnostic" rule on purpose: a connection list lucisv
|
||
misread is a list whose ports it would connect a second time, and a
|
||
duplicate connection is not a refactoring, it is corruption.
|
||
8. **The instantiated module's port list carries compiler directives** —
|
||
*"`sub`'s port list carries compiler directives, so which ports `.*` binds
|
||
depends on the configuration; lucisv does not preprocess, so it made no
|
||
edits."* Writing every arm's ports out produces a connection list no
|
||
configuration ever had. The same sentence guards the **connection list's**
|
||
own directives, where lucisv equally cannot tell which connections are
|
||
explicit in which arm.
|
||
9. **The module is unknown or declared twice** — `locate_module`'s two
|
||
existing sentences, unchanged.
|
||
10. **Nothing is left to bind** — *"`u_x` already connects every port `sub`
|
||
declares, so its `.*` binds nothing."* Not in the plan's list; derived
|
||
from `propagate_ports`'s refusal 16 (*"a 'did nothing' success is a worse
|
||
answer than a sentence"*). Deleting the `.*` instead would be a different
|
||
refactoring — a removal, with a removal's comma and comment problems —
|
||
and nobody asked for it.
|
||
11. **The file is outside the in-scope set**, and **verification fails**
|
||
(the five checks in `docs/features/refactor-ports/README.md`), the ports
|
||
engine's own rules unchanged.
|
||
|
||
Refusals 3–8 and 10 are pinned by a behavior test each; 1, 2, 4, 5, 6, 9 and
|
||
the outside-the-scope one too. Nothing is offered as a code action where the
|
||
refactoring would be refused, so the lightbulb never appears to explain itself.
|
||
|
||
## Assumptions
|
||
|
||
- **The `.*` is the only thing the edit touches.** Nothing outside the
|
||
cursor's own file is read for the edit itself (the module's declaration is
|
||
read, not edited), so `RefactorEdit` names one file. That is what makes the
|
||
lazy code action exact rather than optimistic: the offer's two files —
|
||
buffer plus declaration — are already everything the resolve will read.
|
||
- **A third offer costs a third attempt.** `port_actions` tries three
|
||
refactorings where it tried two, and each one builds its own `Scope` (the
|
||
index over the files it was handed) before it can refuse. So an offered
|
||
menu is now three index builds over that file set rather than two — but the
|
||
file set is the thing §37.1 already shrank: on the lazy path it is the
|
||
buffer plus one declaration, and the gate (`may_have_port_action`, one parse
|
||
of one file, no workspace, no I/O) still answers "nothing here" for almost
|
||
every cursor before any of the three runs. Nothing in this round re-reads
|
||
the fan-out that §37.1 took off the cursor path. A `Scope` shared by all
|
||
three attempts is the obvious next economy and is deliberately not taken
|
||
here: it changes the signatures of three shipped refactorings for a saving
|
||
only the eager path sees.
|
||
- **lucisv does not elaborate.** "Is a signal called `p` in scope here?" is a
|
||
lexical-scope question `vlog_semantic` answers. A name that would come from
|
||
a wildcard package import lucisv cannot resolve reads as *not in scope*, so
|
||
the port is written `.p()` — visibly, in the warning, never `.p(p)` on a
|
||
guess. This is the ports engine's standing assumption; the difference is
|
||
that here a wrong "not in scope" writes an unconnected port rather than a
|
||
`/* TODO */`, which is why the warning names every one of them.
|
||
- **lucisv does not preprocess**, so a port list or a connection list split
|
||
across `` `ifdef`` arms is refused rather than read straight through (the
|
||
refusals above). This is stricter than `add_port`, which warns and appends
|
||
outside every arm; appending one element is configuration-independent,
|
||
while enumerating a whole port set is not.
|
||
- **A module name is unique in scope**, and the index is the server's
|
||
authority on where it is declared — the ports engine's assumptions,
|
||
unchanged.
|
||
|
||
## Handshakes
|
||
|
||
**Consumed from `vlog_parser`** (no change required): `parse_source_tolerant`
|
||
and its `ParseDiagnostic` (refusal 7), `LineIndex`, `TextRange`, and
|
||
`ast::{Connection, Connections, Instance, Instantiation, Item, ListElem}` —
|
||
`Connection::name == "*"` is how the wildcard is recognized, and
|
||
`Connection::span` (the element's *code* extent, comments outside it) is what
|
||
makes the replacement exact. `Instance::conn_directives` is what makes refusal
|
||
8's second half possible.
|
||
|
||
**Consumed from `vlog_semantic`** (no change required, nothing patched):
|
||
`Semantics::{scopes, symbols, symbol}`, `Scope::{span, parent, lookup_local}`,
|
||
and `SymbolKind` — the kind is now *read* rather than only matched against a
|
||
fixed set (below).
|
||
|
||
**Changed inside `vlog_refactor`** — four edits to existing files, all of them
|
||
pure factorings with no behavior change:
|
||
|
||
- `ports/find.rs`: `collect_instantiations` is now a wrapper over
|
||
`walk_instantiations`, which reports of each instantiation whether it is a
|
||
`bind` directive's own. Same walk, same order, one extra bit; every existing
|
||
caller ignores the bit.
|
||
- `ports/find.rs`: `visible_in`'s scope walk moved into `kind_visible_in`,
|
||
which returns the `SymbolKind` it found; `visible_in` is that function plus
|
||
the kind set it always had, so `add_port`, `propagate_ports` and
|
||
`instantiate.rs` answer byte-for-byte as before.
|
||
- `ports/mod.rs`: `expand_wildcard`, `expansion` (the edit plus its connection
|
||
count) and the third `port_actions` offer; plus `is_sites_phrase` beside
|
||
`sites_phrase`.
|
||
- `instantiate.rs`: `ends_escaped` is `pub(crate)` instead of private. One
|
||
word; no call site changed.
|
||
|
||
**Promised to `lucisv_server`**: everything the other port refactorings
|
||
promise. `expand_wildcard` does not panic, returns no partial edit, sorts and
|
||
de-overlaps its edits, and its warnings are informational.
|
||
`PortAction.title` is user-facing text the server does not rewrite — with one
|
||
new obligation, which is why `is_sites_phrase` exists: the server *does*
|
||
rewrite the count in an offered title from its index, and the expansion's
|
||
count is not an instantiation census. The server now asks before recounting.
|
||
|
||
**Changed in `lucisv_server`** (protocol layer only): `EXPAND_WILDCARD`
|
||
(`lucisv.expandWildcard`) added to `ports::commands()` and to
|
||
`ports::execute`; `ports::counted` gated on `vlog_refactor::is_sites_phrase`.
|
||
The dispatch arm, the capability advertisement and the code-action path needed
|
||
no change — commands are advertised from `commands()` and every
|
||
`workspace/executeCommand` already routes through `ports::execute`. **The VS
|
||
Code extension needed nothing**: `editors/vscode/package.json` contributes only
|
||
its own webview commands, and server commands are discovered over LSP.
|
||
|
||
**Requested of nobody.** No change was needed in `vlog_parser`,
|
||
`vlog_semantic`, `vlog_formatter` or `lucisv_core`.
|
||
|
||
**One new dev-dependency**: `vlog_formatter` on `vlog_refactor`, **tests
|
||
only**, the arrangement `vlog_linter` already uses and with the same
|
||
justification written into `Cargo.toml`: the acceptance tests assert that what
|
||
the expansion writes is something the formatter accepts and leaves alone the
|
||
second time, and that cross-tool guarantee cannot be asserted from either
|
||
crate alone. The library still depends on `vlog_parser` + `vlog_semantic`
|
||
alone (`cargo tree -p vlog_refactor -e normal`), and no cycle is possible:
|
||
`vlog_formatter` depends on `vlog_parser` and nothing else.
|
||
|
||
## The LSP surface
|
||
|
||
| Surface | What it says |
|
||
|---|---|
|
||
| Code action, kind `refactor.rewrite.lucisv.ports` | *"lucisv: expand .* (3 connections)"* — offered at a `.*` under the cursor, lazily (`offers` → `resolve`, §37.1) or eagerly (`code_actions`), whichever the client supports. |
|
||
| `lucisv.expandWildcard [uri, Position]` | The same edit for a client with no lightbulb — a Vim user's keybinding. |
|
||
|
||
The count is the connections the wildcard becomes, and it is exact in the
|
||
offer already: the offer's file set (buffer + declaring file) is everything
|
||
the expansion reads. It is written `1 connection` for one, which is why the
|
||
plan's *"(N connections)"* is a shape rather than a literal.
|
||
|
||
## Status / TODO
|
||
|
||
- [x] 50.1 `expand_wildcard` engine (`ports/expand.rs`, 308 lines, 233 of
|
||
them code) + every refusal above
|
||
- [x] 50.1 the LRM kind rule, sharing one scope walk with `visible_in`
|
||
- [x] 50.1 layout (multi-line vs inline) and the three comment positions
|
||
- [x] 50.2 code action through the lazy offer path, with `is_sites_phrase`
|
||
keeping the index from recounting its title — pinned at the level that
|
||
matters rather than as a predicate unit test: the server test
|
||
`the_wildcard_action_is_offered_lazily_and_resolves_to_the_eager_edit`
|
||
asserts the offered title is `lucisv: expand .* (1 connection)` in a
|
||
workspace whose instantiation census would have said something else,
|
||
and the e2e session asserts the same string over the wire
|
||
- [x] 50.2 `lucisv.expandWildcard` in `commands()` / `execute`
|
||
- [x] 50.1 escaped identifiers terminated on both sides of the parens
|
||
- [x] Tests: 32 behavior tests in `vlog_refactor/tests/expand.rs`, 1 corpus
|
||
acceptance test in `tests/corpus.rs`, 3 in `lucisv_server`'s `ports.rs`,
|
||
1 e2e session over the wire
|
||
- [x] Gates: `cargo fmt` per crate, clippy `--all-targets` clean, the
|
||
workspace suite, the corpus gate, byte-identity vs 0.45.0, the VS Code
|
||
smoke test
|
||
- [x] OpenTitan read-only census and ten scratch expansions
|
||
- [ ] Deferred, deliberately: a `.*` inside a `bind` directive (refusal 3) —
|
||
it needs the target's scope, which is elaboration, not lexical lookup.
|
||
It is the *majority* of real wildcard sites in OpenTitan, so it is worth
|
||
a backlog line of its own.
|
||
- [ ] Deferred: the inverse refactoring (named connections → `.*`), which is
|
||
§8's list, not this round's.
|
||
|
||
## Docs to apply at merge (lead)
|
||
|
||
`README.md`, `docs/topo.md`, `docs/repository-analysis.md` and `docs/site/`
|
||
are the lead's; the text for them is here rather than edited in place.
|
||
|
||
**`README.md` — the refactoring list** gains a row beside
|
||
"connect missing ports":
|
||
|
||
> | **expand `.*`** | Writes a wildcard connection out as the named
|
||
> connections it stands for, in the module's declaration order — a port with
|
||
> no same-named signal in scope becomes `.p()` and is named in a warning.
|
||
> Code action at the `.*`, or `lucisv.expandWildcard`. |
|
||
|
||
**`docs/site/` (editors / language-tools page)** — the same sentence in the
|
||
code-action list: *"expand `.*` — the wildcard connection written out as the
|
||
`.p(p)` connections it stands for, so the port list can then diverge from the
|
||
wrapper around it."*
|
||
|
||
**TODO.md §8** (the refactoring backlog): the `.*`-expansion line gains
|
||
*"— shipped in 0.46.0, `docs/features/expand-wildcard/README.md`"*, and the
|
||
list gains a new backlog entry: *"expand a `.*` written in a `bind` directive
|
||
(needs the target's scope — elaboration, not lexical lookup)."*
|
||
|
||
**`docs/topo.md`**: one new edge to record — `vlog_refactor ──▶
|
||
vlog_formatter` **(dev-dependency, tests only)**, the same shape §2's
|
||
`vlog_linter ──▶ vlog_formatter` dev edge already has. No production edge
|
||
changed.
|
||
|
||
## Work log
|
||
|
||
**2026-09-05 — dev agent.** Built `ports/expand.rs`, the third `port_actions`
|
||
offer, and the fourth command. The decisions worth recording:
|
||
|
||
- **A replacement, not an append plus a deletion.** `propagate_ports` was the
|
||
obvious template, and it appends — but the `.*` has to *go*, and the
|
||
cleanest expression of that is one `TextEdit` whose range is the element's
|
||
own span. `check::pieces_match` already handles a replacement exactly (it
|
||
skips old pieces overlapping a non-empty edit range and splices the edit's
|
||
own pieces in at its start); `Shift::map` already handles the length change
|
||
(`a_longer_replacement_shifts_forward` was written for it in M2). So the
|
||
verifier needed nothing new, which is the outcome hard invariant 4 wants:
|
||
no widening of anybody's forgiveness, no new attack surface to test.
|
||
- **The comment rule fell out.** Because the edit's range is the element's
|
||
*code* span, a comment before or after the `.*` is not inside it and is
|
||
simply not touched; a comment *inside* it is, and the splice verifier's
|
||
comment rule refuses the whole thing. Two of the three comment cases are
|
||
therefore properties of the span choice rather than code, and the third is
|
||
a refusal rather than a guess. The one piece of code is the
|
||
comma-before-the-line-comment split, lifted verbatim from
|
||
`append_to_list`'s reasoning.
|
||
- **Parameters are the crux, and they get their own kind reader.** The LRM
|
||
binds `.*` to a net or a variable. `find::visible_in` — the "may lucisv
|
||
write `.p(p)` here" test the other two refactorings use — says yes to
|
||
parameters, localparams, genvars and task arguments as well, and that is
|
||
right *for them*: the user asked for a connection and a parameter is a legal
|
||
expression. It is wrong here, where the question is what the wildcard
|
||
already bound. Rather than adding a flag to `visible_in`, the scope walk was
|
||
factored into `kind_visible_in` (which returns the kind) and each caller
|
||
states its own set. Both readers therefore agree about which declaration a
|
||
name means — the thing that must never diverge — and disagree only where
|
||
they should.
|
||
- **Two refusals stricter than `add_port`'s.** A file with a parse diagnostic,
|
||
and a list carrying compiler directives, are *warnings* or read-throughs
|
||
elsewhere in the ports engine. Here they are refusals, because this
|
||
refactoring enumerates a whole port set rather than appending one element:
|
||
a misread list connects a port twice, and an `` `ifdef``-split port list
|
||
expands into a connection list no configuration ever had. Both are cheap to
|
||
detect and impossible for the verifier to catch (the result parses, resolves
|
||
and matches its shape — it is simply not what the source meant).
|
||
- **`is_sites_phrase` was the one real surprise.** `ports::counted` in the
|
||
server rewrites *any* offered title ending in `(…)` with the index's
|
||
instantiation count, which would have turned "expand .* (3 connections)"
|
||
into "expand .* (updates 5 instantiations)" — a wrong sentence produced by
|
||
a function that had never been wrong before, because until now every title
|
||
with a count carried the same count. The predicate lives next to
|
||
`sites_phrase` in the engine so the phrase has one spelling and one reader.
|
||
- **The bind refusal is not a corner case.** 24 of the 31 `.*` sites under
|
||
OpenTitan's `hw/ip` are inside a `bind` directive. Refusing them is correct
|
||
(§23.3.2.4 resolves those in the target's scope), and it is the reason the
|
||
acceptance sample had to be drawn from a wider tree than `hw/ip` to reach
|
||
ten — recorded in Acceptance and as a backlog line above.
|
||
|
||
Checks at the end are in Acceptance and in the gate list. No
|
||
`unwrap`/`expect`/`panic!` and no `unsafe` in any library path (test modules
|
||
only); `expand.rs` is 308 lines with no function over 45, and every file it
|
||
touches stayed inside the size rule — `ports/mod.rs` 433, `ports/find.rs` 283,
|
||
`lucisv_server/src/ports.rs` 1 430 of which 981 are its `#[cfg(test)]` module.
|
||
|
||
## Gates
|
||
|
||
All guarded (`tools/guard.sh`, 8 GB / 30 min defaults); no guard kill.
|
||
|
||
- **fmt**: `cargo fmt -p vlog_refactor`, `cargo fmt -p lucisv_server`;
|
||
`cargo fmt --all -- --check` clean.
|
||
- **clippy**: `cargo clippy --all-targets`, **0 warnings**, and no new
|
||
`#[allow]` anywhere in the diff.
|
||
- **suite**: `cargo test --workspace` — **3 876 passed, 0 failed, 44 ignored**
|
||
across 50 test binaries (baseline 3 839, +37: 32 behavior, 1 corpus, 3
|
||
server unit, 1 e2e).
|
||
- **corpus gate**: `tools/corpus_check.sh` — **814/820 (99.3%)**, the same six
|
||
known parse errors (`ibex` compare_helper / riscv_core_setting.tpl /
|
||
latch_map.v / riscv_instr_cover_group, `picorv32` romload testbench /
|
||
smtbmc mulcmp), **0 verification errors, 0 crashes**.
|
||
- **formatter byte-identity**: `lucisv format --stdout` over all corpus files,
|
||
this build vs `~/.cache/lucisv-baselines/lucisv-0.45.0` — **854 checked, 0
|
||
differing**, 6 refused by both. `git diff` over `vlog_formatter`,
|
||
`vlog_parser` and `verify.rs` is empty; this round touched neither.
|
||
- **vsix smoke**: `node editors/vscode/smoke.js target/release/lucisv-server`
|
||
— OK, 20 messages.
|
||
- **opentitan after the round**: `git -C ~/repo/opentitan status --porcelain`
|
||
shows only the three pre-existing modifications. Every run over it was
|
||
read-only, and every edited copy went to the session scratchpad.
|
||
|
||
## Acceptance
|
||
|
||
### The corpus
|
||
|
||
`cargo test -p vlog_refactor --test corpus` gained
|
||
`a_wildcard_expanded_in_the_corpus_is_something_the_formatter_accepts`: the
|
||
first three corpus files with a `.*` are expanded into an in-memory copy and
|
||
the copy must format, and formatting it twice must not move it. It expands
|
||
`common_cells`' `cdc_2phase_clearable_tb.sv`, `cdc_2phase_synth.sv` and
|
||
`cdc_2phase_tb.sv` (~2.4 s each in debug, the index build over 860 files) and
|
||
refuses the three `formal/*_properties.sv` sites — every one of them a `bind`.
|
||
|
||
### OpenTitan (read-only)
|
||
|
||
Counted with the plan's grep and with the engine's own scan, which also sees a
|
||
`.*` whose `,`/`)` is on the next line:
|
||
|
||
| Tree | Files | `.*` sites | Expanded | Refused |
|
||
|---|---|---|---|---|
|
||
| `hw/ip` | 1 807 | **31** (29 by line-based grep) | 7 | 24, every one a `bind` |
|
||
| `hw` (all of OpenTitan's Verilog) | 3 979 | **66** | **9** | 57: **50** `bind`, **6** `pinmux` declared in three tops, **1** `ibex_top`'s `` `ifdef``-split port list |
|
||
|
||
**Deviation from the plan, stated plainly: ten expandable sites do not
|
||
exist.** The plan asked for ten scratch expansions; OpenTitan holds nine.
|
||
Every `.sv`/`.svh`/`.v` file in the repository is under `hw/` (checked), and
|
||
of its 66 wildcard sites, 57 are refused — 50 of them by the `bind` rule,
|
||
which is correct and is the backlog line above. So the sample is **all nine**
|
||
of them rather than a chosen ten, plus the three corpus expansions in the test
|
||
suite: twelve real-world expansions, all verified the same way. Each of the
|
||
seven refusal categories that fired did so for a reason on the list, including
|
||
two the synthetic tests could only fake: `pinmux` really is declared three
|
||
times in OpenTitan (one per top), and `ibex_top`'s port list really is split
|
||
across `` `ifdef`` arms.
|
||
|
||
Every expansion was written to a **copy** under the session scratchpad;
|
||
nothing was written into `/Users/guoliangchen/repo/opentitan`, and
|
||
`git -C … status --porcelain` shows the same three pre-existing modifications
|
||
before and after (`hw/ip/aes/dv/tb/tb.sv`,
|
||
`hw/top_darjeeling/ip/ast/rtl/ast.sv`, `hw/top_earlgrey/ip/ast/rtl/ast.sv`).
|
||
|
||
Each of the nine: the copy parses with **zero** diagnostics, formats, formats
|
||
again to the same bytes, and holds the **same instance count** as the
|
||
original. Two of them carry a warning, and both are real findings rather than
|
||
lucisv guessing:
|
||
|
||
- `kmac/fpv/tb/sha3_fpv.sv` — `u_sha3`'s `.*` covers nine ports of `sha3`
|
||
(`rand_update_o`, `squeezing_o`, `block_processed_o`, `run_req_o`,
|
||
`run_ack_i`, `lc_escalate_en_i`, `sparse_fsm_error_o`, `count_error_o`,
|
||
`keccak_storage_rst_error_o`) that the FPV wrapper's own header does not
|
||
declare. The wrapper has drifted behind the module it wraps; the wildcard
|
||
was hiding it, and the expansion says so.
|
||
- `kmac/fpv/tb/sha3pad_fpv.sv` — the same story for `u_keccak`, five ports.
|
||
|
||
The five `aes/dv/err_injection_if/fi_*_wrapper.sv` expansions are the
|
||
textbook case: `fi_core_if fi_if (.*)` becomes
|
||
`fi_core_if fi_if (.clk_i(clk_i), .rst_ni(rst_ni), .aes_ctrl_cs(aes_ctrl_cs))`.
|
||
The last two are `vendor/lowrisc_ibex`'s icache agent interfaces.
|
||
|
||
Reproduced by a throwaway probe binary in the session scratchpad
|
||
(`otprobe`), which depends on `vlog_refactor` + `vlog_formatter` +
|
||
`vlog_parser` by path, walks a tree read-only, and writes every edited copy
|
||
into the scratchpad. Nothing of it is checked in.
|
||
|
||
## QA log
|
||
|
||
**2026-09-05 — QA agent.** Attacked the engine directly
|
||
(`vlog_refactor::expand_wildcard`, temporary `#[test]`s added and removed —
|
||
`tests/zz_qa_expand_attack.rs`, `tests/zz_qa_corpus_sweep.rs`, never
|
||
committed) plus the shipped suites, the two full-workspace gates, a
|
||
full-`hw/` opentitan census (not just the plan's ten), and a diff of every
|
||
opentitan scratch expansion against its original. Verdict: **PASS**.
|
||
|
||
### LRM-rule matrix (18 scratch tests, all against a fresh build)
|
||
|
||
| # | Case | Result |
|
||
|---|---|---|
|
||
| enclosing module's own port | binds (`.clk(clk)`) | as specified |
|
||
| typedef of the same name | not bound, `.done()` + warning | as specified |
|
||
| instance name of the same name | not bound, `.done()` + warning | as specified |
|
||
| instantiation lexically inside a function body | no panic (refusal or edit, either is fine — the plan only asks for no crash) | no crash |
|
||
| sibling generate block's declaration | not visible, `.done()` + warning | as specified |
|
||
| declared *after* the instantiation, module scope | still visible and bound | as specified — declaration order does not matter |
|
||
| `import pkg::*` bringing a same-named package variable into scope | **not bound** — `.name()` + warning, exactly as an unrelated name would be | matches the README's stated assumption, see below |
|
||
| port name shared by both the instantiated and enclosing module | binds (the common case) | as specified |
|
||
| width/type mismatch (`input logic [7:0] clk` vs a 1-bit `clk` in scope) | still binds by name, no warning | as specified — lucisv cannot check types, README says so |
|
||
| interface port (`bus_if.master b`, interface instance `bus_if b()` of the same name) | **not bound** — `.b()` + warning | see finding QA-1 below |
|
||
| escaped port name `\my-port` | bound and terminated on both sides of the parens (`.\my-port (\my-port )`), and unbound the same way | dev's own tests, re-verified |
|
||
| port with an unpacked dimension (`input logic [7:0] data [4]`) | binds (`.data(data)`) | as specified |
|
||
|
||
None of the eighteen attack tests found a mis-binding (an output silently
|
||
tied to a parameter, a genvar, a typedef, an instance, or anything else the
|
||
LRM does not call a signal) or a crash. Two are worth recording explicitly:
|
||
|
||
- **The package-import choice, pinned.** A name reaching the instantiating
|
||
scope only through `import pkg::*;` is read as **not in scope**: `.*`
|
||
writes `.name()` and warns, exactly as if the name did not exist anywhere.
|
||
Traced to source: `kind_visible_in`
|
||
(`crates/vlog_refactor/src/ports/find.rs:214-253`) walks
|
||
`Scope::lookup_local` up the `parent` chain only, and never reads
|
||
`Scope.imports` — the second, separate lookup
|
||
`vlog_semantic::resolve::{lexical, unit}` perform to make a wildcard
|
||
import's names resolvable for *reference* resolution
|
||
(`crates/vlog_semantic/src/resolve.rs:607-684`). So `vlog_semantic`'s own
|
||
full resolver *can* see a wildcard-imported name; `kind_visible_in`
|
||
deliberately (per the README's Assumptions section) does not re-implement
|
||
that half of it. This matches the feature's stated assumption
|
||
word-for-word ("a name that would come from a wildcard package import
|
||
lucisv cannot resolve reads as *not in scope*") — **not a defect**, a
|
||
documented, safe-by-construction limitation: it under-expands (leaves a
|
||
port unconnected and says so) rather than mis-expands. Filing it here
|
||
because the plan asked to "pin it and report the choice."
|
||
- **QA-1 (LOW, pre-existing, not introduced by this round): interface
|
||
instances are never a `.*` target.** `bus_if b(); sub u_sub(.*)` where
|
||
`sub` declares `bus_if.master b` leaves `.b()` unconnected with a warning,
|
||
even though the interface instance `b` is exactly the identifier IEEE 1800
|
||
§23.3.2.4 means to bind an interface port to. Root cause: an interface
|
||
instantiation gets `SymbolKind::Instance`
|
||
(`crates/vlog_semantic/src/bind/item.rs:306`, the same kind a module
|
||
instantiation gets — interfaces are modeled as `Module`s with a different
|
||
keyword), and `signal_visible`'s allowed set
|
||
(`crates/vlog_refactor/src/ports/expand.rs:266-270`) is `Net | Var | Port`
|
||
only. This is not new: `find::visible_in`, which `add_port` and
|
||
`propagate_ports` already share, excludes `Instance` from its own allowed
|
||
set too (`crates/vlog_refactor/src/ports/find.rs:203-217`), so no port
|
||
refactoring in the engine today treats an interface instance as a
|
||
connectable signal by name. Nothing in this round narrowed that — it is
|
||
inherited, and it fails safe (unconnected + warned, never mis-bound) — but
|
||
it means every interface-port wildcard site in a design is likely to
|
||
surface a spurious warning rather than a clean bind. Worth a backlog line
|
||
for the ports engine generally, not a blocker for §50.
|
||
|
||
### Text/layout and refusals
|
||
|
||
Re-verified against source and by test: trailing-comma legality (no result
|
||
ever ends `,)` or has a dangling comma before a line comment), idempotency
|
||
(expanding the result a second time refuses with the exact "writes no `.*`
|
||
to expand" sentence; formatting twice converges; re-expanding the *formatted*
|
||
result also correctly refuses), comment-count preservation, `#(...)`
|
||
parameterized instantiations, and a cursor placed inside one instance of a
|
||
two-instance statement (`sub u_a (.*), u_b (.*);`) expanding only that
|
||
instance rather than tripping the "declares 2 instances" refusal — confirmed
|
||
this refusal fires only when the cursor is on the shared module name/keyword,
|
||
matching `propagate_ports`'s documented rule. All eleven refusal sentences
|
||
in the README's list were exercised (by the dev's own 32-test suite, which
|
||
this session re-ran clean) and match character-for-character.
|
||
|
||
**Server, cursor away from the `.*`:** a cursor placed on `.clk(clk)` inside
|
||
the *same* instantiation as a `.*` still offers `lucisv: expand .* (2
|
||
connections)` — the cursor rule is instance-level (any offset inside the
|
||
instance's span), not token-level, matching `propagate_ports`'s and
|
||
`remove_port`'s own precedent. This is not a bug: the plan's "only the port
|
||
actions that apply" is satisfied — every offered action is one that would
|
||
actually succeed at that instance, and none is limited to the exact `.*`
|
||
token by design elsewhere in the engine either.
|
||
|
||
### Corpus (full sweep, not a sample)
|
||
|
||
Independently re-implemented the dev's own `.*` census (a `.*` followed by
|
||
`,`/`)`, matching the engine's own scan rather than a naïve line grep) and
|
||
ran it over every corpus file, not just the first three the dev's acceptance
|
||
test samples: **21 sites, 11 expanded, 10 refused** — 6 `bind` directives, 2
|
||
"declared in more than one indexed file" (`formal_tb`, genuinely declared
|
||
twice under `corpus/ibex/formal/`), 1 compiler-directives-in-the-port-list
|
||
(`ibex_top`), 1 "no module instantiation at this position" (a `.*` mentioned
|
||
inside a *comment* in `formal_tb_frag.svh`, correctly refused rather than
|
||
corrupting anything). Every one of the 11 expansions: same instance count
|
||
before/after, zero parse diagnostics afterward, formats, and converges on a
|
||
second format. No panics anywhere in the sweep (38.7 s under
|
||
`tools/guard.sh`, no kill).
|
||
|
||
### OpenTitan (read-only, full `hw/`, not a ten-site sample)
|
||
|
||
Reproduced independently with a throwaway probe (`otqa`, path-dependent on
|
||
`vlog_refactor`/`vlog_formatter`/`vlog_parser`, built and run under
|
||
`tools/guard.sh -m 8 -t 600`, nothing checked in): **66 sites, 9 expanded, 57
|
||
refused (50 bind, 6 declared-twice/pinmux, 1 compiler-directives/`ibex_top`)
|
||
— exactly the dev's table.** `git -C ~/repo/opentitan status --porcelain`
|
||
showed only the three pre-existing modifications both before and after.
|
||
|
||
Diffed each of the nine scratch expansions against its opentitan original:
|
||
**every diff touches only the `.*` element** — one line replaced for the
|
||
seven simple sites (the five `fi_*_wrapper.sv` interfaces plus the two
|
||
`ibex_icache_*_if.sv` checkers), a multi-line replacement confined to the
|
||
`u_sha3`/`u_keccak` instantiation block for the two FPV files. Nothing else
|
||
in any of the nine files changed.
|
||
|
||
Verified the two FPV warnings are real, not lucisv guessing: grepped
|
||
`hw/ip/kmac/rtl/sha3.sv`'s port list and confirmed all nine names in
|
||
`sha3_fpv.sv`'s warning (`rand_update_o`, `squeezing_o`, `block_processed_o`,
|
||
`run_req_o`, `run_ack_i`, `lc_escalate_en_i`, `sparse_fsm_error_o`,
|
||
`count_error_o`, `keccak_storage_rst_error_o`) are genuine output/input ports
|
||
of `sha3` absent from `sha3_fpv`'s own header; same check against
|
||
`hw/ip/kmac/rtl/keccak_round.sv` for `sha3pad_fpv.sv`'s five
|
||
(`rand_update_o`, `lc_escalate_en_i`, `sparse_fsm_error_o`,
|
||
`round_count_error_o`, `rst_storage_error_o`). Both wrappers have genuinely
|
||
drifted behind the modules they wrap.
|
||
|
||
### Gates (guarded, re-run independently)
|
||
|
||
- `cargo clippy -p vlog_refactor -p lucisv_server --all-targets` — **0
|
||
warnings**; `cargo clippy --all-targets` over the whole workspace also
|
||
clean.
|
||
- `cargo fmt -p vlog_refactor -p lucisv_server -- --check` and
|
||
`cargo fmt --all -- --check` — clean.
|
||
- `tools/guard.sh -t 1800 -- cargo test --workspace` — **3 876 passed, 0
|
||
failed, 44 ignored**, 50 test binaries — matches the dev's number exactly.
|
||
No guard kill.
|
||
- `tools/guard.sh -t 900 -- tools/corpus_check.sh` — **814/820 (99.3%)
|
||
parsed & formattable, 0 verification errors, 0 crashes**, same six known
|
||
parse errors — matches exactly.
|
||
- Byte-identity: `lucisv format --stdout` over every corpus file, this build
|
||
vs `~/.cache/lucisv-baselines/lucisv-0.45.0` — **860 total, 854 checked
|
||
identical, 0 differing, 6 refused by both** — matches exactly.
|
||
- `node editors/vscode/smoke.js target/release/lucisv-server` — OK, 20
|
||
messages.
|
||
|
||
### Findings
|
||
|
||
- **QA-1 (LOW, informational, not a blocker):** interface instances are
|
||
never bound by `.*` (nor writable by `add_port`/`propagate_ports`) because
|
||
`SymbolKind::Instance` is outside every port refactoring's allowed-kind
|
||
set. Pre-existing across the ports engine, not introduced by §50; fails
|
||
safe (unconnected + warned). Suggest a backlog line for the ports engine
|
||
generally: "an interface instance of the same name as an interface port
|
||
should bind, per IEEE 1800 §23.3.2.4."
|
||
- **Package-import scope choice — verified as documented, not a defect.**
|
||
See the matrix above; matches the README's Assumptions section exactly.
|
||
- No corruption, no dropped comments, no panics, no idempotency break, no
|
||
byte-identity regression found in any of the above. All temporary test
|
||
files and scratch copies were removed after verification; the repository
|
||
tree touched by this QA pass is unchanged apart from this log entry and
|
||
the §50 QA checkbox in `TODO.md`.
|
||
|
||
**Verdict: PASS.**
|
||
|
||
## Review
|
||
|
||
**2026-09-05 — lead.** Accepted; ships in 0.46.0 with §51. The engine is
|
||
one replacement edit through the ports engine's existing splice and
|
||
verifier, which is exactly the shape a lexical refactoring should have,
|
||
and the LRM rule is read strictly — a parameter or genvar of the same name
|
||
does not bind, which is what the compiler would say. The refusal list is
|
||
complete and each refusal is a sentence. The dev found and fixed a real
|
||
title-rewrite bug in the lazy offer path on the way (`counted` rewrote
|
||
any parenthesised title). Ten expandable opentitan sites do not exist —
|
||
57 of the 66 `.*` sites are inside `bind` directives, which need the
|
||
target's scope and are filed as a backlog entry — so the nine that do
|
||
exist were all expanded and verified, and two of them surfaced real
|
||
drift between an FPV wrapper and the module it wraps. The vlog_formatter
|
||
dev-dependency mirrors the linter's and is recorded in topo.
|
||
|
||
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|