No blocking findings over the 8 round-1 clusters: whole-corpus idempotency and comment-preservation sweep clean (796/820), 476-run mutation fuzz clean, no swallowed errors in the diff. Adds reindented_string_inside_a_with_block_is_rejected. Findings (non-blocking) are in each feature README's QA log; the printer fits() / Doc::Inline gap is fixed separately. Co-Authored-By: Claude Fable 5 <[email protected]>
11 KiB
dpi-export
Goal
Parse and format the three constructs the dpi-export corpus bucket is made
of: DPI imports (import "DPI-C" [context|pure] [c_name =] function|task ...;, IEEE 1800 §35.5.1–2), DPI exports (export "DPI-C" [c_name =] function|task name;, §35.5.4) and package re-exports (export pkg::*;,
§26.6). All three are one-line declarations that a real design writes at
package, module, generate-block or class scope; before this change every one
of them was a hard parse error, so 11 corpus files produced no output at all.
A DPI import is grammatically a function/task prototype with a linkage
prefix, so it is modelled as one — which means the argument list breaks with
the same rules as any other function header, and every consumer that already
understands ItemKind::Function sees a DPI-imported function without being
taught anything new.
Assumptions
importfollowed by a string literal is always a DPI import. No package is named by a string, so the one-token lookahead inparse_keyword_itemis unambiguous. Any linkage spec string is accepted, not just"DPI-C"—"DPI-SV"is legal and the LRM lets an implementation define others; the string is stored and reprinted verbatim, never interpreted.contextis not promoted to a keyword. It is a plain identifier everywhere else, and adding it to the keyword table would break any signal or port namedcontext. It is recognised positionally, and only when an=does not follow it —import "DPI-C" context = function void f();is a linkage name spelledcontext, not the property.purealready is a keyword (it is inMEMBER_QUALIFIERS), so the property check tests both spellings.exportwas already a keyword (token.rs'sis_keyword), so nothing in the lexer changed and no file's tokenization moved. Grepping the 820-file corpus for a bareexportused as an identifier found none: every hit is a suffix of a longer name (analysis_export,seq_item_export), which lexes as one identifier and is unaffected.- DPI arguments always carry a name. The LRM allows an unnamed formal
(
function void f(input int););parse_tf_portsrequires a name and this work did not change that, so the unnamed form is still a parse error. Zero corpus files write it. Fixing it is aparse_tf_portschange that would affect ordinary functions too, which is outside this feature's scope. - Import and export lists are printed on one line.
ItemKind::Importalready does this, and no corpusexportlist is long enough for a breakable group to earn its keep. A DPI import's argument list is a normal breakable group, because those do get long. - A DPI import declares a prototype, so
is_prototypeis true and there is noendfunction/endtask— the same shapeexternandpure virtualalready produced.
Handshakes
Consumed
Parser::parse_function_decl/parse_task_decl(renamed fromparse_function/parse_task, which now delegate) — the DPI import path reuses ANSI argument parsing, the return-type sniffing and the prototype handling wholesale.Parser::parse_package_paths— factored out ofparse_import_listsoexportcan share thepkg::item/pkg::*loop.importcalls it withallow_star_pkg: false; onlyexportadmits*::*.Fmt::tf_argsandFmt::delimitedfor the argument group.
Promised
FunctionDeclandTaskDeclgaineddpi: Option<DpiImport>. Both are constructed only inparser.rs, so nothing outside had to change; a consumer that ignores the field keeps its old behavior exactly.is_prototypeis now true for DPI imports as well asextern/pure virtual— its documented meaning ("body-less, noend*keyword") is unchanged.ItemKind::Export(ExportDecl)is a new variant. Exhaustive matches overItemKindlive invlog_semantic/src/bind.rs(one arm added, see below) andvlog_parser/tests/spans.rs(arms added).vlog_linter/src/visit.rshas a_ => {}fallback and needed no change.
Requests to other modules (not done here, deliberately)
- vlog_semantic:
ItemKind::Exportis bound as an opaque leaf. Two things abind.rsowner may want later: (a) a package re-export'spkg::itemhalves are real references and would resolve for go-to-definition with the samebind_import_pathanimportuses — but a re-export does not bring the name into the exporting scope, so reusingbind_import_pathas-is would also push a scope import, which is a semantics change I did not want to make unasked; (b) a DPI export'snamerefers to a function declared elsewhere in the same scope and could be ause_name. Note the*::*form has"*"as its package name, which no existing code expects. - vlog_semantic / vlog_linter: DPI-imported functions and tasks now arrive
as ordinary
ItemKind::Function/ItemKind::Taskwithstmtsempty andis_prototypeset, sobind_functionalready declares them as symbols — a DPI-imported function is a known name for go-to-definition with no further work. If a rule ever wants to treat them differently,decl.dpi.is_some()is the test. - dv-statements owner:
corpus/ibex/vendor/lowrisc_ip/dv/sv/csr_utils/ csr_utils_pkg.svwas in this bucket; itsexportat line 10 now parses and the file advanced toforeach (paths[0].slices[i])at line 290 — aforeachloop-variable list with an indexed expression, which is a dv-statements blocker, not mine.
Status / TODO
import "DPI-C" function <ret> <name> (<ansi args>);, including the form split across lines (env_dpi.sv:7) and the no-parens form (ibex_simple_system_cosim_checker.sv:29)contextandpureproperties (ascon_model_dpi_pkg.sv:8, crypto_dpi_prince_pkg.sv:14)chandleandlongint unsignedreturn types; arguments with no direction keyword; packed multi-dimensional and unsized-unpacked argument types (crypto_dpi_present_pkg.sv:12, ascon_model_dpi_pkg.sv:15)- DPI-imported
task c_identifier =linkage names on both import and export (zero corpus hits; same grammar, so supported and tested)export "DPI-C" function|task name;at module scope and inside a generate block under an`ifdef(ibex_simple_system.sv:369, ibex_if_stage.sv:378)export pkg::*;andexport pkg::a, pkg::b;(ibex_mem_intf_agent_pkg.sv:28, csr_utils_pkg.sv:10)export *::*;(LRM form, zero corpus hits)- Case table
crates/vlog_formatter/tests/cases/dpi_export.cases(19 cases: one per corpus shape, plus comments, averilog_format: offfence, the 100/101-column boundary, a class body, compilation-unit scope, and an ordinary packageimportnext to a DPI one) - Parser unit tests and a
tests/spans.rssource covering every shape - Unnamed DPI formals (
function void f(input int);) — see Assumptions; needs aparse_tf_portschange that touches ordinary functions
Work log
2026-08-20 — Implemented the whole bucket.
- Baseline:
{"passing":661,"total":820,"pct":80.6,"failures_by_category": {"interface":31,"bind":28,"dv-statements":25,"expressions":19, "directive-split":14,"assertions":13,"dpi-export":11,"types-decls":11, "invalid-or-fragment":3,"lex-macro-number":2,"not-verilog":1,"other":1}} - After:
{"passing":671,"total":820,"pct":81.8,"failures_by_category": {"interface":31,"bind":28,"dv-statements":26,"expressions":19, "directive-split":14,"assertions":13,"types-decls":11, "invalid-or-fragment":3,"lex-macro-number":2,"not-verilog":1,"other":1}}—dpi-exportis gone; the passing set is a strict superset of the baseline's (checked withcommon the two TSVs: zero regressions, ten new passes).dv-statements25 → 26 is csr_utils_pkg.sv arriving from this bucket at its next blocker, described in Handshakes.
Key decision — modelling. Two shapes were possible for a DPI import: a new
ItemKind::DpiImport node, or a FunctionDecl/TaskDecl with a linkage
field. I chose the field. A new item kind would have forced arms in every
exhaustive ItemKind match, and — worse — would have hidden DPI-imported
functions from bind_function, visit.rs's function walk and every rule that
looks for functions, so a DPI-imported function would not be a symbol. The
field costs one Option on two structs, both built in one file, and makes the
formatter's job a two-line prefix. Export is genuinely a different construct
(it declares nothing and has no arguments), so it is a new ItemKind.
Key decision — one ExportDecl enum, not two item kinds. export reads
its next token to decide: a string literal is DPI, anything else starts a
package path list. Keeping both under one variant keeps the new-arm cost at one
per exhaustive match.
Lexer. Untouched. export was already a keyword; context deliberately is
not (see Assumptions). chandle was already a type keyword, so
function chandle get; needed nothing special — the ordinary return-type path
handles it.
Formatting decisions. The linkage prefix is emitted as flat text in front
of the existing function/task header (Fmt::dpi_import_prefix), so a DPI
import lays out exactly like the prototype it is: header on one line, argument
list a breakable group that goes one-per-line when it does not fit. The
multi-line import "DPI-C" / function ... spelling the ibex DV files use
collapses onto one line, which is what every other multi-line header in vfmt
does. Exports print flat.
Safety net. verify.rs was not touched and did not need to be: every one
of these constructs is printed by re-emitting exactly the tokens the source
wrote (the linkage string verbatim, the property, the linkage name, the
keyword, the names, the paths), so the equivalence check passes on token
identity, not on forgiveness. No new normalization, so no masked-corruption
attack tests are owed under CLAUDE.md invariant 4.
Checks. cargo fmt --all clean, cargo clippy --all-targets clean,
cargo test green (509 formatter cases, spans, verification, linter, server).
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 (see item-misc log
for the shared methodology); 476-case mutation fuzz clean (0 panics/hangs/bad
exit codes/non-idempotent output).
Targeted attacks:
-
contextrecognized positionally, not as a keyword. Triedcontextused as an ordinary identifier in the position where it would be confused with the DPI property:import "DPI-C" function void context();(function namedcontext) formats correctly and is not swallowed by the positional check. Also exercised the real grammar order (context/purebefore the optionalc_identifier =, IEEE 1800 §35.5.2) —import "DPI-C" context mycid = function void f1();and thepurevariant both parse and round-trip. -
export *::*→ImportPathwith package"*".package p; export *::*; endpackageformats unchanged and is idempotent (target/release/vfmt --stdouttwice,cmpclean). -
is_prototypedoubling as "DPI import". No case found where this conflation produces a wrong-but-plausible read; every DPI import/export variant tried (context,pure,c_identifier =, task vs function, package export lists, package export with comma-separated names) round-trips or cleanly errors.
No BLOCKING findings for this cluster.