- L-1: an unowned block's closing label is a use of a same-named block only for block constructs and only when it spells the construct's own opening label (use_block_end_label); a mismatched `end : a` or an `endfunction : g` beside block `g` records nothing. - L-2: duplicate-declaration stays silent for two block labels only when both may be arms of one generate if/case; sibling `for` blocks and a procedural block beside a generate one are reported in either order. OpenTitan check: 1 158 findings, identical to 0.60.0. - L-3: a block comment between `.` and the name is still dotted. - L-4: a bind file that does not lex counts as binding (K2); a pasted fragment that does not lex is said, not skipped. - L-12: no unchecked slice in rename/arms.rs. - L-13: expand/ansi/inline/extract messages name files by Scope::name_of. 7 tests (L-3/L-4's fail with the fixes disabled). Per-crate suites under the guard: 80 suites, 5 085 passed, 0 failed, 51 ignored (one combined run was cut at 1 800 s in vlog_refactor/tests/corpus.rs with syspolicyd at 95 % — the §65.3 stall). Co-Authored-By: Claude Opus 5.5 <[email protected]>
174 lines
7.6 KiB
Rust
174 lines
7.6 KiB
Rust
//! A rename's text warnings are about the renamed declaration (TODO §65.1,
|
|
//! lead's inspection 2026-09-30): a module member's bare spelling in another
|
|
//! module's macro argument, `` `define`` body or unstructured assertion is
|
|
//! that module's own signal, not news; a dotted spelling may be a path to it
|
|
//! and is still said; a package-level name is still warned about everywhere.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use vlog_refactor::rename;
|
|
|
|
fn workspace(files: &[(&str, &str)]) -> Vec<(PathBuf, String)> {
|
|
files.iter().map(|(name, text)| (PathBuf::from("/rtl").join(name), text.to_string())).collect()
|
|
}
|
|
|
|
const DEFS: &str = "`define ASSERT(n, e) n: assert property (e);\n`define PEEK_A tb.u_a.state_q\n`define LOCAL_B state_q\n";
|
|
const A: &str = "module a (input logic clk);
|
|
logic state_q;
|
|
always_ff @(posedge clk) state_q <= ~state_q;
|
|
`ASSERT(A_Toggles, state_q)
|
|
// state_q is a's register
|
|
initial $display(\"state_q\");
|
|
endmodule
|
|
";
|
|
const B: &str = "module b (input logic clk);
|
|
logic state_q;
|
|
a u_a (.clk);
|
|
always_ff @(posedge clk) state_q <= ~state_q;
|
|
`ASSERT(B_Own, state_q)
|
|
`ASSERT(B_Peek, u_a.state_q)
|
|
// state_q is b's register
|
|
initial $display(\"state_q\");
|
|
endmodule
|
|
";
|
|
|
|
/// The warnings of renaming `a`'s `state_q`.
|
|
fn warnings_of_renaming_a() -> Vec<String> {
|
|
let files = workspace(&[("defs.svh", DEFS), ("a.sv", A), ("b.sv", B)]);
|
|
let at = A.find("logic state_q").expect("decl") as u32 + 6;
|
|
rename(&files, &PathBuf::from("/rtl/a.sv"), at, "state_r").expect("renames").warnings
|
|
}
|
|
|
|
#[test]
|
|
fn only_the_renamed_modules_bare_macro_argument_is_warned_about() {
|
|
let warnings = warnings_of_renaming_a();
|
|
let macro_args: Vec<&String> =
|
|
warnings.iter().filter(|w| w.contains("arguments of the macro invocation")).collect();
|
|
assert_eq!(macro_args.len(), 2, "{warnings:#?}");
|
|
assert!(macro_args[0].contains("a.sv:4"), "a's own `ASSERT: {warnings:#?}");
|
|
assert!(macro_args[1].contains("b.sv:6"), "b's dotted `u_a.state_q`: {warnings:#?}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_foreign_define_body_is_said_only_when_it_spells_the_name_dotted() {
|
|
let warnings = warnings_of_renaming_a();
|
|
let bodies: Vec<&String> = warnings.iter().filter(|w| w.contains("body of macro")).collect();
|
|
assert_eq!(bodies.len(), 1, "{warnings:#?}");
|
|
assert!(bodies[0].contains("`PEEK_A`"), "{warnings:#?}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_package_level_name_is_still_warned_about_in_every_module() {
|
|
let pkg = "package p;\n localparam int W = 1;\nendpackage\n";
|
|
let user = "module u import p::*; (input logic clk);\n `ASSERT(U_W, W > 0)\nendmodule\n";
|
|
let other =
|
|
"module v (input logic clk);\n localparam int W = 2;\n `ASSERT(V_W, W > 0)\nendmodule\n";
|
|
let files = workspace(&[("defs.svh", DEFS), ("p.sv", pkg), ("u.sv", user), ("v.sv", other)]);
|
|
let at = pkg.find("W =").expect("decl") as u32;
|
|
let edit = rename(&files, &PathBuf::from("/rtl/p.sv"), at, "WIDTH").expect("renames");
|
|
let macro_args: Vec<&String> =
|
|
edit.warnings.iter().filter(|w| w.contains("arguments of the macro invocation")).collect();
|
|
assert_eq!(macro_args.len(), 2, "both, as before: {:#?}", edit.warnings);
|
|
}
|
|
|
|
/// Rework 5, N1: a port rename edits every instantiating file, and each of
|
|
/// those asserts on its *own* `clk_i` — the scope lookup in an edited file
|
|
/// says those are not the renamed port. The declaring module's own
|
|
/// assertion still warns.
|
|
#[test]
|
|
fn an_instantiating_modules_own_bare_spelling_is_not_news() {
|
|
let flop = "module flop (input logic clk_i, input logic d, output logic q);
|
|
always_ff @(posedge clk_i) q <= d;
|
|
`ASSERT(FlopKnown_A, !$isunknown(clk_i))
|
|
endmodule
|
|
";
|
|
let user = |n: u32| {
|
|
format!(
|
|
"module user{n} (input logic clk_i, input logic d, output logic q);
|
|
flop u_flop (.clk_i(clk_i), .d, .q);
|
|
`ASSERT(User{n}Clk_A, clk_i)
|
|
endmodule
|
|
"
|
|
)
|
|
};
|
|
let (u1, u2, u3) = (user(1), user(2), user(3));
|
|
let files = workspace(&[
|
|
("defs.svh", DEFS),
|
|
("flop.sv", flop),
|
|
("user1.sv", &u1),
|
|
("user2.sv", &u2),
|
|
("user3.sv", &u3),
|
|
]);
|
|
let at = flop.find("clk_i").expect("port") as u32;
|
|
let edit = rename(&files, &PathBuf::from("/rtl/flop.sv"), at, "clk_x").expect("renames");
|
|
assert_eq!(edit.edits.len(), 4, "the port and the three connections");
|
|
let macro_args: Vec<&String> =
|
|
edit.warnings.iter().filter(|w| w.contains("arguments of the macro invocation")).collect();
|
|
assert_eq!(macro_args.len(), 1, "{:#?}", edit.warnings);
|
|
assert!(macro_args[0].contains("flop.sv:3"), "{:#?}", edit.warnings);
|
|
}
|
|
|
|
/// Review M-1: a use in an include-related file that the rename *did* edit
|
|
/// is not reported as "left unchanged". `all.sv` includes `m.sv` and `n.sv`,
|
|
/// so `n.sv` is pasted around `m.sv`; its instantiation of `m` is a
|
|
/// cross-file reference the rename rewrites.
|
|
#[test]
|
|
fn an_edited_use_in_an_include_related_file_is_not_said_to_be_left_unchanged() {
|
|
let m = "module m (input logic clk);\nendmodule\n";
|
|
let n = "module n (input logic clk);\n m u_m (.clk(clk));\nendmodule\n";
|
|
let all = "`include \"m.sv\"\n`include \"n.sv\"\n";
|
|
let files = workspace(&[("m.sv", m), ("n.sv", n), ("all.sv", all)]);
|
|
let at = m.find("module m").expect("decl") as u32 + 7;
|
|
let edit = rename(&files, &PathBuf::from("/rtl/m.sv"), at, "m2").expect("renames");
|
|
assert_eq!(edit.edits_for(&PathBuf::from("/rtl/n.sv")).len(), 1, "the instantiation moves");
|
|
let left = edit.warnings.iter().any(|w| w.contains("n.sv:2") && w.contains("left unchanged"));
|
|
assert!(!left, "{:#?}", edit.warnings);
|
|
}
|
|
|
|
/// The warnings of renaming the first `logic state_q` in `m.sv` among `files`.
|
|
fn warnings_renaming_m_state_q(files: &[(&str, &str)]) -> Vec<String> {
|
|
let text = files.iter().find(|(n, _)| *n == "m.sv").map(|(_, t)| *t).expect("m.sv");
|
|
let at = text.find("logic state_q").expect("decl") as u32 + 6;
|
|
let set = workspace(files);
|
|
rename(&set, &PathBuf::from("/rtl/m.sv"), at, "state_r").expect("renames").warnings
|
|
}
|
|
|
|
/// Review L-3: a comment between the `.` and the name is still a path.
|
|
#[test]
|
|
fn a_path_with_a_comment_after_its_dot_is_said() {
|
|
let m = "module m (input logic clk);\n logic state_q;\nendmodule\n";
|
|
let tb = "module tb;\n m u_m (.clk(1'b0));\n initial $display(\"%b\", `Q(u_m. /* c */ state_q));\nendmodule\n";
|
|
let warnings = warnings_renaming_m_state_q(&[
|
|
("defs.svh", "`define Q(x) x\n"),
|
|
("m.sv", m),
|
|
("tb.sv", tb),
|
|
]);
|
|
assert!(warnings.iter().any(|w| w.contains("tb.sv:3")), "{warnings:#?}");
|
|
}
|
|
|
|
/// Review L-4: a file that spells `bind` but does not lex is counted as
|
|
/// binding into the module, so the macros it invokes are followed.
|
|
#[test]
|
|
fn a_bind_file_that_does_not_lex_still_makes_its_macros_home() {
|
|
let m = "module m (input logic clk);\n logic state_q;\nendmodule\n";
|
|
let binds = "module binds;\n bind m chk u_chk (.s(`SIG));\n initial $display(\"unterminated);\nendmodule\n";
|
|
let warnings = warnings_renaming_m_state_q(&[
|
|
("defs.svh", "`define SIG state_q\n"),
|
|
("m.sv", m),
|
|
("binds.sv", binds),
|
|
]);
|
|
assert!(warnings.iter().any(|w| w.contains("defs.svh:1")), "{warnings:#?}");
|
|
}
|
|
|
|
/// Review L-4: an included fragment that does not lex is said, not skipped.
|
|
#[test]
|
|
fn an_included_fragment_that_does_not_lex_is_said() {
|
|
let m = "module m (output logic o);\n logic state_q;\n`include \"frag.svh\"\nendmodule\n";
|
|
let frag = " assign o = state_q;\n initial $display(\"unterminated);\n";
|
|
let warnings = warnings_renaming_m_state_q(&[("m.sv", m), ("frag.svh", frag)]);
|
|
assert!(
|
|
warnings.iter().any(|w| w.contains("frag.svh") && w.contains("could not read")),
|
|
"{warnings:#?}"
|
|
);
|
|
}
|