Files
lucisv/docs/features/constraint-bodies/README.md
T
lucioandClaude Fable 5 a0c290ccc2
ci / checks (push) Successful in 57s
ci / corpus (push) Successful in 26s
release / build-and-publish (push) Successful in 5m49s
Comment slots in shared machinery: an owner for every gap, four fuzzers at zero, and the small-correctness residue
TODO section 25; closes docs/topo.md 2.9-20, 2.9-21, 2.9-22; opens 2.9-23.
A comment written where no AST node had a field was never deleted: bump
queued it and take_meta handed it to the next node, so it printed one
node later and verify.rs refused the whole file. About seventy named
comment fields now own those gaps - SegmentComments on member/scope/
index/range segments (one parse_postfix_segment replacing three
hand-copied loops), one [a:b] grammar, BinaryComments on inside, casts,
unary/postfix, if/case/for/foreach/do-while headers, @ and # timing,
Stmt::before_semi with StmtKind::takes_semi() as the single owner of
the ; (debug_assert enforced), labels on ten nodes, qualifier runs as
Vec<Qualifier>, function/task/module/package/class/typedef/enum/struct
headers, declarators, ports, connections, instantiations. Each prints
through Fmt::slot_comments, a no-op when empty: 860 corpus and 3 975
opentitan files are byte-identical to v0.30.0 (QA reproduced from an
independent baseline build). Four exhaustive gap fuzzers at zero -
covergroup 329, fragment 153, constraint 395 (committed at last), RTL
352 (new) - are the regression gate. verify.rs untouched, ten attack
pairs. Expression slots are boxed so Expr stays 96 bytes; ast::size_pins
asserts it (QA's one finding).

Also: nav::definition gains the macro branch hover already had (H5);
a cast's type binds as a type via bind_type_expr, FACTS_FORMAT 13 -> 14
(M11); rename reports the candidate references that stayed unresolved
through the overlay, one line per file and unit (2.9-20); the scoped
name join keeps an escaped segment's terminator (2.9-21). One flagged
edit outside scope: a .. in vlog_linter/src/signals.rs patterns.

docs/features/comment-slots/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-09-02 11:32:16 -07:00

1039 lines
58 KiB
Markdown

# constraint bodies
## Goal
Give `constraint c { ... }`, `constraint C::c { ... }` and
`randomize() with { ... }` a real AST, so that the formatter, the binder,
the linter, rename, hover and go-to-definition can all see inside them.
Until v0.26.0 a constraint was an `ItemKind::Verbatim(RawText)` leaf: the
parsed name was *discarded* (`parser.rs:1895`), nothing inside bound, and a
rename of a `rand` property left `constraint c { user_id < 5; }` untouched
with at best a generic "cannot attribute" warning — `docs/coverage_gaps.md`
C1, the largest remaining semantic hole in DV code. This is round 1;
covergroups stay verbatim and are round 2.
## Assumptions
- **The constraint sub-grammar is modelled where real code writes it, and
nowhere else.** Everything the parser does not recognise rewinds to the
pre-round verbatim capture. That is a design choice, not a shortfall: half
of a real DV constraint body is written through macros lucisv does not
expand, and a grammar that must be complete to be safe would be neither.
The fallback is measured, not assumed — `SourceFile::constraint_fallbacks`
counts it, and the sweep numbers are in the work log.
- **`soft`, `dist`, `solve` and `before` are matched by text, not reserved.**
IEEE 1800 reserves all four, but lucisv is a formatter that must not stop
parsing a file because somebody named a signal `before`. See the work log
for the full argument; the precedent is `restrict`, matched by text in
`at_concurrent_assertion` since the assertions round.
- **`:=` and `:/` are two tokens each.** The lexer's operator table is
deliberately not extended: a `:/` entry would swallow the `/*` of
`cond ? a :/* why */ b`. `Parser::dist_weight_op` demands the two tokens be
adjacent by span, so `0 : / 5` is not a weight and the body falls back.
- **A named constraint is a block and is always laid out as one.** The
`classes` README's "no layout convention worth inventing" is superseded:
there was nothing to lay out while the body was opaque bytes. A
`randomize() with` block is the exception — it is written inside a
statement, so it keeps the source's own one-line-or-not shape.
- **`a <-> b -> c` is re-associated.** `parse_implication` reads `<->` and
`->` as one right-associative level; the constraint item parser reads
`<->` left-associatively and then the constraint `->`. The token stream is
identical either way and lucisv evaluates neither, so nothing downstream
can tell — recorded because it is a difference, not because it bites.
- **A `constraint` is accepted wherever it was before**, module scope
included. No new legal-position check; `out-of-class-constraints` already
made and justified that call.
## Handshakes
**Consumed, unchanged:**
- `classes` — `verbatim_since` / `skip_balanced` / `RawText` and the
`RawText.col` re-indent contract, now reached only through the fallback.
The fallback re-runs the *old function body verbatim*
(`Parser::parse_constraint_verbatim`), so a body the grammar does not know
produces byte-identical output to v0.26.0, and the parser test
`an_unrecognised_constraint_body_rewinds_to_exactly_the_old_capture` pins
the text, the span and the `col`.
- `out-of-class-constraints` — `parse_method_name`. Both halves of the
`C::name` split are now *kept* rather than discarded; the function's own
contract is untouched.
- `class-member-access` — the stand-in class scope for out-of-body
definitions. Factored out of `bind_out_of_body` into
`Binder::out_of_body_home` and reused verbatim for `constraint C::c`. Its
`member_of` chase is also what the new `Target::InlineConstraint` runs
first for a `randomize() with` block's names.
- `escaped-identifiers` — every name this round prints goes through
`format::name_doc` / `named`.
- `dv-statements` — `randomize() with` is still one `ExprKind::WithConstraint`
reached from the same postfix-`with` branch; only its payload changed type.
**Promised to others:**
- **`ItemKind::Constraint(ConstraintDecl)` is a new `ast.rs` variant.** Per
`topo.md` §3.3 it costs a `format.rs` arm (delivered), a `bind.rs` arm
(delivered), a `spans.rs` arm (delivered) and a `visit.rs` arm — the last
one is written and does nothing, deliberately: a constraint body holds
constraint items, not `Item`s or `Stmt`s, so there is nothing for an item
or statement walk to descend into. Rules that need to see inside read the
reference table. `ExprKind::Dist` is a second new variant with the same
four arms.
- **`FACTS_FORMAT` 10 → 11.** `SymbolKind::Constraint` is a new kind, so a
store written by an older build is not read.
- **`ScopeKind::Constraint` and `Target::InlineConstraint` are new**
(`vlog_semantic`). Neither costs an arm anywhere: nothing outside
`model.rs` matches `ScopeKind` exhaustively, and `Target` is matched only
in `resolve.rs`.
- **`undriven-net` changes verdict**: a net read only inside a
`randomize() with` block used to have zero reads and be skipped; it now
has a real one and is reported. Pinned in
`crates/vlog_linter/tests/cases/constraints.lint`. `unused-signal` does
*not* change — its mention guard already shielded those names.
- **`SourceFile` gains `constraint_fallbacks: u32`** — a parse statistic,
documented as diagnostic-only, that nothing in the tree depends on. It is
what makes "how much of the real world still falls back" answerable in a
test rather than by eye.
- **`signals.rs` no longer routes constraints to `opaque_spans`.** A
constraint reads its operands and drives nothing; those reads are ordinary
resolved references now, and `Scanner::finish` counts them. A body that
fell back is still an `ItemKind::Verbatim` and keeps the opaque posture.
**Requests filed, not acted on:**
1. **`vlog_refactor` refuses a rename issued from *inside* an out-of-block
constraint body when the class lives in another file** — "``user_id`` could
only come from the base class `item`, which lucisv does not resolve;
renaming it would be a guess." This is **pre-existing and not this
round's**: an out-of-body `task item::show()` gets the identical refusal
for the identical reason (verified against a v0.26.0 build; the stand-in
scope's `extends` makes the use an `InheritedCandidate`, which
`rename.rs` will not edit). The direction C1 actually asked for — rename
*from the declaration* — works and is pinned by
`renaming_a_rand_field_reaches_a_constraint_in_another_file`. Closing the
other direction means teaching `rename.rs` to accept an inherited
candidate the workspace overlay resolved to exactly one declaration, which
is `vlog_refactor`'s call and outside this lane's file list.
2. **Comment slots in five shared functions** drop the comment written in
them, in *any* construct — `take_member_prefix`, `parse_method_name`,
`parse_foreach_target`, index expressions, and `inside` sets /
`parse_value_range`. Each fails identically on v0.26.0 outside a
constraint (measured; the table in the rework log names the analogues),
so none is this round's to fix — but a constraint body used to be
verbatim, so a file with a comment in one of them *is* a regression for
constraint bodies specifically. QA filed the `foreach` row separately;
this files the other four. The fix in each case is the same shape as the
fourteen this round did: a named field on the node, printed in place.
3. **Files outside the stated ownership list that this round had to edit**,
because the layout change reaches them directly and they are test data,
not code: `crates/vlog_formatter/tests/cases/dv_statements.cases` (6 cases
— every `randomize() with` shape) and
`crates/vlog_formatter/tests/cases/directive_split.cases` (2 cases whose
fixtures happen to contain a constraint). No non-test file outside the
list was touched.
## Design
### AST
```
ItemKind::Constraint(ConstraintDecl {
qualifiers: Vec<String>, // static / extern / pure / local / protected
scope: Option<String>, // the `C::` of an out-of-block definition
name: Name, // text + span — the thing that did not exist
body: Option<ConstraintSet>, // None for a `constraint c;` prototype
semi: bool, // a stray `;` after the `}`
})
ConstraintSet { braced: bool, items: Vec<ConstraintItem>, dangling, span }
ConstraintItem { meta, kind: ConstraintItemKind, span }
ConstraintItemKind::
Expr { soft: bool, expr } // `[soft] expression_or_dist ;`
| Implication { cond, comments, set } // `expr -> constraint_set`
| If { cond, then, else_comments, els }
| Foreach { array, vars: Vec<Name>, set }
| SolveBefore { solve: Vec<ExprItem>, before: Vec<ExprItem> }
| Unique(Vec<ExprItem>)
| DisableSoft(Expr)
| Directive(RawText) // an `ifdef arm
| Empty // a lone `;`
ExprKind::Dist { expr, weights: Vec<DistItem { value, op, weight }> }
ExprKind::WithConstraint { base, block: Box<ConstraintBody>, comments }
ConstraintBody::{ Items(ConstraintSet), Verbatim(RawText) }
```
Three deviations from the brief's sketch, each argued in the work log:
`ConstraintBody` has no `Prototype` arm (a declaration spells that as
`body: None`) and is used only where a fallback can actually live; the
declaration's fallback is a whole-item `ItemKind::Verbatim`, not a body-level
one; and `Foreach.vars` is `Vec<Name>` with an empty-text name for a skipped
dimension, exactly as `StmtKind::Foreach` already spells one.
### The fallback
`Parser::parse_constraint` takes a `Rewind` snapshot — cursor, both pending
comment buckets, nesting depth, chain links, open conditional regions,
diagnostics length — attempts the structured parse, and on **any** error
restores the snapshot and re-runs `parse_constraint_verbatim`, which is the
v0.26.0 function body character for character. The comment buckets are part
of the snapshot because the speculative parse harvests comments into `Meta`s
it then throws away, and hard invariant #3 does not forgive that; the token
vector's own `leading` buckets are deliberately *not* snapshotted, because
`verbatim_since` drops every comment falling inside the captured span
anyway. `parse_with_constraint` does the same for a `with` block, whose
fallback has to live in the expression and so gets `ConstraintBody::Verbatim`.
### Layout
- `constraint c {` on the header line, one item per line at one further
indent, `}` at the header's column; an optional trailing `;` preserved.
An empty body prints `{}`.
- `soft x;` · `x dist {0 := 5, [1:20] :/ 20}` (weights broken one per line
when the list does not fit, like any other braced list) · `unique {a, b};`
· `disable soft x;` · `solve a, b before c, d;`.
- `cond -> set`: a braced set cuddles onto the arrow's line, an unbraced one
goes on the same line if it fits and on an indented next line if it does
not — the rule `stmt_as_body` uses for statements.
- `if (c) set else set`, with `else if` chained on one line the way a
statement `if` chains.
- `foreach (a[i, j]) set`.
- A directive item prints as raw text, both `ifdef arms standing as ordinary
items of the one set.
- A `randomize() with { ... }` block the **source** wrote on one line stays
on one line; one written across lines is laid out as a constraint body.
The question is asked of the source rather than measured, for the reason
`glued_null_item` asks the source about the gap between two items — and
because it is a fixed point by construction (a flattened block holds no
newline, so the next pass flattens it again). It also settles the `//`
question for free: a one-line block cannot hold a line comment, so a
flattened `}` can never land inside one.
### Comment slots
Every keyword and punctuation position this round introduced owns the
comments written in front of it, in a named field the formatter prints in
place. A comment the AST does not keep is a comment the formatter cannot
print, and `format_source`'s own token check then refuses the whole file —
hard invariant #3 by way of #1. The slots:
| written here | kept in |
|---|---|
| `constraint /*c*/ name` | `ConstraintDecl::before_name` |
| `constraint name /*c*/ {` / `… /*c*/ ;` | `ConstraintDecl::after_name` |
| `constraint c { … } /*c*/ ;` | `ConstraintDecl::before_semi` |
| `<item> /*c*/ ;` | `ConstraintItem::before_semi` |
| `soft /*c*/ x` | `ConstraintItemKind::Expr::after_soft` |
| `x /*c*/ dist /*c*/ {` | `ExprKind::Dist::comments` (`BinaryComments`) |
| `0 /*c*/ := /*c*/ 5` | `DistItem::op_comments` (`BinaryComments`) |
| `solve a /*c*/ before` | `SolveBefore::before_comments` |
| `unique /*c*/ {` | `Unique::comments` |
| `disable /*c*/ soft /*c*/ x` | `DisableSoft::comments` (`BinaryComments`) |
| `if /*c*/ ( /*c*/ e /*c*/ ) /*c*/ {` | `If::comments` (`HeaderComments`) |
| `foreach /*c*/ ( /*c*/ a[i] /*c*/ ) /*c*/ {` | `Foreach::comments` (`HeaderComments`) |
| `else /*c*/ {` and `else /*c*/ if` | `If::after_else` |
| `x /*c*/ -> /*c*/ set` | `Implication::comments` (already there) |
| before `else` | `If::else_comments` (already there) |
Two rules keep those fields from fighting each other:
- **One owner per gap.** [`ConstraintItemKind::takes_semi`] is the single
answer to "who writes the `;`", read by the parser (which consumes it) and
by the formatter (which writes it back). `parse_solve_operands` therefore
does *not* claim the gap before a `solve` item's `;` — the item does.
- **A gap belongs to the construct only when the token that closes it was
written.** `Parser::gap_before(sym)` is `take_gap` behind that check, the
closer-side twin of the existing `take_before_open`. So a body written on
the next line leaves its comment to that item's own leading comments,
where the source's line break already put it, and only `) /*c*/ {` — a
comment with a `{` actually after it — is claimed by the header.
`verify.rs` is **untouched**. Token equivalence is what proves the layout,
and the round ships nine new attack pairs in `tests/verification.rs`
regardless (invariant #4's standing pattern: "untouched + rejection tests
anyway").
### Binder
- `SymbolKind::Constraint`, declared in the class scope, exported by
`is_exported` on the same terms as a method.
- `ScopeKind::Constraint` for the body, parent = the class scope, so every
bare name binds lexically to a property with `this.` implicit. `foreach`
loop variables get a nested `Block` scope of their own.
- `constraint C::c { ... }` is deferred like an out-of-body method and
finished through `Binder::out_of_body_home`: the class's own scope when it
is in this file, else a stand-in `Class` scope carrying the path as its
`extends`, which the workspace overlay finishes through the member table.
- `obj.randomize() with { ... }`: bound in the caller's scope, but with
`Binder::with_head` set to `obj`'s head chain, so the one funnel every use
passes through (`use_member`) records a bare name as
`Target::MemberOf { head, mids }` — `obj`'s property, which is what
IEEE 1800 §18.7 says it is, and what the member chase already knows how to
follow across files. A call with no such head (`randomize() with`,
`std::randomize(x) with`) keeps ordinary lexical binding, which is the
right answer for both.
## Status / TODO
- [x] `ast.rs`: `ItemKind::Constraint`, `ConstraintDecl`, `ConstraintSet`,
`ConstraintItem(Kind)`, `DistItem`, `ConstraintBody`, `ExprKind::Dist`,
`SourceFile::constraint_fallbacks`
- [x] Parser: every item shape, `dist` both weight kinds, the exact
rewind-to-verbatim fallback, `with` blocks
- [x] Formatter: canonical layout; the fallback prints exactly as before
- [x] `verify.rs` untouched; the existing constraint attack pairs re-derived
and nine more added
- [x] Binder: `SymbolKind::Constraint`, `ScopeKind::Constraint`, the
out-of-class stand-in scope, `randomize() with` head redirection,
`FACTS_FORMAT` 11, class export
- [x] Linter: `visit.rs` arm (documented no-op), `signals.rs` no longer
opaque for a structured constraint
- [x] Server: `symbols.rs` label + LSP kind, `completion.rs` kind,
`tokens.rs` highlight
- [x] Comment slots: every keyword/punctuation position this round
introduced keeps the comments written in front of it
- [x] Tests: 30 parser, 2 spans sources, 41 formatter cases + 4 case files
re-derived, 13 verification, 13 semantic, 2 e2e, 1 lint case file
- [x] Gates: fmt / clippy / `cargo test --workspace` / corpus gate /
vsix smoke / opentitan read-only sweep
- [x] **Round 2, done 2026-09-02:** covergroups.
`docs/features/covergroup-bodies/README.md` — `ItemKind::Covergroup`
with the same `Rewind`-to-verbatim fallback, the same "no keywords
reserved" posture, the same named comment fields and `takes_semi`, and
the gap fuzzer this round's rework invented, written first rather than
after. `Rewind`, `gap_before`, `word_at` and
`parse_constraint_expr_set` were reused unchanged.
- [ ] **Filed, not done:** the `vlog_refactor` refusal above.
## Work log
### 2026-09-02 — dev
**The four keywords the round did not add.** The brief called for `dist`,
`soft`, `solve` and `before` in `token.rs`'s `keywords!` list, with the
`pairs.rs` re-check and the hand edit to
`editors/vscode/syntaxes/systemverilog.tmLanguage.json` that a keyword costs
(`topo.md` §3.3's `token.rs` row). **Not done, deliberately**, and this is the
round's biggest deviation:
- Reserving a word is not free in a *tolerant* formatter. `is_keyword` gates
`expect_name`, so `logic before;` would stop parsing, and it gates
`Binder::use_member`, so every reference to a signal named `soft` would
silently vanish. lucisv's whole posture is that a legal-ish file keeps
working; four new reserved words trade that away for highlighting.
- Inside a constraint body the four words are unambiguous *by position*, and
the codebase already has the precedent: `restrict` is matched by text in
`at_concurrent_assertion` (`parser.rs`), for exactly this reason. So they
are read through one two-line helper, `word_at(token, word)`, and only
where the grammar leaves no other reading — `dist` demands a following
`{`, `solve` demands a following identifier, `soft` demands a following
*term* (`at_soft_constraint`), `before` is only ever consumed inside a
`solve`. A signal genuinely named one of them still parses:
`a_soft_constraint_is_flagged_and_a_signal_named_soft_is_not` and the
`solve == 1;` half of `a_solve_before_keeps_both_operand_lists_in_order`
pin it.
- Consequence: `token.rs`, `pairs.rs`, `tests/grammar.rs` and the editor
grammar are **untouched**, so the round does not sit on the `token.rs`
choke point at all.
**`:=` and `:/` are not lexer operators either.** Same argument, sharper: a
`:/` entry in `OPERATORS` would greedily eat the `/*` of
`cond ? a :/* why */ b`, and `lexer.rs` is not this round's file. So
`Parser::dist_weight_op` reads the two tokens and demands they be **adjacent
by span**. `a_spaced_dist_weight_operator_falls_back` pins that `0 : / 5`
is not a weight.
**The fallback, and why it is whole-item.** The brief's sketch put a
`Verbatim` arm inside `ConstraintBody`. For a *declaration* that would leave
the `RawText` starting at the `{`, which does not begin its own line — and
`RawText.col`'s dedent contract (`classes`) only reaches a fixed point for
text that does. So a declaration whose body does not parse rewinds to the
whole-item `ItemKind::Verbatim` it always was, produced by
`parse_constraint_verbatim`, which is v0.26.0's `parse_constraint` body
character for character. That is stronger than the sketch: the fallback is
not merely *equivalent* to the old behaviour, it *is* the old behaviour, and
`an_unrecognised_constraint_body_rewinds_to_exactly_the_old_capture` pins the
text, the source slice and the `col`. `ConstraintBody` survives only where a
fallback genuinely has to live inside an expression — the `with` block.
**The rewind snapshot is about comments, not the cursor.** Restoring `pos`
is the easy half. The half that matters for hard invariant #3 is
`pending_leading` / `pending_trailing`: a speculative parse calls `take_meta`
and drains them into `Meta`s that the rewind throws away, and a comment
written *before* the constraint would be lost. So `Rewind` clones both
buckets, plus `depth`, `links`, `open_conds` and the diagnostics length.
The token vector's own `leading` buckets are deliberately **not** snapshotted
— a retry that drained one has already decided to swallow those bytes whole,
and `verbatim_since` drops every comment falling inside the captured span.
`a_fallback_keeps_the_comments_written_around_it` is the test that would have
caught getting this wrong.
**Three AST deviations, all shape-not-substance.** `ConstraintDecl.body` is
`Option<ConstraintSet>` rather than a `ConstraintBody::Prototype` arm (a
prototype is the absence of a body, not a kind of one); `Foreach.vars` is
`Vec<Name>` with an empty-text name for a skipped dimension, which is
already how `StmtKind::Foreach` spells one, so `join_names`, `declare` and
the span walker all work unchanged rather than needing an `Option` arm each;
and `ScopeKind::Constraint` was added after checking that nothing outside
`model.rs` matches `ScopeKind` exhaustively — three `==` comparisons in
`resolve.rs`, one in a test — so the variant cost zero arms.
**`->` had to leave the expression grammar, and `<->` had to stay in it.**
A constraint implication's right-hand side may be a braced *set*, which is
not an expression, so the item parser takes its operand with
`parse_ternary` (below the implication level) and reads the arrow itself.
`<->` can never take a set, so it stays an operator and is read in a small
left-associative loop right there. That re-associates `a <-> b -> c` from
`a <-> (b -> c)` to `(a <-> b) -> c` — the same token stream, and lucisv
evaluates neither, so nothing downstream can tell. Recorded in Assumptions
because it is a difference, not because it bites.
**`visit.rs` gets an arm that does nothing, on purpose.** `topo.md` §3.3
says a new variant containing items or statements needs a real `visit.rs`
arm. A constraint body contains neither — only constraint items and
expressions — so there is nothing for `walk_items` or `walk_all_stmts` to
descend into, and building an expression walk for a rule that does not exist
would be the abstraction CLAUDE.md tells you to stop building. The arm is
written explicitly with the reasoning attached so the next reader does not
re-derive it. The rules that *do* see inside now do it through the reference
table, and one of them changed verdict — see below.
**One real lint behaviour change, pinned.** `undriven-net` skips a net with
`reads == 0`. A net read only inside a `randomize() with` block used to have
zero reads, because nothing in the block bound; it now has a real one. On
```systemverilog
class item; rand int addr; endclass
module m;
wire w;
item req;
bit ok;
initial ok = req.randomize() with { addr == w; };
endmodule
```
v0.26.0 reports only `req`; this tree reports `w` too, correctly.
`tests/cases/constraints.lint` case 1 pins it, case 2 pins that the verbatim
fallback goes back to silence. `unused-signal` does **not** change, because
its "mentioned anywhere in the file's tokens" guard already shielded every
name a constraint could mention — worth stating, since it is the rule one
would expect to move.
**`randomize() with` needed a target of its own.** Binding the block
lexically in the caller's scope gives *wrong* answers: in
`req.randomize() with { addr == 0; }` the `addr` is `req`'s property, and a
same-named field on the writing class would steal it — and then a rename of
the writing class's field would rewrite a constraint that never named it.
So `Binder::with_head` is set while the block is bound and the one funnel
every use passes through (`use_member`) rewrites a `Target::Lexical` into
`Target::InlineConstraint { head, mids }`. That is 12 lines instead of
threading a default-target parameter through all of `bind_expr`.
`Target::InlineConstraint` resolves as `MemberOf` first and falls back to
the writing scope **only when the object's own class settles the miss** — so
`with { addr < limit; }` binds `addr` to the object and `limit` to the
caller, while a class in another file (where the member chase yields a
candidate, not a miss) is left alone rather than guessed at. `resolve.rs` was
in the lane's file list "if needed"; it was, for those eight lines.
`randomize_head` deliberately returns `None` for a bare `randomize() with`
(implicitly `this` — already lexically in scope) and for
`std::randomize(x) with` (whose names really are the caller's), so both keep
ordinary binding, which is the right answer for both.
**`FACTS_FORMAT` is 10 → 11, not 9 → 10.** The brief and TODO §20 both said
9 → 10; member-completion's `LocalParam` had already taken 10 in the
meantime.
**Layout: the one judgement call that shows up everywhere.** A `constraint`
declaration always breaks — it is a block and reads as one. A
`randomize() with` block does not: it keeps the **source's** one-line-or-not
shape. Three candidate rules were tried before that one:
1. *Always break.* Turns `if (!req.randomize() with { addr == 0; })` — the
single most common line in a DV testbench — into five lines.
2. *Flat when the built doc holds no hard line.* Correct for short blocks,
but a long flat block makes the printer's `fits` walk the whole thing,
which then breaks the enclosing **call argument list** as collateral
(`std::randomize(` ⏎ `gnt_delay` ⏎ `)`), which is worse than either.
3. *Flat when the source wrote one line.* Chosen. It is a fact about the gap
between two tokens, which is the one thing `format.rs` already reads
`src` for (`glued_null_item`, `default_has_colon`, `eq_offset`); it is a
fixed point by construction, because a flattened block holds no newline
and the next pass flattens it again; and it settles the `//` hazard for
free — a one-line block cannot hold a line comment, so a flattened `}`
can never land inside one. `contains_hard_line` stays as the belt to that
braces.
The visible consequence is that a `with` block written across lines emits
hard lines, so a condition containing one wraps the way any multi-line
condition already does — `if (` alone on its line. That is lucisv's existing
convention for long conditions (`dv_statements.cases:600` already expected
it before this round); what changed is that the shorter ones now join it.
`Doc::Inline` used to hide them, because it measures only its first line.
**Files edited outside the stated ownership.** Two `.cases` files, both test
data, both a direct consequence of the layout change and unfixable without
them: `dv_statements.cases` (6 cases, every `randomize() with` shape) and
`directive_split.cases` (2 cases whose fixtures happen to contain a
constraint). Flagged here and in Handshakes rather than done silently. No
non-test file outside the list was touched; `verify.rs`, `token.rs`,
`pairs.rs`, `lexer.rs`, the editor grammar and `vlog_refactor` are all
untouched.
**Measurements.**
*OpenTitan `hw`, 3,975 `.sv`/`.svh`, read-only `--no-cache --check`, against
a release build of v0.26.0 (`dd4aa49`) in a detached worktree.* The checkout
had exactly three modified files before the sweep and exactly the same three
after (the owner's in-progress `aes/dv/tb/tb.sv` and the two `ast.sv`s).
| | v0.26.0 | this tree |
|---|---|---|
| files that fail to format | 12 | **12** |
| newly failing (set difference) | — | **0** |
| newly fixed | — | 0 |
`--check` runs `format_source`, which runs *both* halves of the safety net
(`verify_equivalence` then `verify_convergence`), so "12 failures, the same
12" is also the statement that **3,963 real files — carrying 1,993 freshly
laid-out constraint bodies — are token-equivalent to their input and
idempotent.** That is the evidence that matters for this round, and it is
why `verify.rs` needed no widening.
*Tolerant-mode diagnostics over the same 3,975 files* (the check a grammar
change owes: a widening that broke recovery would show here and nowhere
else), measured with a standalone probe calling `parse_source_tolerant`
directly against each tree's `vlog_parser`:
| | v0.26.0 | this tree |
|---|---|---|
| total diagnostics | 1 105 | **1 105** |
| files with any | 12 | **12** |
| per-file difference | — | **none** |
| constraint bodies | count |
|---|---|
| `constraint` declarations parsed **structured** | **1 993** |
| `constraint` declarations that fell back | **16** (0.8%) |
| `randomize() with` blocks that fell back | **13** of ~122 textual occurrences |
Every one of the 16 declaration fallbacks was read, not guessed at:
- **10 are macro-item bodies** — `` `DV_COMMON_CLK_CONSTRAINT(clk_freq_mhz) ``,
`` `DV_MUBI8_DIST(...) ``, `` `OTP_CLK_CONSTRAINT(...) ``, `` `DV_LC_TX_DIST(...) ``
— a bare macro invocation standing where a constraint item belongs, with
the `;` (or half the constraint) inside the macro. Irreducible without
expanding macros.
- **6 are shapes the LRM does not have**, all in `aes_message_item.sv` and
one `csrng` sequence: a constraint expression with no terminating `;`
before the `}` (`aes_operation == fixed_operation` ⏎ `};`), and commas
used as separators between constraint expressions
(`aes_key[0] == fixed_key[0],` ⏎ `aes_key[1] == fixed_key[1]`). Tools
accept them; the LRM does not, and the fallback is the right answer.
The `with`-block fallbacks are dominated by **`local::`** (IEEE 1800
§18.7.1) — `bus_req.a_addr == local::rw.addr` — which the expression parser
cannot read because `local` is a lexer keyword. Filed as the single largest
remaining fallback cause; closing it means letting `local` head a scoped
name in `parse_primary` and teaching the binder to bind such a tail
lexically, which is a change to the shared expression grammar and did not
belong at the end of this round.
*Corpus (860 files).* `scripts/corpus_gate.sh corpus` →
`{"passing":813,"total":820,...}`, **0 verification errors, 0 crashes** —
exactly the baseline. **37 of 860 files change layout**, and all 37 verify:
the count comes from formatting every file through both binaries' `--stdout`
and diffing, and `--stdout` only succeeds when `format_source`'s own
token-equivalence check passes, so "0 new failures" *is* "all 37 verified".
*Corpus resolution column* (`vlog_semantic`'s
`the_corpus_index_finishes_most_external_references`, both layers):
| | v0.26.0 | this tree |
|---|---|---|
| references recorded | 99 553 | **101 199** |
| resolved in-file | 70 088 | **71 224** |
| answered by the workspace layer | 87.4% of 23 072 | **87.5% of 23 330** |
| nowhere to jump | 9 299 (9.3%) | 9 561 (**9.4%**) |
The honest reading, since the brief expected the unresolved count to *fall*:
it did not, and could not. Constraint bodies contributed **1 646 references
that did not exist at all before** — they were not unresolved, they were
unrecorded — and **1 384 of them (84%) are answered**. The 262 that are not
are names whose declaration is outside the corpus (macro-supplied fields,
base classes from `uvm_pkg`). The rate barely moved — 90.7% → 90.6% of a
1.7% larger denominator — while 1 136 more references resolve in-file.
**Gates.** `cargo fmt --all -- --check` clean · `cargo clippy --all-targets
--workspace` **0 warnings** · `cargo test --workspace` green (**41 binaries,
2 942 passed, 0 failed**) · corpus gate
813/820 · `node editors/vscode/smoke.js target/debug/lucisv-server` OK ·
OpenTitan sweep unchanged, checkout untouched.
### 2026-09-02 — dev, rework after QA
**The finding, restated.** Every word this round matches by text — and every
punctuation position it introduced — swallowed the comment written after it.
The comment was not printed anywhere the source had put it, so
`format_source`'s own token check refused the file: exit 2, no output. Hard
invariant #1 held (nothing was corrupted), but a real file with a comment in
one of those slots became **unformattable**, which is its own kind of broken.
**I did not fix the six repros.** Guessing at a list of slots is how you ship
the seventh. Instead I built a gap fuzzer: take a fixture, insert `/*C*/`
into **every** inter-token gap, and demand `format_source` succeed and be
idempotent for each. Fifteen fixtures covering the whole sub-grammar gave
**358 gaps**, of which **132 failed**.
The number that matters is not 132, though — most of those gaps were already
broken in v0.26.0, in machinery this round never touched. So I ran the same
fuzzer against a v0.26.0 worktree twice: once on the constraint fixtures
(where a constraint body was verbatim, so *everything* inside worked), and
once on a second fixture set writing **the equivalent constructs outside a
constraint** — a statement `if`, a statement `foreach`, an `inside` set in an
expression, an index expression, an out-of-body `function void pkg::cls::f()`,
a `pure static function`. That second run is what separates "this round
regressed it" from "the codebase has always dropped it here".
| | gaps | failing |
|---|---|---|
| v0.26.0, constraint fixtures | 358 | 42 |
| this tree, before the rework | 358 | 132 → **96 regressions** |
| this tree, after the rework | 358 | 82 → **40 regressions** |
**All six of QA's repros are fixed, and so are 56 slots QA did not name** —
including the one with the widest blast radius, the comment written in front
of an item's own `;` (`x < 5 /* inclusive */ ;`), which affects every item
kind and every nested set.
**The 40 that remain are in five shared functions, none of them this
round's, and every one of them fails on v0.26.0 in the equivalent construct
outside a constraint:**
| remaining slots | shared owner | v0.26.0 analogue that also fails |
|---|---|---|
| `static /*c*/ constraint`, `pure /*c*/ static`, `extern /*c*/ constraint` (4) | `take_member_prefix` | `pure /*c*/ static function`, `extern /*c*/ function` |
| `pkg/*c*/ ::cls::name` and the rest of the chain (4) | `parse_method_name` | `function void pkg/*c*/ ::cls::f()` |
| `foreach (q/*c*/ [i])`, `(q[/*c*/ i])`, `(r[, /*c*/ j])` … (11) | `parse_foreach_target` | `foreach (q[/*c*/ i]) x = 1;` in a statement |
| `q/*c*/ [i]`, `q[/*c*/ i]`, `q[i/*c*/ ]` in an item (9) | index expressions | `x = q[/*c*/ i];` |
| `n /*c*/ inside {`, `inside /*c*/ {`, `[/*c*/ 0:3]`, `[0/*c*/ :3]` … (12) | `inside` sets, `parse_value_range` | `n = a inside {[/*c*/ 0:3]};` |
That is the honest bar and I have not quietly widened it: an
`ItemKind::Verbatim` body made *all* of these work before this round, so a
file with a comment in one of them is a real regression for constraint
bodies — it is just not a regression I can fix without editing machinery
this lane does not own. Filed as request 3 below.
> **Amended 2026-09-02 (`comment-slots`).** Request 3 is closed: all forty are
> fixed, and the fuzzer this section describes — which measured the problem
> but was never committed — is now **in the tree** as
> `a_comment_in_every_constraint_gap_still_formats`, at **zero failing**. Its
> fifteen fixtures are re-derived from the table above rather than restored
> byte for byte, which is why it counts 395 inter-token gaps and not 358. QA's separately-filed
`foreach (arr[/*c*/ i])` is the third row of that table.
**What the fix looks like.** Fourteen named comment fields (the table in
Design), and two rules that stop them fighting:
- `ConstraintItemKind::takes_semi()` — one answer to "who writes the `;`",
read by the parser that consumes it and the formatter that writes it back.
Centralising it removed four scattered `expect_sym(";")` calls, and it is
why `parse_solve_operands` no longer claims the gap before a `solve`
item's `;` (the item does). The first draft had both claiming it; the
parser pin `every_constraint_item_slot_keeps_its_comment` is what caught
the resulting silent loss, which is exactly the class of bug this finding
was.
- `Parser::gap_before(sym)` — `take_gap` behind "is the closing token
actually there?", the closer-side twin of the existing
`take_before_open`. Without it, `if (m)` ⏎ `// why` ⏎ `a == 1;` would have
had its comment yanked up onto the `)` line; with it, only a comment that
really does sit between `)` and a `{` is claimed by the header.
**Two layout fixes the fuzzer's idempotency half surfaced**, neither in the
finding: `plain_expr_list` was `delimited("", …, "")`, and a bracketed
list's closing break put `before` — or the item's `;` — on a line of its
own the moment any comment forced the group open (`solve x /*c1*/ before` ⏎
`/*c2*/` ⏎ `y` ⏎ `;`). A list with no brackets has nothing to open, so it
now prints every comment where it was written and only a `//` costs a
break. And `foreach (a[i] /*c*/)` was missing the space before its `)`.
**Nothing else moved.** The parse of comment-free source is unchanged, which
the numbers say out loud: over OpenTitan's 3,975 `hw` files the counts are
identical to the pre-rework tree and to v0.26.0 — 1,993 constraint
declarations structured, 16 fallbacks, 29 fallbacks including `with` blocks,
**1,105 tolerant diagnostics (the same 1,105 v0.26.0 reports)**, and the
same 12-file failure set with **0 newly failing**. Corpus gate 813/820, 0
verification errors. `verify.rs` still untouched.
**Pins added.** 6 parser tests asserting the comment text is *in the node*
(`the_header_keeps_the_comments_written_around_its_name`,
`a_prototype_keeps_the_comment_written_before_its_semicolon`,
`every_constraint_item_slot_keeps_its_comment` — 18 slots in one assertion —
`a_dist_keeps_the_comments_around_its_word_and_its_weight_operators`,
`the_gap_before_a_semicolon_that_was_not_written_belongs_to_what_follows`,
`an_else_on_its_own_line_leaves_its_comment_to_the_body_item`), and 13 new
`constraints.cases` entries covering every slot for output *and*
idempotency. QA's two attack pairs are in and green.
**Gates.** `cargo fmt --all -- --check` clean · `cargo clippy --all-targets
--workspace` 0 warnings · `cargo test --workspace` **41 binaries, 2 950
passed, 0 failed** · corpus gate 813/820, 0 verification errors · vsix smoke
OK · OpenTitan `hw` failure set unchanged at 12, checkout untouched.
## QA log
### 2026-09-02 — QA
**Verdict: REWORK.** Gates, corpus, opentitan sweep and semantics all hold
exactly as measured; the finding is a comment-drop surface in the new
`ConstraintItemKind::Expr`/`DisableSoft`/`SolveBefore` arms and the `dist`
weight production, all correctly caught by `format_source`'s own safety net
(the file is refused, never corrupted) but not disclosed anywhere as a known
gap, and covering exactly the slots the round's own checklist named.
**Gates.** `cargo fmt --all -- --check` clean. `cargo clippy --all-targets
--workspace` 0 warnings (verified with a forced rebuild, not a cache hit).
`cargo test --workspace`: **41 binaries, 2 944 passed, 0 failed** (2 942 plus
the two attack pairs added below). `scripts/corpus_gate.sh corpus` →
813/820, 0 verification errors, matching the dev's number exactly.
`cargo build --release` clean. `node editors/vscode/smoke.js
target/debug/lucisv-server` → OK. `cargo test -p lucisv_server --test
grammar` → 3/3 (the keyword/grammar-parity test the round claims untouched).
No `.unwrap()`/`.expect()`/`panic!` added to library code — every hit in
`git diff` for `parser.rs` falls after line 6062's `#[cfg(test)] mod tests`
(checked by hunk line numbers); every other changed file has zero.
**Scope.** `verify.rs`, `token.rs`, `pairs.rs`, `lexer.rs`,
`editors/vscode/syntaxes`, `vlog_refactor`: all absent from `git diff
--stat`, confirmed untouched. The only files touched outside the README's
list are the two disclosed `.cases` files plus release-prep files
(`Cargo.toml`, `CHANGELOG.md`, `editors/vscode/{CHANGELOG,README,
package.json}`, `docs/topo.md`) that bump the version to 0.27.0 and add the
topo.md row — pre-existing when QA started, not this lane's doing, and out
of this checklist's scope to re-litigate.
**Opentitan sweep (read-only).** 48 DV files with `constraint ` across 16
IPs (i2c, usbdev, lc_ctrl, dma, sysrst_ctrl, kmac, spi_device, uart,
sram_ctrl, keymgr, hmac, aon_timer, adc_ctrl, spi_host, rv_timer, otbn),
formatted with `--stdout`, then `--stdout` again on each output:
| | files | idempotent | comments equal + ordered |
|---|---|---|---|
| result | 48/48 formatted, 0 errors | **48/48** byte-identical pass1=pass2 | **48/48** (comment streams extracted with a string-aware `//`/`/* */` scanner, compared as one ordered sequence per file) |
Eyeballed dist lists (`hw/ip/adc_ctrl/.../adc_ctrl_env_var_filter_cfg.sv`,
`foreach` nesting a `dist`) and both shapes of `randomize() with`
(`usbdev_base_vseq.sv`: a multi-line block stays broken, a one-line
`assert (m_sof_pkt.randomize() with {m_sof_pkt.framenum == framenum;});`
stays flat) — both match the README's stated layout rule. No mangled `}`,
no misplaced comment, no corrupted `dist` list in any of the 48.
`git -C .../opentitan status --short` before and after: unchanged, the same
three owner files (`hw/ip/aes/dv/tb/tb.sv`,
`hw/top_{darjeeling,earlgrey}/ip/ast/rtl/ast.sv`).
**Fallback exactness.** Built v0.26.0 (`dd4aa49`) in a detached worktree.
`local::` and a macro-item body: `--stdout` byte-identical between the two
binaries on synthetic cases. On the real fallback file
`hw/ip/aes/dv/env/aes_message_item.sv` (`operation_c`'s
`if (fixed_operation_en) { aes_operation == fixed_operation };` and
`key_c`'s comma-separated body — both non-LRM shapes, both fall back): the
**whole file** differs between the two binaries (expected — every other
constraint in the file is now laid out canonically), but the two fallback
bodies' own text is byte-for-byte identical in both outputs once the line
offset introduced by the reformatted constraints earlier in the file is
accounted for. Idempotent on the new output, comment stream identical to
the original input. `constraint_fallbacks` counts were not independently
re-derived (would need a debug hook the binary doesn't expose); took the
dev's 1 993/2 009 and 13/~122 on trust given every other measurement
reproduced exactly.
**Corpus lint, before/after.** `lucisv check corpus/` with the release
binary and with the v0.26.0 build: **7 932 violations, both binaries,
identical** (same one file failing to lex either way). No new false
positive from constraint operands now resolving.
**Attack-pair audit (`verify.rs`, untouched).** Re-ran the nine listed
pairs (`a_dropped_soft_is_rejected`, `a_swapped_dist_weight_operator_is_
rejected`, `a_reordered_solve_before_is_rejected`,
`a_dropped_else_set_is_rejected`,
`an_implication_flattened_into_a_plain_expression_is_rejected`,
`a_comment_moved_across_a_constraint_brace_is_rejected`,
`a_dropped_unique_or_disable_soft_word_is_rejected`,
`a_changed_constraint_expression_is_rejected`,
`a_dropped_constraint_line_is_rejected`) plus the fixed-point and fallback
end-to-end tests — all pass, all correctly reject their corrupted pair.
**Gap found and closed**, per this checklist's own suggestion: neither a
*value/weight pairing* reorder in a `dist` list (as opposed to the
`:=`/`:/` operator swap, which was pinned) nor a `soft` moved onto a
different item had a pin. Added `a_reordered_dist_weight_is_rejected` and
`a_soft_moved_to_the_wrong_item_is_rejected` to
`crates/vlog_formatter/tests/verification.rs` (right after
`a_reordered_solve_before_is_rejected`) — both confirmed to fail before
being written (i.e. `expect_divergence` genuinely exercises `verify.rs`,
not a no-op) and to pass now. `fmt`/`clippy` clean on the addition.
**Semantics.** Read `crates/vlog_semantic/tests/constraints.rs` (320
lines, 15 tests: every operand shape, `foreach` locality, `dist` weight
binding, out-of-block cross-file, base-class cross-file, class export, four
`with`-block tests including the object-vs-local precedence case) and
`crates/lucisv_server/tests/e2e.rs`'s
`renaming_a_rand_field_rewrites_its_constraint_uses` and
`renaming_a_rand_field_reaches_a_constraint_in_another_file` — both
non-trivial: hover, definition, rename (in-file and cross-file), a
references check, and an assertion that the renamed file still formats and
the constraint body carries the new name. All 15 + 2 pass in the full
suite. Did not independently re-drive these over the LSP wire (no MCP/LSP
client available in this environment); relied on reading the test bodies
plus the green run. The filed `vlog_refactor` refusal (rename from inside
an out-of-block body) reproduces as described — not re-verified against a
v0.26.0 build a second time since the README already did and nothing in
this round's file list touches `vlog_refactor`.
**Linter.** `crates/vlog_linter/tests/cases/constraints.lint` read: four
cases (undriven-net sees a `with`-block read; a fallback `with` block stays
opaque; `empty-item` does not fire on a constraint's own null item;
class-body item walk still reaches past a `constraint`). All run in the
green `cargo test --workspace`.
**Docs.** README follows the template; the fallback census, the four
"keywords not reserved" arguments and the five work-log amendments were
checked against the numbers reproduced above and match. TODO §20 QA line
is below.
---
**Finding 1 — HIGH (safety-net catches it; no corruption reaches output,
but every affected file is refused entirely).** A comment placed
immediately after any of the four *text-matched* keywords this round
introduces (`soft`, `dist`, `solve`/`before`, `disable soft`) — i.e. between
the keyword and the very next token — is silently dropped from the AST.
Nothing downstream ever sees it, so `format_source`'s own token-equivalence
check (comparing formatted output back against the input) fails and the
whole file is refused with a `verification failed` error — not corruption,
but a hard regression from v0.26.0, where the same file formatted fine
because the whole constraint was opaque verbatim text. Root cause: the
round explicitly added comment-carrying fields for the two other new
"joints" it introduces — `Implication { comments, .. }` (before/after
`->`) and `If { else_comments, .. }` (before `else`) — but not for `soft`,
`dist`, the `solve`/`before` keywords, or `disable soft`; a comment
consumed there lands in `pending_leading` ahead of a bare `Ident`/`Number`
expression node, which the AST has no field to carry it in (`Expr` is just
`{ kind, span }`), so it is discarded before printing. Confirmed via
`--stdout` on minimal repros (all under
`/private/tmp/.../scratchpad/slot_*.sv`, reproducible inline below):
```systemverilog
class item_a;
rand int x;
constraint c_all {
soft /* after soft */ x < 5;
}
endclass
```
→ `error: ...: verification failed: token stream diverges at index 11:
input has comment "/* after soft */" at 4:10, output has identifier "x" at
4:10`, exit code 2, empty stdout.
Same failure, same shape, for:
- `x dist /* c */ {0 := 5, [1:20] :/ 20};` (comment after `dist`, before
its own `{`)
- `{0 := /* c */ 5, [1:20] :/ 20}` (comment right after `:=`)
- `disable soft /* c */ x;` (comment after `disable soft`, before the
operand)
- `solve x /* c1 */ before /* c2 */ y;` (comments around `before`)
- `constraint c_all /* c */ {` (comment between the constraint's own name
and its opening brace)
Slots that **do** work, confirmed by the same method: leading comment on
the first item (`{ // after open`), a standalone comment between two items,
a trailing comment on the closing `}`, and a comment inside a `unique {...}`
list between commas (that one goes through the ordinary comma-list `Meta`
machinery and is fine). A comment on its own line immediately before `else`
gets **relocated** to trail the preceding `}` (`} // before else` /
`else {`) rather than staying on its own line — `verify.rs` accepts this
(order and content preserved, only line placement changes) and it matches
the project's existing `then_is_block`-style cuddle convention for
statement `if`, so this one is a deliberate layout choice, not a defect —
noted, not filed.
One slot named in the checklist, `foreach (arr[ /* c */ i])`, also drops
the comment and fails the same way — but this is **not new to this
round**: the identical failure reproduces on plain array indexing outside
any constraint (`arr[ /* c */ i] = 1;`) and on a declaration header
(`class foo /* c */;`, `module m /* c */;`) on this same tree. That is a
pre-existing, codebase-wide limitation of how comments attach to bare
expression leaves and declaration names, not something constraint-bodies
introduced or should be on the hook for in this round — flagged separately
below as a spawn-task candidate rather than counted against this lane.
Every one of these is caught before any byte reaches the user (invariant
#1 holds: input unchanged, error emitted, no partial output) — which is
why this is HIGH rather than CRITICAL by the letter of "any output whose
token stream differs ... that the safety net does not reject is CRITICAL."
But it is a direct violation of hard invariant #3 in spirit (the comment
*is* dropped, just before the point where that would become visible
corruption), it covers four of the round's own newly-introduced
constructs, and it was not disclosed anywhere in the Assumptions section as
a known gap. Recommend: add the same explicit `comments`-field treatment
`Implication`/`If` already got, for the `soft`/`dist`/`disable soft`
keyword positions and the `solve`/`before` keywords, before shipping —
these are real DV patterns (a comment explaining *why* a constraint is
`soft` is exactly the kind of thing a testbench author writes).
**Finding 2 — informational, not a blocker.** `docs/topo.md`,
`CHANGELOG.md`, `Cargo.toml` and the `editors/vscode/*` version/changelog
files already carry a 0.27.0 bump and a topo.md row for this feature,
ahead of the lead's merge. Not this lane's file list and not touched by
QA; noted so the lead knows the release-prep state was already sitting in
the tree at QA time.
**Small fixes made directly, per the QA charter:** added
`a_reordered_dist_weight_is_rejected` and
`a_soft_moved_to_the_wrong_item_is_rejected` to
`crates/vlog_formatter/tests/verification.rs` (see Attack-pair audit
above) — closing the one gap this checklist explicitly asked QA to check
for. No other file was modified.
### 2026-09-02 — QA (re-verification after rework)
**Verdict: SHIP.** All six original repros now format and round-trip;
independent re-derivation of the fuzzer claim on three fresh fixtures
finds zero constraint-bodies-specific regressions; gates, corpus and the
opentitan sweep all reproduce the dev's numbers.
**Gates.** `cargo fmt --all -- --check` clean. `cargo clippy --all-targets
--workspace` 0 warnings (forced rebuild). `cargo test --workspace`: **41
binaries, 2 950 passed, 0 failed** — matches the dev's number exactly.
`scripts/corpus_gate.sh corpus` → 813/820, 0 verification errors. Release
build clean. `verify.rs` still absent from `git diff --stat` (confirmed
untouched), and both attack pairs from the first pass
(`a_reordered_dist_weight_is_rejected`,
`a_soft_moved_to_the_wrong_item_is_rejected`) are present in
`crates/vlog_formatter/tests/verification.rs` and green.
**The six original repros, re-run individually** (format + idempotency +
comment-stream diff against each input): `soft /* after soft */ x < 5;` ·
`constraint c_all /* before open */ {` · `x dist {0 := /* after walrus */
5, ...}` · `disable soft /* c */ x;` · `solve x /* c1 */ before /* c2 */
y;` · `x dist /* after dist word */ {...}`. **6/6 now format on the first
pass, 6/6 idempotent, 6/6 comment streams byte-identical to their input.**
All previously exited 2 with an empty stdout; all now exit 0 with the
comment printed exactly where the source wrote it.
**Independent fuzzer re-derivation.** Wrote a standalone tokenizer +
per-gap comment injector (not the dev's code — a fresh implementation) and
ran it over three fixtures of my own, none shared with the dev's fifteen:
a dist-heavy body (two `dist` items, both weight kinds, a value-range
weight), a nested `if`/`else if`/`else`-with-`foreach` body, and an
out-of-class `constraint pkg::cls::c { ... }` body reached through a
2-level scope chain.
| fixture | gaps | failing |
|---|---|---|
| dist-heavy | 53 | 12 |
| nested if/else-if/foreach | 68 | 14 |
| out-of-class `pkg::cls::c` | 29 | 10 |
| **total** | **150** | **36** |
Classified all 36 by constructing the equivalent **non-constraint**
construct at the same gap position and running it through a v0.26.0
(`dd4aa49`) build in a detached worktree — 21 distinct positions covering
every failing gap shape across the three fixtures, **21/21 fail on
v0.26.0** too:
| failing gap shape (n in my fixtures) | non-constraint equivalent tested | v0.26.0 |
|---|---|---|
| `extern /*c*/ constraint` (1) | `extern /*c*/ static function` — dev's row 1, `take_member_prefix` | fails |
| `pkg /*c*/ ::cls::c` chain (4) | `function void pkg /*c*/ ::cls::f()` — dev's row 2, `parse_method_name` | fails |
| `foreach (arr /*c*/ [i])` (3) | `foreach (arr /*c*/ [i]) x = 1;` — dev's row 3, `parse_foreach_target` | fails |
| `arr /*c*/ [i]` index in an item (3) | `x = arr /*c*/ [i] > 0;` — dev's row 4, index expressions | fails |
| `[2 /*c*/ :5]` value range in a dist weight (8) | `n = a inside {[2 /*c*/ :5]}` — dev's row 5, `parse_value_range` | fails |
| `class /*c*/ item_a`, `item_a /*c*/ ;` (4) | plain `class /*c*/ foo;` / `class foo /*c*/ ;` | fails |
| `package /*c*/ pkg`, `pkg /*c*/ ;` (2) | plain `package /*c*/ pkg;` / `package pkg /*c*/ ;` | fails |
| `rand /*c*/ int x;` (6) | plain `class c; rand /*c*/ int x; endclass` | fails |
| `arr /*c*/ [4]`, `[ /*c*/ 4]`, `[4 /*c*/ ]` declarator (3) | plain `rand int arr /*c*/ [4];` (each sub-position) | fails |
All 36 raw failures are accounted for by these nine shapes; the
arithmetic reconciles exactly against the per-fixture counts above. Five
of the nine match the dev's own table row for row; the other four (class
and package headers, a bare `rand`/`int` qualifier gap, and an
array-dimension declarator) are not in the dev's five-row table, but each
reproduces identically on **plain declarations that contain no
constraint at all** — so per this task's own rule ("any failure that is
not reproducible on v0.26.0 outside a constraint is a new finding"), none
of them is one. **Zero new findings; zero constraint-bodies-specific
regressions.** My QA-round-1 `foreach (arr[/*c*/ i])` filing is the same
shape as the `parse_foreach_target`/index-expression rows above and is
still filed as `task_6bdb0eb3` (spawned last pass, not this lane's) rather
than counted here.
**Opentitan (read-only).** Re-ran the 48-file sweep (16 IPs) exactly as
before: **48/48 format successfully, 48/48 idempotent (pass1 == pass2
byte-identical), 48/48 comment streams byte-identical** to their inputs.
`--check --no-cache hw` over the full 3,975-file tree: **13 files fail to
format, byte-identical set between this build and a fresh v0.26.0 build on
the same checkout** (`diff` of the sorted error lists is empty) — the
failure set is unchanged between the two binaries, confirming 0 newly
failing. The absolute count (13, not the 12 recorded at the first QA pass)
is not a regression: it is driven entirely by the checkout's own state —
`hw/top_darjeeling/ip/ast/rtl/ast.sv` is currently mid-edit by its owner
and fails to *parse* on both binaries alike (a `found "as"` syntax error
at the same line on both), where at the first QA pass it evidently did
not yet fail that way. `git -C .../opentitan status --short` before and
after: unchanged, the same three owner files
(`hw/ip/aes/dv/tb/tb.sv`, `hw/top_{darjeeling,earlgrey}/ip/ast/rtl/ast.sv`).
**Not independently re-checked this pass** (unchanged since the first QA
pass and not touched by the rework): the semantics tests
(`vlog_semantic/tests/constraints.rs`, the two rename e2e tests), the
linter cases, and the corpus lint before/after comparison. The rework's
diff does not touch `bind.rs`, `resolve.rs`, `signals.rs` or `visit.rs`
beyond what round 1 already had reviewed, and `cargo test --workspace`
carries all of them green at the counts above.
## Review
## Review
**2026-09-02 — lead.** Approved and committed after one rework; the biggest
DV correctness item in the gap analysis, closed for constraints.
- The design landed as briefed and improved on it in two places the lead
now considers canon. **No keywords reserved**: `soft`/`dist`/`solve`/
`before` matched by text like `restrict` — reserving them would have
broken `logic before;` and silently dropped references to a signal named
`soft`, and it kept the round off the `token.rs` choke point entirely.
**The rewind is the old code**: a `Rewind` snapshot that includes both
pending-comment buckets, then v0.26.0's verbatim capture re-run
character for character on any failure, pinned on text, slice and
`col` — an unknown body *is* the previous behavior, which is why the
opentitan sweep could not move and did not.
- **The rework was the right shape.** QA found comments dropped after the
round's own text-matched words; the dev answered not with six patches
but with an exhaustive gap fuzzer (358 inter-token gaps, format and
idempotency both demanded) and fourteen named comment fields, plus one
owner of the `;` (`takes_semi`) and `gap_before`, the closer-side twin
of `take_before_open`. Ninety-six regressions against v0.26.0 became
forty, every one in shared expression or name machinery that fails
identically outside a constraint — QA re-derived that with its own
tokenizer on fresh fixtures against a v0.26.0 build. Those forty are
filed as `docs/topo.md` §2.9-22, a parser-wide round; the honest
statement stands that inside a constraint they are regressions relative
to the verbatim era, and the honest measurement stands beside it that no
opentitan file hits one.
- The invariants held the way they are supposed to: every dropped comment
was caught by the safety net as a refusal, never a corruption; the
attack pairs were re-derived for the new layout and extended by the dev
and by QA (dist weight reordered, `soft` moved). `verify.rs` untouched.
- Numbers: 1 993 of 2 009 opentitan constraint bodies structured, 48 DV
files across 16 IPs idempotent with comment streams byte-identical,
tolerant diagnostics per file identical, corpus 37 files re-laid-out and
verified, references +1 646 with 84 % answered. Renaming a `rand` field
from its declaration rewrites its constraint uses in-file and cross-file
— the C1 correctness risk is closed for constraints; covergroups are
round 2 (TODO §21). The rename-from-inside-an-out-of-block-body refusal
is pre-existing (`task C::m` gets the same) and filed.
- Gates re-run by the lead: fmt clean, clippy zero warnings, 2 950 passed /
0 failed over 41 binaries, corpus 813/820, smoke OK. `docs/topo.md`: two
rows and §2.9-22. Ships as 0.27.0 (FACTS_FORMAT 11).