14 KiB
interfaces
Goal
Make interface … endinterface and the two constructs that only live
inside one — modport and clocking — first-class, structurally parsed
and canonically laid out, and make a virtual <iface> type reference
legal in every type position rather than only as a class property. An
interface header is the module header's grammar (IEEE 1800-2017 §25.3
vs §23.2.1) and an interface body is the module body's item list plus
those two extra items, so the whole feature is mostly a matter of
sharing the module machinery rather than writing a second copy of it.
At the start of this round interface was the corpus's top blocker at
31 of 820 files.
Assumptions
- An interface is a
Modulenode with a different keyword. There is noItemKind::Interface:ItemKind::Modulecarrieskw(module/macromodule/interface) andModule::end_kw()derivesendmodule/endinterfacefrom it. Everything that already walks a module — the formatter,fence.rs,range.rs,vlog_linter::visit,vlog_semantic::bind— therefore handles interfaces unchanged, and the parser's header and body code is literally the same code. The cost is that a consumer that wants to tell the two apart must readkw; that is the same thing it already had to do formacromodule. interface classis not an interface (IEEE 1800-2017 §8.26). It is a class-like construct with a different body grammar. This round left it as an "unsupported construct" parse error; amended 2026-09-02 byvendor-formal-grammar, it now parses — as anItemKind::Classwhoseprefixholds the wordinterface, never as aModule. The guard this round wrote inparse_keyword_item("interface" if !self.nth(1).is_kw("class")) is what routes it, and it is unchanged: aninterfacefollowed byclasshas always been something else, and now there is somewhere for it to go. Still 0 of 820 corpus files.program … endprogramwas out of scope for this round. Amended bytestbench-mopup: it now shares the module header/body grammar and is formatted structurally. No corpus file used it when this round was measured.- A modport port is a direction keyword plus the names it governs.
The source's grouping is preserved (
input valid, datais one group, not two ports), because regrouping it would be a token-order change for no gain. The explicit modport port (.name(expr)) is not supported. The modport method prototype (import task drive(int x)with a signature) was not either; amended 2026-09-02 byinterface-dpi-armsit is —ModportPort::prototypeholds the header, printed through the same printer a realtask/functionheader uses, and its name resolves to the interface's own subroutine. One narrowing survives: animport/exportgroup carries one prototype, not the LRM's comma-separated list ofmodport_tf_ports (import task t(), drive2still errors). Neither form occurs in the corpus. - A clocking skew is kept as text as written (
#2,#1step,negedge), not as an expression: it is a delay or an edge and lucisv never re-lays-out either. The#(min:typ:max)skew spelling is not supported (0 corpus uses). - A clocking item's optional
= expression(input data = top.dut.d;, IEEE 1800-2017 §14.4) was not supported in this round. Amended bytestbench-mopup: it is now structural. The original corpus had 0 uses. virtual/virtual interfacein a type position is recorded onDataType::virtas a one-byteVirtualKw, not as aString: everyExprcarries aDataTypethroughExprKind::Type, and aStringthere pushesDimKindpast clippy'slarge_enum_variantthreshold (measured:DimKind::Range192 → 208 bytes). A declaration keeps the prefix where it always did, inDataDecl::qualifiers, so the class-property path is untouched.- A
// verilog_format: offfence inside a modport or clocking body is not a fence scope, exactly as a fence inside a class body or a statement body is not (fence.rs::scan_nestedhas no arm for either). A fence in an interface body works, because that is a module body.
Handshakes
Consumed:
Parser::parse_module,parse_param_port_list,parse_port_list,parse_sens_list, and the wholeFmt::module/module_headlayout — all reused verbatim for interfaces.Fmt::delimited_danglingfor a modport's port list, so it breaks and aligns exactly like a header port list.
Promised / changed for others:
ast::Modulenow also models an interface.Module::kwmay be"interface";Module::end_kw()is the closing keyword. Any consumer that assumedItemKind::Modulemeansmodulemust readkw.ast::DataTypehas a new field,virt: Option<VirtualKw>.DataType::is_implicit()now returnsfalsewhen it is set.DataType::default()is unchanged, so constructing one still compiles.- Two new
ItemKindvariants,Modport(Vec<ModportDecl>)andClocking(ClockingDecl). Minimal arms were added where the match had to stay exhaustive:vlog_semantic::bind::bind_item(both are opaque leaves) andvlog_parser/tests/spans.rs.vlog_linter::visit,fence.rs,range.rsandlucisv_serverall have catch-all arms and needed no change. clockingandendclockingare now reserved words (token.rs). A design that used either as an identifier would change meaning; no corpus file does, and the passing set was verified to be a strict superset.module-filenamenow applies to interfaces and its message names the construct (interface \bus_if` does not match file name …`) instead of hard-coding "module". This is the intended behaviour: a one-interface file is looked up by its interface name exactly the way a one-module file is.
Requests to other owners (not done here):
Delivered 2026-09-01 —vlog_semantic:SymbolKind::Interface, plus modport and clocking symbols.docs/features/interface-semantics/README.md. An interface isSymbolKind::Interface, withLspKind::INTERFACEand the hover label "interface"; amodportisSymbolKind::Modportand a namedclockingblock isSymbolKind::Clocking; every signal, method and block name written inside either is a reference to the enclosing interface's own declaration; and an interface exports its signals, sovif.sigresolves across files. Go-to-definition on an interface instantiation still works — throughSymbolKind::is_instantiable()rather than through the shared kind.- expressions owner:
corpus/ibex/dv/formal/check/top.sv:432now parses past its interface/default clockingblockers and fails on(data_we_o -> …), the implication operator in an ordinary expression.corpus/ibex/vendor/lowrisc_ip/dv/sv/common_ifs/pins_if.sv:97likewise fails on the drive-strength specassign (pull0, pull1) x = …. Both are classifiedexpressionsbyscripts/score.sh. - whoever owns the
otherbucket:corpus/ibex/vendor/lowrisc_ip/dv/sv/dv_utils/dv_utils_pkg.sv:104now fails onfunction automatic int max(const ref int int_q[$]);— theconstqualifier on a task/function argument, whichParser::parse_tf_portsdoes not accept. program … endprogram: whoever picks it up gets it for two lines inparse_keyword_itemplus one inModule::end_kw, since the grammar is the one already implemented here.
Status / TODO
interface [import pkg::*;] [#(params)] [(ports)]; … endinterface [: label], sharing the module header and body parseimport pkg::*;between the name and the#(/(— verified it already worked for modules too (Module::imports), so nothing new was needed there; a module case was added to the case table- ANSI ports with no type (
inout clk,input rst_n), string parameters, multi-parameter headers endinterface : labelmodport a (…), b (…);—input/output/inout/ref/import/export/clockinggroups, several modports per declarationclocking name @(event); … endclocking [: label],default clocking, anonymousdefault clocking @(…), body-lessdefault clocking cb;- clocking items:
default input #s output #s;,input [skew] a, b;,output [skew] c;,inout d; virtual [interface] <iface>[#(…)]in a typedef base type and in a task/function argument (the declaration position already worked)module-filenamegeneralized to interfaces, with a test- 22 formatter cases in
crates/vlog_formatter/tests/cases/interfaces.casesplus 8 parser unit tests, covering every corpus shape cited above, comments in every position, averilog_format: offfence and the line-length boundary - Not done, and not planned here: explicit modport ports,
#(min:typ:max)skews (see Assumptions). Modport method prototypes landed 2026-09-02 ininterface-dpi-arms.programand clocking= expritems landed in §11 round 2;interface classlanded 2026-09-02 invendor-formal-grammar— as a class, which is what it is
Work log
2026-08-20 — dev
Baseline (cargo build --release && scripts/score.sh, at d488f0a):
{"passing":712,"total":820,"pct":86.8,"failures_by_category":{"interface":31,"dv-statements":26,"expressions":19,"directive-split":14,"types-decls":11,"invalid-or-fragment":3,"lex-macro-number":2,"not-verilog":1,"other":1}}
After:
{"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}}
+28 files, 0 lost — the passing set was verified to be a strict superset
by diffing the before/after .score-results.tsv by path. The
interface bucket is empty; the 3 files that did not reach pass
advanced to blockers owned by other categories (listed in Handshakes).
All 28 newly-formatting files were additionally round-tripped twice to
confirm idempotency on the real sources.
Key decisions:
- Reuse
Moduleinstead of adding anInterfacenode. The header grammar and the body item list are the same grammar; the only difference is the closing keyword.parse_moduletook anend_kwparameter andparse_keyword_itemgained one arm. This is what made the headerimport(the interesting bit of §25.3) work with no new code at all:Module::importsalready existed formodule m import pkg::*; (…), so both §23.2.1 and §25.3 are the same code path. A case for the module spelling was added to lock that in. modportport lists reusedelimited_dangling, so they collapse onto one line when they fit and break one direction group per line when they do not — the same rule every other bracketed list in lucisv follows.interface STREAM_DV's three modports collapse; a 100-column one breaks.- Clocking blocks are parsed structurally, not kept verbatim: the
item grammar is small and closed (
default input/output <skew>, and direction groups with an optional skew), so there was no reason to hand it to the verbatim path. One item per line, indented, closing keyword aligned with the opener. virtualmoved intoparse_opt_data_type. That one place is reached by the typedef base type, task/function arguments, struct members, ports and parameter ports, so a single change generalized it to every type position. The declaration path (parse_data_decl) is untouched: it consumesvirtualintoqualifiersbefore ever reachingparse_opt_data_type, so the class-property behaviour and its tests are bit-identical.DataType::virtis a one-byte enum, not aString. The first cut usedOption<String>and made clippy'slarge_enum_variantfire onDimKind(Rangegrew 192 → 208 bytes, past the 200-byte threshold) — everyExprcarries aDataType.Option<Box<str>>was still 208.VirtualKw(1 byte, with atext()accessor) fits in the existing padding and is honest: the prefix is one of exactly two spellings.
Deviations from the brief: none, except that default disable iff (…)
was looked for in the corpus (grep -rn 'default disable' corpus) and
does not occur in any .sv/.v file, so it was not implemented.
verify.rs was not touched: nothing here widens the safety net's
forgiveness, so no masked-corruption attack tests are owed.
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:
-
clocking/endclockingreserved globally.logic clocking; logic endclocking; initial clocking = 1;now cleanly errors ("expected identifier (foundclocking)"), exit 2, no output. This matches real IEEE 1800 (clockingis a reserved word there too), so not a regression in practice — real RTL essentially never uses these as identifiers. Confirmed clean, not corrupting. -
fence.rs/range.rs(--lines) on interfaces.--lines 3-3on a 6-item interface (ports/modport/clocking) reformats only the targeted line and leaves everything else byte-identical;// verilog_format: off/... onfences inside an interface correctly protect the fenced region while the rest of the interface still gets formatted. No issues found. -
module-filename lint firing on interfaces. Read
crates/vlog_linter/src/rules/module_filename.rs:ItemKind::Moduleis shared bymodule/interface(distinguished by.kw), and the rule requires exactly one such item in the file. Confirmed a file with both amodule foo;and aninterface bar_if;is silent (two "module-like" items → rule doesn't fire), and a loneinterface bus_if;in a mismatched-name file fires withinterface \bus_if` does not match file name ...(matches the new testan_interface_is_held_to_the_same_rule`). Correct.
No BLOCKING findings for this cluster.