Rename: an include-related file's use that the rename edits is not said to be left unchanged (review M-1)
fragment_use_warnings ignored the rename's edits, so renaming module `m` while `all.sv` includes `m.sv` and `n.sv` rewrote `n.sv`'s instantiation and still warned "n.sv:2: `m` is used in a file that includes `m.sv` … and was left unchanged". Tokens covered by an edit in that file are skipped. Test: rename_warning_scope.rs (fails with the skip disabled). Workspace: 80 suites, 5 077 passed, 0 failed, 51 ignored (first run cut by the guard at 1 800 s launching a fresh test binary — the §65.3 stall; re-run green). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
eadee02c37
commit
38244e6aaf
5 files changed
+59
-7
No files matched your search
@@ -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<String> {
|
||||
/// 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<TextEdit>)],
|
||||
) -> Vec<String> {
|
||||
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<TextRange> = 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<u32> {
|
||||
/// 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<u32> {
|
||||
let mut lines: Vec<u32> = 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<u32>
|
||||
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);
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
|
||||
+1
-1
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user