Files
lucisv/crates/vlog_refactor/tests/rename_warning_scope.rs
T
Guoliang ChenandClaude Mythos 5.2 71d13b5fbe
ci / checks (push) Successful in 1m0s
ci / corpus (push) Successful in 18s
ci / linux (push) Successful in 6m4s
release / build-and-publish (push) Successful in 5m31s
Release 0.66.2: every source file names its author
Every tracked file that can carry a comment (880 of them) now opens with
"Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with
"Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love,
luciochen.com", in the file's own comment syntax. No behaviour change: the
diff outside the version bump and changelogs is comment lines only.

- tools/stamp_author.py: writes the lines; idempotent, `--check` lists
  what is missing. Headers go under a shebang and under Markdown front
  matter.
- Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON
  and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the
  LICENSE files (already carry the copyright line).
- tools/linux_check.sh: --help reads its header from line 3, now that the
  author line sits under the shebang.
- tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-24 12:11:09 -08:00

178 lines
7.7 KiB
Rust

// Author: Guoliang Chen, a Senior Digital Design Engineer
//! 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:#?}"
);
}
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com