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]>
87 lines
4.1 KiB
Rust
87 lines
4.1 KiB
Rust
//! QA attacks on TODO §65.1 over the wire: `references` and `rename` through
|
|
//! a block label with the other files closed, and the `member_key` spelling
|
|
//! of a block that lives inside a function.
|
|
//! `docs/features/generate-label-rename/README.md`, QA log 2026-09-30.
|
|
|
|
use super::*;
|
|
|
|
/// `(file name, line)` of every location in a `references` answer.
|
|
fn places(found: &Value) -> Vec<(String, u64)> {
|
|
let mut out: Vec<(String, u64)> = found
|
|
.as_array()
|
|
.expect("an array")
|
|
.iter()
|
|
.map(|l| {
|
|
let uri = l["uri"].as_str().unwrap_or("?");
|
|
let name = uri.rsplit('/').next().unwrap_or("?").to_string();
|
|
(name, l["range"]["start"]["line"].as_u64().unwrap_or(0))
|
|
})
|
|
.collect();
|
|
out.sort();
|
|
out
|
|
}
|
|
|
|
fn position(uri: &Uri, text: &str, line: usize, name: &str) -> Value {
|
|
let row = text.lines().nth(line).expect("the line");
|
|
let character = row.find(name).expect("the name on that line");
|
|
serde_json::json!({
|
|
"textDocument": { "uri": uri },
|
|
"position": { "line": line, "character": character },
|
|
"context": { "includeDeclaration": true },
|
|
})
|
|
}
|
|
|
|
/// A module `ff` with a block `fb` holding `t`, and — in another file — a
|
|
/// function `ff` with a named block `fb` holding its own `t`. The function's
|
|
/// `t` is a local: nothing outside the function can name it, and the module's
|
|
/// `t` is a different declaration.
|
|
const MODULE_FF: &str = "module ff;\n if (1) begin : fb\n logic t;\n end\nendmodule\n";
|
|
const USER: &str =
|
|
"module user (output logic o);\n ff u_ff ();\n assign o = u_ff.fb.t;\nendmodule\n";
|
|
const FUNC: &str = "module host;\n function automatic void ff();\n begin : fb\n logic t;\n t = 1'b0;\n end\n endfunction\nendmodule\n";
|
|
|
|
#[test]
|
|
fn a_function_local_in_a_named_block_is_never_mistaken_for_a_modules_block_member() {
|
|
let tree = Tree::new("qa_genlabel_member_key");
|
|
tree.write("ff.sv", MODULE_FF);
|
|
tree.write("user.sv", USER);
|
|
tree.write("host.sv", FUNC);
|
|
let mut session = Session::wide(vec![tree.path.clone()], false);
|
|
let host = session.open(&tree.path.join("host.sv"), FUNC);
|
|
let found = places(&session.result(References::METHOD, position(&host, FUNC, 3, "t;")));
|
|
assert_eq!(found, vec![("host.sv".to_string(), 3), ("host.sv".to_string(), 4)]);
|
|
|
|
let mut params = position(&host, FUNC, 3, "t;");
|
|
params["newName"] = serde_json::json!("t2");
|
|
let answer = session.request(Rename::METHOD, params).response_result.expect("renames");
|
|
let changes = answer["changes"].as_object().expect("changes");
|
|
assert_eq!(changes.len(), 1, "only host.sv: {answer:#}");
|
|
}
|
|
|
|
/// Three files: the block's module, an intermediate module instantiating it,
|
|
/// and a testbench naming a member through two instances and the block. Only
|
|
/// the declaring file is open.
|
|
const LEAF: &str = "module leaf;\n for (genvar i = 0; i < 2; i++) begin : g_l\n logic s;\n end : g_l\nendmodule\n";
|
|
const MID: &str = "module mid;\n leaf u_leaf ();\nendmodule\n";
|
|
const TB: &str = "module tbq (output logic o);\n mid u_mid ();\n assign o = u_mid.u_leaf.g_l[1].s;\nendmodule\n";
|
|
|
|
#[test]
|
|
fn a_two_instance_path_through_a_block_is_renamed_with_every_other_file_closed() {
|
|
let tree = Tree::new("qa_genlabel_two_hops");
|
|
tree.write("leaf.sv", LEAF);
|
|
tree.write("mid.sv", MID);
|
|
tree.write("tbq.sv", TB);
|
|
let mut session = Session::wide(vec![tree.path.clone()], false);
|
|
let leaf = session.open(&tree.path.join("leaf.sv"), LEAF);
|
|
let found = places(&session.result(References::METHOD, position(&leaf, LEAF, 1, "g_l")));
|
|
let at = |f: &str, l| (f.to_string(), l);
|
|
assert_eq!(found, vec![at("leaf.sv", 1), at("leaf.sv", 3), at("tbq.sv", 2)]);
|
|
|
|
let mut params = position(&leaf, LEAF, 2, "s;");
|
|
params["newName"] = serde_json::json!("s_q");
|
|
let answer = session.request(Rename::METHOD, params).response_result.expect("renames");
|
|
let changes = answer["changes"].as_object().expect("changes");
|
|
let tb = path_to_uri(&tree.path.join("tbq.sv")).expect("a uri");
|
|
assert_eq!(changes.get(tb.as_str()).and_then(Value::as_array).map_or(0, Vec::len), 1);
|
|
}
|