Checkpoint of the interrupted dev work (rate limit) so master stays clean. Known state: a_half_typed_instantiation_is_one_error_node (expected to invert) and tolerant_parse_equals_strict_parse_on_valid_ sources FAIL; the error_recovery test binary exceeds 6 GB under tools/guard.sh (a non-advancing recovery loop under the delete-any- character / truncate fuzzers). Resume in a worktree of this branch, under tools/guard.sh, fixing the advance guarantee first. Co-Authored-By: Claude Fable 5 <[email protected]>
556 lines
25 KiB
Rust
556 lines
25 KiB
Rust
//! Concurrent assertions, property/sequence declarations, action blocks and
|
|
//! `default disable iff`.
|
|
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn a_property_declaration_in_a_class_is_a_real_node() {
|
|
// Since `sva-bodies` a `property`/`sequence` declaration is a node
|
|
// rather than a verbatim leaf, and its span still covers exactly the
|
|
// bytes the old capture handed back.
|
|
let src = "class c;\n property p;\n a |-> b;\n endproperty : p\nendclass\n";
|
|
let f = parse_ok(src);
|
|
let items = &class_of(&f).items;
|
|
let ItemKind::PropSeqDecl(d) = &items[0].kind else { panic!("expected a property") };
|
|
assert_eq!(d.kw, "property");
|
|
assert_eq!(d.name.text, "p");
|
|
assert_eq!(d.end_label.as_ref().expect("the end label").text, "p");
|
|
assert_eq!(&src[items[0].span.as_range()], "property p;\n a |-> b;\n endproperty : p");
|
|
}
|
|
|
|
#[test]
|
|
fn a_comment_after_a_property_declaration_stays_outside_it() {
|
|
// The comment is written past the declaration's last token, so it
|
|
// must not be swallowed *or* dropped from the plumbing.
|
|
let f = parse_ok(
|
|
"class c;\n property p;\n a |-> b;\n endproperty // why\n int b;\nendclass\n",
|
|
);
|
|
let items = &class_of(&f).items;
|
|
assert!(matches!(items[0].kind, ItemKind::PropSeqDecl(_)));
|
|
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_a_real_node() {
|
|
let src = "module m;\n assert property (@(posedge clk) a |-> ##[1:3] b);\nendmodule\n";
|
|
let f = parse_ok(src);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::Assertion(a) = &items[0].kind else { panic!("expected an assertion") };
|
|
assert_eq!(a.kw, "assert");
|
|
assert_eq!(a.kw2, "property");
|
|
assert!(a.spec.clocking.is_some(), "the clocking event is a node");
|
|
assert!(a.action.pass.is_none() && a.action.fail.is_none(), "the bare `;` form");
|
|
assert_eq!(
|
|
&src[items[0].span.as_range()],
|
|
"assert property (@(posedge clk) a |-> ##[1:3] b);"
|
|
);
|
|
}
|
|
|
|
#[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"));
|
|
let ItemKind::Assertion(a) = &module_of(&f).items[0].kind else {
|
|
panic!("`{kw} property` did not parse as an assertion")
|
|
};
|
|
assert_eq!(a.kw, kw);
|
|
}
|
|
}
|
|
|
|
/// QA §27, round 1 (HIGH): IEEE 1800-2017 **Table 16-3** puts
|
|
/// `nexttime`/`s_nexttime` on `not`'s row, and ties the `always` /
|
|
/// `eventually` / `accept_on` family to `if`/`case` on the loosest row.
|
|
/// The first draft read the table from Table 11-2 instead: it grouped
|
|
/// `nexttime` with `always`, and gated the whole loose row on `min_prec`
|
|
/// while leaving only `if`/`case` position-independent. Every shape below
|
|
/// is legal SVA and every one of them fell back to the verbatim capture.
|
|
#[test]
|
|
fn a_loose_prefix_operator_is_read_wherever_a_property_expression_may_stand() {
|
|
for body in [
|
|
"p1 and nexttime p2",
|
|
"p1 and always p2",
|
|
"p1 and accept_on(e) p2",
|
|
"p1 and s_eventually p2",
|
|
"p1 or s_always p2",
|
|
"p1 and sync_reject_on(e) p2",
|
|
"a |-> nexttime b",
|
|
"not nexttime a and b",
|
|
"a or always b |-> c",
|
|
] {
|
|
let src = format!("module m;\n assert property ({body});\nendmodule\n");
|
|
let f = parse_ok(&src);
|
|
assert!(
|
|
matches!(module_of(&f).items[0].kind, ItemKind::Assertion(_)),
|
|
"`{body}` must be a node, not the verbatim fallback"
|
|
);
|
|
assert_eq!(
|
|
&src[module_of(&f).items[0].span.as_range()],
|
|
format!("assert property ({body});")
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The other half of the same table row: `nexttime` binds *tighter* than
|
|
/// `and`, so it may not swallow one — `not`'s rule, which it now shares.
|
|
#[test]
|
|
fn nexttime_binds_tighter_than_and_the_way_not_does() {
|
|
let f = parse_ok("module m;\n assert property (nexttime a and b);\nendmodule\n");
|
|
let ItemKind::Assertion(x) = &module_of(&f).items[0].kind else {
|
|
panic!("expected an assertion")
|
|
};
|
|
// `(nexttime a) and b`: the root is the `and`, not the `nexttime`.
|
|
let PropKind::Binary(b) = &x.spec.expr.kind else {
|
|
panic!("expected a binary root, got {:?}", x.spec.expr.kind)
|
|
};
|
|
assert!(matches!(&b.op, PropOp::Word(w) if w == "and"));
|
|
assert!(matches!(b.lhs.kind, PropKind::Unary(_)), "{:?}", b.lhs.kind);
|
|
// And `always` on the loosest row does the opposite: it takes the
|
|
// whole `a and b` to its right.
|
|
let f = parse_ok("module m;\n assert property (always a and b);\nendmodule\n");
|
|
let ItemKind::Assertion(x) = &module_of(&f).items[0].kind else {
|
|
panic!("expected an assertion")
|
|
};
|
|
let PropKind::Unary(u) = &x.spec.expr.kind else {
|
|
panic!("expected a unary root, got {:?}", x.spec.expr.kind)
|
|
};
|
|
assert_eq!(u.op, "always");
|
|
assert!(matches!(u.expr.kind, PropKind::Binary(_)), "{:?}", u.expr.kind);
|
|
}
|
|
|
|
/// `nexttime` keeps its optional `[n]` count on its new row — the one
|
|
/// thing it does that `not` does not.
|
|
#[test]
|
|
fn nexttime_still_carries_its_bracketed_count() {
|
|
let f = parse_ok("module m;\n assert property (nexttime [2] a and b);\nendmodule\n");
|
|
let ItemKind::Assertion(x) = &module_of(&f).items[0].kind else {
|
|
panic!("expected an assertion")
|
|
};
|
|
let PropKind::Binary(b) = &x.spec.expr.kind else { panic!("expected a binary root") };
|
|
let PropKind::Unary(u) = &b.lhs.kind else { panic!("expected a unary lhs") };
|
|
assert_eq!(u.op, "nexttime");
|
|
assert!(u.count.is_some(), "the `[2]` count survives the regrouping");
|
|
}
|
|
|
|
#[test]
|
|
fn cover_sequence_is_the_one_spelling_that_names_a_sequence() {
|
|
let f = parse_ok("module m;\n cover sequence (a ##1 b);\nendmodule\n");
|
|
let ItemKind::Assertion(a) = &module_of(&f).items[0].kind else {
|
|
panic!("expected an assertion")
|
|
};
|
|
assert_eq!((a.kw.as_str(), a.kw2.as_str()), ("cover", "sequence"));
|
|
}
|
|
|
|
#[test]
|
|
fn a_label_before_a_concurrent_assertion_is_part_of_the_item() {
|
|
let src = "NoNMI: assume property (~irq_nm_i);\n";
|
|
let f = parse_ok(src);
|
|
let ItemKind::Assertion(a) = &f.items[0].kind else { panic!("expected an assertion") };
|
|
assert_eq!(a.label.as_ref().expect("the label").text, "NoNMI");
|
|
assert_eq!(&src[f.items[0].span.as_range()], "NoNMI: assume property (~irq_nm_i);");
|
|
}
|
|
|
|
#[test]
|
|
fn an_assertion_action_block_is_part_of_the_item() {
|
|
let src = "module m;\n assert property (a) else $error(\"no\");\nendmodule\n";
|
|
let f = parse_ok(src);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::Assertion(a) = &items[0].kind else { panic!("expected an assertion") };
|
|
assert!(a.action.pass.is_none(), "the `else`-only spelling has no pass statement");
|
|
assert!(a.action.fail.is_some());
|
|
assert_eq!(&src[items[0].span.as_range()], "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::Assertion(a) = &items[0].kind else { panic!("expected an assertion") };
|
|
let fail = a.action.fail.as_ref().expect("the fail statement");
|
|
assert!(matches!(fail.kind, StmtKind::Block { .. }));
|
|
assert_eq!(
|
|
&src[items[0].span.as_range()],
|
|
"assert property (a) else begin\n $error(\"no\");\n end"
|
|
);
|
|
assert!(matches!(items[1].kind, ItemKind::DataDecl(_)), "the next item was swallowed");
|
|
}
|
|
|
|
#[test]
|
|
fn an_action_block_keeps_a_nested_begin_end_whole() {
|
|
// QA round-1 of `assertions`: the scan used to stop at the first `;`
|
|
// inside the nested block, leaving its `end` (and the `else`) behind.
|
|
// The action block is a real statement now, but the extent it covers
|
|
// is still exactly what that fix established.
|
|
let src = "module m;\n assert property (a |-> b)\n if (c) begin\n x = 1;\n end\n else y = 2;\n wire w;\nendmodule\n";
|
|
let f = parse_ok(src);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::Assertion(a) = &items[0].kind else { panic!("expected an assertion") };
|
|
assert!(matches!(a.action.pass.as_ref().map(|s| &s.kind), Some(StmtKind::If { .. })));
|
|
assert_eq!(
|
|
&src[items[0].span.as_range()],
|
|
"assert property (a |-> b)\n if (c) begin\n x = 1;\n end\n else y = 2;"
|
|
);
|
|
assert!(matches!(items[1].kind, ItemKind::DataDecl(_)), "the next item was swallowed");
|
|
}
|
|
|
|
#[test]
|
|
fn an_action_block_may_be_a_fork_or_a_case() {
|
|
// `disable fork` / `wait fork` name the enclosing block rather than
|
|
// opening one, so neither may end the action statement early.
|
|
let fork = "fork\n x = 1;\n begin\n disable fork;\n wait fork;\n end\n join_none";
|
|
let case =
|
|
"case (s)\n 1: x = 1;\n default: begin\n y = 2;\n end\n endcase";
|
|
for body in [fork, case] {
|
|
let src = format!("module m;\n assert property (a)\n {body}\n wire w;\nendmodule\n");
|
|
let f = parse_ok(&src);
|
|
let items = &module_of(&f).items;
|
|
assert!(
|
|
matches!(items[0].kind, ItemKind::Assertion(_)),
|
|
"expected an assertion for {body}"
|
|
);
|
|
assert_eq!(&src[items[0].span.as_range()], format!("assert property (a)\n {body}"));
|
|
assert!(matches!(items[1].kind, ItemKind::DataDecl(_)), "the next item was swallowed");
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn an_unbalanced_action_block_is_a_clean_error() {
|
|
// Never past the end of the file, never a loop.
|
|
assert_eq!(
|
|
parse_err("module m;\n assert property (a)\n if (c) begin\n x = 1;\nendmodule\n"),
|
|
"expected `;` (found \"<eof>\")"
|
|
);
|
|
// A closer with nothing open ends the scan where it stands.
|
|
assert_eq!(
|
|
parse_err("module m;\n initial begin\n assert property (a)\n end\nendmodule\n"),
|
|
"expected `;` (found \"end\")"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn both_halves_of_an_action_block_are_captured() {
|
|
let src =
|
|
"module m;\n assert property (a) $info(\"y\"); else $error(\"n\");\n wire w;\nendmodule\n";
|
|
let f = parse_ok(src);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::Assertion(a) = &items[0].kind else { panic!("expected an assertion") };
|
|
assert!(a.action.pass.is_some() && a.action.fail.is_some());
|
|
assert_eq!(
|
|
&src[items[0].span.as_range()],
|
|
"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") };
|
|
assert!(
|
|
matches!(stmts[0].kind, StmtKind::Assertion(_)),
|
|
"expected an assertion statement, got {:?}",
|
|
stmts[0].kind
|
|
);
|
|
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_real_nodes() {
|
|
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::PropSeqDecl(p) = &items[0].kind else { panic!("expected a property") };
|
|
assert_eq!(p.name.text, "p");
|
|
assert_eq!(oks(&p.args.as_ref().expect("the formal list").args)[0].name, "w");
|
|
assert_eq!(p.locals.len(), 1, "the `realtime t;` local variable");
|
|
assert!(p.spec_semi, "the spec's own `;`");
|
|
assert_eq!(
|
|
&src[items[0].span.as_range()],
|
|
"property p(int w);\n realtime t;\n a |-> b;\n endproperty : p"
|
|
);
|
|
let ItemKind::PropSeqDecl(s) = &items[1].kind else { panic!("expected a sequence") };
|
|
assert_eq!((s.kw.as_str(), s.name.text.as_str()), ("sequence", "s"));
|
|
assert_eq!(&src[items[1].span.as_range()], "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 expect_with_a_sequence_operator_is_an_assertion() {
|
|
for body in [
|
|
"expect (@(posedge clk) a ##1 b) else $error(\"no\");",
|
|
"expect (a |-> b);",
|
|
"expect (a |=> b);",
|
|
"expect (a throughout b);",
|
|
"expect (disable iff (rst) a ##1 b);",
|
|
] {
|
|
let f = parse_ok(&format!("module m;\n initial begin\n {body}\n end\nendmodule\n"));
|
|
let m = module_of(&f);
|
|
let ItemKind::Initial(stmt) = &m.items[0].kind else { panic!("expected an initial") };
|
|
let StmtKind::Block { stmts, .. } = &stmt.kind else { panic!("expected a block") };
|
|
assert!(
|
|
matches!(stmts[0].kind, StmtKind::Assertion(_)),
|
|
"{body} should be an assertion, got {:?}",
|
|
stmts[0].kind
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn expect_of_an_argument_list_is_still_a_task_call() {
|
|
// The 41-site regression guard: `expect(word1[7:0]);` in picorv32's
|
|
// spiflash testbench is a task, and nothing this round did may change
|
|
// that. An argument list cannot hold `##`, `|->`, `|=>`, `throughout`,
|
|
// `disable iff` or `@(`, which is the whole reason the rule is safe.
|
|
for body in ["expect(word1[7:0]);", "expect(x, y);", "expect(a[i] + 1);", "expect();"] {
|
|
let f = parse_ok(&format!("module m;\n initial begin\n {body}\n end\nendmodule\n"));
|
|
let m = module_of(&f);
|
|
let ItemKind::Initial(stmt) = &m.items[0].kind else { panic!("expected an initial") };
|
|
let StmtKind::Block { stmts, .. } = &stmt.kind else { panic!("expected a block") };
|
|
assert!(
|
|
!matches!(stmts[0].kind, StmtKind::Verbatim(_)),
|
|
"{body} must stay a call, got {:?}",
|
|
stmts[0].kind
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_default_disable_iff_is_a_real_node() {
|
|
// OpenTitan hw/ip/tlul/rtl/tlul_assert.sv:36 — IEEE 1800 §16.15.
|
|
// Since `sva-bodies` it is a node with its condition as an ordinary
|
|
// expression, so the signals it names are references.
|
|
let src = "module m;\n default disable iff disable_sva || !rst_ni;\n wire w;\nendmodule\n";
|
|
let f = parse_ok(src);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::DefaultDisable(d) = &items[0].kind else {
|
|
panic!("expected a default disable, got {:?}", items[0].kind)
|
|
};
|
|
assert!(!d.parens, "the item spelling writes no parentheses");
|
|
assert_eq!(&src[items[0].span.as_range()], "default disable iff disable_sva || !rst_ni;");
|
|
// The item after it is still read normally.
|
|
assert!(matches!(items[1].kind, ItemKind::DataDecl(_)), "{:?}", items[1].kind);
|
|
}
|
|
|
|
#[test]
|
|
fn a_default_disable_iff_stops_at_its_own_semicolon() {
|
|
// A `;` inside a bracketed run does not end the item; a missing one
|
|
// is still an error rather than a swallowed rest-of-file. The `dist`
|
|
// spelling is an `expression_or_dist`, which the expression grammar
|
|
// reads since `constraint-bodies`.
|
|
let src = "module m;\n default disable iff x dist {1 := 1, 2 := 2};\n wire w;\nendmodule\n";
|
|
let f = parse_ok(src);
|
|
let items = &module_of(&f).items;
|
|
assert!(matches!(items[0].kind, ItemKind::DefaultDisable(_)), "{:?}", items[0].kind);
|
|
assert_eq!(&src[items[0].span.as_range()], "default disable iff x dist {1 := 1, 2 := 2};");
|
|
assert!(matches!(items[1].kind, ItemKind::DataDecl(_)));
|
|
assert!(
|
|
parse_err("module m;\n default disable iff a\nendmodule\n").starts_with("expected `;`")
|
|
);
|
|
// `default disable` without `iff` is not the item: the dispatch is on
|
|
// the two keywords, and the third is required.
|
|
assert!(parse_err("module m;\n default disable a;\nendmodule\n").starts_with("expected `iff`"));
|
|
}
|
|
|
|
// QA (2026-08-29, `docs/features/clocking-wave/README.md`): a `;` inside a
|
|
// string literal or a comment must not end the item early, and two
|
|
// `default disable iff`s in a row must not merge into one capture. The
|
|
// scan only special-cases `(`/`[`/`{`, so both rely on the lexer already
|
|
// treating strings as one token and comments as trivia rather than tokens
|
|
// — verified directly rather than assumed.
|
|
#[test]
|
|
fn a_default_disable_iff_is_not_ended_by_a_semicolon_inside_a_string() {
|
|
let src = "module m;\n default disable iff x == \"a;b\";\n wire w;\nendmodule\n";
|
|
let f = parse_ok(src);
|
|
let items = &module_of(&f).items;
|
|
assert!(matches!(items[0].kind, ItemKind::DefaultDisable(_)), "{:?}", items[0].kind);
|
|
assert_eq!(&src[items[0].span.as_range()], "default disable iff x == \"a;b\";");
|
|
assert!(matches!(items[1].kind, ItemKind::DataDecl(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn a_default_disable_iff_is_not_ended_by_a_semicolon_inside_a_comment() {
|
|
let src = "module m;\n default disable iff /* ; */ x;\n wire w;\nendmodule\n";
|
|
let f = parse_ok(src);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::DefaultDisable(d) = &items[0].kind else { panic!("expected a default disable") };
|
|
assert_eq!(d.after_iff.len(), 1, "the comment has a slot of its own");
|
|
assert_eq!(&src[items[0].span.as_range()], "default disable iff /* ; */ x;");
|
|
assert!(matches!(items[1].kind, ItemKind::DataDecl(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn two_default_disable_iffs_in_a_row_are_captured_separately() {
|
|
let src =
|
|
"module m;\n default disable iff a;\n default disable iff b;\n wire w;\nendmodule\n";
|
|
let f = parse_ok(src);
|
|
let items = &module_of(&f).items;
|
|
assert!(matches!(items[0].kind, ItemKind::DefaultDisable(_)));
|
|
assert_eq!(&src[items[0].span.as_range()], "default disable iff a;");
|
|
assert!(matches!(items[1].kind, ItemKind::DefaultDisable(_)));
|
|
assert_eq!(&src[items[1].span.as_range()], "default disable iff b;");
|
|
assert!(matches!(items[2].kind, ItemKind::DataDecl(_)));
|
|
}
|
|
|
|
#[test]
|
|
fn a_macro_may_be_a_concurrent_assertions_whole_action_statement() {
|
|
// OpenTitan hw/ip/adc_ctrl/dv/sva/adc_ctrl_fsm_sva_if.sv:35 — the
|
|
// `else` arm is a macro invocation with no `;` after it.
|
|
let f = parse_ok(
|
|
"module m;\n A_A: assert property (a |=> b)\n else `ASSERT_ERROR(A_A)\n assign x = 1;\nendmodule\n",
|
|
);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::Assertion(a) = &items[0].kind else { panic!("expected an assertion") };
|
|
let fail = a.action.fail.as_ref().expect("the fail statement");
|
|
assert!(matches!(fail.kind, StmtKind::MacroStmt(_)), "{:?}", fail.kind);
|
|
assert!(matches!(items[1].kind, ItemKind::ContAssign(_)), "{:?}", items[1].kind);
|
|
}
|
|
|
|
#[test]
|
|
fn a_macro_inside_an_action_statement_is_an_operand_not_a_terminator() {
|
|
// Only a macro *starting* a statement ends it; one standing mid-way
|
|
// through an expression is a value, and the `;` still terminates.
|
|
let f = parse_ok(
|
|
"module m;\n A_A: assert property (a) else x = `VAL + 1;\n assign y = 1;\nendmodule\n",
|
|
);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::Assertion(a) = &items[0].kind else { panic!("expected an assertion") };
|
|
let fail = a.action.fail.as_ref().expect("the fail statement");
|
|
assert!(matches!(fail.kind, StmtKind::Assign { .. }), "{:?}", fail.kind);
|
|
assert!(matches!(items[1].kind, ItemKind::ContAssign(_)), "{:?}", items[1].kind);
|
|
}
|
|
|
|
// QA (2026-08-29, `docs/features/clocking-wave/README.md` round 2) —
|
|
// QA round-2 finding, fixed by the rework (`docs/features/clocking-wave/
|
|
// README.md`, work log 2026-08-29 rework): `skip_action_stmt` used to
|
|
// treat a macro standing first in an action as *always* the whole action.
|
|
// That is false whenever the macro's expansion is a signal name and the
|
|
// statement goes on to assign to, read or increment it — ordinary
|
|
// RTL/testbench idiom, and a parse error on input trunk accepts. The scan
|
|
// now decides by what *follows* the call (`Parser::at_statement_tail`),
|
|
// so all four shapes below parse exactly as they do on trunk while
|
|
// `` else `ASSERT_ERROR(A) `` still ends where it ends.
|
|
#[test]
|
|
fn a_macro_used_as_an_lvalue_is_not_the_whole_action_statement() {
|
|
// A macro standing for a signal name, assigned to from an `else` arm.
|
|
let f = parse_ok(
|
|
"module m;\n A_A: assert property (a) else `SOME_SIGNAL = 1'b1;\n assign y = 1;\nendmodule\n",
|
|
);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::Assertion(a) = &items[0].kind else { panic!("expected an assertion") };
|
|
let fail = a.action.fail.as_ref().expect("the fail statement");
|
|
assert!(matches!(fail.kind, StmtKind::Assign { .. }), "{:?}", fail.kind);
|
|
assert!(matches!(items[1].kind, ItemKind::ContAssign(_)), "{:?}", items[1].kind);
|
|
}
|
|
|
|
#[test]
|
|
fn a_macro_used_as_an_operand_before_an_operator_is_not_the_whole_action_statement() {
|
|
// `` `MSG(x) + 1; `` — the macro is an operand, and the `+ 1;` that
|
|
// follows it is the rest of the same statement.
|
|
let f = parse_ok(
|
|
"module m;\n A_A: assert property (a) else `MSG(x) + 1;\n assign y = 1;\nendmodule\n",
|
|
);
|
|
let items = &module_of(&f).items;
|
|
// The one shape of the four that the SVA grammar hands back to the
|
|
// verbatim fallback: a macro standing first in a statement is a
|
|
// `MacroStmt`, so the `+ 1;` after it is a token the action block's
|
|
// statement parser cannot place. The fallback's flat scan still
|
|
// covers the whole item, which is what this test has always pinned.
|
|
let ItemKind::Verbatim(raw) = &items[0].kind else {
|
|
panic!("expected the verbatim fallback, got {:?}", items[0].kind)
|
|
};
|
|
assert!(raw.text.ends_with("`MSG(x) + 1;"), "{:?}", raw.text);
|
|
assert!(matches!(items[1].kind, ItemKind::ContAssign(_)), "{:?}", items[1].kind);
|
|
}
|
|
|
|
#[test]
|
|
fn a_macro_counter_increment_is_not_the_whole_action_statement() {
|
|
// A common RTL/testbench idiom: a macro standing for a counter
|
|
// register, incremented from the `else` arm.
|
|
let f = parse_ok(
|
|
"module m;\n A_A: assert property (a) else `CNT <= `CNT + 1;\n assign y = 1;\nendmodule\n",
|
|
);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::Assertion(a) = &items[0].kind else { panic!("expected an assertion") };
|
|
let fail = a.action.fail.as_ref().expect("the fail statement");
|
|
assert!(matches!(fail.kind, StmtKind::Assign { .. }), "{:?}", fail.kind);
|
|
assert!(matches!(items[1].kind, ItemKind::ContAssign(_)), "{:?}", items[1].kind);
|
|
}
|
|
|
|
#[test]
|
|
fn a_macro_postfix_increment_is_not_the_whole_action_statement() {
|
|
// The fourth shape of the same finding: the macro is the operand of a
|
|
// postfix `++`, so the statement runs on past the call.
|
|
let f = parse_ok(
|
|
"module m;\n A_A: assert property (a) else `CNT++;\n assign y = 1;\nendmodule\n",
|
|
);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::Assertion(a) = &items[0].kind else { panic!("expected an assertion") };
|
|
assert!(a.action.fail.is_some(), "the `++` is part of the fail statement");
|
|
assert!(matches!(items[1].kind, ItemKind::ContAssign(_)), "{:?}", items[1].kind);
|
|
}
|
|
|
|
#[test]
|
|
fn a_macro_action_still_ends_where_no_statement_tail_follows() {
|
|
// The other side of the same decision, in each shape that can stand
|
|
// after a complete macro action: the next item's keyword, an
|
|
// identifier opening a label, another macro, and a directive.
|
|
for next in ["assign y = 1;", "B_B: assert property (b);", "`ASSERT_INIT(C, 1)", "`endif"] {
|
|
let src = format!(
|
|
"module m;\n A_A: assert property (a)\n else `ASSERT_ERROR(A_A)\n {next}\nendmodule\n"
|
|
);
|
|
let f = parse_ok(&src);
|
|
let items = &module_of(&f).items;
|
|
let ItemKind::Assertion(a) = &items[0].kind else {
|
|
panic!("expected an assertion for {next:?}")
|
|
};
|
|
let fail = a.action.fail.as_ref().expect("the fail statement");
|
|
assert!(matches!(fail.kind, StmtKind::MacroStmt(_)), "{next:?}: {:?}", fail.kind);
|
|
assert_eq!(items.len(), 2, "{next:?}: {:?}", items.len());
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_label_before_a_concurrent_assertion_still_takes_the_assertion_path() {
|
|
// The concurrent-assertion check runs first and takes the label with
|
|
// it, so the general statement-label path never sees one.
|
|
let f = parse_ok(
|
|
"module m;\n initial begin\n NoNMI: assert property (@(posedge c) a);\n end\nendmodule\n",
|
|
);
|
|
let StmtKind::Assertion(a) = &initial_stmts(&f)[0].kind else {
|
|
panic!("expected an assertion statement")
|
|
};
|
|
assert_eq!(a.label.as_ref().expect("the label").text, "NoNMI");
|
|
}
|