types-decls
Goal
Close the types-decls bucket of scripts/score.sh: the seven declaration
shapes that real RTL writes and lucisv could not parse. All of them are about a
type standing somewhere lucisv only accepted a name — an anonymous
enum/struct/union used as a type in place, a typedef'd name carrying
packed dimensions, a type parameter outside the #( ... ) list — plus a
for loop whose init declares more than one variable.
Assumptions
- An anonymous aggregate is the type: it never shares a
DataTypewith a name, signing or packed dimensions of its own. Any dimensions written after the closing}belong to the declarator, which is whereparse_declaratorsalready puts them. enum/struct/unionat item and statement position always opens a data declaration. Thetypedefspelling is taken by an earlier arm, and there is no other construct those keywords can begin there.- At item position, an identifier followed by balanced
[...]groups and then another identifier is a declaration, not an expression. A range select followed by a name is not a legal statement, so nothing is stolen from the expression grammar. The same test gates statement position, where it is what keepsx[i] = 1;an assignment: what follows the brackets there is=. - Enum member names introduced by an anonymous enum are not entered into the
semantic model's scopes (only
typedef enummembers are). Nothing in the formatter needs them; see Handshakes. - An anonymous
struct/unionbody always breaks one member per line, like thetypedef structpath it shares. An anonymousenumbody is a group: one line if it fits, else one member per line — again thetypedef enumrule. Both are the layout the corpus already writes.
Handshakes
Consumed
vlog_parser::parser—parse_opt_data_typeis the one door every type position goes through (declarations, ports,typedefbases, tf arguments, struct members,parameter typedefaults). Teaching it about anonymous aggregates is what made shapes 1, 2 and 5 land together.vlog_formatter::format—delimited_dangling(the fit-or-break list) andindent/Doc::HardLinefor the struct body; both were already what thetypedefpath used.vlog_formatter::verify— not modified. Every shape here adds tokens to the AST rather than normalizing them away, so the existing equivalence and convergence checks cover the new output unchanged.
Promised / changed for other modules
ast::DataTypelostparams: Option<Box<RawText>>and gainedextra: Option<Box<TypeExtra>>, read through the accessorsDataType::params()andDataType::inline(). The two rare tails share one box on purpose:DataTyperides inside everyExprthroughExprKind::Type, and a secondOption<Box<..>>field pushedDimKindpast clippy'slarge_enum_variantthreshold. Onlyformat.rsand two parser sites read the field.ast::ParamDeclgainedis_type: bool(localparam type payload_t = ...;).vlog_linter'sexplicit-parameter-storage-typenow exempts it, matching the exemption the parameter-port path already made forparameter type T = int— a type parameter has no storage type to declare. Fixed here rather than filed, because the false positive is created by this change.ast::{EnumType, EnumMember, StructType, StructMember, Declarator, ListDirective}now deriveClone, soDataTypecan keep deriving it.- No new
ItemKind/StmtKind/ExprKindvariants, so no exhaustive-match arms were needed invlog_linter::visit,vlog_semanticorlucisv_server.
Requests for other modules (not done here)
vlog_semantic::binddeclarestypedef enummembers andtypedef structmembers as symbols (bind.rs:395,bind.rs:406). The equivalent members of an anonymous aggregate —enum {A, B} x;, the nestedstruct packed {...} q;of a register-package typedef — are not declared, so go-to-definition and hover do not find them. Purely an LSP completeness gap; the formatter and the corpus metric do not depend on it.vlog_linter'senum-name-style/struct-union-name-styleonly look atItemKind::Typedef, so an anonymous aggregate is out of their reach by construction. That is correct today (an anonymous type has no name to style), but a future rule about member naming would want the inline bodies too.
Status / TODO
- 1. Anonymous
enumas a variable declaration, with and without a base type —corpus/common_cells/src/deprecated/clock_divider.sv:59,generic_fifo.sv:61,generic_fifo_adv.sv:39 - 1b. Anonymous packed
struct/uniondeclarations (no corpus hit; same machinery, cases added) - 2.
struct packed { ... }/enum { ... }as aparameter typedefault —corpus/common_cells/src/ecc_decode.sv:36,ecc_encode.sv:29 - 3. A typedef'd type with packed dimensions before the declarator —
corpus/common_cells/src/stream_omega_net.sv:162,stream_xbar.sv:98; also as a function local and a class property - 4.
typedef enum <typedef'd_base_t> { ... } name_t;—corpus/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_count_pkg.sv:10 - 5. A nested anonymous aggregate as a struct member —
corpus/opentitan/hw/ip/uart/rtl/uart_reg_pkg.sv:30 - 6.
localparam type/parameter typeas a body item —corpus/common_cells/test/lossy_valid_to_stream_tb.sv:26 - 7. A
forloop declaring several variables in its init —corpus/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_sparse_fsm_flop.sv:48 - Cases in
crates/vlog_formatter/tests/cases/types_decls.cases(22 cases: one per shape, the negativex[i] = 1;statement, a// verilog_format: offfence, comment attachment, and the line-length boundary), plus 9 parser unit tests cargo fmt/cargo clippy --all-targets/cargo testclean- No corpus regression: the passing set after is a strict superset
Work log
2026-08-21 — dev
Baseline {"passing":740,"total":820,"pct":90.2,"failures_by_category": {"dv-statements":26,"expressions":21,"directive-split":14,"types-decls":11, "invalid-or-fragment":3,"lex-macro-number":2,"other":2,"not-verilog":1}}
After {"passing":751,"total":820,"pct":91.6,"failures_by_category": {"dv-statements":26,"expressions":21,"directive-split":14, "invalid-or-fragment":3,"lex-macro-number":2,"other":2,"not-verilog":1}}
All 11 types-decls files pass; the category is gone from the JSON. No file
that passed before fails now (comm on the two .score-results.tsv pass
sets is empty in the regression direction).
Parser. The shape of the change is one refactor plus six small openings:
parse_typedef's enum and struct bodies moved out intoparse_enum_type/parse_struct_type, which run from the keyword through the closing}.typedefnow calls them and appends the name; so does everything below.parse_opt_data_typetakes anenum/struct/unionat the cursor and stores the body inDataType::extra. Because that function is the single door to every type position, this one hook delivered shapes 1, 2 (throughparse_type_expr, which aparameter typedefault already used) and 5 (throughparse_struct_type's own member loop — the recursion is free).at_typed_declaratorreplaces the two hand-rolled copies of the "identifier type?" lookahead (inparse_opt_data_typeandparse_assign_or_expr_stmt) with one that also skips a run of balanced[...]groups. Shape 3, at item, statement and class-member position at once.scan_matchingis strictly increasing on a[, so the skip loop terminates.parse_enum_type's base type goes through the newparse_type_ref, which falls back to a bare identifier (plus::chain,#( ... )and packed dims) whenparse_opt_data_typedeclines — shape 4.parse_type_exprwas a cut-down copy of that fallback and now delegates to it.parse_param_decleats an optionaltypekeyword and parses each= ...as a type rather than an expression — shape 6.parse_declaratorsgrew aparse_declarator_list(type_init)sibling for that.- The
forinit accepts an identifier type whenat_typed_declaratorsays a declarator follows it — shape 7. The comma-separated step list already worked. parse_keyword_itemandparse_keyword_stmtrouteenum/struct/uniontoparse_data_declinstead of erroring.
Formatter. typedef's two big arms became enum_type / struct_type,
which data_type also calls for an inline aggregate — so a nested struct
member indents one more level for free, and an anonymous enum inherits the
fit-or-break group the typedef path already had. param_decl and
param_decl_cells print the type keyword; putting it in the prefix cell
is what keeps a run of aligned localparam type lines aligned.
Decision: one box, not two. Adding inline: Option<Box<InlineType>>
beside params: Option<Box<RawText>> grew DataType by 8 bytes, which grew
Expr (it carries a DataType through ExprKind::Type), which took
DimKind::Range { a: Expr, b: Option<Expr> } from 200 to 208 bytes and
tripped clippy's large_enum_variant at its 200-byte threshold. Rather than
#[allow] a lint on a shared AST node for a rare field, the two mutually
exclusive tails were merged into extra: Option<Box<TypeExtra>> with
params() / inline() accessors — which is what params' own doc comment
had been asking for since it was written. DataType is back to its original
size and clippy is clean with no suppressions.
Not fixed, and why.
corpus/ibex/vendor/google_riscv-dv/src/isa/custom/riscv_custom_instr_enum.sv
is an include fragment — a bare CUSTOM_1, at top level, meant to be
pasted inside an enum body. It is not a translation unit and lucisv should keep
rejecting it. It is classified invalid-or-fragment, not types-decls, in
both the before and after TSVs, so it was never in this bucket's count.
QA log
2026-08-21 — round-1 adversarial QA
Verified: cargo test --workspace/clippy/fmt clean; corpus score 796/820;
whole-corpus idempotency + comment-preservation sweep clean; 476-case mutation
fuzz clean.
Targeted attacks: fed the statement-position ident [..] ... ident lookahead
every shape from the hit-list plus variants — x[i] y;, a [b] = c;,
foo [1] ;, x [i] = y;, arr[3] = val;, x[i][j] y;, x [7:0] y, z;,
x[7:0] y = 1;, x[a+b] y;, x [1] y [2];. Findings:
a [b] = c;,foo [1] ;,arr[3] = val;correctly stay ordinary statements (array-index assignment / index expression) — not reinterpreted as declarations.x[i] y;and friends (a trailing bare identifier before;with no assignment) are reinterpreted as declarations (space normalized tox [i] y;). This is not a corruption risk: under real SV grammar,ident [expr] ident;with no operator between the two identifiers has no valid non-declaration reading (bare juxtaposition isn't a legal expression/statement), so there is nothing else this string could have meant — the old behavior was simply "reject it," the new behavior is "accept the only grammatical reading." Confirmed idempotent (x[i] y;case,cmpclean across two passes).- No case found where the lookahead grabs something that was a genuinely valid other statement before this change.
Also exercised parse_opt_data_type's inline-aggregate acceptance with
DataType::extra via the corpus sweep and mutation fuzz (delete ;/paren,
comment-in-every-gap, fenced) over 3 samples from types_decls.cases — no
panics, no idempotency breaks.
No BLOCKING findings for this cluster.