diff --git a/crates/vlog_refactor/src/rename/scoped.rs b/crates/vlog_refactor/src/rename/scoped.rs index 5cde558..4258508 100644 --- a/crates/vlog_refactor/src/rename/scoped.rs +++ b/crates/vlog_refactor/src/rename/scoped.rs @@ -51,6 +51,7 @@ use super::home::{home_of, invoked_from, macro_names, Home}; use super::sites::nearest; use super::Target; use crate::scope::Scope; +use crate::TextEdit; /// What the text scans need to know about the renamed declaration. pub(super) struct Scoping { @@ -204,7 +205,13 @@ impl<'a> Scope<'a> { /// file includes (or that includes it). That text is analysed on its own, /// outside the module's scope, so no reference there is the declaration's /// and the rename cannot edit it: one warning per file, with its lines. - pub(super) fn fragment_use_warnings(&mut self, scoping: &Scoping) -> Vec { + /// A use the rename does edit (`edits`: a cross-file reference the index + /// resolved, such as an instantiation of a renamed module) is not one. + pub(super) fn fragment_use_warnings( + &mut self, + scoping: &Scoping, + edits: &[(usize, Vec)], + ) -> Vec { let name = scoping.name.clone(); let declaring = self.name_at(scoping.declaring()); let mut out = Vec::new(); @@ -215,7 +222,12 @@ impl<'a> Scope<'a> { } let Ok(tokens) = vlog_parser::tokenize(text) else { continue }; let Some(analysis) = self.analysis(file) else { continue }; - let lines = bare_unbound_uses(&analysis.semantics, &tokens, &name); + let edited: Vec = edits + .iter() + .filter(|(i, _)| *i == file) + .flat_map(|(_, e)| e.iter().map(|e| e.range)) + .collect(); + let lines = bare_unbound_uses(&analysis.semantics, &tokens, &name, &edited); if lines.is_empty() { continue; } @@ -235,8 +247,14 @@ impl<'a> Scope<'a> { /// The lines of `name` tokens in one fragment's plain code that are a use no /// declaration of that fragment answers: not a declaration, not after a `.`, -/// and not a reference resolved inside the fragment itself. -fn bare_unbound_uses(sem: &Semantics, tokens: &[Token], name: &str) -> Vec { +/// not a reference resolved inside the fragment itself, and not covered by +/// one of the rename's `edited` ranges in it. +fn bare_unbound_uses( + sem: &Semantics, + tokens: &[Token], + name: &str, + edited: &[TextRange], +) -> Vec { let mut lines: Vec = Vec::new(); for (i, token) in tokens.iter().enumerate() { if token.kind != TokenKind::Ident || token.text != name { @@ -248,6 +266,9 @@ fn bare_unbound_uses(sem: &Semantics, tokens: &[Token], name: &str) -> Vec if sem.symbol_at(token.span.start).is_some() { continue; } + if edited.iter().any(|e| e.start <= token.span.start && token.span.end <= e.end) { + continue; + } let local = sem.reference_at(token.span.start).is_some_and(|r| r.resolved().is_some()); if !local && lines.last() != Some(&token.line) { lines.push(token.line); diff --git a/crates/vlog_refactor/src/rename/warnings.rs b/crates/vlog_refactor/src/rename/warnings.rs index e449465..8394519 100644 --- a/crates/vlog_refactor/src/rename/warnings.rs +++ b/crates/vlog_refactor/src/rename/warnings.rs @@ -126,7 +126,7 @@ impl<'a> Scope<'a> { warnings.extend(fallbacks); warnings.extend(unfinished); warnings.extend(trace.paths.measure(|| self.path_warnings(target, edits))); - warnings.extend(trace.paths.measure(|| self.fragment_use_warnings(&scoping))); + warnings.extend(trace.paths.measure(|| self.fragment_use_warnings(&scoping, edits))); for (i, edits) in edits { let mut scan = kept.remove(i).unwrap_or_default(); warnings.extend( @@ -172,7 +172,7 @@ impl<'a> Scope<'a> { warnings.extend(self.unresolved_candidate_warnings(i, name, &mut FileScan::default())); } warnings.extend(self.path_warnings(target, edits)); - warnings.extend(self.fragment_use_warnings(&scoping)); + warnings.extend(self.fragment_use_warnings(&scoping, edits)); for (i, edits) in edits { warnings.extend(self.unaccounted_warnings(*i, name, edits, &mut FileScan::default())); } diff --git a/crates/vlog_refactor/tests/rename_warning_scope.rs b/crates/vlog_refactor/tests/rename_warning_scope.rs index b8eae5e..002403b 100644 --- a/crates/vlog_refactor/tests/rename_warning_scope.rs +++ b/crates/vlog_refactor/tests/rename_warning_scope.rs @@ -107,3 +107,20 @@ endmodule 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); +} diff --git a/docs/features/generate-label-rename/README.md b/docs/features/generate-label-rename/README.md index 2052cd9..9b5edd6 100644 --- a/docs/features/generate-label-rename/README.md +++ b/docs/features/generate-label-rename/README.md @@ -551,6 +551,20 @@ carrying disabled): `entropy_src_main_sm.state_q` 47 = 47 warnings, `hmac_core.StIdle` 0 = 0, `prim_count.cnt_q` 13 = 13, timing unchanged (~2.9 s) — no noise added there. +**2026-10-07 — fix for review M-1.** The H4 fragment warning +(`Scope::fragment_use_warnings`) ignored the rename's own edits, so a use in +an include-related file that the rename *did* rewrite (a cross-file +reference, such as `n.sv`'s instantiation of a renamed module `m` when +`all.sv` includes both) was reported as "left unchanged". Tokens covered by +an edit in that file are now skipped. Test: +`tests/rename_warning_scope.rs` +`an_edited_use_in_an_include_related_file_is_not_said_to_be_left_unchanged` +(fails with the skip disabled). Workspace: 80 suites, 5 077 passed, 0 +failed, 51 ignored; the first run was **cut by the guard** at 1 800 s while +launching the freshly linked `vlog_semantic/tests/struct_members` binary +(`syspolicyd` at 71 % CPU: the §65.3 stall), limit not raised; the +identical re-run passed. + ## QA log **2026-09-30 — QA agent (Opus).** Verdict: **PASS with findings** — no diff --git a/oct_review.md b/oct_review.md index 0366288..c1fff57 100644 --- a/oct_review.md +++ b/oct_review.md @@ -65,7 +65,7 @@ It is a read-only review. The only file written is this one. ## MEDIUM -### M-1. The H4 fragment warning reports uses the rename *did* edit as "left unchanged" +### M-1. The H4 fragment warning reports uses the rename *did* edit as "left unchanged" — **FIXED 2026-10-07** - **Where:** `scoped.rs:~181-231` (`fragment_use_warnings` / `bare_unbound_uses`). It ignores the rename's edit ranges. - **Repro** (reviewer B, PI):