TODO section 27; the SVA half of coverage_gaps C1/M8; docs/topo.md
2.9-18's engine half.
property/sequence declarations, concurrent assert/assume/cover/restrict
property, expect, cover sequence and default disable iff were verbatim
text. They are nodes now: sequence_expr/property_expr as one
precedence-climbing extension of parse_expr (IEEE 1800-2017 Table 16-3
row by row - QA caught two rows transcribed from Table 11-2 and the
rework fixed them: nexttime on not's row, the whole loosest row read
position-independently), typed formals, assertion variables, action
blocks as the statements they are - behind a Rewind snapshot with a
byte-exact per-construct fallback that fires on 0 of 4 792 corpus and
opentitan files. No keyword reserved: operator words are text-matched
in SVA position only. One layout rule: top-level |->, |=>, ##, and, or
break one per line at the parent's indent when the spec does not fit.
SVA gap fuzzer 705 gaps / 0 failing; 46 attack pairs; verify.rs
untouched.
Semantics: SymbolKind::{Property, Sequence}, ScopeKind::PropSeq, formals
and locals scoped, instances resolve in-file and cross-file
(FACTS_FORMAT 15 -> 16); rename, references, document symbols and the
lints see inside; Scope::sva_fallback_warnings names what would still
fall back. macro_use_warnings pinned for a file whose only relationship
to the name is a macro argument (the server half stays filed).
Output moved in 13 corpus and 36 opentitan files, every changed line
inside an SVA construct (proved by tests/census.rs::sva_lines and by
QA's independent re-implementation); the 4 854 ASSERT macro uses are
byte-identical. Corpus 814/820.
docs/features/sva-bodies/README.md. Also carries TODO section 28
(decomposition, planned) and the topo rows for this round.
Co-Authored-By: Claude Fable 5 <[email protected]>
215 lines
7.3 KiB
Rust
215 lines
7.3 KiB
Rust
//! SVA bodies: what a `property`/`sequence` declaration declares, where the
|
|
//! names inside a property spec bind, and how a sequence instance reaches its
|
|
//! declaration across files. The rules live in
|
|
//! `docs/features/sva-bodies/README.md`.
|
|
|
|
use std::path::PathBuf;
|
|
use vlog_parser::parse_source;
|
|
use vlog_semantic::{
|
|
analyze, resolve_external, Def, ExternalTarget, Semantics, SymbolKind, WorkspaceIndex,
|
|
};
|
|
|
|
fn sem(src: &str) -> Semantics {
|
|
let file = parse_source(src).expect("fixture must parse");
|
|
analyze(&file, src)
|
|
}
|
|
|
|
/// Offset of the `n`th (0-based) occurrence of `needle`.
|
|
fn nth(src: &str, needle: &str, n: usize) -> u32 {
|
|
src.match_indices(needle).nth(n).expect("occurrence must exist").0 as u32
|
|
}
|
|
|
|
/// The declaration the use at `offset` points at, by name and kind.
|
|
fn defines(s: &Semantics, offset: u32) -> Option<(String, SymbolKind)> {
|
|
let d = s.definition_of(offset)?;
|
|
Some((d.name.clone(), d.kind))
|
|
}
|
|
|
|
fn kind_of(s: &Semantics, name: &str) -> SymbolKind {
|
|
s.symbols()
|
|
.iter()
|
|
.find(|sym| sym.name == name)
|
|
.unwrap_or_else(|| panic!("no symbol {name}"))
|
|
.kind
|
|
}
|
|
|
|
fn index(files: &[(&str, &str)]) -> WorkspaceIndex {
|
|
WorkspaceIndex::build(files.iter().map(|(name, src)| (PathBuf::from(name), *src)))
|
|
}
|
|
|
|
fn overlay_def(ws: &WorkspaceIndex, src: &str, offset: u32) -> Option<Def> {
|
|
let s = sem(src);
|
|
let id = s.reference_id_at(offset)?;
|
|
resolve_external(&s, ws).get(id).and_then(ExternalTarget::best).cloned()
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// What a declaration declares
|
|
// ----------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn a_property_declares_itself_its_formals_and_its_locals() {
|
|
let src = "\
|
|
module m;
|
|
logic clk, a, b;
|
|
property p (int w, sequence s);
|
|
logic v;
|
|
@(posedge clk) a ##w b |-> s;
|
|
endproperty : p
|
|
endmodule
|
|
";
|
|
let s = sem(src);
|
|
assert_eq!(kind_of(&s, "p"), SymbolKind::Property);
|
|
assert_eq!(kind_of(&s, "w"), SymbolKind::TfArg);
|
|
assert_eq!(kind_of(&s, "s"), SymbolKind::TfArg);
|
|
assert_eq!(kind_of(&s, "v"), SymbolKind::Var);
|
|
// The formals and the local live in the declaration's own scope, so the
|
|
// module's own `a` is not shadowed by them.
|
|
assert_eq!(defines(&s, nth(src, "a ##w", 0)), Some(("a".into(), SymbolKind::Var)));
|
|
assert_eq!(defines(&s, nth(src, "##w", 0) + 2), Some(("w".into(), SymbolKind::TfArg)));
|
|
assert_eq!(defines(&s, nth(src, "|-> s", 0) + 4), Some(("s".into(), SymbolKind::TfArg)));
|
|
}
|
|
|
|
#[test]
|
|
fn a_sequence_declares_a_sequence_symbol() {
|
|
let src = "module m;\n sequence sq;\n a ##1 b;\n endsequence\nendmodule\n";
|
|
let s = sem(src);
|
|
assert_eq!(kind_of(&s, "sq"), SymbolKind::Sequence);
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Every identifier in a body is an ordinary use — M8
|
|
// ----------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn every_name_in_a_concurrent_assertion_is_a_reference() {
|
|
let src = "\
|
|
module m;
|
|
logic clk, rst, req, gnt, ack;
|
|
assert property (@(posedge clk) disable iff (rst) req |-> ##[1:2] gnt) else $error(ack);
|
|
endmodule
|
|
";
|
|
let s = sem(src);
|
|
for (name, occurrence) in [("clk", 1), ("rst", 1), ("req", 1), ("gnt", 1), ("ack", 1)] {
|
|
let at = nth(src, name, occurrence);
|
|
assert_eq!(
|
|
defines(&s, at),
|
|
Some((name.to_string(), SymbolKind::Var)),
|
|
"`{name}` inside the assertion must resolve to its declaration"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn every_operand_shape_of_the_grammar_records_its_names() {
|
|
// One fixture per node kind that carries an expression: the repetition
|
|
// bound, the delay count, the abort condition, the `if` selector, the
|
|
// `case` labels, the match items and a `first_match` filter.
|
|
// The names are spelled so that no one of them is a substring of another
|
|
// word in the fixture — `y` alone would match inside `property`.
|
|
let src = "\
|
|
module m;
|
|
logic n_sel, n_cond, n_rep, n_hi, n_lhs, n_rhs;
|
|
assert property (
|
|
accept_on (n_cond) if (n_sel) n_lhs[*n_rep] ##[1:n_hi] n_rhs
|
|
else case (n_sel) n_rep: n_lhs; default: n_rhs; endcase
|
|
);
|
|
assert property (first_match(n_lhs ##1 n_rhs, n_hi = n_rep) |->
|
|
not strong(n_lhs within n_rhs));
|
|
endmodule
|
|
";
|
|
let s = sem(src);
|
|
for name in ["n_cond", "n_sel", "n_rep", "n_hi", "n_lhs", "n_rhs"] {
|
|
let at = nth(src, name, 1);
|
|
assert!(
|
|
s.reference_at(at).is_some(),
|
|
"`{name}` inside the property expression must be a reference"
|
|
);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn a_default_disable_iff_records_its_condition() {
|
|
let src = "module m;\n logic rst_n;\n default disable iff !rst_n;\nendmodule\n";
|
|
let s = sem(src);
|
|
assert_eq!(defines(&s, nth(src, "rst_n", 1)), Some(("rst_n".into(), SymbolKind::Var)));
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Instances resolve to their declaration
|
|
// ----------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn a_sequence_instance_resolves_to_its_declaration_in_the_same_file() {
|
|
let src = "\
|
|
module m;
|
|
logic clk, a, b;
|
|
sequence handshake;
|
|
a ##1 b;
|
|
endsequence
|
|
assert property (@(posedge clk) handshake);
|
|
assert property (@(posedge clk) handshake.triggered);
|
|
endmodule
|
|
";
|
|
let s = sem(src);
|
|
assert_eq!(
|
|
defines(&s, nth(src, "handshake", 1)),
|
|
Some(("handshake".into(), SymbolKind::Sequence))
|
|
);
|
|
assert_eq!(
|
|
defines(&s, nth(src, "handshake", 2)),
|
|
Some(("handshake".into(), SymbolKind::Sequence))
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn a_property_declared_in_a_package_resolves_across_files() {
|
|
let lib = "package p;\n property req_ack;\n a |-> b;\n endproperty\nendpackage\n";
|
|
let user = "module m;\n import p::*;\n assert property (req_ack);\nendmodule\n";
|
|
let ws = index(&[("lib.sv", lib), ("user.sv", user)]);
|
|
let def = overlay_def(&ws, user, nth(user, "req_ack", 0)).expect("the overlay resolves it");
|
|
assert_eq!(def.kind, SymbolKind::Property);
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Round 3's pins for the rest of the tree
|
|
// ----------------------------------------------------------------------
|
|
|
|
#[test]
|
|
fn a_property_is_a_document_symbol_with_its_own_children() {
|
|
let src = "\
|
|
module m;
|
|
property p (int w);
|
|
logic v;
|
|
a ##w b;
|
|
endproperty
|
|
endmodule
|
|
";
|
|
let s = sem(src);
|
|
let outline = s.document_symbols();
|
|
let module = outline.first().expect("the module");
|
|
let prop = module
|
|
.children
|
|
.iter()
|
|
.find(|d| s.symbol(d.symbol).is_some_and(|sym| sym.name == "p"))
|
|
.expect("the property is in the outline");
|
|
let names: Vec<&str> = prop
|
|
.children
|
|
.iter()
|
|
.filter_map(|c| s.symbol(c.symbol).map(|sym| sym.name.as_str()))
|
|
.collect();
|
|
assert!(names.contains(&"w") && names.contains(&"v"), "{names:?}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_spec_the_grammar_cannot_read_stays_opaque() {
|
|
// The verbatim fallback keeps the pre-round posture exactly: nothing
|
|
// inside binds, and nothing about the enclosing module changes.
|
|
let src = "module m;\n logic sig;\n assert property (sig |-> $blah $blah);\nendmodule\n";
|
|
let s = sem(src);
|
|
assert!(
|
|
s.reference_at(nth(src, "sig", 1)).is_none(),
|
|
"a fallback region is opaque to name resolution, as it always was"
|
|
);
|
|
}
|