Add concurrent assertions, sequence and property as verbatim items
assert/assume/cover/restrict property (...) [action block], optionally labeled, at item and statement position; sequence...endsequence and property...endproperty declarations. Verbatim pass-through like constraint/covergroup; verify.rs untouched, attack tests added. Coverage loop round 1, cluster 4: 699 -> 712 / 820 (85.2% -> 86.8%). Feature README: docs/features/assertions/README.md Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
f7c66c79bf
commit
e24d33afab
9 files changed
+938
-7
No files matched your search
@@ -345,6 +345,18 @@ Basic Verilog-2001 and the common synthesizable SystemVerilog subset:
|
||||
c { ... }` and `covergroup … endgroup` are **passed through verbatim** — two
|
||||
grammars with no layout convention worth inventing. See
|
||||
`docs/features/classes/README.md`
|
||||
- Concurrent assertions (IEEE 1800 §16): `assert`/`assume`/`cover`/`restrict
|
||||
property ( ... )` with an optional `label:` prefix and an action block
|
||||
(`else $error(...)`, `$info(...); else ...`, `else begin ... end`), wherever
|
||||
a module item or a statement can appear — module and package bodies,
|
||||
generate regions, `begin`/`end`, and at file scope. Plus `sequence ...
|
||||
endsequence` and `property ... endproperty` declarations. All of it is
|
||||
**passed through verbatim**, for the same reason `constraint` is: the
|
||||
property/sequence expression language (`|->`, `##[1:3]`, `throughout`,
|
||||
`disable iff`, `$rose`) is a second grammar with no layout convention worth
|
||||
inventing. Only the first line is re-indented to the item's level; the
|
||||
relative layout the source wrote is what survives. See
|
||||
`docs/features/assertions/README.md`
|
||||
- Dynamic types: queues (`string q[$]`, bounded `[$:N]`), dynamic arrays
|
||||
(`int a[]`), associative arrays (`[*]`, `[string]`, `[key_t]`) — in
|
||||
declarations, class properties, typedefs and function/task arguments; the
|
||||
@@ -443,10 +455,15 @@ corpus baseline this ordering comes from:
|
||||
7. ~~DPI~~ — **done**; see `docs/features/dpi-export/README.md`. DPI imports
|
||||
and exports plus package re-exports unblocked 10 corpus files and moved the
|
||||
parse rate from 80.6% to 81.8%; the 11th advanced to a `foreach` blocker in
|
||||
the dv-statements bucket. Still open in this item: concurrent assertions
|
||||
(`assert property`), non-simple casts
|
||||
8. Interfaces/modports, `case ... inside`, streaming operators, specify
|
||||
blocks, `let`/`checker`, sequences — rare in the corpus RTL
|
||||
the dv-statements bucket. Still open in this item: non-simple casts
|
||||
7b. ~~Concurrent assertions (`assert`/`assume`/`cover`/`restrict property`),
|
||||
`sequence`/`property` declarations~~ — **done**; see
|
||||
`docs/features/assertions/README.md`. Unblocked all 13 files of the
|
||||
`assertions` bucket and moved the parse rate from 85.2% to 86.8%.
|
||||
`picorv32.v` — 3000 lines of Verilog-2001, blocked on `restrict property`
|
||||
since item 6 — now formats end to end
|
||||
8. Interfaces/modports/clocking blocks, streaming operators, specify blocks,
|
||||
`let`/`checker` — rare in the corpus RTL
|
||||
|
||||
Like ruff, `vfmt` refuses to output anything for a file it cannot fully
|
||||
parse, so it can never corrupt code.
|
||||
|
||||
@@ -2380,6 +2380,8 @@ impl<'a> Fmt<'a> {
|
||||
// so the match stays total.
|
||||
StmtKind::Error(d) => self.raw_text(d),
|
||||
StmtKind::MacroStmt(m) => self.macro_call(m),
|
||||
// A concurrent assertion: verbatim source, like its item twin.
|
||||
StmtKind::Verbatim(raw) => self.raw_text(raw),
|
||||
StmtKind::Assert { kw, cond, then, els } => {
|
||||
let mut docs = vec![text(format!("{kw} ")), self.parens(cond)];
|
||||
match (then, els) {
|
||||
|
||||
@@ -0,0 +1,267 @@
|
||||
# concurrent assertions at module scope, one per line
|
||||
# corpus/common_cells/test/cdc_fifo_tb.sv:42-45
|
||||
module m;
|
||||
assert property (@(posedge src_clk_i) !$isunknown(src_valid_i) && !$isunknown(src_ready_o));
|
||||
assert property (@(posedge dst_clk_i) dst_valid_o |-> !$isunknown(dst_data_o));
|
||||
endmodule
|
||||
----
|
||||
module m;
|
||||
assert property (@(posedge src_clk_i) !$isunknown(src_valid_i) && !$isunknown(src_ready_o));
|
||||
assert property (@(posedge dst_clk_i) dst_valid_o |-> !$isunknown(dst_data_o));
|
||||
endmodule
|
||||
====
|
||||
# `assume property` with the clocking event inside the parens
|
||||
# corpus/common_cells/formal/counter_properties.sv:38
|
||||
module counter_properties;
|
||||
assume property (@(posedge clk_i) (!init) |-> !rst_ni);
|
||||
endmodule
|
||||
----
|
||||
module counter_properties;
|
||||
assume property (@(posedge clk_i) (!init) |-> !rst_ni);
|
||||
endmodule
|
||||
====
|
||||
# a multi-line property spec keeps its own line structure, re-indented as a
|
||||
# whole -- exactly what a `constraint` block does
|
||||
# corpus/common_cells/formal/counter_properties.sv:48-50
|
||||
module counter_properties;
|
||||
assert property (@(posedge clk_i)
|
||||
disable iff (!rst_ni)
|
||||
(count_up && !resetting) |=> q_o == $past(q_o) + {{WIDTH-1{1'b0}}, 1'b1});
|
||||
endmodule
|
||||
----
|
||||
module counter_properties;
|
||||
assert property (@(posedge clk_i)
|
||||
disable iff (!rst_ni)
|
||||
(count_up && !resetting) |=> q_o == $past(q_o) + {{WIDTH-1{1'b0}}, 1'b1});
|
||||
endmodule
|
||||
====
|
||||
# `cover property` and `restrict property`; `restrict` is not a lexer keyword,
|
||||
# it is recognised by the `property` that follows it
|
||||
# corpus/picorv32/picorv32.v:2109,2112
|
||||
module picorv32;
|
||||
cover property (@(posedge clk) mem_valid);
|
||||
restrict property (|last_mem_nowait || mem_ready || !mem_valid);
|
||||
restrict property (resetn != $initstate);
|
||||
endmodule
|
||||
----
|
||||
module picorv32;
|
||||
cover property (@(posedge clk) mem_valid);
|
||||
restrict property (|last_mem_nowait || mem_ready || !mem_valid);
|
||||
restrict property (resetn != $initstate);
|
||||
endmodule
|
||||
====
|
||||
# a label before the keyword, at file scope
|
||||
# corpus/ibex/dv/formal/check/protocol/irqs.sv:12-13
|
||||
NoNMI: assume property (~irq_nm_i);
|
||||
NoFastIRQ: assume property (~(|irq_fast_i));
|
||||
----
|
||||
NoNMI: assume property (~irq_nm_i);
|
||||
NoFastIRQ: assume property (~(|irq_fast_i));
|
||||
====
|
||||
# a labeled assertion whose property spec spans lines
|
||||
# corpus/ibex/dv/formal/check/peek/mem.sv:32-34
|
||||
LoadMemEarlyResp: assume property (
|
||||
early_resp |-> data_rdata_i == spec_mem_read_fst_rdata
|
||||
);
|
||||
----
|
||||
LoadMemEarlyResp: assume property (
|
||||
early_resp |-> data_rdata_i == spec_mem_read_fst_rdata
|
||||
);
|
||||
====
|
||||
# an `else` action block, at item position inside a generate `begin`
|
||||
# corpus/common_cells/test/fifo_tb.sv:155-156
|
||||
module fifo_tb;
|
||||
if (FALL_THROUGH) begin
|
||||
assert property (@(posedge clk_i) ((empty & ~push) ##1 push) |-> rdata == wdata)
|
||||
else $error("Input did not fall through");
|
||||
end
|
||||
endmodule
|
||||
----
|
||||
module fifo_tb;
|
||||
if (FALL_THROUGH) begin
|
||||
assert property (@(posedge clk_i) ((empty & ~push) ##1 push) |-> rdata == wdata)
|
||||
else $error("Input did not fall through");
|
||||
end
|
||||
endmodule
|
||||
====
|
||||
# label plus `else` action, inside a generate `for`
|
||||
# corpus/common_cells/test/clk_int_div_static_tb.sv:62-63
|
||||
module clk_int_div_static_tb;
|
||||
for (genvar i = 1; i < MaxClkDiv; i++) begin : gen_clk_divs
|
||||
assert_period_period: assert property (@(posedge clk_out[i]) T_clk(TClkIn*i)) else
|
||||
$error("Output period of div %d clock is incorrect.", i);
|
||||
end
|
||||
endmodule
|
||||
----
|
||||
module clk_int_div_static_tb;
|
||||
for (genvar i = 1; i < MaxClkDiv; i++) begin : gen_clk_divs
|
||||
assert_period_period: assert property (@(posedge clk_out[i]) T_clk(TClkIn*i)) else
|
||||
$error("Output period of div %d clock is incorrect.", i);
|
||||
end
|
||||
endmodule
|
||||
====
|
||||
# both halves of an action block: pass statement, then `else`
|
||||
module m;
|
||||
assert property (@(posedge clk) w) $info("pass"); else $error("fail");
|
||||
endmodule
|
||||
----
|
||||
module m;
|
||||
assert property (@(posedge clk) w) $info("pass"); else $error("fail");
|
||||
endmodule
|
||||
====
|
||||
# an action block written as a `begin`/`end` block, with no trailing `;`
|
||||
module m;
|
||||
assert property (@(posedge clk) v) else begin
|
||||
$error("in a block");
|
||||
end
|
||||
wire w;
|
||||
endmodule
|
||||
----
|
||||
module m;
|
||||
assert property (@(posedge clk) v) else begin
|
||||
$error("in a block");
|
||||
end
|
||||
wire w;
|
||||
endmodule
|
||||
====
|
||||
# `sequence ... endsequence` declarations
|
||||
# corpus/ibex/vendor/lowrisc_ip/ip/prim/rtl/prim_alert_sender.sv:305-307
|
||||
module prim_alert_sender;
|
||||
if (AsyncOn) begin : gen_async_assert
|
||||
sequence PingSigInt_S;
|
||||
alert_rx_i.ping_p == alert_rx_i.ping_n [*2];
|
||||
endsequence
|
||||
end
|
||||
endmodule
|
||||
----
|
||||
module prim_alert_sender;
|
||||
if (AsyncOn) begin : gen_async_assert
|
||||
sequence PingSigInt_S;
|
||||
alert_rx_i.ping_p == alert_rx_i.ping_n [*2];
|
||||
endsequence
|
||||
end
|
||||
endmodule
|
||||
====
|
||||
# a `property` declaration with arguments, local variables and a `: label`
|
||||
# corpus/common_cells/test/clk_int_div_static_tb.sv:40-47
|
||||
module clk_int_div_static_tb;
|
||||
property T_clk(real clk_period);
|
||||
realtime current_time;
|
||||
realtime actual_period;
|
||||
disable iff (!rstn || !enable)
|
||||
(('1, current_time = $realtime)) |=>
|
||||
('1, actual_period = $realtime - current_time);
|
||||
endproperty : T_clk
|
||||
endmodule
|
||||
----
|
||||
module clk_int_div_static_tb;
|
||||
property T_clk(real clk_period);
|
||||
realtime current_time;
|
||||
realtime actual_period;
|
||||
disable iff (!rstn || !enable)
|
||||
(('1, current_time = $realtime)) |=>
|
||||
('1, actual_period = $realtime - current_time);
|
||||
endproperty : T_clk
|
||||
endmodule
|
||||
====
|
||||
# statement position: a concurrent assertion is legal wherever a statement is
|
||||
module m;
|
||||
initial begin
|
||||
assert property (@(posedge clk) a |-> b) else $error("bad");
|
||||
x = 1;
|
||||
end
|
||||
always @(posedge clk) begin
|
||||
cover property (@(posedge clk) c);
|
||||
end
|
||||
endmodule
|
||||
----
|
||||
module m;
|
||||
initial begin
|
||||
assert property (@(posedge clk) a |-> b) else $error("bad");
|
||||
x = 1;
|
||||
end
|
||||
always @(posedge clk) begin
|
||||
cover property (@(posedge clk) c);
|
||||
end
|
||||
endmodule
|
||||
====
|
||||
# the immediate assertion is untouched: no `property`, so it keeps its own
|
||||
# statement node and its canonical layout
|
||||
module m;
|
||||
always_comb begin
|
||||
assert(x==1) else $error("immediate still works");
|
||||
end
|
||||
endmodule
|
||||
----
|
||||
module m;
|
||||
always_comb begin
|
||||
assert (x == 1) else $error("immediate still works");
|
||||
end
|
||||
endmodule
|
||||
====
|
||||
# comments attach the ordinary way: one on the line before, one after the `;`
|
||||
module m;
|
||||
// the FIFO never reports unknown data
|
||||
assert property (@(posedge clk) q); // checked every cycle
|
||||
wire w;
|
||||
endmodule
|
||||
----
|
||||
module m;
|
||||
// the FIFO never reports unknown data
|
||||
assert property (@(posedge clk) q); // checked every cycle
|
||||
wire w;
|
||||
endmodule
|
||||
====
|
||||
# a comment written *inside* the captured span stays inside it, printed once
|
||||
module m;
|
||||
assert property (@(posedge clk)
|
||||
// only while enabled
|
||||
en |-> ready);
|
||||
endmodule
|
||||
----
|
||||
module m;
|
||||
assert property (@(posedge clk)
|
||||
// only while enabled
|
||||
en |-> ready);
|
||||
endmodule
|
||||
====
|
||||
# a `// verilog_format: off` fence still wins: every byte as written
|
||||
module m;
|
||||
// verilog_format: off
|
||||
assert property (@(posedge clk) a |-> b);
|
||||
// verilog_format: on
|
||||
assert property (@(posedge clk) c);
|
||||
endmodule
|
||||
----
|
||||
module m;
|
||||
// verilog_format: off
|
||||
assert property (@(posedge clk) a |-> b);
|
||||
// verilog_format: on
|
||||
assert property (@(posedge clk) c);
|
||||
endmodule
|
||||
====
|
||||
# a string literal carrying a line break through an action block is emitted
|
||||
# byte for byte -- its leading whitespace is data, not layout, so the block is
|
||||
# not re-indented at all (the same rule `constraint` blocks follow)
|
||||
module m;
|
||||
assert property (@(posedge clk) a |-> b)
|
||||
else $error("line one
|
||||
line two indented");
|
||||
endmodule
|
||||
----
|
||||
module m;
|
||||
assert property (@(posedge clk) a |-> b)
|
||||
else $error("line one
|
||||
line two indented");
|
||||
endmodule
|
||||
====
|
||||
# a property spec far past the line limit is *not* broken: the property
|
||||
# expression is a grammar vfmt does not model, so it is reproduced as written
|
||||
module m;
|
||||
assert property (@(posedge clk_i) disable iff (!rst_ni) some_very_long_signal_name_here |-> ##[1:3] another_quite_long_signal_name);
|
||||
endmodule
|
||||
----
|
||||
module m;
|
||||
assert property (@(posedge clk_i) disable iff (!rst_ni) some_very_long_signal_name_here |-> ##[1:3] another_quite_long_signal_name);
|
||||
endmodule
|
||||
====
|
||||
@@ -947,3 +947,104 @@ fn a_reindented_dynamic_type_declaration_is_accepted() {
|
||||
let output = "class c;\n string q [$] = {};\n rand int offset [];\nendclass\n";
|
||||
verify_equivalence(input, output).expect("whitespace is not part of the token stream");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Verbatim concurrent assertions (`docs/features/assertions/README.md`).
|
||||
//
|
||||
// Assertions reuse the class round's verbatim capture: no normalization was
|
||||
// added to `verify.rs` for them, so these are the invariant-#4 pairs proving
|
||||
// the net refuses a real change inside an assertion rather than forgiving it
|
||||
// as "just re-indentation".
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn a_concurrent_assertion_may_be_reindented() {
|
||||
let input =
|
||||
"module m;\nassert property (@(posedge clk)\ndisable iff (!rst_n)\na |-> b);\nendmodule\n";
|
||||
let output = "module m;\n assert property (@(posedge clk)\n disable iff (!rst_n)\n a |-> b);\nendmodule\n";
|
||||
verify_equivalence(input, output).expect("only per-line indentation changed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_changed_assertion_operator_is_rejected() {
|
||||
let input = "module m;\n assert property (@(posedge clk) a |-> b);\nendmodule\n";
|
||||
let output = "module m;\n assert property (@(posedge clk) a |=> b);\nendmodule\n";
|
||||
expect_divergence(input, output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_changed_assertion_delay_range_is_rejected() {
|
||||
let input = "module m;\n assert property (@(posedge clk) a |-> ##[1:3] b);\nendmodule\n";
|
||||
let output = "module m;\n assert property (@(posedge clk) a |-> ##[1:4] b);\nendmodule\n";
|
||||
expect_divergence(input, output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dropped_disable_iff_clause_is_rejected() {
|
||||
let input =
|
||||
"module m;\n assert property (@(posedge clk) disable iff (!rst_n) a |-> b);\nendmodule\n";
|
||||
let output = "module m;\n assert property (@(posedge clk) a |-> b);\nendmodule\n";
|
||||
expect_divergence(input, output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dropped_assertion_action_block_is_rejected() {
|
||||
let input = "module m;\n assert property (@(posedge clk) a) else $error(\"no\");\nendmodule\n";
|
||||
let output = "module m;\n assert property (@(posedge clk) a);\nendmodule\n";
|
||||
expect_divergence(input, output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dropped_assertion_label_is_rejected() {
|
||||
let input = "module m;\n NoNMI: assume property (~irq_nm_i);\nendmodule\n";
|
||||
let output = "module m;\n assume property (~irq_nm_i);\nendmodule\n";
|
||||
expect_divergence(input, output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dropped_comment_inside_an_assertion_is_rejected() {
|
||||
let input = "module m;\n assert property (@(posedge clk)\n // only while enabled\n en |-> ready);\nendmodule\n";
|
||||
let output = "module m;\n assert property (@(posedge clk)\n en |-> ready);\nendmodule\n";
|
||||
expect_divergence(input, output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_reindented_string_inside_an_assertion_action_is_rejected() {
|
||||
let input = "module m;\n assert property (a) else $error(\"one\n two\");\nendmodule\n";
|
||||
let output = "module m;\n assert property (a) else $error(\"one\n two\");\nendmodule\n";
|
||||
expect_divergence(input, output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_assertion_carrying_a_multiline_string_is_left_alone_end_to_end() {
|
||||
// The formatter must not move those bytes at all: `raw_text` emits a
|
||||
// token whose line break falls inside a string verbatim.
|
||||
let input = "module m;\nassert property (@(posedge clk) a |-> b)\nelse $error(\"line one\n line two indented\");\nendmodule\n";
|
||||
let output = format_source(input, &Config::default()).expect("must format");
|
||||
assert!(
|
||||
output.contains("\"line one\n line two indented\""),
|
||||
"the string's bytes changed:\n{output}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_changed_sequence_body_is_rejected() {
|
||||
let input = "module m;\n sequence s;\n a ##1 b;\n endsequence\nendmodule\n";
|
||||
let output = "module m;\n sequence s;\n a ##2 b;\n endsequence\nendmodule\n";
|
||||
expect_divergence(input, output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dropped_endproperty_label_is_rejected() {
|
||||
let input = "module m;\n property p;\n a |-> b;\n endproperty : p\nendmodule\n";
|
||||
let output = "module m;\n property p;\n a |-> b;\n endproperty\nendmodule\n";
|
||||
expect_divergence(input, output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_property_declarations_local_variable_may_not_be_dropped() {
|
||||
let input =
|
||||
"module m;\n property p;\n realtime t;\n a |-> b;\n endproperty\nendmodule\n";
|
||||
let output = "module m;\n property p;\n a |-> b;\n endproperty\nendmodule\n";
|
||||
expect_divergence(input, output);
|
||||
}
|
||||
@@ -233,8 +233,10 @@ pub enum ItemKind {
|
||||
/// A `class` / `virtual class` declaration and its body.
|
||||
Class(ClassDecl),
|
||||
/// A block vfmt deliberately does not model, kept byte-for-byte:
|
||||
/// `constraint c { ... }` and `covergroup ... endgroup`. See
|
||||
/// `docs/features/classes/README.md` for why each one is verbatim.
|
||||
/// `constraint c { ... }`, `covergroup ... endgroup`, a concurrent
|
||||
/// assertion (`assert property ( ... );`) and a `property`/`sequence`
|
||||
/// declaration. See `docs/features/classes/README.md` and
|
||||
/// `docs/features/assertions/README.md` for why each one is verbatim.
|
||||
Verbatim(RawText),
|
||||
Defparam(Vec<(Expr, Expr)>),
|
||||
/// Source that could not be parsed as an item, kept verbatim.
|
||||
@@ -999,6 +1001,11 @@ pub enum StmtKind {
|
||||
Directive(RawText),
|
||||
/// Macro invocation used as a statement.
|
||||
MacroStmt(MacroCall),
|
||||
/// A concurrent assertion written in statement position
|
||||
/// (`assert property ( ... ) else $error("...");` inside an `initial`),
|
||||
/// kept byte-for-byte. The statement-level twin of the assertion half of
|
||||
/// [`ItemKind::Verbatim`]; see `docs/features/assertions/README.md`.
|
||||
Verbatim(RawText),
|
||||
/// Immediate assertion: kept simple — `assert (expr) stmt else stmt;`
|
||||
Assert {
|
||||
kw: String,
|
||||
|
||||
@@ -1055,6 +1055,12 @@ impl<'a> Parser<'a> {
|
||||
TokenKind::Directive => Ok(ItemKind::Directive(self.take_raw_text())),
|
||||
TokenKind::Keyword => self.parse_keyword_item(),
|
||||
TokenKind::Ident if self.at_bind_directive() => self.parse_bind().map(ItemKind::Bind),
|
||||
// `NoNMI: assume property (...)` and `restrict property (...)`:
|
||||
// a label, or the non-keyword `restrict`, in front of a
|
||||
// concurrent assertion.
|
||||
TokenKind::Ident if self.at_concurrent_assertion() => {
|
||||
self.parse_concurrent_assertion().map(ItemKind::Verbatim)
|
||||
}
|
||||
TokenKind::Ident => self.parse_ident_item(),
|
||||
TokenKind::SystemIdent if ELAB_TASKS.contains(&t.text.as_str()) => {
|
||||
let call = self.parse_expr()?;
|
||||
@@ -1139,6 +1145,10 @@ impl<'a> Parser<'a> {
|
||||
"class" => self.parse_class().map(ItemKind::Class),
|
||||
"constraint" => self.parse_constraint().map(ItemKind::Verbatim),
|
||||
"covergroup" => self.parse_covergroup().map(ItemKind::Verbatim),
|
||||
"assert" | "assume" | "cover" if self.at_concurrent_assertion() => {
|
||||
self.parse_concurrent_assertion().map(ItemKind::Verbatim)
|
||||
}
|
||||
"property" | "sequence" => self.parse_property_decl().map(ItemKind::Verbatim),
|
||||
// A run of member qualifiers (`virtual`, `local rand`, `static`,
|
||||
// `pure virtual`, ...) does not say what it qualifies; the first
|
||||
// keyword past the run does. Nothing is consumed here, so each
|
||||
@@ -1504,6 +1514,125 @@ impl<'a> Parser<'a> {
|
||||
Ok(self.verbatim_since(start, col))
|
||||
}
|
||||
|
||||
/// True when the cursor opens a concurrent assertion (IEEE 1800 §16.14):
|
||||
/// `[label :] assert|assume|cover|restrict property ( ... )`.
|
||||
///
|
||||
/// The `property` keyword is what makes this unambiguous, and demanding
|
||||
/// it is what leaves the *immediate* assertion path (`assert (expr) ...`,
|
||||
/// which is a real statement node) exactly as it was. `restrict` is not a
|
||||
/// lexer keyword — it is an ordinary identifier everywhere else — so it is
|
||||
/// matched by text, which is safe for the same reason: no type or instance
|
||||
/// name can be followed by the `property` keyword.
|
||||
fn at_concurrent_assertion(&self) -> bool {
|
||||
let mut i = 0;
|
||||
if self.cur().kind == TokenKind::Ident && self.nth(1).is_sym(":") {
|
||||
i = 2;
|
||||
}
|
||||
let head = self.nth(i);
|
||||
let opens = head.is_kw("assert")
|
||||
|| head.is_kw("assume")
|
||||
|| head.is_kw("cover")
|
||||
|| (head.kind == TokenKind::Ident && head.text == "restrict");
|
||||
opens && self.nth(i + 1).is_kw("property")
|
||||
}
|
||||
|
||||
/// A concurrent assertion, kept as verbatim source.
|
||||
///
|
||||
/// `assert property (@(posedge clk) a |-> ##[1:3] b) else $error("...");`
|
||||
/// — the property expression is a grammar of its own (`|->`, `##[1:3]`,
|
||||
/// `throughout`, `disable iff`, `$rose`) that vfmt models none of, and
|
||||
/// there is no layout convention worth inventing for it, so the whole
|
||||
/// item is copied out of the source by span exactly as a `constraint` is.
|
||||
fn parse_concurrent_assertion(&mut self) -> PResult<RawText> {
|
||||
let start = self.here();
|
||||
let col = self.cur().col;
|
||||
if self.cur().kind == TokenKind::Ident && self.nth(1).is_sym(":") {
|
||||
self.bump();
|
||||
self.bump();
|
||||
}
|
||||
// `assert` / `assume` / `cover` / `restrict`.
|
||||
self.bump();
|
||||
self.expect_kw("property")?;
|
||||
self.expect_sym("(")?;
|
||||
self.skip_balanced("(", ")")?;
|
||||
self.skip_action_block()?;
|
||||
Ok(self.verbatim_since(start, col))
|
||||
}
|
||||
|
||||
/// The action block after a concurrent assertion's property spec: a bare
|
||||
/// `;`, a pass statement, an `else` fail statement, or both.
|
||||
fn skip_action_block(&mut self) -> PResult<()> {
|
||||
if self.eat_kw("else") {
|
||||
return self.skip_action_stmt();
|
||||
}
|
||||
self.skip_action_stmt()?;
|
||||
if self.eat_kw("else") {
|
||||
self.skip_action_stmt()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// One `statement_or_null` of an action block, skipped verbatim: a
|
||||
/// `begin ... end` block, or everything through the next `;`. Brackets are
|
||||
/// skipped as units so a `;` written inside one cannot end the scan early.
|
||||
fn skip_action_stmt(&mut self) -> PResult<()> {
|
||||
if self.cur().is_kw("begin") {
|
||||
self.bump();
|
||||
let mut depth = 1usize;
|
||||
while depth > 0 {
|
||||
if self.at_eof() {
|
||||
return self.error("expected `end`");
|
||||
}
|
||||
let t = self.cur();
|
||||
if t.is_kw("begin") {
|
||||
depth += 1;
|
||||
} else if t.is_kw("end") {
|
||||
depth -= 1;
|
||||
}
|
||||
self.bump();
|
||||
}
|
||||
self.parse_label()?;
|
||||
return Ok(());
|
||||
}
|
||||
loop {
|
||||
if self.at_eof() {
|
||||
return self.error("expected `;`");
|
||||
}
|
||||
let t = self.cur();
|
||||
if t.is_sym("(") {
|
||||
self.bump();
|
||||
self.skip_balanced("(", ")")?;
|
||||
} else if t.is_sym("[") {
|
||||
self.bump();
|
||||
self.skip_balanced("[", "]")?;
|
||||
} else if t.is_sym("{") {
|
||||
self.bump();
|
||||
self.skip_balanced("{", "}")?;
|
||||
} else if self.eat_sym(";") {
|
||||
return Ok(());
|
||||
} else {
|
||||
self.bump();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `property name [( ... )]; ... endproperty [: name]`, and its
|
||||
/// `sequence` / `endsequence` twin, kept as verbatim source for the reason
|
||||
/// [`Parser::parse_concurrent_assertion`] gives — the body is written in
|
||||
/// the same second grammar, with local variable declarations mixed in.
|
||||
fn parse_property_decl(&mut self) -> PResult<RawText> {
|
||||
let start = self.here();
|
||||
let col = self.cur().col;
|
||||
let end_kw = if self.cur().is_kw("sequence") { "endsequence" } else { "endproperty" };
|
||||
self.bump();
|
||||
while !self.at_eof() && !self.cur().is_kw(end_kw) {
|
||||
self.bump();
|
||||
}
|
||||
self.expect_closer(end_kw)?;
|
||||
self.parse_label()?;
|
||||
Ok(self.verbatim_since(start, col))
|
||||
}
|
||||
|
||||
/// True when the cursor opens a parameterized type's `#( ... )`.
|
||||
fn at_type_params(&self) -> bool {
|
||||
self.cur().is_sym("#") && self.nth(1).is_sym("(")
|
||||
@@ -2773,6 +2902,12 @@ impl<'a> Parser<'a> {
|
||||
if self.at_macro_item() || self.at_spaced_macro_call() {
|
||||
return Ok(StmtKind::MacroStmt(self.parse_macro_call()?));
|
||||
}
|
||||
// A concurrent assertion is legal wherever a statement is, and the
|
||||
// `property` keyword is what tells it apart from the immediate
|
||||
// `assert (expr)` handled below.
|
||||
if self.at_concurrent_assertion() {
|
||||
return Ok(StmtKind::Verbatim(self.parse_concurrent_assertion()?));
|
||||
}
|
||||
let t = self.cur();
|
||||
if t.kind == TokenKind::Directive {
|
||||
return Ok(StmtKind::Directive(self.take_raw_text()));
|
||||
@@ -4848,6 +4983,120 @@ mod tests {
|
||||
assert_eq!(items[0].meta.trailing.as_ref().expect("the comment survived").text, "// why");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Concurrent assertions (`docs/features/assertions/README.md`)
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn a_concurrent_assertion_is_captured_verbatim() {
|
||||
let src = "module m;\n assert property (@(posedge clk) a |-> ##[1:3] b);\nendmodule\n";
|
||||
let f = parse_ok(src);
|
||||
let ItemKind::Verbatim(raw) = &module_of(&f).items[0].kind else {
|
||||
panic!("expected a verbatim block")
|
||||
};
|
||||
assert_eq!(raw.text, "assert property (@(posedge clk) a |-> ##[1:3] b);");
|
||||
assert_eq!(raw.text, src[raw.span.as_range()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_concurrent_assertion_keyword_parses_at_item_position() {
|
||||
// `restrict` is not a lexer keyword — it reaches the item dispatch as
|
||||
// an identifier — so it is worth pinning next to the other three.
|
||||
for kw in ["assert", "assume", "cover", "restrict"] {
|
||||
let f = parse_ok(&format!("module m;\n {kw} property (a |-> b);\nendmodule\n"));
|
||||
assert!(
|
||||
matches!(module_of(&f).items[0].kind, ItemKind::Verbatim(_)),
|
||||
"`{kw} property` did not parse as a verbatim item"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_label_before_a_concurrent_assertion_is_part_of_the_capture() {
|
||||
let f = parse_ok("NoNMI: assume property (~irq_nm_i);\n");
|
||||
let ItemKind::Verbatim(raw) = &f.items[0].kind else { panic!("expected a verbatim block") };
|
||||
assert_eq!(raw.text, "NoNMI: assume property (~irq_nm_i);");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_assertion_action_block_is_part_of_the_capture() {
|
||||
let f = parse_ok("module m;\n assert property (a) else $error(\"no\");\nendmodule\n");
|
||||
let ItemKind::Verbatim(raw) = &module_of(&f).items[0].kind else {
|
||||
panic!("expected a verbatim block")
|
||||
};
|
||||
assert_eq!(raw.text, "assert property (a) else $error(\"no\");");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_assertion_action_block_may_be_a_begin_end_block() {
|
||||
let src = "module m;\n assert property (a) else begin\n $error(\"no\");\n end\n wire w;\nendmodule\n";
|
||||
let f = parse_ok(src);
|
||||
let items = &module_of(&f).items;
|
||||
let ItemKind::Verbatim(raw) = &items[0].kind else { panic!("expected a verbatim block") };
|
||||
assert_eq!(raw.text, "assert property (a) else begin\n $error(\"no\");\n end");
|
||||
assert!(matches!(items[1].kind, ItemKind::DataDecl(_)), "the next item was swallowed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn both_halves_of_an_action_block_are_captured() {
|
||||
let f = parse_ok(
|
||||
"module m;\n assert property (a) $info(\"y\"); else $error(\"n\");\n wire w;\nendmodule\n",
|
||||
);
|
||||
let items = &module_of(&f).items;
|
||||
let ItemKind::Verbatim(raw) = &items[0].kind else { panic!("expected a verbatim block") };
|
||||
assert_eq!(raw.text, "assert property (a) $info(\"y\"); else $error(\"n\");");
|
||||
assert!(matches!(items[1].kind, ItemKind::DataDecl(_)), "the next item was swallowed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_concurrent_assertion_also_parses_in_statement_position() {
|
||||
let f = parse_ok(
|
||||
"module m;\n initial begin\n assert property (@(posedge clk) a |-> b);\n x = 1;\n end\nendmodule\n",
|
||||
);
|
||||
let ItemKind::Initial(stmt) = &module_of(&f).items[0].kind else {
|
||||
panic!("expected an initial block")
|
||||
};
|
||||
let StmtKind::Block { stmts, .. } = &stmt.kind else { panic!("expected a block") };
|
||||
let StmtKind::Verbatim(raw) = &stmts[0].kind else {
|
||||
panic!("expected a verbatim statement, got {:?}", stmts[0].kind)
|
||||
};
|
||||
assert_eq!(raw.text, "assert property (@(posedge clk) a |-> b);");
|
||||
assert!(matches!(stmts[1].kind, StmtKind::Assign { .. }), "the next statement was lost");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_immediate_assertion_still_takes_the_statement_path() {
|
||||
// No `property` keyword, so nothing about the verbatim capture may
|
||||
// pre-empt the structural immediate-assertion node.
|
||||
let f = parse_ok("module m;\n initial assert (x == 1) else $error(\"no\");\nendmodule\n");
|
||||
let ItemKind::Initial(stmt) = &module_of(&f).items[0].kind else {
|
||||
panic!("expected an initial block")
|
||||
};
|
||||
assert!(matches!(stmt.kind, StmtKind::Assert { .. }), "got {:?}", stmt.kind);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn property_and_sequence_declarations_are_captured_verbatim() {
|
||||
let src =
|
||||
"module m;\n property p(int w);\n realtime t;\n a |-> b;\n endproperty : p\n \
|
||||
sequence s;\n a ##1 b;\n endsequence\nendmodule\n";
|
||||
let f = parse_ok(src);
|
||||
let items = &module_of(&f).items;
|
||||
let ItemKind::Verbatim(p) = &items[0].kind else { panic!("expected a verbatim block") };
|
||||
assert_eq!(p.text, "property p(int w);\n realtime t;\n a |-> b;\n endproperty : p");
|
||||
let ItemKind::Verbatim(s) = &items[1].kind else { panic!("expected a verbatim block") };
|
||||
assert_eq!(s.text, "sequence s;\n a ##1 b;\n endsequence");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unclosed_property_declaration_is_an_error_not_a_swallowed_file() {
|
||||
assert!(
|
||||
parse_err("module m;\n property p;\n a |-> b;\nendmodule\n")
|
||||
.contains("expected `endproperty`"),
|
||||
"an unterminated property must be reported"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_parameterized_type_is_a_declaration_and_a_parameterized_module_is_an_instance() {
|
||||
let f =
|
||||
|
||||
@@ -760,7 +760,9 @@ fn check_stmt(src: &str, stmt: &Stmt, parent: TextRange) {
|
||||
StmtKind::ParamDecl(p) => check_declarators(src, &p.declarators, here),
|
||||
StmtKind::PortDecl(p) => check_declarators(src, &p.declarators, here),
|
||||
StmtKind::Return(e) => check_opt_expr(src, e.as_ref(), here),
|
||||
StmtKind::Directive(raw) | StmtKind::MacroStmt(MacroCall { raw, .. }) => {
|
||||
StmtKind::Directive(raw)
|
||||
| StmtKind::Verbatim(raw)
|
||||
| StmtKind::MacroStmt(MacroCall { raw, .. }) => {
|
||||
assert_inside(src, "raw text", raw.span, here);
|
||||
}
|
||||
StmtKind::Assert { cond, then, els, .. } => {
|
||||
|
||||
@@ -952,6 +952,9 @@ impl<'a> Binder<'a> {
|
||||
| StmtKind::Directive(_)
|
||||
| StmtKind::MacroStmt(_)
|
||||
| StmtKind::Null
|
||||
// Verbatim source: opaque to name resolution, exactly as the
|
||||
// item-level `ItemKind::Verbatim` is.
|
||||
| StmtKind::Verbatim(_)
|
||||
| StmtKind::Error(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,283 @@
|
||||
# assertions
|
||||
|
||||
## Goal
|
||||
|
||||
Parse and emit SystemVerilog **concurrent assertions** (IEEE 1800-2017 §16)
|
||||
and the two declarations they use, so the `assertions` bucket of
|
||||
`scripts/score.sh` — 13 corpus files, the fourth-largest blocker at the start
|
||||
of this round — stops being a parse error. The lead's decision, taken before
|
||||
any code was written, is that all of it is **verbatim pass-through**, exactly
|
||||
like `constraint { ... }` and `covergroup ... endgroup` already are: the
|
||||
property/sequence expression grammar (`|->`, `|=>`, `##[1:3]`, `[*2]`,
|
||||
`throughout`, `disable iff`, `$rose`, `$past`) is a second language that vfmt
|
||||
models nowhere else, and there is no layout convention worth inventing for it.
|
||||
The payoff of a hand-rolled property grammar would be zero; the risk — a new
|
||||
place to drop a token — would be real.
|
||||
|
||||
## What is captured, and where the evidence is
|
||||
|
||||
Every shape below is taken from a corpus file, named so the next reader can
|
||||
check the evidence rather than the reasoning.
|
||||
|
||||
| shape | corpus evidence |
|
||||
|---|---|
|
||||
| `assert property ( ... );` at module scope | `common_cells/test/cdc_fifo_tb.sv:42-45`, `cdc_fifo_clearable_tb.sv:47-50` |
|
||||
| `assume property (@(posedge clk) ... );` | `common_cells/formal/counter_properties.sv:38`, `fall_through_register_properties.sv:36`, `fifo_v3_properties.sv:61` |
|
||||
| a property spec spanning several lines (`disable iff` on its own line) | `counter_properties.sv:48-50` |
|
||||
| `restrict property ( ... );` | `picorv32/picorv32.v:2109,2112` |
|
||||
| `cover property ( ... );` | taken with the other three — one keyword list, `picorv32.v:2115` has it commented out |
|
||||
| `<label>: assume property ( ... );` at **file** scope | `ibex/dv/formal/check/protocol/irqs.sv:12-13` |
|
||||
| a labeled assertion whose spec spans lines | `ibex/dv/formal/check/peek/mem.sv:32-34` |
|
||||
| `assert property ( ... ) else $error("...");` at item position inside a generate `begin` | `common_cells/test/fifo_tb.sv:155-156` |
|
||||
| label + `else` action, inside a generate `for` | `common_cells/test/clk_int_div_static_tb.sv:62-63` |
|
||||
| `sequence <name>; ... endsequence` | `lowrisc_ip/ip/prim/rtl/prim_alert_sender.sv:305-310`, `prim_alert_rxtx_assert_fpv.sv:58`, `prim_alert_rxtx_async_assert_fpv.sv:91` |
|
||||
| `property <name>(args); <local decls> ... endproperty [: name]` | `common_cells/test/clk_int_div_static_tb.sv:40-47` |
|
||||
|
||||
Taken for completeness, without corpus evidence, because they are the rest of
|
||||
the same two grammar rules and cost nothing:
|
||||
|
||||
- statement position (`assert property (...)` inside an `initial begin`) —
|
||||
concurrent assertions are legal wherever a statement is. The one corpus
|
||||
occurrence that *looked* like this (`fifo_tb.sv:155`) turned out to sit in a
|
||||
generate `if ... begin`, i.e. item position; the statement path is pinned by
|
||||
a case and a parser test instead.
|
||||
- the pass half of an action block (`assert property (p) $info("y"); else
|
||||
$error("n");`) and a `begin ... end` action block.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **The `property` keyword is the whole disambiguator.** `at_concurrent_
|
||||
assertion` fires only on `[ident :] (assert|assume|cover|restrict)
|
||||
property`. That is what keeps the *immediate* assertion path — `assert
|
||||
(expr) stmt else stmt;`, a real `StmtKind::Assert` node with canonical
|
||||
layout — byte-for-byte unchanged, and it is why a label in front of an
|
||||
immediate assertion (`check_decode: assert (x) ...`, the dv-statements
|
||||
cluster's problem) is not pre-empted here.
|
||||
- **`restrict` is deliberately *not* promoted to a lexer keyword.** It reaches
|
||||
the item dispatch as an ordinary identifier and is matched by text, only
|
||||
when the very next token is the `property` keyword. Adding it to
|
||||
`token.rs`'s keyword list would have changed the lexing of every
|
||||
Verilog-2001 file that uses `restrict` as a signal or type name, for no gain.
|
||||
- **`expect property` and `cover sequence` are not implemented.** Neither
|
||||
appears in the corpus, and both would be a guess at an action-block shape
|
||||
nothing exercises. They still error out, as before.
|
||||
- **`default clocking` / `default disable iff` are not implemented.** Clocking
|
||||
blocks are the `interface` cluster's (`ibex/dv/formal/check/top.sv:143` is
|
||||
categorized there). `default` at item position is left untouched by this
|
||||
work.
|
||||
- **A verbatim block's *relative* layout is what survives, not its absolute
|
||||
indent.** Only the first line is re-indented to the item's level; the
|
||||
continuation lines are dedented by the block's original start column and the
|
||||
printer indents them back — the same fixed-point trick `constraint` uses
|
||||
(`Fmt::raw_lines`). A property spec written entirely at column 1 comes out
|
||||
entirely at the item's indent, relative shape intact.
|
||||
- **A verbatim block is never reflowed to the line limit.** A 130-column
|
||||
property expression stays 130 columns. There is no grammar to break it on.
|
||||
Pinned by the last case in `assertions.cases`.
|
||||
|
||||
## Handshakes
|
||||
|
||||
### Consumed
|
||||
|
||||
- `Parser::verbatim_since(start, col)` (from the classes round) — slices
|
||||
`source[span]` into a `RawText` and drops the comments the capture
|
||||
swallowed, so a comment *inside* an assertion prints once and a comment
|
||||
*after* its `;` stays pending for the next node. Used unchanged.
|
||||
- `Parser::skip_balanced(open, close)` — used for the property spec's parens
|
||||
and for brackets inside an action block.
|
||||
- `Fmt::raw_text(raw)` — prints a `RawText` re-indented, **except** when
|
||||
`crosses_line_inside_string` says a line break falls inside a string
|
||||
literal, in which case the text is emitted as one `Doc::Text` and the
|
||||
printer copies the newlines through without touching them. This is what
|
||||
makes a multi-line string inside `else $error("...")` byte-identical, and it
|
||||
needed no change. `verify.rs::line_starts_inside_string` is the shared
|
||||
reading of "which line breaks are data" that the safety net uses on the
|
||||
other side of the same question.
|
||||
|
||||
### Promised / changed for others
|
||||
|
||||
- **New AST variant `StmtKind::Verbatim(RawText)`** (`vlog_parser/src/ast.rs`)
|
||||
— the statement-level twin of `ItemKind::Verbatim`, for a concurrent
|
||||
assertion in statement position. Minimal arms added:
|
||||
- `vlog_formatter/src/format.rs`: `StmtKind::Verbatim(raw) =>
|
||||
self.raw_text(raw)`.
|
||||
- `vlog_semantic/src/bind.rs:955`: folded into the no-op group next to
|
||||
`StmtKind::Directive`/`MacroStmt` — verbatim source is opaque to name
|
||||
resolution, exactly as `ItemKind::Verbatim` already is at
|
||||
`bind.rs:306`.
|
||||
- `vlog_parser/tests/spans.rs`: folded into the `Directive | MacroStmt`
|
||||
raw-text arm.
|
||||
- `vlog_linter/src/visit.rs` needed **no** arm — `walk_stmts` ends in a
|
||||
`_ => {}`.
|
||||
- **`ItemKind::Verbatim` gained a third and fourth producer** (concurrent
|
||||
assertions, `property`/`sequence` declarations). No signature changed; every
|
||||
existing consumer already treats it as an opaque leaf.
|
||||
- **No change to `crates/vlog_formatter/src/verify.rs`.** No forgiveness was
|
||||
widened. The attack tests below exist anyway, per CLAUDE.md invariant #4,
|
||||
because the capture is forgiveness-*adjacent*: a verbatim block is re-lexed
|
||||
as ordinary tokens on both sides, so every token inside it must still match.
|
||||
|
||||
### Requests to other clusters
|
||||
|
||||
- **interface cluster**: `assert property` inside an `interface` body cannot
|
||||
be tested yet — `interface` itself is still a parse error
|
||||
(`unsupported construct starting with keyword \`interface\``). Once an
|
||||
interface body parses through the ordinary item path
|
||||
(`Parser::parse_item_kind`), concurrent assertions inside it work with no
|
||||
further change, because that is the same dispatch module bodies use. Worth
|
||||
one case in `interface.cases` when that lands.
|
||||
- **dv-statements cluster**: if you add a general `label:` prefix for
|
||||
*statements*, note that `Parser::parse_stmt_kind` already consults
|
||||
`at_concurrent_assertion()` before the keyword dispatch, and that check
|
||||
consumes `ident :` itself when a `property` keyword follows. Keep the
|
||||
general label path from firing on `[label:] assert property`, or the
|
||||
assertion will be split in two.
|
||||
- **linter**: AST-driven rules do not descend into a verbatim assertion — a
|
||||
`case` written inside an action block's `begin ... end` would not be seen by
|
||||
`case-missing-default`. This is the pre-existing posture for `constraint`
|
||||
and `covergroup` and is left as is; the text-driven rules (`no-tabs`,
|
||||
`no-trailing-whitespace`) still fire inside these blocks, verified by hand.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] Baseline `scripts/score.sh` recorded and TSV saved before any edit.
|
||||
- [x] AST: `StmtKind::Verbatim(RawText)`; doc comment on `ItemKind::Verbatim`
|
||||
widened to name its two new producers.
|
||||
- [x] Parser: `at_concurrent_assertion`, `parse_concurrent_assertion`,
|
||||
`skip_action_block`, `skip_action_stmt`, `parse_property_decl`.
|
||||
- [x] Parser dispatch: `parse_keyword_item` (`assert`/`assume`/`cover` behind
|
||||
the guard, `property`/`sequence`), `parse_item_kind`'s `Ident` arm
|
||||
(labels and `restrict`), `parse_stmt_kind` (statement position).
|
||||
- [x] Formatter: one arm, `StmtKind::Verbatim(raw) => self.raw_text(raw)`.
|
||||
- [x] Downstream exhaustive matches: `bind.rs`, `spans.rs`.
|
||||
- [x] 19 cases in `crates/vlog_formatter/tests/cases/assertions.cases`, one
|
||||
per corpus shape cited above plus: comments before/after, a comment
|
||||
*inside* the capture, a `// verilog_format: off` fence, a multi-line
|
||||
string in an action block, the immediate-assertion negative case, and a
|
||||
past-the-line-limit spec.
|
||||
- [x] 11 parser unit tests in `parser.rs`, including the four keywords, the
|
||||
label form, both action-block halves, the `begin`/`end` action block,
|
||||
statement position, the immediate-assertion negative case, and an
|
||||
unterminated `property` erroring rather than swallowing the file.
|
||||
- [x] 12 invariant-#4 attack tests in
|
||||
`crates/vlog_formatter/tests/verification.rs`.
|
||||
- [x] `cargo fmt --all`, `cargo clippy --all-targets`, `cargo test` (whole
|
||||
workspace) all clean.
|
||||
- [x] Idempotency swept by hand over all 712 passing corpus files, not just
|
||||
the 13 new ones.
|
||||
- [ ] **Not done, deliberately:** canonical layout for property/sequence
|
||||
expressions; `expect property`; `cover sequence`; `default clocking` /
|
||||
`default disable iff` (interface cluster's).
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-08-20 — dev
|
||||
|
||||
**Baseline** (`cargo build --release && scripts/score.sh`):
|
||||
|
||||
```json
|
||||
{"passing":699,"total":820,"pct":85.2,"failures_by_category":{"interface":31,"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}}
|
||||
```
|
||||
|
||||
**After**:
|
||||
|
||||
```json
|
||||
{"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}}
|
||||
```
|
||||
|
||||
`assertions` is gone from the bucket list: **13 of 13 files fixed, 0 remain**.
|
||||
The set of passing files is a strict superset of the baseline's — `comm -23`
|
||||
over the two sorted pass lists is empty, and `comm -13` is exactly the 13
|
||||
files of this bucket, nothing else moved in either direction.
|
||||
|
||||
`corpus/picorv32/picorv32.v` — 3000 lines of Verilog-2001, blocked on
|
||||
`restrict property` at line 2109 since the directives-in-lists round — now
|
||||
formats end to end and needed no follow-up: it did **not** advance to a new
|
||||
blocker, it passes.
|
||||
|
||||
Key decisions and how they were reached:
|
||||
|
||||
1. **Reused `ItemKind::Verbatim` rather than adding an assertion variant.**
|
||||
The classes round already documents that leaf as "a block vfmt
|
||||
deliberately does not model, kept byte-for-byte", and every consumer
|
||||
already treats it as opaque. A new item variant would have bought nothing
|
||||
and cost exhaustive-match arms in four crates. Only the *statement* side
|
||||
needed a new variant, because none existed.
|
||||
2. **`skip_action_block` / `skip_action_stmt` rather than "scan to the next
|
||||
`;`".** A naive scan is wrong for `assert property (p) $info("y"); else
|
||||
$error("n");` (two `;`, the item ends at the second) and for `else begin
|
||||
... end` (no trailing `;` at all). The two functions mirror the grammar's
|
||||
`action_block ::= statement_or_null | [statement] else statement_or_null`
|
||||
literally, so both fall out. Brackets are skipped as units so a `;` inside
|
||||
one cannot end the scan early. Both shapes are pinned by a parser test that
|
||||
also asserts **the following item was not swallowed** — the failure mode
|
||||
that matters.
|
||||
3. **`property`/`sequence` declarations scan to their closer like
|
||||
`covergroup` does**, via `expect_closer`, so an unterminated one is a
|
||||
clean parse error in strict mode and a recorded diagnostic in tolerant
|
||||
mode. Pinned by `an_unclosed_property_declaration_is_an_error_not_a_
|
||||
swallowed_file`.
|
||||
4. **The multi-line-string question needed no new machinery.** `Fmt::raw_text`
|
||||
already routes a `RawText` whose line break falls inside a string literal
|
||||
to an untouched `Doc::Text`, using `crosses_line_inside_string`, which is
|
||||
built on the same `verify.rs::line_starts_inside_string` the safety net
|
||||
uses. So an `else $error("line one\n line two")` comes out
|
||||
byte-identical — the *first* line is still indented (the printer's indent
|
||||
lands before the first character of the doc) but no continuation line is
|
||||
touched, which is a fixed point on the second pass. Verified end to end by
|
||||
`an_assertion_carrying_a_multiline_string_is_left_alone_end_to_end`, and
|
||||
the corrupting direction is refused by
|
||||
`a_reindented_string_inside_an_assertion_action_is_rejected`. The visible
|
||||
consequence — an action block that stays at column 1 under an assertion
|
||||
indented to column 3 — is the correct trade: those bytes are string *data*.
|
||||
5. **`verify.rs` untouched.** All 13 corpus files pass through the runtime
|
||||
safety net (`scripts/score.sh` runs `vfmt --check`, which verifies), so no
|
||||
forgiveness needed widening. The 12 attack pairs were written anyway and
|
||||
each one is refused: a changed `|->` → `|=>`, a changed `##[1:3]` range, a
|
||||
dropped `disable iff` clause, a dropped action block, a dropped label, a
|
||||
dropped comment inside the spec, a re-indented multi-line string, a changed
|
||||
`sequence` body, a dropped `endproperty : p` label, and a dropped local
|
||||
variable declaration inside a `property`. The matching *legitimate*
|
||||
transformation (`a_concurrent_assertion_may_be_reindented`) is accepted, so
|
||||
the ten rejections are not vacuous.
|
||||
|
||||
Answers to the three questions the brief asked to check and report:
|
||||
|
||||
- **`generate` block, item position** — works; case
|
||||
`sequence ... endsequence` inside `if (AsyncOn) begin : gen_async_assert`
|
||||
and case `assert property ... else $error` inside `if (FALL_THROUGH) begin`
|
||||
both come from real corpus files and both pass.
|
||||
- **`always` block, statement position** — works; covered by the
|
||||
statement-position case (`cover property` inside `always @(posedge clk)
|
||||
begin`) and by
|
||||
`a_concurrent_assertion_also_parses_in_statement_position`.
|
||||
- **inside an `interface`** — **cannot be tested yet**: `interface` is itself
|
||||
a parse error, and is the interface cluster's (31 files). No change here is
|
||||
needed for it; see Handshakes.
|
||||
|
||||
Linter check, as asked: no rule needs to descend. AST rules see the assertion
|
||||
as one opaque `Verbatim` leaf, which is what `constraint` and `covergroup`
|
||||
already are; `vlog_linter/src/visit.rs`'s `walk_stmts` ends in `_ => {}` so it
|
||||
needed no arm at all. The text-driven rules still work over these lines —
|
||||
checked by hand on a file with a tab-indented and trailing-whitespaced
|
||||
assertion, which reported `no-tabs` and `no-trailing-whitespace` at the right
|
||||
columns. `vfmt check` runs clean (exit 0/1) on all 13 new files; that is part
|
||||
of what `scripts/score.sh` counts as a pass.
|
||||
|
||||
Files changed:
|
||||
|
||||
- `crates/vlog_parser/src/ast.rs` — `StmtKind::Verbatim`, widened doc on
|
||||
`ItemKind::Verbatim`
|
||||
- `crates/vlog_parser/src/parser.rs` — five new functions, three dispatch
|
||||
sites, 11 unit tests
|
||||
- `crates/vlog_parser/tests/spans.rs` — one match arm
|
||||
- `crates/vlog_formatter/src/format.rs` — one match arm
|
||||
- `crates/vlog_formatter/tests/cases/assertions.cases` — new, 19 cases
|
||||
- `crates/vlog_formatter/tests/verification.rs` — 12 attack tests
|
||||
- `crates/vlog_semantic/src/bind.rs` — one match arm
|
||||
- `README.md` — "Supported syntax" bullet, roadmap items 7/7b/8
|
||||
- `docs/features/assertions/README.md` — this file
|
||||
|
||||
## QA log
|
||||
|
||||
## Review
|
||||
Reference in new issue
Block a user