# top-rooted-paths TODO §65.4 (from §65.1 QA F1). Wave 0.62.0 (§65.7), serial after lane A. ## Goal A hierarchical path whose head is a top-level module declared in another file — `tb.dut.u_x.sig`, the shape every opentitan DV `force`, `$deposit` and `uvm_hdl_*` path takes (IEEE 1800 §23.6: a top-level module name is the root of a hierarchical name) — resolved nothing: `tb` was a `Target::Lexical` use that missed in the writing file, `resolve::head_site` stopped the spine there, no segment after it was a reference, and a rename of `dut`'s declarations left the path behind (since §65.1 with a warning). The goal is that such a path resolves through the workspace exactly as an instance path does, so `find_references` and LSP references list its segments and `rename` rewrites them, while a root the workspace does not declare stays unchanged and is warned about. ## Design - **The head is its own target.** `bind/expr.rs`: the bare identifier that heads a dotted path (`ExprKind::Member` whose base is an `Ident`) is bound as `Target::PathHead` instead of `Target::Lexical`. Only the head of a dotted path: a bare identifier anywhere else is unchanged, so a value-position miss is still never swept through the unit table (the reason `lexical`'s doc gives). The `with`/`bind` funnel in `bind/mod.rs::use_member` treats `PathHead` exactly as `Lexical`. - **`resolve/root.rs` (new)** holds the root rules. **The governing rule (lead, after QA): a path is rooted only when this file shows the head can be nothing but a top-level module or interface; in doubt it is not, and the path stays unresolved and warned about.** - `roots_at_top(scopes, from)`: false when any scope from the use up to the file is a class (a member, inherited or macro-declared, is never a provable path into the hierarchy; a class in a package may not reference it at all) or holds an unexpanded macro invocation where a declaration could stand (`Scope::macro_items`, set by `Binder::mark_macro_declarations` for an item, a statement or block item in any `begin`/`end`, `fork`, task or function body, and a port-list entry or an unreadable port element; it may declare the name). A macro inside an expression or used as a data type cannot declare a name and does not block. - `path_head`: the lexical answer; on a plain `NotFound` that `roots_at_top` allows, the candidate `ExternalCandidate { paths: [head], surface: Hierarchical }`. An import candidate (`import p::*` in scope, which by the LRM could supply the name) is left exactly as `lexical` gave it, whether or not the workspace can answer it; so is an `InheritedCandidate`. - `unit_root`: the site `MemberSite::Unit { path: head, surface: Hierarchical }`. - `$root.tb.…`: `top_site`/`top_module` look `tb` up at file scope only (an in-file module or interface), else the workspace unit. `$root` skips the lexical walk, so a local `tb` does not capture `$root.tb`. - **`resolve.rs::head_site`**: on a plain `NotFound` that `roots_at_top` allows (the same rule as the head's own reference) the resolution walk answers `root::unit_root(head)`, so the head reference and the segments after it are rooted in one unit; anything else roots nothing. The workspace's `fold_path` then walks `tb` → `dut`'s type → … exactly as for an instance path. A system name or a macro (`$unit`, `` `TOP``) roots nothing. - **The completion walk is unchanged.** `member_site` (what `Semantics::member_site` and the completion popup call) and the resolution walk share `spine_site`, parameterised by `HeadMiss`: `member_of` passes `TopModule`, `member_site` passes `Nothing`. A popup after an unknown head keeps answering `None` (so the ordinary tiers run), which the server's completion tests pin; offering `tb.`'s members is a server-side change (Handshake H2). `$root.tb.` is rooted in both walks. - **Only a module or an interface is a root, and a package is never a hop.** `workspace/external.rs`: a bare path equal to the name on the *hierarchical* surface (only a path head produces one) answers through `root_units` — all instantiable, else nothing. And `fold_path`, on the hierarchical surface, checks every unit it stands in (`design_unit`): the first must be declared and only as modules/interfaces; a later one may not be a module and something else at once (the member table is keyed by name and would merge the two). A later unit that is only a package would need a declaration typed with a package's name, which is not code; the separate "never a package" clause was dropped as unreachable (QA M7). So with a module and a package both named `tb` the head *and* every segment answer nothing, and `pk.x` with only a package `pk` resolves to nothing (QA F1). - **The rename's file set (LSP)**: `WorkspaceIndex::path_units_to(def)` (new, `workspace/path_units.rs`) lists every unit an indexed hierarchical use of `def` walks through — the root and each hop's type — read off the facts the index holds. `lucisv_server/src/state/sources.rs:: want_declaration` adds those units' declaring files, so a three-hop `tb.dut.u_core.sig` resolves inside the rename's set as in the whole (QA F3; lead-granted). A unit outside the index scope adds nothing, and the path stays warned about. - **An accurate refusal** (`vlog_refactor/src/rename/mod.rs`): a rename asked at a path segment the workspace could not walk is refused with "`x` is a segment of a hierarchical path lucisv could not resolve to one declaration …", not "declared outside the files lucisv indexes". - **`FACTS_FORMAT` 21 → 22** (`facts.rs`, reason written there): no new field, but new records — a 0.61.0 store would answer as though no DV file's `force tb.dut.…` named anything. - **The §65.1 path warning** (`vlog_refactor/src/rename/paths.rs`): a segment of a top-rooted path (head is `$root`, or the head's reference is a root candidate) whose overlay answer is `StillUnresolved` counts as unresolved, so the warning still fires for a root the workspace does not declare, or declares several times. An `Ambiguous` answer is not flagged: when it can name the renamed declaration `collect_occurrences` already refuses the rename. - **Said once** (Handshake H1, lead-granted): `warnings.rs`'s `unresolved_candidate_warnings` skips a candidate that `paths::names_top_rooted_miss` says the path scan names, so such a line carries only the §65.1 path warning. The file is lexed for that check only when an unanswered candidate is on the hierarchical surface. ## What resolves now - `tb.dut.g_sw[0].buf_q` in a file that does not declare `tb`, with exactly one `module tb` (or `interface tb`) in the set: `tb` → the module, `dut` → the instance, `g_sw` → the block, `buf_q` → the variable. Every segment is a reference: `find_references` lists it, `rename` of any of the four declarations (or from the segment itself) rewrites it, verified as usual. - `$root.tb.dut.…`, the same, and `$root.tb.x` against an in-file `tb`. - Not rooted, by the rule above, and left warned exactly as before §65.4: a head an import could supply, a head inside any class, a head in (or under) a scope holding an item-level macro invocation, a head named both a module and a package, and a package alone. ## Limits - **Several `module tb` in the set** (opentitan: 70 files under `hw/`): `tb` is `Ambiguous`, `tb.dut` names 70 instances, and `member_unit_in` refuses an ambiguous hop, so nothing after the head resolves; the rename leaves the path and warns. Choosing the `tb` whose branch has the next member was considered and rejected: the whole-tree `gen_sw_assigns` case is ambiguous between `keymgr` and `keymgr_dpe` anyway, and an `Ambiguous` answer that can name the renamed declaration makes `collect_occurrences` refuse the whole rename — so branching would turn today's warnings into refusals for every common member name. - **A renamed top module's `tb` heads are references** to it. With several same-named tops a rename of one is refused as ambiguous (pinned: `renaming_one_of_two_same_named_tops_is_refused`); before, the heads were `NotFound` and only the declaration was renamed. - **Any wildcard import in scope stops rooting** — including the `import uvm_pkg::*;` nearly every opentitan DV interface starts with. By the LRM such an import could supply the head, and `uvm_pkg` is not in the tree for the index to rule it out, so the path is doubt. Measured: on opentitan `hw` (and in `hw/ip/keymgr_dpe`) the reference postings are exactly master's — no DV force path roots. Rooting when every supplying import is indexed and shown not to hold the head is possible future work; it would not change opentitan while `uvm_pkg` is outside the tree. - **Any macro where a declaration could stand blocks rooting** from its scope down (lead's R1 ruling): a `` `uvm_info `` statement in the block beside a `force` blocks it too, since the binder cannot tell a logging macro from a declaring one. A macro statement in an unnamed `begin` whose statements bind in the enclosing scope blocks that whole scope. - **Completion after `tb.`** answers nothing (H2, deferred by the lead). - `undeclared-identifier` no longer sees an unknown path head as `NotFound` (it is a root candidate now). Measured on opentitan `hw`: 7 findings before and after, identical. ## Assumptions - A bare identifier followed by `.` whose lexical lookup misses plainly — no import could supply it, no class or item-level macro on the scope chain — is a top-level module name (§23.6); a typo there is an unresolved candidate, not `NotFound`. - Only the head of a dotted path is a root; `tb[0].x` (an indexed head) is not modelled as one. - The surface tag on the head candidate is the only signal that a bare path must be instantiable; nothing else produces a bare hierarchical path. ## Handshakes - **Consumes**: `WorkspaceIndex::member_unit_in` / `fold_path` (unchanged), `hierarchy::member` (unchanged), `Scope::analysis().external`. - **Promises (changed)**: `Resolution::ExternalCandidate` with `surface: Hierarchical` and a bare path is now produced for a path head; `follow_one` answers it with modules and interfaces only. `Semantics:: member_site` is unchanged for every head except `$root`. - **H1 (granted by the lead 2026-10-19, done)**: `warnings.rs` `unresolved_candidate_warnings` skips a segment `paths.rs` names (`paths::names_top_rooted_miss`, `pub(super)`), so an unresolved top-rooted path is said once, in the §65.1 wording. - **F3 (granted by the lead, done)**: `lucisv_server/src/state/sources.rs` `want_declaration` adds the files of `WorkspaceIndex::path_units_to(def)`. **Promised to the server**: `path_units_to` is a pure read of the index's facts (no file is read); its cost is one pass over the reference records of each file holding a use of `def`. - **Outside the listed files, flagged**: `vlog_refactor/src/rename/mod.rs` gained `hierarchical`/`unresolved_path` so the refusal at an unresolved segment is the accurate one the lead's F3 ruling asks for (two call sites, the message only; no rename decision changes). - **H2 (deferred by lead → TODO; `lucisv_server/src/completion/member.rs` untouched)**: to offer `tb.`'s members, call a root-aware member site and answer `None` when the index holds no unit for the root (the server's `an_unresolvable_head_answers_nothing_at_all` must keep passing). ## Status / TODO - [x] root lookup in `head_site`, the head recorded as a module use - [x] QA's repro renames the path instead of warning - [x] the §65.1 warning stays for an undeclared (or ambiguous) root - [x] `find_references` and LSP references list the path segments - [x] the local-shadows-top case - [x] `$root.` (cheap: done) - [x] opentitan index/scan cost before and after; `FACTS_FORMAT` bump reasoned - [x] H1: an unresolved top-rooted path is said once (lead-granted) - [x] rework after QA: F1 (no package root or hop), F2 (an import wins), F3 (LSP rename set holds the path's units; accurate refusal), F4 (no root in a class or beside an item-level macro) - [ ] H2: completion after `tb.` — deferred by lead → TODO ## Work log **2026-10-19 (dev, Opus).** Worktree fast-forwarded ec492cd → 51b975b. - Implemented as designed above. `resolve.rs` 559 → 586 production lines (the walk split `spine_site`/`HeadMiss`); the root rules are the new `resolve/root.rs` (29). - Deviation: the planned single walk would have changed completion after an unknown head (two server tests), so completion keeps its walk (H2). - Deviation: rooting a head on an import miss as well as on `NotFound` — opentitan's DV interfaces import packages, so `NotFound`-only would leave the target shape unresolved. - QA's repro `a_path_rooted_at_another_files_top_module_is_never_silently_left_behind` flipped to assert the rename (granted). Other §65.1 tests that used a declared `tb` as the vehicle for an *unresolved* root now drop `tb.sv` from their set (so the root is genuinely undeclared) and gained the declared counterpart asserting the rename: `qa_generate_label.rs` (three rechecks), `qa_warning_scope.rs` (two), `rename_generate_label.rs` (two, wording), `generate_blocks.rs` / `member_access.rs` (an unknown head's tail is now a candidate, not absent), server `rename_generate_label.rs` (shown wording). - Invariant 4: `vlog_refactor/src/check/` untouched. - Tests: `vlog_semantic/tests/top_rooted_paths.rs` (13), `vlog_refactor/tests/top_rooted_paths.rs` (8), one declared-root counterpart in `qa_generate_label.rs`, `vlog_refactor/tests/ opentitan_top_rooted.rs` (3, ignored), `lucisv_server/src/server/tests/ references_top_rooted.rs` (5). Counts before → after: `vlog_semantic` 401 → 414 (4 ignored), `vlog_refactor` 727 → 736 (3 → 6 ignored), `lucisv_server` 1 865 → 1 870 (40 ignored), `lucisv_mcp` 383 → 383; `vlog_linter` 673 → 673. Gates: fmt, clippy `-D warnings`, the four suites green. One `lucisv_server` run lost two `large::` linear-time tests to host load (load average 14–16, another lane's suites); the re-run was green. *Opentitan* (eval clone `~/.cache/lucisv-eval/ot`, read-only; release; engine API, nothing written — `vlog_refactor/tests/opentitan_top_rooted.rs`, ignored by default): | | before (51b975b) | after | |---|---|---| | `rename gen_sw_assigns`, set `hw/ip/keymgr_dpe` (23 files, the LSP folder scope) | 1 site in 1 file; warnings: `uvm_info` macro arg :523, path :514,515,517 | **4 sites in 2 files** (label + `keymgr_dpe_if.sv:514,515,517`); warning: `uvm_info` :523 only | | same, set `hw` (3 979 files, 70 `module tb`) | 1 site; 4 warnings (2 macro args, 2 path lines `keymgr_if.sv:468,469,471`, `keymgr_dpe_if.sv:514,515,517`) | 1 site; 4 warnings, the same 4 (6 before H1: the 2 candidate lines for the same sites) | | rename time, `hw` | 2.16 s | 2.23 s | | facts, `hw` (encoded) | 54 297 047 B | 54 465 816 B (+0.31 %) | | index postings `reference_sites` / keys | 528 532 / 60 559 | 528 719 / 60 573 | | `WorkspaceIndex::build`, `hw`, best of 3 | 1.65 s | 1.69 s | | `lucisv check hw` wall, two runs each | 1.050 / 1.051 s (re-run 1.059 / 1.063) | 1.064 / 1.065 s | | `lucisv check hw` findings | 1 158 | 1 158, byte-identical output | | `check --select undeclared-identifier hw` | 7 | 7, identical | The host was shared with another lane's suites (load average 14–16), so the sub-2 % time deltas are within noise. **2026-10-19 (dev, Opus) — H1.** Lead granted H1, deferred H2. `paths::names_top_rooted_miss` (`pub(super)`, wraps `is_segment` + `top_rooted_miss`) is asked by `warnings.rs::unresolved_candidate_warnings` for each unanswered hierarchical candidate; a hit is skipped. The tests that tolerated the duplicate now assert exactly one line again (`qa_generate_label.rs` recheck, `rename_generate_label.rs` back to `warnings.len() == 1`, `top_rooted_paths.rs` two, server `an_unresolved_path_in_an_open_buffer_is_shown_as_a_rename_warning` back to `probe.sv:2:` with no "more"), plus a new `an_unresolved_top_rooted_path_is_named_by_exactly_one_warning` (QA's repro undeclared, and with three `module tb`), and the opentitan whole-tree probe asserts the force lines are said once. Opentitan `rename gen_sw_assigns` over `hw`: **6 → 4 warnings** (2 macro arguments, 2 path lines), 1 site, 2.16 s; IP folder unchanged (4 sites in 2 files, 1 warning). Counts: `vlog_refactor` 737 (6 ignored), `lucisv_server` 1 870 (40), `lucisv_mcp` 383 (4) — its `a_rename_names_each_same_named_file_by_its_root_relative_path_once` passes with the two path lines and no candidate lines. fmt and clippy clean. **2026-10-19 (dev, Opus) — rework after QA.** Governing rule (lead): root only when the engine can show the head is a top module or interface. - **F1** (`workspace/external.rs`): `fold_path` checks every unit on the hierarchical surface (`design_unit`): first unit declared and all modules/interfaces; later units never a package nor mixed. Tests: semantic `a_package_never_lends_a_top_rooted_path_its_members`; refactor `qa_f1_a_package_sharing_the_roots_name_lends_the_path_nothing` (QA's B12: renaming the package's `dut`, the module's instance `dut`, or `x` leaves `tb.dut.x` and names it), `qa_f1_a_package_is_never_a_root` (A3/A4). - **F2** (`resolve/root.rs`, `resolve.rs::head_site`): an import candidate is never rooted, and the "bare name last" fallback is gone. Tests: semantic `an_import_in_scope_wins_and_roots_nothing` (replaces `an_import_in_scope_is_tried_before_the_top_module`); refactor `qa_f2_an_imported_head_is_never_rooted_at_a_same_named_module` (A1). - **F3** (`workspace/path_units.rs` new, `lucisv_server/src/state/sources.rs`, `vlog_refactor/src/rename/mod.rs` message): server tests `rename_top_rooted_scope.rs` (5, folder scope): three-hop rename from the declaration and from the segment, the generate-block `buf_q`, LSP equals engine over the scope, and a root outside the scope (warned; segment rename refused with "hierarchical path", not "declared outside"). With the `sources.rs` rung disabled four of the five fail. - **F4** (`Scope::macro_items`, `roots_at_top`): semantic `a_head_inside_a_class_or_beside_a_macro_item_roots_nothing` (A11, D2, A12, and a macro one scope out); refactor `qa_f4_a_head_this_crate_cannot_see_is_never_rooted`. - Mutations: `design_unit` and `roots_at_top` both forced true → both F1 refactor tests and the F4 test fail; `head_site` rooting an import candidate again → the F2 test fails. - Changed tests: `rename_generate_label.rs` genblk1 refusal accepts the new message; the opentitan probe's IP-folder test is now `the_ip_folder_leaves_the_imported_head_and_says_so`. - Counts: `vlog_semantic` 416 (4 ignored), `vlog_refactor` 741 (6), `lucisv_server` 1 875 (40), `lucisv_mcp` 383 (4), `vlog_linter` 673 (0); fmt and clippy `-D warnings` clean; every suite through the guard, exit 0. - Opentitan: `lucisv check hw` stdout and stderr byte-identical to master's binary (1 158 lines); `--select undeclared-identifier` identical (7). `rename gen_sw_assigns`: IP folder 1 site, 2 warnings (`uvm_info` :523, path :514,515,517 — `keymgr_dpe_if.sv` imports `uvm_pkg::*`); whole `hw` 1 site, 4 warnings, 2.13 s — both exactly master's. Index over `hw`: `reference_sites` 528 532 / keys 60 559, equal to master; facts 54 333 266 B (+36 KB, the head candidates). **2026-10-19 (dev, Opus) — rework 2 (R1, M7).** - **R1**: `Binder::mark_macro_declarations(scope)` (`bind/mod.rs`) is now called for an item-level macro (`bind/item.rs`), a macro statement (`bind/stmt.rs`, `StmtKind::MacroStmt`, on the scope the statement binds in) and a header port list holding a `` ` ``-spelled port or an error element (`bind/item.rs::port_list_may_hide_declarations`, on the module's scope). Tests: semantic `a_macro_where_a_declaration_could_stand_roots_nothing` (E1, E2, E6, E3 twice) and `a_macro_that_cannot_declare_the_head_still_roots` (data-type macro, sibling generate block E7, a macro inside an expression); refactor `qa_r1_a_macro_where_a_declaration_could_stand_blocks_rooting` (E1, E2, E6 left and named; E3 left) and `qa_r1_a_macro_off_the_scope_chain_or_as_a_type_still_renames` (E7, E8 shape). With both new flag sites disabled the refactor R1 test fails. - **M7**: the later-hop "never a package" clause in `design_unit` dropped as unreachable (argued in its doc comment); the mixed module+package rule still refuses QA's B12, pinned by the F1 tests. - **QA's cases1–6 re-run** against this build (QA's harness `scratchpad/qa654/attack`, outputs in `scratchpad/p654/cases{1..6}.out`). Every rename either rewrites the correct sites or leaves the path and warns: - A1, A3, A4, A7, A8, A10, A11, A12: left and warned. A2: the package variable renamed with its use (correct). A5, A6, A9: the head is a local (clocking block, interface port, virtual interface handle), the path is another declaration, nothing to warn (correct). - B1, B7, B8, B10: renamed correctly (local `tb` elsewhere warned in B1). B2, B3: `$root` paths renamed; the local-`tb` line warned; two `tb` refused. B4: five colliding renames refused. B5: the instance-array path warned, the unpacked array and the instance array name renamed. B6 (bind) and B9 (forward local) warned. B11: warned. B12: both renames leave `tb.dut.x` and warn. - C1: renamed from the declaration, the segment and the label; refs list all three sites. - D1: the unshadowed module's path renamed, the shadowed one warned. D2, D3 (struct field), D6 (typo head): warned; D3's `acc` renamed. D4, D5: renamed correctly. - E1, E2, E3, E4, E5, E6: left and warned. E7 (sibling block) and E9 (modport macro): renamed, correctly. E8 (data-type macro): the head is the local `st`, warned as an unresolved candidate. - F3 (`cases6`): each `sig` rename edits exactly its own references. - Counts: `vlog_semantic` 418 (4 ignored), `vlog_refactor` 743 (6), `lucisv_server` 1 875 (40), `lucisv_mcp` 383 (4), `vlog_linter` 673 (0); fmt and clippy `-D warnings` clean; every suite through the guard, exit 0. - Opentitan `lucisv check hw`: stdout and stderr byte-identical to master's binary (1 158 lines); `--select undeclared-identifier` identical (7). ## QA log **2026-10-19 — QA agent (Opus).** **Verdict: conditional pass. F1 needs a fix before release, and the lead should rule on F2–F4.** Everything else held: the verifier, the shadow and `$root` rules, the cache bump, opentitan byte identity, and every guard mutated. *Gates* (worktree as handed over, 51b975b + dev diff; every suite through `tools/guard.sh`, guard exit 0 each, logs kept): - `cargo fmt --all --check` clean, and `clippy --workspace --all-targets -D warnings` clean. - Suites: `vlog_semantic` 414 passed (4 ignored), `vlog_refactor` 737 (6), `lucisv_server` 1 870 (40), `lucisv_mcp` 383 (4), `vlog_linter` 673 (0). All 0 failed, and every count matches the work log. No host stall. *Tests read.* The new semantic, refactor and server tests assert what their names say: exact `file:line` sets, the exact texts after the edit, and warning counts. Flipped tests: - `qa_generate_label.rs` and `qa_warning_scope.rs` now drop `tb.sv`, so the root is really undeclared, and each gained a declared counterpart. That is sound. - The server rename test covers only the block label `g_sw`, which is one hop below the root's child. That is exactly the case F3 does not hit. *Mutations.* Each was applied in a scratch copy of the workspace (`scratchpad/qa654/ws`), never in this tree, and each ran the semantic, refactor and server suites: - M1: remove the module/interface-only rule in `root_units`. Caught by 1 semantic test (`only_a_module_or_an_interface_is_a_root`); 0 refactor or server failures. - M2: a local of the head's name no longer shadows, in both `path_head` and `head_site`. Caught by 70 semantic and 37 refactor failures. - M3: `$root.tb` ignores an in-file `tb`, in `top_site` and `top_module`. Caught by 1 semantic test (`dollar_root_reaches_a_top_module_this_file_declares`). - M4: `$root.tb` goes through the lexical walk, so a local `tb` captures it. Caught by 2 semantic tests (`dollar_root_names_the_top_module_and_skips_the_lexical_walk` and the previous one). - All four are caught. M1 and M3 are each pinned by a single unit test, and nothing at the rename level pins them. *Verifier (invariant 4; `check/` untouched).* 8 masked-corruption attacks went into a scratch-only `check/qa_top_rooted.rs` over `dut_a` / `tb` / `probe` (`tb.dut.buf_q` ×2 and `$root.tb.dut.buf_q`). All 8 behaved: three honest edit sets verify, and every corrupt one is refused: - a leaf rename missing each one of the 3 path segments, or missing the declaration; - a top-module rename missing each one of the 3 heads, or also renaming a local `logic tb`; - an instance rename missing each segment. *Opentitan* (`~/.cache/lucisv-eval/ot`, read-only, `git status` clean before and after): - **`lucisv check --no-cache hw`.** Master 51b975b, built in a scratch `git worktree` that has since been removed, and this branch both print 1 158 lines. stdout and stderr are byte-identical. - **`--select undeclared-identifier`.** Identical, 7 findings. - **`find_references` at 48 seeded random positions.** Half of them follow a `.`, over `hw/ip/{keymgr_dpe,aes,uart,i2c}`. Before and after are byte-identical. - **Targeted top-rooted positions.** These were `pwrmgr_if.sv:191` `tb.dut.u_slow_fsm…`, and `otp_ctrl_if.sv:169/287` and `tb.sv:248` under `top_earlgrey/ip_autogen/{pwrmgr,otp_ctrl}`. Every difference is a segment of a top-rooted path that now has references where it had none. For example, `gen_partitions` went from no symbol to 12 references (10 force and release lines, `tb.sv` and the RTL label), and `u_slow_fsm` went from none to 4. - **No other names changed.** *`FACTS_FORMAT` 22.* The server ran over one fixture first with master's binary (format 21), then with this branch. The new server analysed every file afresh, with no `cached:` lines, and answered with the new references. A second run of the new server read its own cache. The unit tests `index_cache.rs:846` and `qa_m6.rs:367` already reject every older format. *Code.* - No new `unwrap`, `expect` or `panic`. The index arithmetic in `paths.rs` `path_head` and `matching_open` is guarded. - Production lines: `resolve.rs` 586, which is under 600 but at the mark, so the next arm goes in a module. `resolve/root.rs` is 29, `paths.rs` 158, `warnings.rs` 555, `external.rs` 224. - `warnings.rs::unresolved_candidate_warnings` is now about 79 lines, including its doc comment. That is just under the 80-line investigate mark (Info). *Findings* - **F1 (High): silent wrong rename and silent miss when a module and a package share the root's name.** Location: `vlog_semantic/src/workspace/external.rs:337-342` (`follow_one`, the multi-segment branch). - What `root_units` guards: only the bare head path `tb`. - What it misses: the next segment's path `tb::dut` folds `tb` and asks `member_chain` on the hierarchical surface, which answers from the package. - Repro: `module tb; dut_a dut (); endmodule`, `package tb; logic dut; endpackage`, and `other.sv`: `initial force tb.dut.x = 0;`. - Renaming the package's `dut` to `d2` rewrites the path to `tb.d2.x`, which is wrong because the path names the module's instance. No warning. - Renaming the module's instance `dut` to `u_dut` leaves the path, also with no warning, because it resolved to a different declaration. - Before §65.4 neither edit touched the path, and the path was warned about. - The same root cause makes `pk.x`, with a package `pk` and no module (illegal code), resolve into the package, and renaming the package member rewrites it (A3/A4, Low on their own). - This contradicts the Design bullet "Only a module or an interface is a root". - Suggested direction, the dev's to choose: apply the instantiable check to the first hop of a hierarchical candidate rooted at a top. Then add a rename-level test, because M1 is caught only by the semantic suite. - **F2 (Medium, a documented limit, but a silent wrong rename): an imported package variable used as a head, next to a same-named module.** Location: `vlog_semantic/src/resolve.rs:408` (`head_site` roots on `ExternalCandidate` as well as on `NotFound`). - Repro: `package p; typedef struct packed {logic field;} s_t; s_t cfg; endpackage`, `module cfg; logic field; endmodule`, and `user.sv`: `import p::*; assign o = cfg.field;`. - The head `cfg` resolves to `p::cfg`, the package variable, but the tail `field` resolves to the module's `field`. - Renaming the module's `field` to `fld2` rewrites `cfg.field` to `cfg.fld2` with no warning. Before, the tail had no reference. - The head and its tail disagree about the root, which is detectable. The tail could carry the head's import paths first (`p::cfg::field`, then `cfg::field`), or rooting could be refused when the head's own answer is not a unit. - **F3 (Medium, loud): LSP rename misses the files of the path's middle hops.** Location: `lucisv_server/src/state/sources.rs:235-285` (`fan_out_of` / `want_declaration`; outside this lane's files, so this is a Handshake request). - The rename set holds the declaration, the reference postings and the instantiation sites of the container. It does not hold the root's file (`tb.sv`) or a middle hop's file. Inside the rename, the root is then undeclared. - Repro, fixture `ip/rtl/{core,dut_a}.sv`, `ip/dv/{tb,probe}.sv`, where `probe.sv` has `force tb.dut.u_core.sig = 1'b0;`, under the default folder scope: - LSP references on `core.sv`'s `sig` list `probe.sv:2`. - LSP rename of `sig` edits `core.sv` only and warns "probe.sv:2: a hierarchical path through `sig` was not resolved…". - Rename from the segment in `probe.sv` is refused with "`sig` is declared outside the files lucisv indexes", which is misleading. - The same happens for `buf_q` inside `g_sw`: references list `probe.sv:2,3`, and rename edits the declaration only. - `top_sig` (one hop) and `g_sw` (the label) rename fine. - The Goal's own shape `tb.dut.u_x.sig` is the failing one, and most opentitan force paths are deeper than one hop. The engine API (and so `lucisv-mcp`) renames them correctly over the whole set. - Not silent, because it is warned, but references and rename disagree over LSP. - **F4 (Low–Medium, by the §23.6 assumption): a head the binder cannot see now roots silently.** Location: `vlog_semantic/src/resolve/root.rs:24` (`path_head`) with `resolve.rs:408`. - Before, these were the §65.1 path warning. Now each is renamed silently through a same-named module: - a class without `extends` whose `cfg` comes from a macro (A11: `` `DECLARE_CFG `` then `cfg.en`); - a module whose struct `st` comes from `` `DECL_STRUCT(st) `` (A12); - a class in a package writing `tb.dut.x` (D2). That is illegal (a package may not reference the hierarchy), but it is renamed anyway. - A cheap narrowing: do not root inside a class scope. Opentitan's DV classes all live in packages, where no head can legally be a top module. - **F5 (Low, documented).** `undeclared-identifier` no longer reports an unknown path head (`tbb.dut.x`), which is now an unresolved candidate. The rename still warns, and the opentitan count is unchanged (7). *Held (no finding).* - **Locals shadow.** A local `tb` net (same file or another) shadows and is warned. A forward-declared local instance `tb` shadows. - **Labels and other heads.** A named block `blk` beats `module blk`. A clocking block `cb.data`, a modport / interface port head and a `virtual bus_if vif` head all stay local. A genvar or parameter head, and `f().x`, are warned. - **Classes.** An extending class leaves the head alone and warns. - **`bind` and `$root`.** A `bind` head is warned (the BindScope funnel). `$root.tb` with a local `tb` reaches the top, and `$unit::` is unaffected. - **Renaming the root and its instance.** Renaming `tb` rewrites every head and `$root.tb`, and skips local `tb`s. Two `module tb` is refused. A colliding rename of a leaf, the instance or the top is refused (5 cases). `tb.dut.x = y` renamed `x` → `y` correctly. - **Arrays.** An instance array `u[2].x` is not descended and is warned. `mem[3]` and the instance array name itself rename. A struct field through `acc[1].rl` is warned. - **Interfaces and upward names.** An interface top works, and so does an upward module-name reference (`par.sig` from a child). - **LSP references.** Correct with the declaring file open or closed. Under `workspace` with two `tb`, they answer nothing and rename is refused. - **H1.** The dedupe predicate is equivalent to the path scan's, and the path scan's text prefilter trims newlines, so a multi-line path is not lost. *Fixes made by QA:* none. Scratch harnesses: `scratchpad/qa654/attack` (case files `cases1–4.txt`), `refs_{new,base}`, `lspfx*`, `probe2.py`. **2026-10-19 — QA agent (Opus), re-check after "rework after QA".** **Verdict: pass for F1–F4 as reworked.** One new Medium finding needs the lead's ruling (R1: a macro that is not item-level can declare the head), and there are two Info notes. No QA fixes were made. *Gates.* Every suite ran through the guard with exit 0. - `cargo fmt --all --check` and `clippy --workspace --all-targets -D warnings` are clean. - Suites: `vlog_semantic` 416 (4 ignored), `vlog_refactor` 741 (6), `lucisv_server` 1 875 (40), `lucisv_mcp` 383 (4), `vlog_linter` 673 (0). All 0 failed, and every count matches the work log. *The old attacks, re-run against the new build* (`cases1–4`, plus LSP `lspfx`, `lspfx2`). - **F1 is fixed.** B12 (a module `tb` beside a package `tb`): renaming the package's `dut` or the module's instance `dut` now leaves `tb.dut.x` and warns about it, both ways. A3 and A4 (`pk.x` through a package) now warn, and the segment refuses. - **F2 is fixed.** A1: the imported `cfg` keeps its head. Renaming the module's `field` leaves `cfg.field` and warns, and the segment has no reference. - **F4 is fixed.** A11 (a class with a macro member), A12 (a macro item in a module) and D2 (a package class) are all warned again, as before §65.4. - **F3 is fixed.** The three-hop `tb.dut.u_core.sig` renames over LSP from the declaration and from the segment: 2 edits in 2 files, equal to the references. So does the generate-block `buf_q` (3 edits in 2 files). Under `workspace` scope with two `tb`, the segment refusal now says "segment of a hierarchical path…". - **Every other round-1 case is byte-identical to round 1.** That covers B1–B11, D1, D3–D6, `$root`, the shadows, the collisions and the arrays. *New attacks.* - **F3's wider set (`lspfx4`).** - The fixture puts an unrelated `sig` in every hop file: `tb.sv` (a local `sig`, plus `dut.sig` and `dut.u_core.sig`), and `dut_a.sv` (its own `sig`, plus `module helper` with a `sig`). - Renaming `core`'s, `dut_a`'s or `tb`'s `sig` over LSP edits exactly the references, and the engine over the whole set gives the same edits. - `helper` is never touched, and neither is the unrelated `sig` in any hop file. - **A macro beside a head that is not item-level** (`cases5.txt`). These are the R1 cases: - E1: `` initial begin `DECL_LOCAL(st) st.a = 1; end `` beside `module st; logic a;`. Renaming `st.a`'s `a` to `b` rewrites `st.a` to `st.b` silently. - E2 and E6: the same inside a task body and a function body. - E3: `` module user (`MY_PORTS, output logic o); … bus.data `` beside `module bus`. The rename rewrites it silently. - **Macro shapes that hold or are warned.** - Held: a macro in a non-ANSI port region (E4), a macro at file scope (E5), and a macro used as a data type (E8). - Rooted, and correctly so: a macro in a *sibling* generate block (E7) is not in the head's lexical chain. - A macro inside a modport list (E9) still roots. A modport declares no variables, so this is no finding. *Mutations* (scratch copy, re-synced): - M5: `roots_at_top` without its class check. Caught by 1 semantic test and `qa_f4_…`. - M6: `roots_at_top` without its macro check. Caught by the same two tests. - M7: `design_unit`'s later-hop "never a package" clause removed. **Not caught** by any of the three suites (Info). A later hop's unit is an instance's or a variable's type, and a module and package sharing a name is already refused by the mixed check. So the clause looks unreachable short of an instance of a package (malformed code). Either pin it with such a test or drop it. *Opentitan* (read-only, `git status` clean): - **`lucisv check --no-cache hw`.** Against master 51b975b (scratch worktree, removed afterwards), stdout and stderr are byte-identical, 1 158 lines each. `--select undeclared-identifier` is identical. - **`find_references` spot checks.** The 48 seeded positions are identical to master. The round-1 top-rooted positions (`pwrmgr_if.sv:191`, `otp_ctrl_if.sv:169/287`) now answer exactly as master, because those interfaces import `uvm_pkg::*` and the owner's conservative ruling applies. - **Info:** on opentitan's DV interfaces the feature is therefore dormant; every one imports a package. *Code.* - No new `unwrap`, `expect` or `panic`. - Production lines: `resolve.rs` 587 (at the mark), `resolve/root.rs` 38, `external.rs` 240, `workspace/path_units.rs` 50, `state/sources.rs` 176. *Findings* - **R1 (Medium, silent wrong rename; the lead to rule): a macro that is not item-level can declare the head.** - Location: `vlog_semantic/src/resolve/root.rs:40` (`roots_at_top`) and `bind/item.rs` (only `ItemKind::MacroItem` sets `macro_items`). - What escapes it: - a macro statement in a `begin`/`end`, task or function body, where a block-item declaration is legal (E1, E2, E6); - a macro in an ANSI port list (E3). - These root the head at a same-named module and rename through it silently. Before §65.4 they were warned about. - Narrowing would follow the same rule as F4: a macro statement in any enclosing procedural scope, and a macro in the port list, also count as doubt. - The coordinator's brief says statement macros were left out by design. E1–E3 show that they can declare the head, so the trade-off is the lead's call. It needs a module sharing the head's name, which is rare in RTL. ## Review **2026-10-19 — lead.** Accepted after two reworks. QA (Opus) found four silent-wrong-rename shapes (F1 a package sharing the root's name; F2 an imported head beside a same-named module; F4 heads the binder cannot see) plus the LSP rename set missing the middle hops (F3); its re-check found R1 (a statement-level or port-list macro declaring the head). All fixed with tests built from QA's repros; QA's cases1–6 re-run against the final build are each warned or correctly renamed. Owner's ruling: stay conservative — a head with an import candidate (e.g. `import uvm_pkg::*` with uvm_pkg not in the project) is doubt and not rooted, so opentitan's DV force paths stay warned exactly as before; the feature applies where the root is provable. `lucisv check hw` byte-identical to master. Granted handshakes: `rename/ warnings.rs` (H1, said once), `lucisv_server/src/state/sources.rs` (F3), the message in `rename/mod.rs`. H2 (completion after `tb.`) deferred as TODO §65.8.