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]>
601 lines
35 KiB
Markdown
601 lines
35 KiB
Markdown
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
||
|
||
# call-hierarchy-everywhere
|
||
|
||
Lane A of a two-lane wave (2026-10-14). Builds on `hierarchy` (M11, the
|
||
module call hierarchy) and `type-hierarchy` (the class tree); both READMEs
|
||
point here for what changed.
|
||
|
||
## Goal
|
||
|
||
A user report: in VS Code, "Show Call Hierarchy" showed nothing. The lead
|
||
reproduced it at the LSP level — `prepareCallHierarchy` answered only with the
|
||
cursor exactly on a module's declaration name or on an instantiated module
|
||
name, and `null` everywhere else (an instance name, anywhere in a module body,
|
||
on or inside a function or task); `prepareTypeHierarchy` answered `null`
|
||
anywhere inside a class body but on its name. An editor that opens nothing
|
||
from 95 % of the positions a user invokes the command from looks broken,
|
||
whatever the protocol allows. This feature makes both views open from wherever
|
||
the cursor is, and gives functions and tasks a call hierarchy of their own —
|
||
callers and callees resolved through the semantic and workspace layers, not by
|
||
name-matching strings.
|
||
|
||
## What each prepare position answers
|
||
|
||
`textDocument/prepareCallHierarchy`, first match wins:
|
||
|
||
| cursor | answer |
|
||
|---|---|
|
||
| a module's own declaration name | that module (M11, byte-identical) |
|
||
| the module name of an instantiation | every declaration of it (M11, byte-identical) |
|
||
| an **instance name** (`u_sub` in `sub u_sub (…)`) | the instantiated module's item(s) — the same answer as its module name |
|
||
| a function or task: its declaration name, a call, the `endfunction : f` label | a function/task item (`FUNCTION`, or `METHOD` in a class); a call two files could answer gives both, as `definition` does |
|
||
| anywhere else inside a function or task body (incl. its header and `endfunction`) | that function or task |
|
||
| anywhere else inside a module, interface or program (incl. its header, comments, strings) | the innermost enclosing module's item, exactly as M11 builds it |
|
||
| a package body outside its functions, a file-level or package-level class body outside its methods, file scope, a large-file buffer | `null` |
|
||
|
||
A class declared *inside a module* is inside that module, so a position in
|
||
its body outside a method answers the enclosing module (the innermost-module
|
||
rule), not `null`. A cursor on a macro use (`` `CALL_IT(1) ``) is no name
|
||
either layer resolves, so it answers the enclosing function or module.
|
||
|
||
A position just past the last character of a name is on that name (M11's
|
||
caret rule, extended to calls: `twice|(v)` prepares `twice`).
|
||
|
||
`textDocument/prepareTypeHierarchy`: the class name or a use of it as before;
|
||
otherwise the **innermost class whose declaration encloses the cursor**; on
|
||
`super`, that class's base(s) (`supertypes` of the enclosing class), falling
|
||
back to the class itself when the base is unresolvable. `this` needs no case —
|
||
it is inside its class. Modules stay off the type hierarchy (the type-hierarchy
|
||
README's lead decision): a position in a module and outside every class is
|
||
still `null`.
|
||
|
||
## Item kinds and `data`
|
||
|
||
| item | `kind` | `data` |
|
||
|---|---|---|
|
||
| module / interface / program | `MODULE` (unchanged) | none (unchanged) |
|
||
| function or task | `FUNCTION`; `METHOD` when declared in a class | `{"kind":"function"\|"task","name":…,"offset":…}` |
|
||
| package caller | `PACKAGE` | `{"kind":"package","name":…,"offset":…}` |
|
||
| class caller | `CLASS` | `{"kind":"class","name":…,"offset":…}` |
|
||
|
||
`offset` is the byte offset of the declared name in the item's file when the
|
||
item was built. `detail` on a function/task/package/class item is the name of
|
||
the container the declaration sits in (`util_pkg`, `counter`), so two `log2`s
|
||
in one list can be told apart; `None` at `$unit`.
|
||
|
||
`incomingCalls`/`outgoingCalls` route on `data`: an item whose `data` parses
|
||
as above goes to `hierarchy/calls.rs`; anything else (no `data`, or `data`
|
||
this server did not write) is a module item and takes the M11 path untouched.
|
||
Package and class caller items answer both directions with nothing.
|
||
|
||
**Re-finding the declaration.** The item's file (the open buffer, else a fresh
|
||
analysis of the file on disk) is searched for symbols of that name and kind:
|
||
the one whose name starts at `offset`, else the one at the item's
|
||
`selectionRange` start, else — by name alone — the **only** one of that name
|
||
and kind declared in the container the item's `detail` names (no container
|
||
for `$unit`). Otherwise the item answers nothing: unlike modules, two
|
||
functions of one name are ordinary, and the old "first of that name" fallback
|
||
let a stale item for `mb`'s `log2` answer for `ma`'s (QA finding 3). `detail`
|
||
is the one echoed field relied on besides `data`, and only as a tie-break.
|
||
|
||
## Incoming and outgoing
|
||
|
||
**A call** is a use of the function's name that the semantic layer resolved
|
||
to the declaration — in the declaring file through the symbol table or the
|
||
workspace overlay (`super.f()` reaches a base-class method through the
|
||
overlay), in another file through the overlay — and that is not one of three
|
||
non-call uses: the `endfunction : f` end label, the name of an out-of-body
|
||
definition (`function void c::f();`, recorded as a redeclaration), and the
|
||
Verilog **result variable**: a function's own name inside its own body with no
|
||
`(` after it, whether written (`f = a;`, `f += 1;`) or read
|
||
(`clog2 = clog2 + 1;`). `f(…)` inside its own body is recursion and is listed;
|
||
a bare `f` in *another* body is a call (a function with no arguments may be
|
||
called without parentheses) and is listed too.
|
||
|
||
**`incomingCalls`** — every call, workspace-wide, from the same files
|
||
`textDocument/references` reads for the same declaration: the declaring file;
|
||
for a declaration the index holds (a package or class member), every open
|
||
buffer plus every closed file the index has a reference posting for. The same
|
||
ambiguity contract too: a declaration whose uses the index marks ambiguous,
|
||
or an open buffer holding an ambiguous use of it, falls back to the declaring
|
||
file alone (references falls back to the cursor's file). Grouped one entry per
|
||
caller — the innermost enclosing function or task, else the enclosing module,
|
||
interface, program, package or class — with `fromRanges` the call names. A
|
||
call at file scope has no caller and is dropped (the same rule as an
|
||
instantiation outside a module). Sorted by caller URI, then line. A **module
|
||
caller** is the very M11 module item (no `data`), so expanding it walks
|
||
instantiations — one level up the design.
|
||
|
||
**`outgoingCalls`** — the calls written in the function's bodies (plural: an
|
||
`extern` prototype and its out-of-body definition are two scopes owned by one
|
||
symbol), each resolved to its declaration, grouped by callee in order of first
|
||
call. **Skipped:** system tasks and functions (`$display` is not a reference
|
||
at all), an unresolved name, and a name the overlay finds ambiguous — the same
|
||
silence M11's `outgoingCalls` keeps for an ambiguous instantiation, for the
|
||
same reason (a node pointing at the wrong one of two declarations is
|
||
unfalsifiable to the reader).
|
||
|
||
**Module items do not mix in function calls** (the brief's default, kept). A
|
||
module's outgoing calls are instantiations; listing `always`-block calls beside
|
||
them would put two relations behind one node with no way for a client to tell
|
||
them apart — exactly the argument the type-hierarchy README makes for keeping
|
||
modules off `typeHierarchy`. The function-to-module direction does mix, on
|
||
purpose: a function's caller may *be* a module, and that node is the module
|
||
item, whose own expansion is the design tree.
|
||
|
||
Each request answers one hop; recursion (`fact` calls `fact`) is the function
|
||
appearing as its own caller and callee, and the client drives the expansion.
|
||
|
||
## Assumptions
|
||
|
||
- **Callers are found by re-analysing files, not from the index's spans.**
|
||
Attribution needs the enclosing scope of every call, which a reference
|
||
posting does not carry, so each candidate closed file is parsed and analysed
|
||
once (`Document::new`) — the cost is one parse per file that references the
|
||
function, the same order as `incomingCalls` for modules reading the files
|
||
that instantiate. The *file selection* is references'; the spans are the
|
||
live analysis's, so a closed file edited on disk since the last index build
|
||
answers with its current text (references would drop the stale span).
|
||
- **The result variable is recognised by scope plus one token:** the use
|
||
resolves to a function, sits in a body that function owns (its own scope
|
||
or an out-of-body definition's), and the next token is not `(`. Tasks have
|
||
no result variable. This is the only token-level judgement; everything else
|
||
is the semantic model's.
|
||
- **An end label is recognised structurally:** it lies inside the extent of
|
||
the scope its declaration opens but is recorded in the scope around it
|
||
(`vlog_semantic`'s `use_end_label`). A recursive call is recorded inside.
|
||
- **Two declarations of one name and kind in one file** resolve by `offset`;
|
||
when an edit has moved both the offset and the selection range, by the
|
||
item's `detail` (container), and otherwise not at all — see "Re-finding the
|
||
declaration".
|
||
- **The two ambiguity fallbacks are defensive.** `indexed_def_for_symbol`
|
||
accepts a declaration only when its unit's member table holds exactly one
|
||
record for the name, and every use's lookup reads that same table, so in a
|
||
consistent workspace no use can be ambiguous *and* include a declaration
|
||
this feature stands on. The decision lives in one predicate, `declined`,
|
||
whose two clauses are each pinned by a unit test that reaches it directly
|
||
(an indexed caller of a twice-declared package; an open buffer outside the
|
||
indexed folder); kept because references has the same contract and a
|
||
future index rule could make the case reachable.
|
||
- **A function's caller inside a class body but outside a method** (a
|
||
property initializer) is the class; inside a package outside a function, the
|
||
package. Both are items with `data` and no further hops.
|
||
|
||
## Limits
|
||
|
||
- **A `$unit` function called from another file** is not resolved: the
|
||
semantic layer finishes an unqualified value-position name only through
|
||
imports, so `ufn(1)` in a file that does not declare `ufn` is `NotFound`.
|
||
In-file calls work. The cursor on such a call falls back to the enclosing
|
||
module. Pinned by
|
||
`hierarchy_everywhere::a_unit_scope_function_answers_in_its_own_file_only`.
|
||
- **A module's own function called hierarchically from another module**
|
||
(`u_core.twice()`) is not a call this feature sees: module-level functions
|
||
are on no index surface (`surface_of(Module, Function)` is `None`).
|
||
- **The end label of an out-of-body definition** records no use in the binder,
|
||
so prepare on it falls back to the enclosing function (the definition's own
|
||
body), which is the right item anyway.
|
||
- **Class methods:** calls through `this.`, a bare name, a typed handle
|
||
(same file and across files, through `import`) and `super.` all resolve and
|
||
are listed. Virtual dispatch is not modelled: `h.f()` is a call of the `f`
|
||
the handle's *declared* class resolves to, not of every override.
|
||
- `prepareTypeHierarchy` on `super` with an unresolvable base answers the
|
||
enclosing class rather than `null`.
|
||
- **Macros are not expanded.** A cursor on a macro use answers the enclosing
|
||
function or module, and a call written inside a macro body (`` `CALL_IT(1) ``
|
||
expanding to `cf(1)`) is not listed by `incomingCalls` or `outgoingCalls` —
|
||
the same answer references gives, since neither layer sees the expansion.
|
||
|
||
## Handshakes
|
||
|
||
- **Consumes `vlog_semantic`** (read-only, nothing new asked): `Semantics`
|
||
scopes/symbols/references/duplicates, `ExternalResolutions::{definition_of,
|
||
get}`, `WorkspaceIndex::{references_to, references_are_ambiguous, path}`.
|
||
- **Consumes `crate::nav::indexed_def_for_symbol`** (already `pub(crate)`)
|
||
— the identity references uses to map a live symbol onto its indexed
|
||
declaration, so this feature and references agree on what "the same
|
||
function" is by construction. `nav.rs` is unchanged.
|
||
- **Consumes `crate::state`**: `Document::new` (a fresh analysis of a closed
|
||
file, as `type_hierarchy::supertypes` already does), `document`,
|
||
`document_for_path`, `open_documents`, `text_of`, `first_token_from`,
|
||
`first_token_reaching`. Unchanged.
|
||
- **Promises `server/dispatch.rs`**: nothing new — `hierarchy::{prepare,
|
||
incoming, outgoing}` and `type_hierarchy::prepare` keep their signatures,
|
||
and the routing on `data` lives inside `hierarchy.rs`. `dispatch.rs` is
|
||
untouched.
|
||
- **Promises clients**: a module item is byte-identical to M11's wherever M11
|
||
answered; `data` is present exactly on function, task, package and class
|
||
items.
|
||
- **REQUEST to the lead — `crates/lucisv_server/tests/e2e.rs` (not in this
|
||
lane's file list).** Two e2e round trips pin the old `null` at positions the
|
||
brief now makes answer, and fail on this lane:
|
||
- `the_module_hierarchy_round_trips_over_the_wire_in_both_directions`,
|
||
line 3401: `assert_eq!(response(5)["result"], Null, "an instance name is
|
||
no module")` — request 5 is the cursor on the instance name `u_mid` of
|
||
`hier_mid u_mid ();`; it now answers the `hier_mid` item. Proposed:
|
||
`assert_eq!(response(5)["result"][0]["name"], "hier_mid", "an instance
|
||
name stands for its module")` (and the comment above request 5, "The
|
||
instance name is not a module, so there is no hierarchy to open.", to
|
||
match).
|
||
- `the_class_hierarchy_round_trips_over_the_wire_in_both_directions`,
|
||
line 4876: `assert_eq!(response(5)["result"], Null, "a property name is
|
||
no class")` — request 5 is the property name `y` inside `type_mid`; it now
|
||
answers `type_mid`. Proposed: `assert_eq!(response(5)["result"][0]["name"],
|
||
"type_mid", "inside a class body, the enclosing class")` (and the comment
|
||
above request 5).
|
||
No other test outside this lane's files moved.
|
||
- **Note for a future `vlog_semantic` round (not a request this lane
|
||
blocks on):** resolving an unqualified call to a `$unit` function declared
|
||
in another file would lift the first limit above. It is a resolution-rule
|
||
change (compilation-unit scope is tool- and filelist-dependent), not
|
||
something to work around here.
|
||
- **`editors/vscode` needs no change** (lane B owns it): the client already
|
||
sends `prepareCallHierarchy`/`prepareTypeHierarchy` from any position.
|
||
|
||
## Status / TODO
|
||
|
||
- [x] `prepareCallHierarchy`: instance name, function/task (declaration, call,
|
||
end label), inside a function/task body, inside a module body, `null`
|
||
elsewhere — `hierarchy.rs::prepare`, `hierarchy/tf.rs`
|
||
- [x] function/task items with `data`; package/class caller items
|
||
- [x] `incomingCalls` with references' file selection and ambiguity fallback,
|
||
grouped by caller — `hierarchy/calls.rs`
|
||
- [x] `outgoingCalls` over the body (and an out-of-body definition), grouped by
|
||
callee; system tasks, unresolved and ambiguous names skipped
|
||
- [x] module items unchanged in both directions
|
||
- [x] `prepareTypeHierarchy` inside a class body, `super` → base —
|
||
`type_hierarchy.rs`
|
||
- [x] tests: 24 LSP-level in `server/tests/hierarchy_everywhere.rs`, 3 in
|
||
`hierarchy/tf.rs`, 4 in `hierarchy/calls.rs`, 1 new in `hierarchy.rs`;
|
||
seven existing unit tests that pinned the old `null` updated (work log)
|
||
- [x] probe before/after on real server binaries (work log)
|
||
- [x] `tests/e2e.rs`: two assertions to update — Handshake request above (lead;
|
||
flipped by the lead, verified green by QA 2026-10-14)
|
||
- [x] `cargo fmt --all --check`, clippy `-D warnings`; `cargo test -p
|
||
lucisv_server` green except the two e2e assertions above
|
||
- [x] rework after QA (2026-10-14): findings 1–5 and 7 fixed, with tests
|
||
|
||
## Work log
|
||
|
||
- **2026-10-14 (dev)** — read CLAUDE.md, the hierarchy and type-hierarchy
|
||
READMEs, `hierarchy.rs`, `type_hierarchy.rs`, `nav.rs` (references),
|
||
`vlog_semantic`'s model, binder and instantiation walk.
|
||
|
||
**Probed the semantic model first** (a throwaway test dumping scopes,
|
||
symbols, references and duplicates for module, package, class, extern and
|
||
`$unit` functions; deleted). What it showed shaped the design: a function's
|
||
scope spans its whole declaration including `endfunction : f`; the end label
|
||
is a reference *recorded in the outer scope*; `f = a;` resolves to `f`;
|
||
`c::ext`'s name is a reference to the prototype *and* a `Duplicate`; the
|
||
out-of-body body is a second scope owned by the prototype's symbol;
|
||
`this.f()` and `h.f()` resolve locally; `$display` records nothing.
|
||
|
||
**Decision — collect callers here rather than reuse `nav::references`.**
|
||
`references` takes a cursor in an *open* document, and the item a client
|
||
expands is very often in a closed one (prepare on a call in `core.sv`,
|
||
the declaration lives in a closed package file). Making `nav.rs` take a
|
||
`&Document` was outside this lane's files, so `calls.rs` reads the same
|
||
file set through the same public index API (`references_to`,
|
||
`references_are_ambiguous`) and the same identity
|
||
(`nav::indexed_def_for_symbol`), and a test
|
||
(`the_cross_file_answer_matches_references`) asserts the two agree
|
||
location for location, end label aside.
|
||
|
||
**Decision — routing on `data` inside `hierarchy.rs`**, so `dispatch.rs`
|
||
is untouched and a module item's path is literally the old code.
|
||
|
||
**Decision — module callers are M11 module items.** Expanding a function's
|
||
caller `top` then shows who instantiates `top`, which reads as one call
|
||
chain up the design; the reverse direction (module → functions) stays
|
||
closed, argued above.
|
||
|
||
**Found while testing:** `super.bump()` resolves through the workspace
|
||
overlay (an inherited candidate), not the local table, so the first cut's
|
||
declaring-file matcher (`resolved() == symbol`) missed it while
|
||
`outgoingCalls` (which reads both layers) found it. Fixed: the declaring
|
||
file accepts either layer; pinned by
|
||
`class_methods_called_through_this_a_handle_and_super`.
|
||
|
||
**Existing tests changed — seven, all pins of the old `null` at positions
|
||
the brief now makes answer** (the brief asks both for these answers and for
|
||
existing tests "green and unchanged"; the two cannot both hold, so each one
|
||
was changed to assert the new answer, renamed where its name stated the old
|
||
one, and given a "Reversed by call-hierarchy-everywhere" doc line):
|
||
`hierarchy.rs`: `a_position_on_no_module_prepares_nothing` →
|
||
`…_prepares_the_enclosing_one_or_nothing` (`module` keyword and a connected
|
||
expression → `top`, instance name → `sub`; the package case still `null`);
|
||
`an_instantiation_of_a_module_nothing_declares_prepares_nothing` →
|
||
`…_prepares_the_enclosing_module`; `qa_prepare_on_a_string_or_comment_is_null`
|
||
→ `…_is_the_enclosing_module_not_the_text`;
|
||
`qa_prepare_on_a_bind_target_module_name_is_currently_null` →
|
||
`…_was_null` (now `top`, the module the bind is written in) plus a new
|
||
`…_is_the_enclosing_module` with the bind moved into a `harness` so target
|
||
and enclosing module differ. `type_hierarchy.rs`:
|
||
`a_position_on_no_class_prepares_nothing` →
|
||
`…_prepares_the_enclosing_one_or_nothing` (`class` keyword and a property →
|
||
`base`; module and wire still `null`);
|
||
`prepare_on_the_extends_keyword_itself_prepares_nothing` →
|
||
`…_prepares_the_class_it_is_written_in` (`child`, never `base`);
|
||
`a_class_name_shadowed_by_a_local_variable_prepares_the_variable_use_as_nothing`
|
||
→ `…_prepares_the_enclosing_class` (`child`, never `base`). The
|
||
generate-class "known gap" pin is unchanged and green: the enclosing-class
|
||
fallback reads the same `classes::declarations` walk, so a class that walk
|
||
cannot see is not a node from the inside either. The two e2e pins of the
|
||
same kind are a Handshake request (not this lane's file).
|
||
|
||
**Probe** (`probe.py` against `proj/`, a `sub`/`top`/`cls` trio; "before"
|
||
is a debug build of master 41a9091 from `git archive`, "after" this lane's
|
||
debug build):
|
||
|
||
```
|
||
position before after
|
||
instance name u_sub null sub (MODULE, data null)
|
||
inside module body (logic r) null sub
|
||
inside always_ff null sub
|
||
function decl inv null inv (FUNCTION, data function)
|
||
call inv(r) null inv
|
||
inside poke body null poke (data task)
|
||
on endfunction keyword null inv
|
||
task decl poke null poke
|
||
module decl sub sub sub (identical)
|
||
call hello() in leaf_c::go null hello (METHOD, base_c's)
|
||
incoming(inv) = [poke @9] outgoing(poke) = [inv @9]
|
||
incoming(hello) = [go (METHOD) @9]
|
||
type: class name mid_c mid_c mid_c
|
||
type: inside leaf_c method body null leaf_c
|
||
type: module body null null
|
||
```
|
||
|
||
**Gates.** `cargo fmt --all --check` clean;
|
||
`tools/guard.sh -- cargo clippy --workspace --all-targets -- -D warnings`
|
||
clean; `tools/guard.sh -t 1800 -- cargo test -p lucisv_server`: unit/server
|
||
binary **1753 passed, 36 ignored** (1757 tests before → 1789 after, +32);
|
||
`tests/e2e.rs` **97 passed, 2 failed, 2 ignored** — the two failures are
|
||
exactly the Handshake request above; `tests/grammar.rs` green. No change to
|
||
`vlog_semantic` or `vlog_refactor` behaviour, so their suites were not
|
||
re-run. No new dependencies. No commits.
|
||
|
||
**Files.** New: `crates/lucisv_server/src/hierarchy/tf.rs`,
|
||
`crates/lucisv_server/src/hierarchy/calls.rs`,
|
||
`crates/lucisv_server/src/server/tests/hierarchy_everywhere.rs`, this README.
|
||
Edited: `crates/lucisv_server/src/hierarchy.rs` (prepare chain, routing on
|
||
`data`, test updates), `crates/lucisv_server/src/type_hierarchy.rs`
|
||
(enclosing-class fallback, `super`, test updates),
|
||
`crates/lucisv_server/src/server/tests/mod.rs` (one `mod` line),
|
||
`docs/features/hierarchy/README.md` and
|
||
`docs/features/type-hierarchy/README.md` (pointer notes). Not touched:
|
||
`dispatch.rs`, `nav.rs`, `main.rs`, `vlog_*`, `editors/`, `TODO.md`.
|
||
|
||
- **2026-10-14 (dev) — rework after QA.** QA's findings 1–5 and 7.
|
||
|
||
1. **Result variable (MEDIUM).** `is_call` now treats a function's own name
|
||
inside a body it owns, with no `(` after it, as the result variable —
|
||
read or written — and drops the separate assignment-operator check it
|
||
subsumes. `f(…)` there stays recursion; a bare `f` from another body
|
||
stays a call. The unit test that pinned `+ f` as a call is flipped;
|
||
new: `the_result_variable_read_in_its_own_body_is_not_a_call` (QA's
|
||
`clog2`), `a_bare_function_name_in_another_body_is_a_call`, and the
|
||
LSP-level `the_classic_clog2_is_not_its_own_caller`.
|
||
2. **Per-callee re-parse (MEDIUM, perf).** `tf::Loaded` holds one
|
||
analysis per path for the life of one request; `outgoingCalls` and
|
||
prepare's multi-declaration answer build every cross-file item through
|
||
it, and `live_symbol` asks identity of the symbol at the recorded
|
||
position first. QA's shape (one closed 430 KB package of 300 functions,
|
||
a caller calling all 300, `scratchpad/lsp/gen_perf.py` + `s_perf.py`),
|
||
release builds, three runs each: **before 3 043 / 3 018 / 3 032 ms,
|
||
after 21 / 18 / 17 ms**.
|
||
3. **Stale item (LOW-MEDIUM).** The "first of that name" fallback is gone:
|
||
by name alone only the one candidate in the item's `detail` container
|
||
answers, asked even of a lone candidate (a renamed-away `mb` leaves
|
||
`ma`'s `log2` as the only one, and it is still the wrong function).
|
||
New: `a_stale_item_never_answers_for_a_same_named_function_elsewhere`
|
||
(QA's `ma`/`mb` reproduction: after the move it answers `mb`'s callers,
|
||
after the rename nothing).
|
||
4. **Ambiguity fallbacks (coverage).** Both checks now sit in one
|
||
predicate, `declined`, called once before any file is read (same
|
||
answers: either clause still returns the declaring file alone). Its
|
||
clauses are each killed by a unit test:
|
||
`an_index_that_marks_the_uses_ambiguous_declines` (no buffer open, an
|
||
indexed `p::f()` with `p` declared twice),
|
||
`an_open_buffer_holding_an_ambiguous_use_declines` (index clean, a
|
||
buffer outside the indexed folder), plus
|
||
`an_ambiguous_use_in_the_declaring_file_itself_does_not_decline`.
|
||
**Not killable end to end, and why:** with a consistent workspace the
|
||
branch cannot be reached through `incomingCalls` — see the new
|
||
Assumption "The two ambiguity fallbacks are defensive". Removing the
|
||
single `if declined(..)` line in `other_files` therefore still survives
|
||
the suite; the predicate it calls does not.
|
||
5. **README.** Limits: macro uses and calls inside macro bodies. The
|
||
prepare table: a class inside a module answers the module.
|
||
|
||
**Gates.** `cargo fmt --all --check` clean; clippy `-D warnings` clean;
|
||
`tools/guard.sh -t 1800 -- cargo test -p lucisv_server`: guard exit 0;
|
||
server binary **1760 passed, 0 failed, 36 ignored** (1753 before the
|
||
rework, +7: five in `hierarchy/calls.rs`, two in
|
||
`server/tests/hierarchy_everywhere.rs`); `tests/e2e.rs` 99 passed, 2
|
||
ignored; `tests/grammar.rs` 3 passed.
|
||
|
||
## QA log
|
||
|
||
### 2026-10-14 — QA agent (Opus)
|
||
|
||
**Verdict: PASS with findings.** No corruption, panic or regression found; the
|
||
M11 module answers are byte-identical and no other client-visible feature moved.
|
||
Two medium findings (a false self-recursion for the classic Verilog result-variable
|
||
idiom, and per-callee re-parsing in `outgoingCalls`) are worth fixing before
|
||
release but block nothing else.
|
||
|
||
**Gates** (in this worktree):
|
||
- `cargo fmt --all --check`: clean.
|
||
- `tools/guard.sh -- cargo clippy --workspace --all-targets -- -D warnings`:
|
||
clean, guard exit 0.
|
||
- `tools/guard.sh -t 1800 -- cargo test -p lucisv_server`: guard exit 0.
|
||
Unit/server binary **1753 passed, 0 failed, 36 ignored**; `tests/e2e.rs`
|
||
**99 passed, 0 failed, 2 ignored** (the lead's two flipped assertions included);
|
||
`tests/grammar.rs` 3 passed. No host stall.
|
||
|
||
**Mutation check** (a scratch copy of the tree, `cargo test -p lucisv_server
|
||
--bin lucisv-server hierarch`, 144 tests in the filter). Killed: return-assignment
|
||
check removed (4 failures), instance-name path removed (2), `data.offset` ignored
|
||
in `tf::target` (1), end-label exclusion removed (3), `super` → base removed (1),
|
||
the caret rule (`offset - 1`) removed (1), the overlay acceptance in the declaring
|
||
file removed (1). **Survived: both ambiguity fallbacks** (finding 4).
|
||
|
||
**Byte-identity vs master 41a9091.** Built 41a9091 in a scratch `git worktree`
|
||
(removed afterwards). Ran `prepareCallHierarchy` at **every character offset** of
|
||
three projects (3 137 positions: the dev's `sub`/`top`/`cls` trio; an attack
|
||
project with packages, classes, DPI, generate and macros; and a module-hierarchy
|
||
project with interfaces, a program, multi-instance statements, generate `for`/`if`,
|
||
parameter overrides, an undeclared module and a `bind`). Wherever the old server
|
||
answered (124 positions), the new answer is identical, byte for byte. The
|
||
`incomingCalls`/`outgoingCalls` answers on all 15 distinct module items are also
|
||
identical. The old server answered 124 positions and the new one answers 2 832.
|
||
|
||
**Other features unchanged.** On two projects, compared `documentSymbol` per file
|
||
plus `definition`, `references` and `hover` at every identifier (1 340 queries)
|
||
between the old and new binaries: **0 differences**.
|
||
|
||
**Attacks over the wire** (`probe.py`, debug build unless noted). Each was as the
|
||
README describes, unless it is listed under findings:
|
||
- Ambiguity. A module two files declare gives both items, and each has the
|
||
instantiating module as its caller. A package two files declare (`pz` in
|
||
`z1.sv`/`z2.sv`): a call prepares both items, as `definition` answers 2; incoming
|
||
is empty for both (the declaring-file fallback).
|
||
- A function and a module with the same name (`module g` plus `function g` in
|
||
`host`). On the instantiation's module name and on its instance name, the answer
|
||
is module `g` (MODULE, no `data`). On the call `g(1)` and on the declaration, it
|
||
is function `g` (FUNCTION, `detail` `host`). A module that nothing declares, named
|
||
like an in-scope function (`nope u1 ();`), answers the enclosing module, never
|
||
the function.
|
||
- Shadowing. In task `sh`, the local `int g`, written or read, prepares `sh`, never
|
||
the function `g`.
|
||
- `extern` prototype, out-of-body `c::ext` name, its end label: all prepare the
|
||
prototype, and outgoing lists the callees in the out-of-body body (`hook`,
|
||
`helper`).
|
||
- `push_back`, `.size()`, `randomize()`, `this.randomize() with {…}`: the
|
||
enclosing method, with no crash and no callee listed.
|
||
- DPI imports (`import "DPI-C" function int c_add…`, a `context task`): FUNCTION
|
||
or TASK items, `detail` none, incoming the module that calls them, outgoing
|
||
empty. That is a sensible answer.
|
||
- `$display` is the enclosing module. A call in a parameter default
|
||
(`#(parameter int P = cf(3))`), a `localparam`, a continuous `assign`, and an
|
||
`assign` in a generate `for` are all credited to the module. A call at file scope
|
||
is dropped.
|
||
- Caller attribution. A call in `initial`, `final`, an `always_comb` named block or
|
||
a `fork` named block is credited to the enclosing module, method or task. A call
|
||
in a package `localparam` is credited to the PACKAGE item, and one in a class
|
||
property initializer to the CLASS item. Qualified `pk::kf` is the same function.
|
||
- Stale and foreign items (finding 3 covers the one gap). These all answer empty
|
||
or correct, never a panic or a wrong file: `offset` 99 999 999, a nonexistent
|
||
name, `kind` `class`/`package`/`task` on a function, selection range line 99 999
|
||
or character 4e9, `untitled:` / `/etc/hosts` / a directory / a missing file as
|
||
URI, `data` missing / null / a string, extra fields in `data`.
|
||
- Large-file mode: in a 5 MB buffer, call prepare, type prepare and the module name
|
||
all answer `null`, and a package function's incoming skips it.
|
||
- UTF-16: ranges after `✓` comments are correct (character 18 where the UTF-16
|
||
count is 18).
|
||
- Type hierarchy: a method body and an out-of-body body give the class; a class
|
||
inside a module gives the class; a module body and a package body give `null`.
|
||
|
||
**Timing.** Release build, 200 closed files each calling `big_pkg::pf` 31 times
|
||
from a module and 10 functions, with only `pkg.sv` and `m000.sv` open:
|
||
- prepare: 2 ms;
|
||
- `incomingCalls`: 76 / 65 / 55 ms over three runs, 2 200 callers and 6 200 ranges.
|
||
This equals `references` (6 200 locations, 23 ms).
|
||
- Server RSS: 13 MB, then 69 MB after the first incoming, then flat.
|
||
- Debug build: incoming 325 / 312 / 302 ms, references 89 ms, 74 MB.
|
||
|
||
The README's "each referencing closed file is parsed once" holds for incoming. It
|
||
does not hold for outgoing (finding 2).
|
||
|
||
**Code review.** Production lines (non-blank, non-comment, before `mod tests`):
|
||
`hierarchy.rs` 212, `hierarchy/tf.rs` 216, `hierarchy/calls.rs` 246,
|
||
`type_hierarchy.rs` 189. All functions are under 50 lines. Production code has no
|
||
`unwrap`/`expect`/`panic`, no new indexing (the one slice in `type_hierarchy.rs`
|
||
predates the lane), and no byte slicing of text (`Positions::offset` clamps). The
|
||
README test counts (24 / 3 / 4) match the code.
|
||
|
||
**Findings**
|
||
|
||
1. **Medium: a Verilog result-variable read is counted as a recursive call.**
|
||
`crates/lucisv_server/src/hierarchy/calls.rs:208-227` (`is_call`). The unit
|
||
test `calls.rs:337-354` pins `+ f` (a bare read) as a call. Reproduction:
|
||
```verilog
|
||
module lg (output integer o);
|
||
function integer clog2(input integer v);
|
||
begin
|
||
clog2 = 0;
|
||
while (v > 1) begin
|
||
clog2 = clog2 + 1;
|
||
v = v >> 1;
|
||
end
|
||
end
|
||
endfunction
|
||
initial o = clog2(16);
|
||
endmodule
|
||
```
|
||
`outgoingCalls(clog2)` = `[clog2 @6]`, and `incomingCalls(clog2)` lists `clog2`
|
||
as its own caller at line 6. That is a false recursion on one of the most common
|
||
Verilog-2001 idioms. Inside a function's own body, its name without a following
|
||
`(` is the result variable, not a call. That is a token-level rule of the same
|
||
kind as the existing `assigned` check, and it applies to functions only.
|
||
2. **Medium (performance): `outgoingCalls` parses a closed callee file once per
|
||
distinct callee.** `calls.rs:272` calls `tf::def_item`, which calls `tf.rs:243`
|
||
`load_path`, which calls `Document::new` for every callee. Reproduction: a
|
||
236 KB closed package with 300 functions, and a caller function `all` that calls
|
||
all 300. In the release build, `outgoingCalls(all)` takes **3 503 ms**, and
|
||
34 ms once the package is open. The cost is about 12 ms per callee for this file
|
||
size. A per-request cache of loaded analyses keyed by path would make it one
|
||
parse per file, as incoming already is.
|
||
3. **Low-Medium: after an edit, a stale item silently resolves to a different
|
||
function with the same name.** `crates/lucisv_server/src/hierarchy/tf.rs:293-295`
|
||
(the `candidates.first()` fallback). Reproduction: `module ma` and `module mb`,
|
||
each declaring `log2`. Prepare `mb`'s `log2`, then `didChange` to add 3 comment
|
||
lines at the top. `incomingCalls` with the old item answers **`ma`'s** caller
|
||
(line 9). After renaming `mb`'s function to `lg`, the old item also answers
|
||
`ma`'s callers. The README documents this fallback (Assumptions, "the module
|
||
rule"), but its own Goal says two functions of one name are ordinary. For
|
||
modules the fallback is rarely wrong; for functions it often is. Suggestion:
|
||
fall back to the first candidate only when it is the only one, or break the tie
|
||
on the item's `detail` (container name).
|
||
4. **Low (coverage): the two ambiguity fallbacks are untested.**
|
||
`calls.rs:79-81` (`references_are_ambiguous`) and `calls.rs:86-88`
|
||
(`names_it_ambiguously`). Each removed alone, the 144 hierarchy tests stay green.
|
||
The README claims "the same ambiguity contract" as references. A test with two
|
||
files declaring one package, and the user file closed and then open, would pin
|
||
it.
|
||
5. **Info: a cursor on a macro use gives the enclosing module, and a call inside a
|
||
macro body is not listed.** For `` `CALL_IT(1) `` expanding to `cf(1)`,
|
||
incoming(`cf`) omits that line. This matches references, since there is no
|
||
macro expansion, but it is not in the README's Limits.
|
||
6. **Info: an ambiguous wildcard import resolves to the first package.** With
|
||
`import pa::*; import pb::*;` and both declaring `f`, `f(1)` prepares `pa::f`
|
||
and is listed in its incoming. This is the semantic layer, and `definition` and
|
||
`references` give the same answer. It is not this lane's.
|
||
7. **Info: the doc row "a class body outside its methods → null" does not apply to
|
||
a class declared inside a module.** There the enclosing module answers. This is
|
||
consistent with the "innermost enclosing module" rule; the table row could say
|
||
"a file-level class".
|
||
|
||
**Fixes made by QA:** ticked the `tests/e2e.rs` Status item, since the lead
|
||
flipped both assertions and the suite is green. No code changed.
|
||
|
||
## Review
|
||
|
||
**2026-10-14 — lead.** Accepted after one rework. The user's report (Show
|
||
Call Hierarchy empty in VS Code) was a prepare that answered only on a
|
||
module name; it now answers from any position inside a module, function or
|
||
task, and functions/tasks are call-hierarchy nodes of their own. QA (Opus)
|
||
confirmed the old module answers byte-identical at 3 137 positions and no
|
||
change in outline/definition/references/hover at 1 340 queries; its two
|
||
mediums (result-variable reads counted as recursion; outgoing re-parsing a
|
||
closed file per callee, 3.0 s → 18 ms) and the stale-item fallback are
|
||
fixed with tests. The e2e handshake is granted: two assertions that pinned
|
||
the old `null` now assert the new answers. The one surviving mutant (the
|
||
`declined` call in `other_files`) guards a branch the index makes
|
||
unreachable today; kept, and recorded as an Assumption. Merged onto master
|
||
with the lane-B references view; gates re-run on the merged tree.
|
||
|
||
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|