A path segment naming a block (bare, indexed, nested, cross-file) is now a reference to its label: vlog_semantic declares a `for` block's label in the enclosing scope, makes `generate … endgenerate` no scope, gives a block a member scope, walks an index in a path, and files blocks on a module's hierarchical surface under `module.label` (FACTS_FORMAT 21). The LSP, CLI and MCP rename/references get it through the engine; lucisv-mcp's `block` refusal is lifted. No verifier normalization (attacks in check/qa_block_paths.rs, qa_block_attacks.rs). Reworks after QA: unresolved path segments warned in every file of the set; sibling-arm members warned; a label beside a net is a duplicate-declaration; function-local block keys never collide; file names path-qualified when base names collide; rename warnings and lucisv-mcp mentions scoped to the declaration's home set (rename/home.rs, scoped.rs), falling back to unscoped on any doubt. TODO §65.4 and §65.6 filed. docs/features/generate-label-rename. Workspace lib/bins/tests: 79 suites, 5 064 passed, 0 failed, 51 ignored (guard exit 0). Co-Authored-By: Claude Opus 5.5 <[email protected]>
110 lines
4.5 KiB
Rust
110 lines
4.5 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);
|
|
}
|