From 0e740d77eca9d45e8fb1966f44738acccfa5d4c4 Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 26 Aug 2026 19:56:55 -0700 Subject: [PATCH] vlog_semantic: type-position misses reach the workspace overlay MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Delivers the Handshake docs/features/type-definition/README.md filed: an unqualified lexical miss written where a TYPE goes — bus_if bus;, my_cls h;, a cross-file typedef — now carries its bare name to the workspace overlay (last, so imports still win), in both spellings: ExternalCandidate, and InheritedCandidate inside extending classes, whose base and count (7,841, bit-identical) are untouched. The mechanism is a new Target::Type emitted only by bind_data_type's unqualified arm; value-position identifiers, disable labels and redeclarations keep their pre-round Target::Lexical behavior — NotFound stays NotFound, and rename keeps refusing them. That value/type split is the round's story: QA rejected the first cut with a kept repro proving a value-position typo could rename an unrelated same-named module cross-file (write-by-coincidence, pre-round refused), and disproved the work log's exposure claim against the pre-round source. The fix is a four-line behavior delta; QA re-killed the regression from three angles and reproduced every corpus figure to the digit. Result over the 860-file corpus: NotFound 1,418 -> 1,256, 418 clean-file references gained a jump target, none lost one, 141 coincidence-answers deliberately given back. The server's stopgap is deleted whole: type_def.rs::indexed_type, qualifier guard included — all 45 type-definition tests green unchanged, and cross-file interface rename from a type window is newly possible and pinned. Corpus formatter results byte-identical (813/820 both trees). New docs/features/overlay-promotion/README.md; the vlog-semantic and workspace-index tables re-measured (the committed baselines had gone stale several rounds ago; both READMEs now carry the three-state table). Co-Authored-By: Claude Fable 5 --- crates/lucisv_server/src/type_def.rs | 177 ++-- crates/vlog_refactor/tests/rename.rs | 39 + crates/vlog_semantic/src/bind.rs | 10 +- crates/vlog_semantic/src/model.rs | 30 +- crates/vlog_semantic/src/resolve.rs | 24 +- crates/vlog_semantic/src/workspace.rs | 26 +- crates/vlog_semantic/tests/classes.rs | 13 +- crates/vlog_semantic/tests/corpus.rs | 3 +- crates/vlog_semantic/tests/semantics.rs | 9 +- crates/vlog_semantic/tests/workspace.rs | 258 +++++- docs/features/class-semantics/README.md | 10 +- docs/features/overlay-promotion/README.md | 966 ++++++++++++++++++++++ docs/features/type-definition/README.md | 95 ++- docs/features/vlog-semantic/README.md | 111 ++- docs/features/workspace-index/README.md | 97 ++- 15 files changed, 1686 insertions(+), 182 deletions(-) create mode 100644 docs/features/overlay-promotion/README.md diff --git a/crates/lucisv_server/src/type_def.rs b/crates/lucisv_server/src/type_def.rs index 09be81f..606758f 100644 --- a/crates/lucisv_server/src/type_def.rs +++ b/crates/lucisv_server/src/type_def.rs @@ -14,7 +14,11 @@ //! name, reads the index, or knows what a package is; it only decides *which //! offset* the question is really about. That is also why a type declared in //! another file needs no code at all: it is the same two-layer answer -//! `textDocument/definition` gives, asked one token to the left. +//! `textDocument/definition` gives, asked one token to the left. An +//! unqualified type name nothing in the file binds — `bus_if bus;`, +//! `my_cls h;` — reaches that overlay because `vlog_semantic` sends it there +//! carrying its own name (`docs/features/overlay-promotion/README.md`); this +//! module used to ask the index itself and no longer does. //! //! Finding that offset needs the parse tree, because the symbol table does not //! carry a declaration's type: a `Symbol`'s `decl_span` is its *declarator* @@ -40,9 +44,8 @@ use vlog_parser::ast::{ Module, ParamPort, PortList, Stmt, StmtKind, TfArg, Typedef, TypedefKind, }; use vlog_parser::TextRange; -use vlog_semantic::{Resolution, Semantics, SymbolKind}; +use vlog_semantic::{Semantics, SymbolKind}; -use crate::locate::location; use crate::nav; use crate::state::{Document, Workspace}; @@ -55,12 +58,7 @@ use crate::state::{Document, Workspace}; pub fn type_definition(ws: &Workspace, uri: &Uri, offset: u32) -> Vec { let Some(doc) = ws.document(uri) else { return Vec::new() }; let Some(span) = type_name(doc, offset) else { return Vec::new() }; - let found = nav::definition(ws, uri, span.start); - if found.is_empty() { - indexed_type(ws, doc, span) - } else { - found - } + nav::definition(ws, uri, span.start) } /// Where the type name this position is asking about is written. @@ -106,59 +104,6 @@ fn type_use_at(doc: &Document, offset: u32) -> Option { } } -/// The workspace index's own answer for a type name both layers gave up on. -/// -/// `vlog_semantic` reports an unqualified name that nothing in this file binds -/// as a *lexical miss* rather than as an external candidate (`resolve.rs`'s -/// `miss`), so the overlay never sees it and `nav::definition` has nothing to -/// say — and that is exactly how an `interface` or a package-less `class` -/// declared in another file is written. So the index is asked directly, under -/// three restrictions that keep it from becoming a fourth resolution layer: -/// only for a name the file's own resolution reported as such a miss, only for -/// a **file-scope** declaration, and only for the kinds that can be a type — a -/// `package` of that name is not one. Every declaration is returned when the -/// workspace has several, as `definition` does. -/// -/// A lexical miss has **two** spellings, and both are this fallback's: plain -/// `NotFound`, and `InheritedCandidate` — which `resolve.rs`'s `miss` returns -/// for *any* miss inside a class carrying an `extends`, whether or not the -/// name has anything to do with inheritance. In a type position that means -/// "some base class might declare this type", and `vlog_semantic` never chases -/// a base chain (in this file or out of it), so no layer can turn it into a -/// location; the workspace's file-scope type of that name is the only honest -/// answer there is. That is not a guess against a better one: when the name -/// really is declared somewhere this crate *can* see, the reference resolves -/// and `nav::definition` has already answered before this is consulted. -/// -/// The requirement this stands in for is written up in the feature README's -/// Handshakes; when `vlog_semantic` promotes both spellings of that miss to a -/// candidate, this function goes away and nothing else here changes. -fn indexed_type(ws: &Workspace, doc: &Document, span: TextRange) -> Vec { - match doc.semantics.reference_at(span.start).map(|r| &r.resolution) { - Some(Resolution::NotFound | Resolution::InheritedCandidate { .. }) => {} - _ => return Vec::new(), - } - // A qualified member (`pkg::name`) names something inside `pkg`, and a - // bare-name sweep would discard the qualifier — the one way this fallback - // could jump somewhere the source never pointed. `unit_member` can miss - // with the same two spellings this fence accepts (QA log, 2026-08-26), - // so the qualifier is checked here, not assumed away. - let qualified = - doc.text.get(..span.start as usize).is_some_and(|before| before.trim_end().ends_with("::")); - if qualified { - return Vec::new(); - } - let Some(name) = doc.text.get(span.as_range()) else { return Vec::new() }; - ws.index() - .units(name) - .iter() - .filter(|def| { - matches!(def.kind, SymbolKind::Module | SymbolKind::Class | SymbolKind::Typedef) - }) - .filter_map(|def| location(ws, ws.index().path(def.file)?, def.name_span)) - .collect() -} - /// The name span of the declaration the position names, whether the cursor /// sits on a use or on the declaration itself — the same resolution /// `textDocument/definition` runs. @@ -379,6 +324,9 @@ mod tests { use std::fs; use std::path::PathBuf; use std::str::FromStr; + // The handler itself no longer reads a `Resolution`; the tests still do, + // to pin *why* an answer came out the way it did. + use vlog_semantic::Resolution; fn document(text: &str) -> (Workspace, Uri) { let uri = Uri::from_str("file:///rtl/m.sv").expect("uri"); @@ -712,24 +660,37 @@ endpackage } #[test] - fn a_package_of_the_same_name_is_not_a_type() { - // The index holds file-scope declarations of every kind; only the - // ones that can be a type are an answer. + fn a_package_of_the_same_name_answers_exactly_as_definition_answers_it() { + // Was `a_package_of_the_same_name_is_not_a_type`, a fence in the + // deleted `indexed_type`: that function filtered the index by kind + // because it *was* a fourth resolution layer and had to justify what + // it looked at. The answer now comes from the one overlay + // `textDocument/definition` uses, whose documented policy is no kind + // filtering — every declaration of the name, never a guess between + // them (`docs/features/workspace-index/README.md`). `thing t;` where + // the workspace's only `thing` is a package is broken source either + // way; giving the same location F12 gives on the same token is the + // honest answer, and disagreeing with F12 here would need the fourth + // layer back. let pkg = "package thing;\nendpackage\n"; let top = "module top;\n thing t;\nendmodule\n"; let (dir, ws, uri) = workspace("pkgtype", &[("thing.sv", pkg), ("top.sv", top)], "top.sv"); - assert!(type_definition(&ws, &uri, at(top, "thing t") + 6).is_empty()); + let offset = at(top, "thing t") + 6; + let found = type_definition(&ws, &uri, offset); + assert_eq!(found.len(), 1, "{found:#?}"); + assert_eq!(found[0].uri, path_to_uri(&dir.join("thing.sv")).expect("uri")); + assert_eq!(found, nav::definition(&ws, &uri, at(top, "thing t")), "one answer, one layer"); let _ = fs::remove_dir_all(&dir); } #[test] fn a_qualified_name_the_overlay_refused_is_not_retried_against_the_index() { - // The index fallback exists for the one miss `vlog_semantic` reports - // as `NotFound`. A `pkg::missing_t` is an *external candidate* the - // overlay answered with nothing, and a module of that name elsewhere - // is not what it meant. + // A `pkg::missing_t` is an *external candidate* the overlay answered + // with nothing, and a module of that name elsewhere is not what it + // meant. Nothing sweeps the bare tail: `resolve.rs`'s `unit_member` + // never promotes, so the qualifier is never discarded. let pkg = "package tdp2;\nendpackage\n"; let decoy = "module missing_t;\nendmodule\n"; let top = "module top;\n tdp2::missing_t s;\nendmodule\n"; @@ -949,10 +910,13 @@ endclass } #[test] - fn the_other_two_fence_conditions_still_hold_under_an_inherited_candidate() { - // Widening the *first* condition must not loosen the other two, so - // each is re-attacked from inside an extending class, where every one - // of these references is an `InheritedCandidate`. + fn an_inherited_candidate_answers_only_what_the_workspace_unit_table_holds() { + // Was `the_other_two_fence_conditions_still_hold_under_an_inherited_candidate`. + // The fences moved into `vlog_semantic` and the index: a promoted miss + // is a *unit-table* lookup of a bare name, so a package member is not + // reachable and a qualified name is never swept. Each is re-attacked + // from inside an extending class, where every one of these references + // is an `InheritedCandidate`. let pkg = "\ package thing; typedef logic [3:0] inner_t; @@ -971,12 +935,17 @@ endclass let files = [("thing.sv", pkg), ("decoy.sv", decoy), ("top.sv", top)]; let (dir, ws, uri) = workspace("fence_inherited", &files, "top.sv"); - // Kind filter: a `package` of that name is not a type. + // A unit of that name, whatever its kind, is what the workspace has to + // say — the same answer `definition` gives, reached through the + // inherited candidate's own promoted path rather than around it. assert_eq!( doc_reference_kind(&ws, &uri, at(top, "thing a")), - Some("InheritedCandidate".to_string()) + Some("InheritedCandidate".to_string()), + "the inherited semantics are untouched by the promotion" ); - assert!(type_definition(&ws, &uri, at(top, "thing a") + 9).is_empty(), "a package"); + let package = type_definition(&ws, &uri, at(top, "thing a") + 9); + assert_eq!(package.len(), 1, "{package:#?}"); + assert_eq!(package[0].uri, path_to_uri(&dir.join("thing.sv")).expect("uri")); // File scope only: `inner_t` is a *member* of `thing`, not a unit, so // the index's unit table does not hold it and no import brought it in. @@ -987,11 +956,12 @@ endclass assert!(type_definition(&ws, &uri, at(top, "inner_t b") + 9).is_empty(), "not file-scope"); // A qualified name the overlay already refused stays refused: it is an - // `ExternalCandidate`, not a lexical miss, so the fence rejects it and - // the decoy module of that name is not offered. + // `ExternalCandidate` carrying `thing::missing_t` and nothing else — + // `unit_member` never adds the bare name — so the decoy module of that + // name is not offered. assert_eq!( doc_reference_kind(&ws, &uri, at(top, "missing_t c")), - Some("Other".to_string()) + Some("ExternalCandidate".to_string()) ); assert!(type_definition(&ws, &uri, at(top, "missing_t c") + 10).is_empty(), "refused"); @@ -1035,9 +1005,9 @@ endmodule let _ = fs::remove_dir_all(&dir); } - /// Whether the reference at `offset` was resolved locally, and by what - /// resolution kind — used to pin down *why* the fence did or didn't fire, - /// rather than only observing the final jump. + /// Which `Resolution` the file's own layer gave the reference at `offset` + /// — used to pin down *why* an answer came out the way it did, rather than + /// only observing the final jump. fn doc_reference_kind(ws: &Workspace, uri: &Uri, offset: u32) -> Option { let doc = ws.document(uri)?; let reference = doc.semantics.reference_at(offset)?; @@ -1045,20 +1015,20 @@ endmodule Resolution::Resolved(_) => "Resolved".to_string(), Resolution::NotFound => "NotFound".to_string(), Resolution::InheritedCandidate { .. } => "InheritedCandidate".to_string(), - _ => "Other".to_string(), + Resolution::ExternalCandidate { .. } => "ExternalCandidate".to_string(), }) } #[test] fn a_plain_expression_use_of_a_workspace_module_name_is_never_a_type_site() { - // `indexed_type` is only ever reached with a span `type_name` produced, - // and `type_name`'s first and third branches both go through - // `site_at`, which is structurally confined to declaration - // containers (`item_site`/`stmt_site`) — an ordinary expression - // statement is not one of them. So a bare identifier that happens to - // share a workspace module's name, used in a value position, must - // never produce a jump — not because a fence catches it, but because - // no `Site` is ever built for it. + // The promotion fires on type positions only, so such an identifier is + // still a plain `NotFound` and no handler answers it — neither this one + // nor `nav::definition`. Two independent fences, both pinned here: the + // model never offers the coincidence, and this handler's confinement is + // structural anyway (`type_name`'s first and third branches both go + // through `site_at`, which only descends declaration containers — + // `item_site`/`stmt_site` — and an ordinary expression statement is not + // one of them). let dup = "module dup;\nendmodule\n"; let top = "module top;\n wire x;\n assign x = dup;\nendmodule\n"; let (dir, ws, uri) = workspace("exprname", &[("dup.sv", dup), ("top.sv", top)], "top.sv"); @@ -1067,7 +1037,11 @@ endmodule assert_eq!( doc_reference_kind(&ws, &uri, offset), Some("NotFound".to_string()), - "an expression identifier nothing declares, and no import to escalate it" + "a value-position miss names no unit and is never swept through the unit table" + ); + assert!( + nav::definition(&ws, &uri, offset).is_empty(), + "so F12 answers nothing rather than a same-named module in another file" ); assert!(type_definition(&ws, &uri, offset).is_empty(), "not a declaration's type window"); @@ -1075,20 +1049,21 @@ endmodule } #[test] - fn indexed_type_returns_every_workspace_declaration_when_the_name_is_ambiguous() { - // The same ambiguity convention as `nav::definition`, but pinned - // through the `indexed_type` fallback path specifically (an - // unqualified `NotFound` reference), which none of the dev's - // ambiguity tests exercise — theirs goes through `Target::Module`'s - // `ExternalCandidate`, a different resolution path that never touches - // `indexed_type` at all. + fn a_promoted_miss_returns_every_workspace_declaration_when_the_name_is_ambiguous() { + // Was `indexed_type_returns_...`: the ambiguity convention is still + // pinned through the promoted-miss path specifically (an unqualified + // lexical miss), which the `Target::Module` ambiguity test does not + // exercise — that one is an external candidate from the start. let iface = "interface bus_if;\nendinterface\n"; let top = "module top;\n bus_if bus;\nendmodule\n"; let files = [("a.sv", iface), ("b.sv", iface), ("top.sv", top)]; let (dir, ws, uri) = workspace("indexed_ambig", &files, "top.sv"); let type_ref_offset = at(top, "bus_if bus"); - assert_eq!(doc_reference_kind(&ws, &uri, type_ref_offset), Some("NotFound".to_string())); + assert_eq!( + doc_reference_kind(&ws, &uri, type_ref_offset), + Some("ExternalCandidate".to_string()) + ); let found = type_definition(&ws, &uri, at(top, "bus_if bus") + 7); assert_eq!(found.len(), 2, "both interfaces, not a guess: {found:#?}"); diff --git a/crates/vlog_refactor/tests/rename.rs b/crates/vlog_refactor/tests/rename.rs index 5e0de59..4f43a39 100644 --- a/crates/vlog_refactor/tests/rename.rs +++ b/crates/vlog_refactor/tests/rename.rs @@ -318,6 +318,27 @@ fn a_port_renames_inside_the_connection_lists_of_other_files() { assert!(after.contains(".rst(1'b1)"), "the other connection is untouched: {after}"); } +#[test] +fn an_interface_renames_from_the_declaration_it_types_in_another_file() { + // Overlay promotion (`docs/features/overlay-promotion/README.md`) made + // this reachable: an unqualified type name nothing in the using file + // binds is now an external candidate the workspace answers, so the two + // halves of the rename are one symbol instead of two unrelated words. + // The interface is written in the body, not in the header: an ANSI port + // list whose first port has no direction does not parse yet + // (`docs/features/type-definition/README.md`, Handshake 2). + let iface = "interface bus_if;\nendinterface\n"; + let top = "module top;\n virtual bus_if vif;\n bus_if other ();\nendmodule\n"; + let files = workspace(&[("bus_if.sv", iface), ("top.sv", top)]); + + let edit = rename(&files, &path("top.sv"), at(top, "virtual", "bus_if"), "fabric_if") + .expect("renames"); + assert!(apply(iface, &edit, &path("bus_if.sv")).contains("interface fabric_if;")); + let after = apply(top, &edit, &path("top.sv")); + assert!(after.contains("virtual fabric_if vif;"), "{after}"); + assert!(after.contains("fabric_if other ()"), "the instantiation too: {after}"); +} + // ---------------------------------------------------------------------- // refusals // ---------------------------------------------------------------------- @@ -375,6 +396,24 @@ fn an_unresolved_name_is_refused_rather_than_guessed() { assert!(message.contains("not resolved"), "{message}"); } +#[test] +fn a_bare_value_position_typo_never_reaches_an_unrelated_same_named_module() { + // The regression the overlay-promotion round shipped and this round took + // back (QA finding 1, 2026-08-26). `typo_name` on an assignment's LHS is a + // plain expression identifier — `Target::Lexical` via `ExprKind::Ident`, + // not a type window — so it is never given the bare-name path that would + // make it an external candidate. Without that, `locate` takes the + // `NotFound` arm and refuses, instead of rewriting an unrelated file's + // module declaration on nothing but a name collision. + let unrelated = "module typo_name;\nendmodule\n"; + let top = "module top;\n assign typo_name = 1'b1;\nendmodule\n"; + let files = workspace(&[("typo_name.sv", unrelated), ("top.sv", top)]); + + let message = rename(&files, &path("top.sv"), at(top, "assign", "typo_name"), "fixed_name") + .expect_err("a value-position typo must not be renamable across files"); + assert!(message.contains("not resolved to any declaration"), "{message}"); +} + #[test] fn a_name_declared_outside_the_indexed_files_is_refused() { let text = "module m;\n import other_pkg::*;\n wire w = FROM_ELSEWHERE;\nendmodule\n"; diff --git a/crates/vlog_semantic/src/bind.rs b/crates/vlog_semantic/src/bind.rs index e808d0b..2cf5c92 100644 --- a/crates/vlog_semantic/src/bind.rs +++ b/crates/vlog_semantic/src/bind.rs @@ -22,6 +22,14 @@ pub(crate) struct Pending { pub(crate) enum Target { /// The lexical chain from `scope` outward, imports included. Lexical, + /// A name written where a **type** goes — the user-defined type of a + /// declaration, a port, a parameter, a return type, a `virtual` interface + /// property. Looked up exactly like [`Target::Lexical`], but a miss also + /// carries the bare name to the workspace, because that is how a + /// cross-file `interface`, `class` or `typedef` is spelled. Every type + /// position reaches this through [`Binder::bind_data_type`]; an + /// identifier in a *value* position never does. + Type, /// A package name: the `p` of `import p::x`. Only a package can be /// imported, so this stays narrower than [`Target::Unit`]. Package, @@ -1220,7 +1228,7 @@ impl<'a> Binder<'a> { } None => { let ns = crate::scan::name_span(self.src, window, &ty.name); - self.use_name(scope, &ty.name, ns, Target::Lexical); + self.use_name(scope, &ty.name, ns, Target::Type); } } } diff --git a/crates/vlog_semantic/src/model.rs b/crates/vlog_semantic/src/model.rs index bcffdf8..3723690 100644 --- a/crates/vlog_semantic/src/model.rs +++ b/crates/vlog_semantic/src/model.rs @@ -71,20 +71,30 @@ pub enum Resolution { Resolved(SymbolId), /// Nothing in this file binds it, but a named external unit could: a /// package imported with `import p::*` / `import p::x`, a package written - /// as `p::x`, or a module instantiated but declared in another file. - /// `paths` names those units — a path containing `::` is a package path, - /// a bare name is a module, package or class name. The workspace index - /// (TODO.md §6) is what finishes these. + /// as `p::x`, a module instantiated but declared in another file, or an + /// unqualified **type** name — an `interface`, a package-less `class` — + /// that only a file-scope declaration somewhere else can be. `paths` names + /// those units — a path containing `::` is a package path, a bare name is a + /// module, package or class name — in the order they are tried, the use's + /// own name last. The workspace index (TODO.md §6) is what finishes these. ExternalCandidate { paths: Vec }, /// A use inside a class that nothing lexical binds, where the class's /// `extends` could: `base` is the base-class path as written - /// (`uvm_component`, `pkg::base`), and `paths` are any import paths the - /// lexical walk collected — either could supply the name. Nothing chases - /// `base`, in this file or out of it; a future hover/index round can, - /// without this crate pretending it did inheritance resolution. See - /// `docs/features/class-semantics/README.md`. + /// (`uvm_component`, `pkg::base`), and `paths` are the import paths the + /// lexical walk collected — plus the use's own name when it was written in + /// a type position — any of which could supply it. Nothing chases `base`, + /// in this file or out of it; the + /// workspace overlay may answer from `paths` without displacing what this + /// says, because a resolved base would have been `Resolved` already. See + /// `docs/features/class-semantics/README.md` and + /// `docs/features/overlay-promotion/README.md`. InheritedCandidate { base: String, paths: Vec }, - /// Nothing in this file binds it and no external unit could. + /// Nothing in this file binds it and no external unit could: a member of a + /// package this file fully declares, a `.port` of a module it declares, a + /// `this.x`/`super.x` with no class or base to blame, or a plain + /// value-position identifier with no import in scope. An unqualified miss + /// in a **type** position is never this — the workspace's unit table could + /// hold it — so that one is an `ExternalCandidate` carrying its own name. NotFound, } diff --git a/crates/vlog_semantic/src/resolve.rs b/crates/vlog_semantic/src/resolve.rs index 584d165..3c0e706 100644 --- a/crates/vlog_semantic/src/resolve.rs +++ b/crates/vlog_semantic/src/resolve.rs @@ -13,7 +13,8 @@ pub(crate) fn resolve(scopes: &[Scope], symbols: &[Symbol], p: &Pending) -> Reso // An end label names the construct it closes; the binder already knew // which symbol that is, so there is nothing to look up. Target::Declaration(id) => Resolution::Resolved(*id), - Target::Lexical => lexical(scopes, p.scope, &p.name), + Target::Lexical => lexical(scopes, p.scope, &p.name, false), + Target::Type => lexical(scopes, p.scope, &p.name, true), Target::Package => named_at_file_scope(scopes, symbols, &p.name, SymbolKind::Package), Target::Module => named_at_file_scope(scopes, symbols, &p.name, SymbolKind::Module), Target::Unit => unit(scopes, symbols, p.scope, &p.name), @@ -36,7 +37,18 @@ pub(crate) fn resolve(scopes: &[Scope], symbols: &[Symbol], p: &Pending) -> Reso /// class whose header says `extends` becomes an inheritance candidate — the /// base (which this crate never chases, in this file or out of it) could /// supply the name, and so could any import path collected on the way out. -fn lexical(scopes: &[Scope], from: ScopeId, name: &str) -> Resolution { +/// +/// `promote` is set for [`Target::Type`] only. A **type** name nothing here +/// binds is exactly how a file-scope `interface`, a package-less `class` or a +/// cross-file `typedef` is written (`bus_if bus;`, `my_cls h;`), so its miss +/// ends carrying the **bare name** as its last path — last, so an import that +/// could supply the name still wins — and the workspace's unit table, the only +/// layer that can say, gets asked. A [`Target::Lexical`] miss is an identifier +/// in a *value* position: a name a `` `define`` would have produced, a typo, a +/// signal declared somewhere this crate does not model. Nothing about it says +/// "file-scope declaration", so it is not swept through the unit table, where a +/// mere name collision would make `rename` rewrite an unrelated file. +fn lexical(scopes: &[Scope], from: ScopeId, name: &str, promote: bool) -> Resolution { let mut external = Vec::new(); let mut current = Some(from); while let Some(id) = current { @@ -66,6 +78,9 @@ fn lexical(scopes: &[Scope], from: ScopeId, name: &str) -> Resolution { } current = scope.parent; } + if promote { + external.push(name.to_string()); + } miss(scopes, from, external, false) } @@ -197,7 +212,10 @@ fn super_member(scopes: &[Scope], from: ScopeId) -> Resolution { /// nearest extends-carrying enclosing class's base could supply the name /// (the LRM even puts it ahead of the enclosing scopes this walk already /// searched — the deliberate inexactness the same README argues), so it -/// becomes `InheritedCandidate`. +/// becomes `InheritedCandidate` — which keeps its base and its paths both, +/// because either could be the answer and nothing here picks between them. +/// A miss with nothing to name at all — no import in scope, no bare name +/// because the use was not a type — is `NotFound`. fn miss(scopes: &[Scope], from: ScopeId, external: Vec, unit_lookup: bool) -> Resolution { if unit_lookup { return Resolution::ExternalCandidate { paths: external }; diff --git a/crates/vlog_semantic/src/workspace.rs b/crates/vlog_semantic/src/workspace.rs index 3d8bb31..1f9adc7 100644 --- a/crates/vlog_semantic/src/workspace.rs +++ b/crates/vlog_semantic/src/workspace.rs @@ -379,13 +379,28 @@ pub enum Definition<'a> { /// /// `sem` is not modified: the answers come back as an overlay the caller /// composes with it (see [`ExternalResolutions::definition_of`]). +/// +/// An [`Resolution::InheritedCandidate`] is not an external candidate and does +/// not become one: its base class is the single-file layer's answer and stays +/// the answer. But its paths are real — the imports the lexical walk collected +/// and the use's own name — so they are tried, and an entry is recorded **only +/// when one of them lands on a declaration**. A name the index cannot answer is +/// left exactly as it was, absent from the overlay, which is what keeps +/// "the overlay holds what the workspace was asked to finish" true. pub fn resolve_external(sem: &Semantics, index: &WorkspaceIndex) -> ExternalResolutions { let mut targets = HashMap::new(); for (i, reference) in sem.references().iter().enumerate() { - let Resolution::ExternalCandidate { paths } = &reference.resolution else { - continue; + let target = match &reference.resolution { + Resolution::ExternalCandidate { paths } => follow_paths(index, &reference.name, paths), + Resolution::InheritedCandidate { paths, .. } => { + match follow_paths(index, &reference.name, paths) { + ExternalTarget::StillUnresolved => continue, + answered => answered, + } + } + _ => continue, }; - targets.insert(ReferenceId(i as u32), follow_paths(index, &reference.name, paths)); + targets.insert(ReferenceId(i as u32), target); } ExternalResolutions { targets } } @@ -429,8 +444,9 @@ impl ExternalResolutions { ids.into_iter().filter_map(|id| self.targets.get(&id).map(|t| (id, t))) } - /// How many external candidates the workspace answered, out of how many - /// there were. + /// How many of the references handed to the workspace layer it answered, + /// out of how many it was handed — every external candidate, plus the + /// inherited candidates it had something to say about. pub fn counts(&self) -> (usize, usize) { let answered = self.targets.values().filter(|t| !t.defs().is_empty()).count(); (answered, self.targets.len()) diff --git a/crates/vlog_semantic/tests/classes.rs b/crates/vlog_semantic/tests/classes.rs index 21328c6..cd68851 100644 --- a/crates/vlog_semantic/tests/classes.rs +++ b/crates/vlog_semantic/tests/classes.rs @@ -206,7 +206,10 @@ endclass let expect = Resolution::InheritedCandidate { base: "uvm_object".into(), paths: Vec::new() }; assert_eq!(resolution_at(&s, nth(src, "super.new", 0) + 6), expect); assert_eq!(resolution_at(&s, nth(src, "super.whatever", 0) + 6), expect); - // A plain call that misses the whole lexical chain blames the base too. + // A plain call that misses the whole lexical chain blames the base too, + // and carries no path: a callee is a value position, and the promotion + // (`docs/features/overlay-promotion/README.md`) fires on type positions + // only, so nothing sweeps `set_name` through the workspace's unit table. assert_eq!( resolution_at(&s, nth(src, "set_name", 0)), Resolution::InheritedCandidate { base: "uvm_object".into(), paths: Vec::new() } @@ -229,6 +232,8 @@ endclass match resolution_at(&s, nth(src, "UVM_LOW", 0)) { Resolution::InheritedCandidate { base, paths } => { assert_eq!(base, "uvm_component"); + // The imports in walk order, and nothing else: a call argument + // is a value position, so the bare name is not appended. assert_eq!(paths, vec!["uvm_pkg::*".to_string()]); } other => panic!("expected an inherited candidate, got {other:?}"), @@ -720,7 +725,11 @@ fn inherited_candidates_are_not_the_workspace_overlays_business() { held.resolution, Resolution::InheritedCandidate { base: "base".into(), paths: Vec::new() } ); + // Two reasons it is absent from the overlay, and both hold: `held = 1` is + // a value position, so the promotion never gave it a path to sweep; and + // even with one, a class property is not a unit, so the sweep would find + // nothing and record nothing. let overlay = resolve_external(&s, &ws); let id = s.reference_id_at(nth(sources[1].1, "held = 1", 0)).expect("an id"); - assert!(overlay.get(id).is_none(), "the overlay holds external candidates only"); + assert!(overlay.get(id).is_none(), "a name the workspace cannot answer is not in the overlay"); } diff --git a/crates/vlog_semantic/tests/corpus.rs b/crates/vlog_semantic/tests/corpus.rs index 5d21b2b..25e7100 100644 --- a/crates/vlog_semantic/tests/corpus.rs +++ b/crates/vlog_semantic/tests/corpus.rs @@ -49,7 +49,7 @@ impl Totals { let pct = |n: usize| 100.0 * n as f64 / self.references.max(1) as f64; println!( "{label}: {} files, {} symbols, {} references — {:.1}% resolved in-file, \ - {:.1}% external candidates, {:.1}% inherited candidates, {:.1}% unresolved, \ + {:.1}% external candidates, {:.1}% inherited candidates, {:.2}% unresolved ({}), \ {} names unplaced", self.files, self.symbols, @@ -58,6 +58,7 @@ impl Totals { pct(self.external), pct(self.inherited), pct(self.unresolved()), + self.unresolved(), self.unplaced, ); } diff --git a/crates/vlog_semantic/tests/semantics.rs b/crates/vlog_semantic/tests/semantics.rs index b1f0db4..543ddf4 100644 --- a/crates/vlog_semantic/tests/semantics.rs +++ b/crates/vlog_semantic/tests/semantics.rs @@ -211,7 +211,10 @@ endmodule let in_loop = s.reference_at(nth(src, "assign w = i", 0) + 11).expect("the use in the body"); assert_eq!(in_loop.resolved(), Some(genvar)); - // Outside the loop the genvar is gone. + // Outside the loop the genvar is gone, and a bare `i` in an expression is + // a value position: nothing in scope names it and nothing offers it to the + // workspace, so it stays `NotFound` (a one-letter name is exactly the kind + // of coincidence a unit-table sweep must not chase). let outside = s.reference_at(nth(src, "assign top_i = i", 0) + 15).expect("the use outside"); assert_eq!(outside.resolution, Resolution::NotFound); @@ -299,7 +302,9 @@ endmodule let s = sem(src); // Only the wildcard could supply this name; the explicit import names - // something else, so it is not offered to the workspace index. + // something else, so it is not offered to the workspace index. No bare + // name either: the promotion is for type positions, and this is a value + // (`docs/features/overlay-promotion/README.md`). let some = s.reference_at(nth(src, "SOMETHING", 0)).expect("the use"); assert_eq!( some.resolution, diff --git a/crates/vlog_semantic/tests/workspace.rs b/crates/vlog_semantic/tests/workspace.rs index 30ac938..8ac6aaf 100644 --- a/crates/vlog_semantic/tests/workspace.rs +++ b/crates/vlog_semantic/tests/workspace.rs @@ -374,6 +374,233 @@ fn counts_report_what_was_indexed() { assert_eq!(counts.defines, 1); } +// ---------------------------------------------------------------------- +// Overlay promotion: unqualified misses reach the unit table +// (docs/features/overlay-promotion/README.md) +// ---------------------------------------------------------------------- + +/// The resolution the single-file layer gave the reference at `needle`. +fn resolution(sem: &Semantics, src: &str, needle: &str) -> Resolution { + let offset = src.find(needle).expect("needle is in the source") as u32; + sem.reference_at(offset).expect("a reference is written here").resolution.clone() +} + +/// Whether the overlay holds any entry at all for the reference at `needle`. +fn in_overlay(sem: &Semantics, ws: &WorkspaceIndex, src: &str, needle: &str) -> bool { + let offset = src.find(needle).expect("needle is in the source") as u32; + let id = sem.reference_id_at(offset).expect("a reference is written here"); + resolve_external(sem, ws).get(id).is_some() +} + +#[test] +fn an_unqualified_type_miss_carries_its_own_name_to_the_unit_table() { + // An `interface` lives at file scope, never in a package, so nothing in + // the using file can bind its name and no import path can carry it. The + // bare name is the whole handshake. + let sources = [ + ("bus_if.sv", "interface bus_if;\nendinterface\n"), + ("top.sv", "module top;\n bus_if bus;\nendmodule\n"), + ]; + let ws = index(&sources); + let sem = semantics(sources[1].1); + + assert_eq!( + resolution(&sem, sources[1].1, "bus_if bus"), + Resolution::ExternalCandidate { paths: vec!["bus_if".to_string()] } + ); + let defs = external_defs(&sem, &ws, sources[1].1, "bus_if bus"); + assert_eq!(defs.len(), 1, "{defs:?}"); + assert_eq!(slice(&ws, &sources, &defs[0]), "bus_if"); + assert_eq!(defs[0].kind, SymbolKind::Module, "an interface is a Module symbol"); +} + +#[test] +fn a_package_less_class_and_a_file_scope_typedef_are_reached_the_same_way() { + let sources = [ + ("cls.sv", "class my_cls;\nendclass\n"), + ("types.sv", "typedef logic [3:0] nib_t;\n"), + ("top.sv", "module top;\n my_cls h;\n nib_t n;\nendmodule\n"), + ]; + let ws = index(&sources); + let sem = semantics(sources[2].1); + + let cls = external_defs(&sem, &ws, sources[2].1, "my_cls h"); + assert_eq!(cls.len(), 1, "{cls:?}"); + assert_eq!(cls[0].kind, SymbolKind::Class); + let nib = external_defs(&sem, &ws, sources[2].1, "nib_t n"); + assert_eq!(nib.len(), 1, "{nib:?}"); + assert_eq!(nib[0].kind, SymbolKind::Typedef); +} + +#[test] +fn a_miss_inside_an_extending_class_is_answered_without_losing_its_base() { + // The UVM shape: almost every class extends something, so almost every + // miss inside one is an `InheritedCandidate`. It stays one — `base` is + // still there for a consumer to read — and the overlay answers it from + // the paths it now carries. + let sources = [ + ("clk_rst_if.sv", "interface clk_rst_if;\nendinterface\n"), + ("env.sv", "class env extends uvm_object;\n virtual clk_rst_if vif;\nendclass\n"), + ]; + let ws = index(&sources); + let sem = semantics(sources[1].1); + + assert_eq!( + resolution(&sem, sources[1].1, "clk_rst_if vif"), + Resolution::InheritedCandidate { + base: "uvm_object".to_string(), + paths: vec!["clk_rst_if".to_string()], + }, + "the inherited semantics other consumers read are untouched" + ); + let defs = external_defs(&sem, &ws, sources[1].1, "clk_rst_if vif"); + assert_eq!(defs.len(), 1, "{defs:?}"); + assert_eq!(slice(&ws, &sources, &defs[0]), "clk_rst_if"); +} + +#[test] +fn an_inherited_member_the_unit_table_cannot_hold_stays_exactly_what_it_was() { + // The other half of the same shape: an ordinary member miss. The sweep is + // a *unit* lookup, and a property or a method is not a unit, so nothing + // answers and the reference keeps its base and no overlay entry. + let sources = [ + ("base.sv", "class base;\n int held;\nendclass\n"), + ( + "child.sv", + "class child extends base;\n function void f();\n held = 1;\n endfunction\nendclass\n", + ), + ]; + let ws = index(&sources); + let sem = semantics(sources[1].1); + + assert!(matches!( + resolution(&sem, sources[1].1, "held = 1"), + Resolution::InheritedCandidate { .. } + )); + assert!(!in_overlay(&sem, &ws, sources[1].1, "held = 1")); +} + +#[test] +fn a_qualified_miss_is_never_promoted_in_either_spelling() { + // `unit::member` names something *inside* `unit`; sweeping the bare tail + // would discard the qualifier and jump somewhere the source never + // pointed. `resolve.rs`'s `unit_member` never adds the bare name, in + // either of the two spellings its misses take. + let decoy = ("missing_t.sv", "module missing_t;\nendmodule\n"); + let from_package = + [decoy, ("top.sv", "package p;\nendpackage\nmodule top;\n p::missing_t s;\nendmodule\n")]; + let ws = index(&from_package); + let sem = semantics(from_package[1].1); + assert_eq!(resolution(&sem, from_package[1].1, "missing_t s"), Resolution::NotFound); + assert!(!in_overlay(&sem, &ws, from_package[1].1, "missing_t s")); + assert!(external_defs(&sem, &ws, from_package[1].1, "missing_t s").is_empty()); + + let from_class = [ + decoy, + ( + "top.sv", + "class base;\nendclass\nclass top extends base;\nendclass\nmodule m;\n top::missing_t s;\nendmodule\n", + ), + ]; + let ws = index(&from_class); + let sem = semantics(from_class[1].1); + assert_eq!( + resolution(&sem, from_class[1].1, "missing_t s"), + Resolution::InheritedCandidate { base: "base".to_string(), paths: Vec::new() }, + "no paths at all: nothing for the overlay to try" + ); + assert!(!in_overlay(&sem, &ws, from_class[1].1, "missing_t s")); + assert!(external_defs(&sem, &ws, from_class[1].1, "missing_t s").is_empty()); +} + +#[test] +fn a_value_position_miss_is_never_promoted_even_onto_a_same_named_unit() { + // The twin of `an_unqualified_type_miss_carries_its_own_name_to_the_unit + // _table`, and the fence the fix round exists for. The same word, the same + // workspace, the only difference being where it is written: a type window + // is a claim about a declaration somewhere, a bare expression identifier + // is not. So this one keeps its pre-promotion spelling, the overlay is + // never asked, and `rename` goes on refusing it (QA finding 1, 2026-08-26). + let sources = [ + ("typo_name.sv", "module typo_name;\nendmodule\n"), + ("top.sv", "module top;\n assign typo_name = 1'b1;\nendmodule\n"), + ]; + let ws = index(&sources); + let sem = semantics(sources[1].1); + + assert_eq!(resolution(&sem, sources[1].1, "typo_name = 1"), Resolution::NotFound); + assert!(!in_overlay(&sem, &ws, sources[1].1, "typo_name = 1")); + assert!(external_defs(&sem, &ws, sources[1].1, "typo_name = 1").is_empty()); +} + +#[test] +fn a_value_position_miss_inside_an_extending_class_gains_no_path_either() { + // The twin of `a_miss_inside_an_extending_class_is_answered_without + // _losing_its_base`. An inherited candidate from a *value* position is + // exactly what it was before the promotion: its base and nothing else, so + // the sweep has nothing to try and the overlay records nothing — even + // though the workspace does declare a unit of that name. + let sources = [ + ("held.sv", "interface held;\nendinterface\n"), + ( + "env.sv", + "class env extends uvm_object;\n function void f();\n held = 1;\n endfunction\nendclass\n", + ), + ]; + let ws = index(&sources); + let sem = semantics(sources[1].1); + + assert_eq!( + resolution(&sem, sources[1].1, "held = 1"), + Resolution::InheritedCandidate { base: "uvm_object".to_string(), paths: Vec::new() }, + "no paths: a value position is offered nothing to sweep" + ); + assert!(!in_overlay(&sem, &ws, sources[1].1, "held = 1")); +} + +#[test] +fn a_local_declaration_of_a_promoted_name_still_wins() { + // The promotion happens only after the lexical walk gives up, so a name + // this file declares never reaches the workspace at all. + let sources = [ + ("bus_if.sv", "interface bus_if;\nendinterface\n"), + ("top.sv", "module top;\n typedef logic bus_if;\n bus_if bus;\nendmodule\n"), + ]; + let ws = index(&sources); + let sem = semantics(sources[1].1); + + assert!(matches!(resolution(&sem, sources[1].1, "bus_if bus"), Resolution::Resolved(_))); + assert!(!in_overlay(&sem, &ws, sources[1].1, "bus_if bus")); + match resolve_external(&sem, &ws) + .definition_of(&sem, sources[1].1.find("bus_if bus").expect("needle") as u32) + { + Some(Definition::Local(sym)) => assert_eq!(sym.kind, SymbolKind::Typedef), + other => panic!("expected the local typedef, got {other:?}"), + } +} + +#[test] +fn an_import_that_can_supply_the_name_still_wins_over_a_same_named_unit() { + // Order matters: the bare name goes last, so a package member reached + // through an import is preferred over a workspace unit that happens to + // share the name. That is the pre-promotion answer, kept. + let sources = [ + ("pkg.sv", "package tdp;\n typedef logic [1:0] state_t;\nendpackage\n"), + ("decoy.sv", "module state_t;\nendmodule\n"), + ("top.sv", "module top;\n import tdp::*;\n state_t s;\nendmodule\n"), + ]; + let ws = index(&sources); + let sem = semantics(sources[2].1); + + assert_eq!( + resolution(&sem, sources[2].1, "state_t s"), + Resolution::ExternalCandidate { paths: vec!["tdp::*".to_string(), "state_t".to_string()] } + ); + let defs = external_defs(&sem, &ws, sources[2].1, "state_t s"); + assert_eq!(defs.len(), 1, "{defs:?}"); + assert_eq!(defs[0].kind, SymbolKind::Typedef, "the package's typedef, not the decoy module"); +} + // ---------------------------------------------------------------------- // Corpus acceptance // ---------------------------------------------------------------------- @@ -441,7 +668,8 @@ fn the_corpus_index_finishes_most_external_references() { let (tree, diags) = parse_source_tolerant(src); let sem = analyze(&tree, src); let overlay = resolve_external(&sem, &ws); - let mut file_tally = Tally { references: sem.references().len(), ..Tally::default() }; + let (in_file, references) = sem.resolution_counts(); + let mut file_tally = Tally { references, in_file, ..Tally::default() }; for (id, target) in overlay.iter() { let reference = sem.reference(id).expect("id came from the overlay"); let name = &reference.name; @@ -486,10 +714,17 @@ struct Tally { /// Every reference the single-file layer recorded, external or not — the /// denominator the vlog-semantic baseline reports percentages against. references: usize, + /// The ones it resolved on its own, which the workspace layer never sees. + in_file: usize, total: usize, resolved: usize, ambiguous: usize, unresolved: usize, + /// Answers for references the single-file layer left as + /// `InheritedCandidate` — the bucket overlay-promotion added. Counted + /// separately because they are a *bonus*: an inherited candidate is not + /// an external one and only appears here when the sweep landed. + inherited: usize, /// Unresolved import path → how many uses it left open, and one example /// name each: the honest-gaps report. misses: std::collections::BTreeMap, @@ -498,6 +733,7 @@ struct Tally { impl Tally { fn count(&mut self, target: &ExternalTarget, reference: &vlog_semantic::Reference) { self.total += 1; + self.inherited += usize::from(reference.is_inherited_candidate()); match target { ExternalTarget::Resolved(_) => self.resolved += 1, ExternalTarget::Ambiguous(_) => self.ambiguous += 1, @@ -515,10 +751,12 @@ impl Tally { fn merge(&mut self, other: &Tally) { self.references += other.references; + self.in_file += other.in_file; self.total += other.total; self.resolved += other.resolved; self.ambiguous += other.ambiguous; self.unresolved += other.unresolved; + self.inherited += other.inherited; for (path, (n, example)) in &other.misses { let entry = self.misses.entry(path.clone()).or_insert((0, example.clone())); entry.0 += n; @@ -529,20 +767,30 @@ impl Tally { self.resolved + self.ambiguous } + /// References with nowhere at all to jump: neither layer answered them. + /// The one number that must never rise — the buckets above it move + /// between themselves whenever a miss changes its spelling. + fn nowhere(&self) -> usize { + self.references - self.in_file - self.answered() + } + fn report(&self, label: &str) { let pct = |n: usize, of: usize| 100.0 * n as f64 / of.max(1) as f64; println!( - "{label}: {} references, {} external candidates ({:.1}%) — the workspace answers \ - {:.1}% of them ({:.1}% one target, {:.1}% ambiguous), {:.1}% still unresolved. \ - External-candidate rate after the workspace layer: {:.1}% of all references.", + "{label}: {} references, {} handed to the workspace layer ({:.1}%, of which {} \ + inherited candidates) — it answers {:.1}% of them ({:.1}% one target, {:.1}% \ + ambiguous), {:.1}% still unresolved. Nowhere to jump after both layers: \ + {} references, {:.1}% of all.", self.references, self.total, pct(self.total, self.references), + self.inherited, pct(self.answered(), self.total), pct(self.resolved, self.total), pct(self.ambiguous, self.total), pct(self.unresolved, self.total), - pct(self.unresolved, self.references), + self.nowhere(), + pct(self.nowhere(), self.references), ); let mut top: Vec<(&String, &(usize, String))> = self.misses.iter().collect(); top.sort_by(|a, b| b.1 .0.cmp(&a.1 .0).then(a.0.cmp(b.0))); diff --git a/docs/features/class-semantics/README.md b/docs/features/class-semantics/README.md index af4db7a..c461196 100644 --- a/docs/features/class-semantics/README.md +++ b/docs/features/class-semantics/README.md @@ -48,10 +48,14 @@ the deviations are stated where they happen. `Resolution::InheritedCandidate { base, paths }` — `base` is the extends path as written (`uvm_component`, `pkg::base`), `paths` are the import paths the lexical walk collected on the way out (both could supply the - name; recording both is the honest answer). Nothing chases `base`, in + name; recording both is the honest answer), **plus, since 2026-08-26, the + use's own name last** (`docs/features/overlay-promotion/README.md`), so a + cross-file `interface` or class written as the type of a member of a UVM + class reaches the workspace's unit table. Nothing chases `base`, in this file or out of it: a future hover/index round can, without this - crate pretending it did inheritance resolution. The fallback applies to - *member* uses only — a **unit-name** miss (a `p::x` head, an + crate pretending it did inheritance resolution. The overlay may now answer + such a reference from `paths` — it never rewrites it, and `base` stays. + The fallback applies to *member* uses only — a **unit-name** miss (a `p::x` head, an `extends`/`implements` base) stays `ExternalCandidate` even inside an extending class, because a base class supplies members, not package or class names (QA-found, lead-ruled; pinned by diff --git a/docs/features/overlay-promotion/README.md b/docs/features/overlay-promotion/README.md new file mode 100644 index 0000000..caf55ae --- /dev/null +++ b/docs/features/overlay-promotion/README.md @@ -0,0 +1,966 @@ +# overlay-promotion + +## Goal + +An unqualified name nothing in a file binds — `bus_if bus;`, `my_cls h;`, +`virtual clk_rst_if vif;` — used to die inside `vlog_semantic`. `resolve.rs`'s +lexical walk ended in `Resolution::NotFound` when the file had collected no +import paths, or in `Resolution::InheritedCandidate` when the miss happened +inside a class with an `extends`, and neither spelling reached +`resolve_external`, so the workspace overlay never saw the name. That is +exactly how an `interface` is written (interfaces live at file scope, never in +a package) and how a package-less `class` is used, and the `InheritedCandidate` +half covers nearly every UVM class, since almost all of them extend something. +This feature makes both spellings carry the **bare name** as their last +candidate path **when the name was written in a type position**, so the +workspace's unit table — the one that already answers `sub u_sub (...)` — gets +asked. An identifier in a value position is left alone: it makes no claim about +a file-scope declaration, and matching one on name alone is how `rename` came +to rewrite an unrelated file (QA finding 1, fixed in the round below). +`textDocument/definition`, `typeDefinition`, +`references` and `rename` all gain the answer at once, because all four read +the same overlay; and `lucisv_server`'s stopgap `type_def::indexed_type`, which +asked the index directly under a three-condition fence, is deleted whole (the +Handshake `docs/features/type-definition/README.md` filed, delivered here). + +## Assumptions + +- **A bare miss *in a type position* is a name the workspace could declare.** + Nothing in the file binds it and no import path in scope can supply it, so + the only remaining source is a file-scope declaration in another file. This + is what makes the promotion honest rather than a guess: the alternative + answer is no answer at all, and the name really is spelled the way a + cross-file `interface`/`class`/`module`/`typedef` use is spelled. The + qualifier "in a type position" is load-bearing and was missing from the + round's first cut — see the fourth assumption below. +- **A qualified miss is not one of these, and is never promoted.** + `p::missing_t` names something *inside* `p`; sweeping the bare tail through + the unit table would discard the qualifier and jump somewhere the source + never pointed (the lead's ruling on the deleted fence, 2026-08-26). This is + structural, not a check: `resolve.rs`'s `unit_member` returns its own + `NotFound`/`InheritedCandidate` and never calls `miss`, so the bare name is + added on exactly the two paths that should have it (`lexical`, `unit`). +- **The unit table has no kind filter, here as everywhere.** `units(name)` + returns every file-scope `module`, `package`, `typedef` and `class` of that + name, and the overlay offers all of them — the documented duplicate policy + (`docs/features/workspace-index/README.md`). A promoted miss therefore *can* + answer with a `package` of that name, which the deleted `indexed_type` + excluded. That exclusion was a property of a fourth, private resolution + layer; with the answer coming from the shared overlay, + `typeDefinition` gives what `definition` gives on the same token, and + disagreeing would mean building the fourth layer again. The source that + provokes it (`thing t;` where the workspace's only `thing` is a package) does + not compile either way. +- **Only a name written where a type goes is offered to the unit table.** + ~~An identifier in a value position that nothing declares — a name a + `` `define`` would have produced, a typo — now resolves to a same-named unit + if the workspace has one. That is the same exposure `Target::Module` and + `Target::Unit` have always had.~~ **Both halves of that were wrong, and QA + disproved them (finding 1, 2026-08-26).** The exposure was *not* the same: + `Target::Module`/`Unit`/`Package` are emitted only where the source names a + unit — an instantiation, an `extends` base, the head of `p::x` — so their + bare-name sweep asks a question the source actually asked. `Target::Lexical` + is emitted for two unrelated things: a declaration's type window + (`bind.rs`'s `bind_data_type`) and every plain expression identifier + (`ExprKind::Ident`). Promoting it promoted both, and a value-position typo + became an `ExternalCandidate` that `rename` rewrote across files on nothing + but a name collision. Nor was it bounded by anything: the unit table holding + only file-scope declarations is what makes the collision *plausible*, not + what makes it safe. The fix round split the target — `Target::Type`, emitted + by `bind_data_type`'s unqualified arm alone — so the promotion asks the unit + table only about names the source wrote as types. A value-position miss keeps + its pre-round spelling and `rename` goes on refusing it. `rename` still gains + the ability to rename an interface from its use as a type — the intended win, + and the only one claimed. +- **The overlay is consulted after the in-file layer, always.** A name this + file declares never reaches the promotion at all, so shadowing needs no code + and cannot regress. + +## Handshakes + +**Consumed from `vlog_parser`:** nothing new. + +**Changed in `vlog_semantic` (this crate), and what each consumer sees:** + +0. `bind.rs` gains `Target::Type`, emitted by `bind_data_type`'s unqualified + arm and by nothing else. It is resolved exactly like `Target::Lexical` — + same walk, same shadowing, same import precedence — and differs only in what + its miss carries. Every type position in the language reaches it, because + every one of them goes through `bind_data_type` (call-site map in the fix + round's work log). +1. `resolve.rs::lexical` pushes the reference's own name onto the candidate + paths before the miss is spelled, **for `Target::Type` only** and **last**, + after every import collected on the way out, so an import that can supply + the name still wins (unchanged precedence, pinned by a test). +2. An unqualified **type** miss is therefore + `ExternalCandidate { paths: [..imports.., name] }`, or + `InheritedCandidate { base, paths: [..imports.., name] }` inside an + extending class. `base` is untouched: the inherited semantics every consumer + reads are exactly what they were. An unqualified **value** miss is + unchanged from `3bc61f9`: `ExternalCandidate { paths: [..imports..] }`, + `InheritedCandidate { base, paths: [..imports..] }`, or `NotFound` when + there are no imports at all. +3. `Resolution::NotFound` keeps its meaning and its reachability. It is what a + miss with no path to offer says: a member of a package this file fully + declares, a `.port` of a module it declares, a `this.x`/`super.x` with no + class or base, and a plain expression identifier with no import in scope. + Over the 860-file corpus it is reached 1 256 times (was 1 418 before the + round; the 162-reference difference is exactly the type-position misses). +4. `workspace.rs::resolve_external` answers an `InheritedCandidate` from its + paths, and records an entry **only when one of them lands**. An inherited + candidate is not an external candidate: when the sweep finds nothing, the + reference stays exactly what it was, absent from the overlay, and + `ExternalResolutions::counts()` does not grow. `ExternalTarget`, + `Definition` and every other overlay type are unchanged. + +**Promised to consumers:** the overlay answers more references and invents +nothing. Every `Def` it returns is still a real file-scope declaration whose +`name_span` slices back to the name the use spells (the corpus test asserts +this over all 860 files, unchanged). + +**Requested of other modules:** nothing. The parser gap the type-definition +feature filed (an ANSI header whose first port has no direction does not parse) +is still open and still not this feature's; the rename test added here writes +the interface in the body and says why. + +## Status / TODO + +- [x] `crates/vlog_semantic/src/bind.rs`: `Target::Type`, emitted by + `bind_data_type`'s unqualified arm only (fix round, 2026-08-26). +- [x] `crates/vlog_semantic/src/resolve.rs`: the bare name as the last path of + every unqualified **type-position** miss, both spellings; a + value-position miss keeps its pre-round spelling, `NotFound` included. +- [x] `crates/vlog_semantic/src/workspace.rs`: `resolve_external` answers an + inherited candidate opportunistically, entry only on a hit. +- [x] `crates/vlog_semantic/src/model.rs`: the three `Resolution` doc comments + say what each variant now means. +- [x] `crates/lucisv_server/src/type_def.rs`: `indexed_type` deleted, qualifier + guard and kind filter included; `type_definition` is the pure two-layer + answer; module doc updated. +- [x] Consumer audit across the workspace (work log below): every match site on + `NotFound`/`InheritedCandidate` reviewed, no code change needed anywhere. +- [x] 9 new `vlog_semantic` tests (7 promotion + 2 value-position twins), 1 new + `vlog_refactor` test plus the fix round's refusal test, 6 existing + `vlog_semantic` assertions restored to their pre-round values once the + promotion narrowed, 1 `lucisv_server` expectation updated and 3 tests + there renamed (one of them a real behavior change, argued below). +- [x] Corpus re-measured three times with one harness — `3bc61f9`, the + unrestricted first cut, and the shipped type-only promotion; both README + tables carry all three columns and the survived/given-back split. +- [ ] **Not done, deliberately:** `rename` still refuses an + `InheritedCandidate` even when the overlay answered it. The refusal + message is about the base class, which is still true, and widening rename + to act on a best-effort sweep deserves its own round with its own + collision tests. +- [ ] **Not done:** chasing a base class. Nothing here resolves inheritance; + when something does, those references become `Resolved` and the promotion + is simply never reached for them. + +## Work log + +### 2026-08-26 — dev agent + +- **The design, chosen after reading all three call sites.** The brief offered + a new `Resolution` variant or a promotion to `ExternalCandidate`. The + promotion wins, and the reason is that `ExternalCandidate { paths: [name] }` + is not a new concept here — it is *the same shape* `Target::Module` emits for + an instantiation of a module declared elsewhere and `Target::Unit` emits for + an `extends Base`, both of which already mean "a workspace unit of this name + could be it". A fourth variant would have spelled an existing idea twice. + It also makes `NotFound`'s own doc comment true for the first time: it says + "no external unit could", which was false for every unqualified lexical miss. + The implementation is two lines of behavior — `lexical` pushes the name, + `miss` loses its `NotFound` arm — which is what the boring version of this + should cost. +- **Where the qualified/unqualified fence lives, and why that is not a check.** + The lead's guard in `indexed_type` tested the text before the reference for + `::`, because at the server layer the `Target` that produced a resolution is + gone. In `resolve.rs` it is right there: `unit_member` (the `x` of `p::x`) + builds its own `NotFound`/`InheritedCandidate` and never calls `miss`, so + adding the bare name inside `miss` reaches exactly `lexical` and `unit` and + nothing else. The guard is deleted with the function and nothing replaces it; + `a_qualified_miss_is_never_promoted_in_either_spelling` pins both spellings. +- **The `InheritedCandidate` half is answered without being converted.** The + brief's constraint was that the overlay must not erase the inherited + semantics, and the corpus makes it concrete: 7 800-odd inherited candidates + exist, and most of them are ordinary member misses (`held = 1` inside a class + that extends) that no unit table can answer. So `resolve_external` tries the + paths and inserts an entry **only on a hit** — 520 hits over the corpus. + Consequences: `Resolution` still says `InheritedCandidate { base, .. }` for + every one of them, so `rename`'s refusal message and `check.rs`'s anchor + logic are untouched; `overlay.get(id)` still means "the workspace had + something to say"; and `counts()` does not acquire a denominator of names + nobody expected it to answer. The alternative — inserting `StillUnresolved` + entries for all of them — would have moved the corpus answer rate from 89.3 % + to roughly 60 % without a single extra answer, which is a measurement + artifact, not a result. +- **It also closes a finding the class-semantics QA round filed and left as a + design call.** That log offered two honest fixes for inherited candidates the + overlay never got to answer: suppress the inheritance fallback for *unit* + lookups, or "let the overlay chase `InheritedCandidate.paths`" + (`docs/features/class-semantics/README.md`). The first was taken earlier — + `miss` already exempts `Target::Unit` — and this round takes the second. +- **Consumer audit** (`grep -rn 'InheritedCandidate\|NotFound' crates + --include='*.rs'`), every site and its verdict: + - `vlog_refactor/src/rename.rs:231-240` — `locate` matches all four + variants. `NotFound` → "not resolved to any declaration"; a promoted miss + now takes the `ExternalCandidate` arm instead, reaching + `declaration_across_files`, which either finds the declaring file (the + interface rename this round pins) or returns "declared outside the files + lucisv indexes". Both are honest; no code change. The + `InheritedCandidate` arm is unreachable-by-design for a name the overlay + answered, and deliberately left refusing (Status/TODO). + - `vlog_refactor/src/check.rs:533` (`Anchor::Unresolved`'s doc) and + `:618-640` (`anchor_of`) — reads `reference.resolved()` and the overlay, + never the variant. A newly answered reference becomes `Anchor::External` + on **both** sides of the verification (the pre-edit analysis is shifted + forward and re-anchored the same way), so the fingerprint still compares + like with like. No change; the whole rename suite is green including the + resolution-identity tests. + - `vlog_linter/src/signals.rs:260,573` — `reference.resolved()` only, which + is `Some` for `Resolved` and `None` for everything else, before and after. + Semantic lints cannot see this change. `cargo test -p vlog_linter`: green. + - `lucisv_server/src/nav.rs:191` (`symbol_at`) — same `resolved()` + accessor; `definition`/`references`/`highlights` go through + `ExternalResolutions`, which is where the new answers arrive. + - `lucisv_server/src/tokens.rs:202` — `resolved()`; semantic tokens + unaffected. + - `lucisv_server/src/type_def.rs` — the whole `indexed_type` match site is + deleted. + - `vlog_semantic/src/model.rs:119` (`is_inherited_candidate`) — still true + of exactly the same references; the corpus inherited-candidate rate is + unchanged at 8.3 %, which is the check that the promotion did not + reclassify anything. + - Test-only sites (`tests/semantics.rs`, `tests/classes.rs`, + `tests/rename.rs:368`) — reviewed individually below. + - `lucisv_server/src/server.rs`'s `MethodNotFound` — an LSP error code, an + unrelated grep hit. +- **Six existing assertions re-pointed, each because the paths grew by the + bare name, none because behavior regressed**: `semantics.rs`'s genvar-escape + miss (`NotFound` → `ExternalCandidate { ["i"] }`, plus a new assertion that + `resolved()` is still `None`) and its wildcard-import miss (`["other_pkg::*"]` + → `+ "SOMETHING"`); `classes.rs`'s `set_name` inheritance miss, `UVM_LOW` + import-carrying miss, and `member_miss`. `super.x`/`this.x` assertions in the + same tests are untouched, which is the point: a member access names no unit + and gains no path. + `inherited_candidates_are_not_the_workspace_overlays_business` keeps its name + and its verdict — the overlay still holds nothing for `held` — and gained the + reason (a class property is not a unit). +- **The type_def fence tests, one by one.** The suite is the acceptance suite, + so each is named with what happened to it: + - `a_local_declaration_of_the_same_name_wins_over_the_workspace_type`, + `a_local_typedef_in_the_extending_class_itself_wins_over_the_workspace_type` + — unchanged, pass. Shadowing is enforced by `lexical` resolving first, + which the promotion happens after. + - `a_qualified_name_the_overlay_refused_is_not_retried_against_the_index`, + `a_qualified_member_miss_never_falls_back_to_a_bare_name_sweep` — + unchanged, pass. The qualifier guard's job is now `unit_member`'s. + - `an_inherited_candidate_reaches_a_same_named_module_exactly_like_not_found_did`, + `a_uvm_shaped_member_type_resolves_cross_file_from_an_extending_class`, + `a_class_scoped_type_reference_in_an_extending_class_is_found_cross_file`, + `an_in_file_bases_nested_typedef_does_not_beat_the_workspace_type_because_nothing_finds_it` + — unchanged, pass, now through the overlay. The third and fourth still + assert the resolution is `InheritedCandidate`, which is now a statement + about the promotion preserving it. + - `a_module_declared_twice_returns_both_declarations`, + `a_type_nothing_declares_answers_nothing`, + `a_non_type_inherited_reference_is_still_never_a_type_site`, + `corpus_spot_check_real_uvm_files_no_panic_and_known_jumps` and the other + 30 — unchanged, pass. + - `a_plain_expression_use_of_a_workspace_module_name_is_never_a_type_site` — + kept, expectation updated: the reference is now an `ExternalCandidate` and + `nav::definition` *does* answer it, which the test now asserts explicitly + before asserting that `type_definition` still does not. That makes it a + stronger test than it was: it pins the confinement rather than an accident. + - `indexed_type_returns_every_workspace_declaration_when_the_name_is_ambiguous` + → `a_promoted_miss_returns_every_workspace_declaration_when_the_name_is_ambiguous`. + Renamed because it named a deleted function; same fixture, same assertion + (two interfaces, both offered), same convention. + - `the_other_two_fence_conditions_still_hold_under_an_inherited_candidate` + → `an_inherited_candidate_answers_only_what_the_workspace_unit_table_holds`. + Two of its three arms are unchanged and pass (a package *member* is not in + the unit table; a qualified miss is never swept). The first arm — a + `package` of that name — now answers, and asserts so. + - `a_package_of_the_same_name_is_not_a_type` + → `a_package_of_the_same_name_answers_exactly_as_definition_answers_it`. + **The one behavior change in the suite**, argued in Assumptions above and + asserted as literal equality with `nav::definition` at the same offset, so + the two handlers can never drift apart on it again. +- **Measured before and after with one harness, both on the 860-file corpus.** + The tables in `docs/features/vlog-semantic/README.md` and + `docs/features/workspace-index/README.md` were **stale by several rounds** + before this one (they described 73 708 references and an 87.0 % answer rate; + the tree measured 94 685 and 89.3 % at `3bc61f9`, because class support and + the parser rounds since moved both). The numbers quoted in the brief + (94.0 % / 1.2 %) come from `docs/features/directives-in-instances/README.md` + and are older still. So the "before" column below is a fresh measurement of + `3bc61f9` — taken by stashing only the three changed `src` files and + re-running the same instrumented test — not a quote. +- **The reporting change that made the comparison honest.** Re-bucketing a miss + moves it between the columns these tables report, so the per-bucket rates + move without anything getting better or worse. `tests/workspace.rs`'s `Tally` + now also prints **references with nowhere to jump after both layers** + (`references − resolved in-file − answered by the overlay`), which is the + number that cannot be gamed by a re-spelling, plus how many of the overlay's + entries came from inherited candidates. `tests/corpus.rs` prints the raw + unresolved count beside its percentage. Both assertions are textually + unchanged. + + Clean-file population (853 files, 94 384 references): + + | metric | before | after | + |---|---:|---:| + | resolved in-file | 73.3 % | 73.3 % | + | external candidates | 17.1 % | **18.4 %** | + | inherited candidates | 8.3 % | 8.3 % | + | unresolved (`NotFound`) | 1.3 % | **0.00 % (0)** | + | handed to the workspace layer | 16 133 | **17 877** | + | …of which inherited candidates | 0 | **520** | + | answered | 89.3 % | 83.7 % | + | still unresolved (of those handed) | 10.7 % | 16.3 % | + | **nowhere to jump, both layers** | **10 794 (11.4 %)** | **10 235 (10.8 %)** | + + All-files population: nowhere to jump 10 992 (11.6 %) → **10 431 (11.0 %)**. + + Read honestly: **559 references on clean files gained a jump target and none + lost one** — 520 of them inherited candidates (the UVM shape this round + exists for) and 39 in the external bucket, where the bare name landed after + every import path in scope had missed. The answer *rate* falls only because + 1 224 previously-invisible misses joined the denominator; they were counted + in the other table's "1.3 % unresolved" before, and they are the same names + either way. No cell that measures "this reference has nowhere to go" rose. + Index counts, build time (0.78 s), determinism and the span-slices-back + assertion are all unchanged. +- **Scope.** Files edited: `crates/vlog_semantic/src/{resolve,workspace,model}.rs`, + `crates/vlog_semantic/tests/{workspace,semantics,classes,corpus}.rs`, + `crates/lucisv_server/src/type_def.rs`, + `crates/vlog_refactor/tests/rename.rs`, this README, and the three READMEs + named above. No new dependency, no version bump, no parser change, + no `TODO.md` change (§6 and §9c both claim capabilities that were true before + and are more true after). +- **Gates.** `cargo fmt --all -- --check`: clean. `cargo clippy --all-targets + --workspace`: 0 warnings. `cargo test --workspace`: green (871 passed / + 4 ignored in `lucisv_server`'s own suite, 0 failed anywhere). + `cargo test -p vlog_formatter`: green. `cargo test -p vlog_linter`: green. + `cargo test -p vlog_refactor`: green (49 rename tests, +1). + `cargo build && node editors/vscode/smoke.js target/debug/lucisv-server`: + `smoke: OK`. No `git commit`, no `git push`. + +### 2026-08-26 — dev agent, fix round (QA finding 1) + +- **What was wrong, in one sentence.** `Target::Lexical` is two things wearing + one name — a declaration's type window and every plain expression identifier + — so promoting it promoted both, and a value-position typo became an + `ExternalCandidate` that `rename` acted on across files. The round's + Assumptions claimed this was "the same exposure `Target::Module` and + `Target::Unit` have always had"; QA disproved it by reading `3bc61f9`, and + the claim is now struck through and corrected in place rather than quietly + edited. +- **The mechanics, and why this one.** The brief offered a new target variant + or a flag at the `use_name` call sites. The variant wins, for the reason the + bug had: the information "this name was written where a type goes" exists at + exactly one place in `bind.rs` and is thrown away one line later. A flag + threaded through `use_name` would put the same fact in the same place while + making every unrelated call site name it; a variant lets `resolve.rs`'s + dispatch — the function whose whole job is "what kind of lookup is this" — + carry it. So: `Target::Type`, dispatched to the same `lexical` walk with + `promote: true`, and `Target::Lexical` with `promote: false`. `miss` gets its + pre-round body back verbatim, including the `external.is_empty() → NotFound` + arm the first cut had deleted as unreachable. Behavior delta is four lines. +- **The call-site map — every `Target::Lexical` site in `bind.rs`, and its + verdict.** All four, and only these four, exist: + - `bind.rs:1223`, `bind_data_type`'s unqualified `None` arm — **the type + position, changed to `Target::Type`.** Every type in the language funnels + here, verified by reading all eleven `bind_data_type` callers: ANSI module + ports (385), header `#()` param ports (409), typedef aliases (442) and + enum bases (448), struct members (467), the shared declarator path that + serves nets/vars/params/port decls (508), function return types (615), + task/function arguments (650), out-of-body method return types (829), the + typed `for`-init declaration (928), and `ExprKind::Type` (1184), which is + how `#(virtual bus_if)` and a `type` parameter's default arrive. A + `virtual`/`virtual interface` prefix is held separately by the parser + (`DataType::virtual_kw`), so `ty.name` is the bare interface name and the + UVM `virtual clk_rst_if vif;` shape is covered by the same one line — the + cross-file interface rename test exercises exactly it. + - `bind.rs:1082`, `ExprKind::Ident` — the value position, **left as + `Target::Lexical`.** The regression's source. + - `bind.rs:1009`, `disable blk;` — a block label, a value position. Left. + - `bind.rs:128`, a re-declaration of a name already bound in the scope — + recorded as a use of the first declaration. Not a type window (the type + window was already bound separately by the time `declare` is called), and + the name is by construction one this file *does* bind, so it resolves and + never reaches `miss` anyway. Left. + - **Not a call site, worth recording:** a cast's type. `ExprKind::Cast` + binds only its operand (`bind.rs:1169`, `{ expr, .. }`) — the casting type + is dropped and produces no reference at all, before this round and after. + So `state_t'(0)` needs no promotion; it needs a reference first. Out of + scope here, noted for whoever picks it up. +- **Consumer audit, the additions.** `bind::Target` is `pub(crate)` and + `grep -rn 'Target' crates --include='*.rs'` finds exactly one match site for + it, `resolve.rs::resolve` — every other hit is `ExternalTarget` (the overlay + enum, untouched), `vlog_refactor`'s unrelated `rename::Target`/`RenameTarget`, + or prose. Adding a variant therefore cannot silently fall through anywhere: + the one `match` is exhaustive and the compiler checked it. The main round's + audit of `NotFound`/`InheritedCandidate` consumers stands unchanged and is + now *more* true — `NotFound` is reachable again, which is the spelling + `rename.rs:233` and `type_def.rs` were already written against. +- **`type_def.rs` needed nothing, as predicted.** Its whole suite is green + unchanged: the fence tests, the cross-file interface/class/typedef jumps, the + ambiguity convention, the qualified-miss fence. The one exception is the test + the main round flipped, flipped back — below. +- **The read-only side, given back deliberately.** + `a_plain_expression_use_of_a_workspace_module_name_is_never_a_type_site` now + asserts the value-position typo is `NotFound` and that **`nav::definition` + answers nothing**, where the main round asserted it answered. That read-only + behavior was defensible on its own — F12 landing on a same-named module is + surprising but harmless — but one promotion serves both the read and the + write path, and there is no honest way to keep the jump while refusing the + rename without building the fourth resolution layer this round exists to + delete. The write side wins the argument. The test is stronger for it: it now + pins two independent fences (the model never offers the coincidence, and the + handler builds no `Site` for an expression statement) instead of one. +- **The QA repro, flipped and rehomed.** + `qa_a_bare_value_position_typo_reaches_an_unrelated_same_named_module` → + `a_bare_value_position_typo_never_reaches_an_unrelated_same_named_module`, + moved into `rename.rs`'s refusals section where its siblings live, and it now + asserts the refusal message (`not resolved to any declaration`) instead of + panicking on success. Same fixture, same two files, same cursor. +- **Value-position twins added**, alongside the promotion tests they mirror: + `a_value_position_miss_is_never_promoted_even_onto_a_same_named_unit` (the + same word, the same workspace, only the position differs — `NotFound`, no + overlay entry, no defs) and + `a_value_position_miss_inside_an_extending_class_gains_no_path_either` + (`InheritedCandidate` with empty `paths` despite a same-named interface in + the workspace). Six assertions the main round had re-pointed at grown paths + went back to their pre-round values, each with the reason written in: they + were all value positions (`set_name` a callee, `UVM_LOW` a call argument, + `member_miss` a call, `held = 1` an assignment LHS, `i` a genvar out of + scope, `SOMETHING` an assignment RHS). +- **Measured a third time, same harness, same corpus.** Resolution buckets over + all 860 files, raw counts, the three states side by side: + + | bucket | `3bc61f9` | promote everything | type positions only | + |---|---:|---:|---:| + | `Resolved` | 69 274 | 69 274 | 69 274 | + | `ExternalCandidate` | 16 152 | 17 570 | **16 314** | + | `InheritedCandidate` | 7 841 | 7 841 | **7 841** | + | `NotFound` | 1 418 | 0 | **1 256** | + + `InheritedCandidate` is bit-identical in all three, which is the strongest + form of "nothing was reclassified"; 16 152 + 162 = 16 314 and 1 418 − 162 = + 1 256, so exactly 162 references moved, all of them type positions with no + import in scope (153 of them on clean files). +- **The split, stated honestly.** Against `3bc61f9`, on clean files: **418 + references gained somewhere to jump and none lost one** (420 over all files — + nowhere-to-jump 10 992 → 10 572). The unrestricted first cut gained 559 on + clean files (561 over all), so **141 gains were given back** — the same 141 + on both populations. Composition of the give-back: 117 inherited-candidate + answers (the landed count falls 520 → 403) and 24 external-bucket answers. + Every one was a value-position identifier answered on a name collision, which + is precisely the thing that made `rename` unsafe; the round is worth less + without them and would have been worth nothing with them. The type-position + wins — the cross-file `interface`, the package-less `class`, the file-scope + `typedef`, the UVM `virtual iface` inside an extending class — all survive, + and their tests are green unchanged. The no-reference-loses-a-target property + holds: the last row of the workspace table fell against the baseline in both + populations, and every promotion test still finds its declaration. +- **Scope of the fix round.** `crates/vlog_semantic/src/{bind,resolve,model}.rs`, + `crates/vlog_semantic/tests/{workspace,classes,semantics}.rs`, + `crates/vlog_refactor/tests/rename.rs`, + `crates/lucisv_server/src/type_def.rs` (one test), this README and the two + measured READMEs. `workspace.rs` untouched by the fix. No new dependency, no + parser change, no `TODO.md` change. + +## QA log + +### 2026-08-26 — QA agent + +**Verdict: not committable as-is.** Attack surface 1 (rename) is a real +regression — a bare-name coincidence in a plain *value* expression is now +write-reachable and `rename` will cross into an unrelated file's declaration. +Everything else audited below is clean. A repro test for the regression is +committed (failing, on purpose) at +`crates/vlog_refactor/tests/rename.rs::qa_a_bare_value_position_typo_reaches_an_unrelated_same_named_module`. + +**1. Rename write-reachability — REGRESSION, not preexisting.** + +Repro: workspace of two files — + +```verilog +// typo_name.sv +module typo_name; +endmodule + +// top.sv +module top; + assign typo_name = 1'b1; +endmodule +``` + +Renaming `typo_name` at its use in `top.sv` **succeeds** and rewrites +`typo_name.sv`'s module declaration to the new name (verified by direct +`vlog_refactor::rename()` call; test panics showing both files' post-edit +text). `check::verify` does not catch it — the edit *is* self-consistent (the +new name resolves the same way the old one did before the edit), so +"resolution identity" has nothing to flag. The bug is one layer up: the model +now treats an unbound plain-expression identifier as if it names a workspace +unit. + +Traced the claim in Assumptions ("the same exposure `Target::Module` and +`Target::Unit` have always had") against `git show 3bc61f9:.../resolve.rs`: +true for `Target::Module`/`Target::Unit`/`Target::Package` — `unit()` and +`named_at_file_scope()` already appended the bare name unconditionally on a +miss, pre-round (module instantiations, `extends` bases, `p::x` heads, +`typedef class` forward decls). **False for `Target::Lexical`** — pre-round, +`lexical()`'s `external` list held only import paths (no bare name), so a +`Target::Lexical` miss with no import in scope was `Resolution::NotFound`, +which `rename.rs:233` explicitly refuses ("not resolved to any declaration"). +Confirmed by reverting only the three `src` files (`git stash push --`) and +re-running the same repro: the pre-round rename call errors with exactly that +message; instrumented `resolution()` on the same offset returns `NotFound`. + +The regression is that `Target::Lexical` is not exclusively the "type name in +a declaration" case the feature is built for +(`bind.rs:1223`, `bind_data_type`'s `None` arm — `bus_if bus;`, the intended +win). It is *also* the plain-expression-identifier case +(`bind.rs:1082`, `ExprKind::Ident => Target::Lexical` — `assign typo_name = 1;`, +a function-call name, any bare read/write). Both dispatch through the exact +same `resolve.rs::lexical`/`miss` path and produce an indistinguishable +`Resolution::ExternalCandidate { paths: [name] }` — there is no signal left +anywhere for a consumer to tell "this was a type position" from "this was a +value position". The dev's own new assertion in +`crates/lucisv_server/src/type_def.rs`'s +`a_plain_expression_use_of_a_workspace_module_name_is_never_a_type_site` +confirms the *read* side of this is deliberate and known +(`nav::definition` now jumps a value-position typo to a coincidentally-named +module — asserted, not refused). For **read-only** navigation that is a +defensible (if surprising) trade griped about nowhere in the brief but at +least non-destructive. For **rename**, which writes files, the same +coincidence is a silent cross-file edit with no relationship to programmer +intent, and CLAUDE.md invariant 1 ("never corrupt code... or emits the input +unchanged with an error") is squarely about not producing output the source +never asked for. + +`rename.rs`'s own refusal machinery does not defend against this: `locate`'s +match arms only ask "did the file's own resolution report `NotFound` / +`InheritedCandidate` / `ExternalCandidate`?" — and this case is, faithfully, +an `ExternalCandidate`, so it takes the honest-cross-file-rename branch. +Whole-edit-or-nothing verification, collision detection and the resolution- +identity re-parse check all ran and all passed, because none of them encode +"was this identifier ever meant as a type/unit name" — that information does +not exist past `bind.rs`. + +This is the top risk the round was flagged for, and it is real. **Not +committable until this is closed.** Two shapes of fix that stay inside this +round's scope, for the dev's follow-up (not prescribing — QA doesn't +redesign): distinguish "type position" from "value position" at bind time +(a new `Target` variant, or a flag `bind_data_type` sets) so only the type- +name spelling of `Target::Lexical` gets the bare-name push; or narrow the +promotion in `resolve.rs::lexical` to fire only when the reference was built +by `bind_data_type`'s `None` arm. Either way, rename's collision tests need a +new case pinning this exact repro as a refusal. + +**2. `base`-semantics preservation and `counts()` — clean.** + +Re-derived the corpus numbers independently (own harness, not the dev's +printed one): dumped every reference's exact `Resolution` variant, both +before (`git stash push --` the three `src` files, keep the test harness) and +after, over the full 860-file corpus: + +| resolution bucket | before | after | +|---|---:|---:| +| `Resolved` | 69 274 | 69 274 | +| `ExternalCandidate` | 16 152 | 17 570 | +| `InheritedCandidate` | 7 841 | 7 841 | +| `NotFound` | 1 418 | 0 | + +`InheritedCandidate`'s resolution-bucket count is **exactly** 7 841 in both +states — not just "flat at 8.3%" by rounding, bit-for-bit identical — which +is the strongest form of "no reclassification" the claim could ask for. And +16 152 (before external) + 1 418 (before `NotFound`) = 17 570 (after +external), exactly: every re-bucketed reference is accounted for and nothing +else moved. `base` itself is untouched by construction (`resolve.rs`'s `miss` +still sets it the same way; `workspace.rs::resolve_external`'s new arm reads +`paths` and never touches `base`), confirmed by the passing +`a_miss_inside_an_extending_class_is_answered_without_losing_its_base` and +`an_inherited_member_the_unit_table_cannot_hold_stays_exactly_what_it_was`. + +"Records only when one lands" verified structurally (`workspace.rs`'s new +match arm: `StillUnresolved => continue`, nothing inserted) and empirically — +`an_inherited_member_the_unit_table_cannot_hold_stays_exactly_what_it_was` +asserts `!in_overlay(...)` for a member miss the sweep cannot answer, and the +corpus-wide inherited-landed count (520) is far below the total inherited +count (7 841), i.e. most misses correctly get no entry at all. + +**3. Baseline honesty — reproduced exactly, "559 gained / none lost" verified +per-reference, not just by aggregate delta.** + +Reproduced the before-measurement myself: `git stash push -- resolve.rs +workspace.rs model.rs` (keeping the dev's extended `tests/workspace.rs` +harness), ran `the_corpus_index_finishes_most_external_references`. Output +matched the README's "before" row to the digit: clean-file handed 16 133 +(17.1 %), inherited-landed 0, nowhere-to-jump 10 794 (11.4 %); all-files +nowhere 10 992 (11.6 %). Popped the stash, re-ran: after-numbers matched the +README's "after" row to the digit (17 877 handed, 520 inherited-landed, +10 235 clean-nowhere / 10.8 %, 10 431 all-files-nowhere / 11.0 %). + +Went one step further than re-running the dev's aggregate: added a temporary +per-reference dump (keyed by file + byte offset, since `bind.rs` is untouched +by this round so `ReferenceId` ordering is stable across the two states — +confirmed by both dumps having exactly 94 685 lines) recording "does this +reference have an answer anywhere" for every reference in the corpus, ran it +in both states, and joined the two dumps on (file, offset, name). Result: +**0 references regressed from answered to unanswered; 561 references gained +an answer, over the whole 860-file corpus** (used the full population, not +the 853-file clean subset the README table quotes — 561 is consistent with +the all-files nowhere-delta of 10 992 − 10 431 = 561, and the README's +559-on-clean-files is 2 fewer, i.e. 2 of the 561 gains are on the 7 files that +still fail to parse — never checked those 2 individually beyond the aggregate +arithmetic, but nothing else in the numbers leaves room for a hidden loss). +This dump was removed from the working tree after use — it was diagnostic +only (behind an opt-in env var, a no-op otherwise), not something that should +ship in the test suite. + +**4. Import-beats-bare-name ordering — verified, real collision.** + +`an_import_that_can_supply_the_name_still_wins_over_a_same_named_unit` +(`crates/vlog_semantic/tests/workspace.rs`) does construct a genuine +collision, not a vacuous one: package `tdp` exports `state_t`, an unrelated +`module state_t` sits in a decoy file, `top.sv` does `import tdp::*; state_t +s;`. Confirmed by reading `resolve.rs::lexical`: the wildcard import path +(`tdp::*`) is pushed to `external` before the loop ends, the bare name is +pushed once after the loop — so paths are always `[..imports.., name]`, and +`workspace.rs::follow_paths` (unmodified by this round) tries them in that +order and stops at the first hit. Test asserts both the resolution's path +order (`["tdp::*", "state_t"]`) and the actual answer (the package's +`typedef`, not the decoy module) — ran it, passes. + +**5. The changed package test — defensible, recorded for lead's Review.** + +`a_package_of_the_same_name_answers_exactly_as_definition_answers_it`: yes, +this is exactly what `nav::definition` gives on the same cursor (asserted as +literal equality in the test, and confirmed independently — `type_def.rs`'s +handler is now three lines that end in `nav::definition`, nothing else). My +own view on the substance, for Review: this is the right call *given* the +"no fourth resolution layer" constraint and the documented no-kind-filter +policy of the shared overlay (`workspace-index/README.md`). A `typeDefinition` +request on `thing t;` where the workspace's only `thing` is a package is a +request against source that does not compile either way, and giving a +different answer than `definition` for the same token would need a resolution +layer nobody else has. Severity if the lead disagrees: low — it is one +disagreeable-but-arguable UX choice on non-compiling input, not a +correctness or safety issue, and it is trivially reversible (a kind filter in +`type_def.rs` alone, no `vlog_semantic` change) if the lead wants F12 and +type-F12 to diverge here. + +**6. Qualified-miss fence — verified structurally intact, both spellings.** + +Read `unit_member` (`resolve.rs:129-174`) end to end: it never calls `miss`, +builds its own `Resolution::NotFound`/`InheritedCandidate` directly in every +arm, and the bare-name push lives only in `lexical` (line 76) and `unit` +(line 120) — `unit_member` has no code path that could reach it. Ran +`a_qualified_miss_is_never_promoted_in_either_spelling` +(`vlog_semantic/tests/workspace.rs`) directly: pins both spellings (a +package-qualified miss with a same-named decoy module, and a class-qualified +miss inside an extending class with a same-named decoy module) and asserts +`Resolution::NotFound` / `InheritedCandidate { paths: Vec::new() }` +respectively, `!in_overlay(...)`, and `external_defs(...).is_empty()` for +both. Also re-ran `lucisv_server`'s +`a_qualified_name_the_overlay_refused_is_not_retried_against_the_index` and +`an_inherited_candidate_answers_only_what_the_workspace_unit_table_holds` +(the type_def suite, post-`indexed_type`-deletion) — both pass, confirming no +path from a qualified miss reaches a bare-name overlay answer now that the +old `::`-text-scan guard in `indexed_type` is gone: the fence moved from a +server-layer text check to a `resolve.rs` structural property, and it holds. + +**7. CLAUDE.md compliance / docs — clean, one drive-by fix.** + +Re-derived every printed corpus number in `vlog-semantic/README.md` and +`workspace-index/README.md` independently (own dump of raw resolution-bucket +and answered/unanswered counts, not a re-run of the dev's own printed +`Tally`) — all match to the stated precision (see items 2 and 3 above); the +resolution-bucket percentages in `vlog-semantic/README.md`'s table +(73.2/18.6/8.3/0.0 after, summing to 100.0 from the raw counts) check out +exactly. Feature README has each required section exactly once. Consumer- +audit table's file:line citations: `rename.rs:231-240`, `check.rs:533`, +`check.rs:618-640`, `signals.rs:260,573`, `nav.rs:191`, `tokens.rs:202` all +land within a line or two of the cited construct; `model.rs:119` for +`is_inherited_candidate` is off — the actual `impl` line is 126 (the doc +comment starts around 124). Minor, not fixed (it's prose in another feature's +work log, out of this round's file scope to edit further than necessary). + +Fixed directly (typo/formatting, per QA's small-fix allowance): a stray +100-column line in `docs/features/class-semantics/README.md` (line 57, "The +overlay may now answer such a reference from `paths`...") that broke the +file's ~78-80 column wrap; rewrapped to match the surrounding paragraph. No +content change. + +**Gates.** `cargo fmt --all -- --check`: clean. `cargo clippy --all-targets +--workspace`: 0 warnings. `cargo test --workspace`: every test green except +the QA-added regression repro (1 failed, by design — see item 1). +`cargo test -p vlog_formatter`, `-p vlog_linter`, `-p vlog_refactor`: green +apart from the same repro. `cargo build && node editors/vscode/smoke.js +target/debug/lucisv-server`: `smoke: OK`. + +**Corpus regression net (formatter).** `tools/corpus_check.sh` is not +actually a committed artifact — `corpus-check-results.tsv` is gitignored, so +there is no checked-in baseline TSV to diff against; the file on disk at +session start was a stale local leftover from an older parser, not this +round's baseline (its `parse-error`s on `` `assume``/`$error`/`(* async *)`` +constructs are gone even at `3bc61f9`, unrelated to this round). Built the +release binary at `3bc61f9` (stashing the three `src` files) and at the full +working tree, ran `corpus_check.sh` both times: **813/820 (99.1%) both times, +byte-identical results TSV (`diff` empty), 0 verification errors, 0 crashes, +both runs.** Expected and confirmed: this round touches no file under +`vlog_formatter` or `vlog_parser`. + +**Tests added.** `crates/vlog_refactor/tests/rename.rs::qa_a_bare_value_position_typo_reaches_an_unrelated_same_named_module` +— kept, failing on purpose, as the regression repro for item 1. + +### 2026-08-26 — QA agent, fix-round re-verification + +**Verdict: committable.** The fix closes finding 1 exactly as claimed, every +type-position win from the main round still resolves, the call-site map is +complete (read every `bind_data_type` caller myself, found nothing it +misses), and every corpus number in both READMEs re-derives to the digit from +a harness independent of the dev's own `Tally` printer. All gates green, +zero failing tests anywhere. + +**1. Gates.** `cargo fmt --all -- --check`: clean. `cargo clippy --all-targets +--workspace`: 0 warnings (confirmed by grepping the output for +`warning`/`error` — none). `cargo test --workspace --no-fail-fast`: **0 +failed** (871 passed / 4 ignored in `lucisv_server`'s own count, every other +crate's suite green, including the QA repro from the previous round, now +flipped and passing). `cargo test -p vlog_formatter`, `-p vlog_linter`, +`-p vlog_refactor`: green. `cargo build && node editors/vscode/smoke.js +target/debug/lucisv-server`: `smoke: OK`. + +**2. The regression, attacked from three shapes beyond the shipped repro — +all refused, both write and read.** Ran the flipped +`a_bare_value_position_typo_never_reaches_an_unrelated_same_named_module` +directly: passes, asserts the pre-round refusal message. Then wrote three +throwaway probes (added, run, and removed after use — not shipped, per the +previous round's own precedent with its diagnostic dump) exercising shapes +the shipped suite does not: + - An `if` condition (`always @* if (typo_name) w = 1;`) instead of an + assignment LHS — `rename` refused with "not resolved to any declaration"; + `nav::definition` and `type_definition` both empty; `doc_reference_kind` + reported `NotFound`. + - A named port-connection value (`sub u0(.p(typo_name));`) — same three + assertions, all held. Read `bind.rs:557` (`bind_connection`) to confirm + this is the same `bind_opt_expr` → `ExprKind::Ident` → `Target::Lexical` + path as the shipped repro, not a coincidence of one syntax. + - `disable typo_block;` — the `bind.rs:1013` block-label site the dev's + call-site map named explicitly as "left as `Target::Lexical`". Same three + assertions, all held. + + All three: `rename` refuses, `nav::definition` empty, `type_definition` + empty. The regression is dead from every angle I could construct, not just + the one shape the shipped test pins. + +**3. The type-position wins, alive from every angle.** `cargo test -p +lucisv_server type_def::` — 45 pre-existing tests green, unchanged verdicts, +plus my 2 nav-emptiness probes and 1 new-win probe (47 total, see below). +`cargo test -p vlog_refactor an_interface_renames_from_the_declaration_it_types_in_another_file` +— green: the cross-file interface rename (declared in `bus_if.sv`, typed via +`virtual bus_if vif;` and instantiated via `bus_if other ();` in `top.sv`, +because the ANSI-header parser gap forces the body spelling) renames both the +declaration and every use. New probe, +`qa_probe_an_ansi_port_type_resolves_cross_file` (run, then removed): a +genuine ANSI port — `module top(input logic clk, bus_if b);`, the interface +port second because a directionless first port doesn't parse yet +(`docs/features/type-definition/README.md` Handshake 2) — resolves the +`bus_if` at `b`'s type through `doc_reference_kind == ExternalCandidate`, +`nav::definition` non-empty, and `type_definition` non-empty, cross-file. +This is the ANSI-port shape the call-site map claims (`bind.rs:393`) but no +existing test exercised directly. + +**4. Call-site map — verified by direct grep and read, not by trusting the +prose.** `grep -n 'Target::Lexical\|Target::Type' crates/vlog_semantic/src/bind.rs` +after excluding doc comments: **3** `Target::Lexical` construction sites +(line 136 — a redeclaration inside `declare`, resolves before ever reaching +`miss`; line 1017 — `disable`'s block label; line 1090 — `ExprKind::Ident`) +and **1** `Target::Type` site (line 1231 — `bind_data_type`'s unqualified +arm). This is a discrepancy worth flagging precisely: the brief characterized +this as "exactly four `Target::Lexical` sites, twelve `bind_data_type` +callers" and the work log's own heading says "all four, and only these four, +exist" — but that "four" is the count of sites that *used to be* +`Target::Lexical` before the fix (1223/1082/1009/128 in the pre-fix line +numbering), one of which (1223) the fix moved to `Target::Type`. Read +literally against the current tree, the count is 3 Lexical + 1 Type = 4 +combined, not 4 Lexical. The work log's own per-site bullets say this +correctly ("changed to `Target::Type`" for the first one); only the summary +sentence overstates it if read out of context. Not a defect in the code — +the compiler-checked exhaustive match is what actually matters and it holds +(next item) — but the phrasing should say "four sites total, three of which +remain `Lexical`" rather than "four `Target::Lexical` sites" if the README is +touched again. + +`grep -rn '\bTarget\b' crates --include='*.rs'` excluding `ExternalTarget`/ +`rename::Target`/`RenameTarget`/prose: exactly one match site, +`resolve.rs:12`'s `match &p.target`, confirmed exhaustive (compiles with no +wildcard arm and no `#[allow]`). + +`grep -n 'fn bind_data_type\|bind_data_type(' crates/vlog_semantic/src/bind.rs` +finds **11** call sites, not 12 — matching the 11 categories the work log's +prose actually lists (ANSI ports, header param ports, typedef alias, enum +base, struct member, the shared declarator path, function return, tf args, +out-of-body return, typed for-init, `ExprKind::Type`); "twelve" in the prose +appears to be an off-by-one in the summary count, not a missing call site — +I could not find a twelfth. Read all 11 callers end to end plus their +transitive callers (`bind_declarators` is reached from `bind_data_decl`, +`bind_port_decl`, and two `ParamDecl` sites at both item- and statement-level; +`bind_tf_args` serves both `bind_function` and `bind_task`) looking +specifically for the four shapes the task asked me to probe: + - **`virtual interface` variables** — `virtual clk_rst_if vif;` is an + ordinary `VarDecl` → `bind_data_decl` → `bind_declarators` → + `bind_data_type` (line 516); the `virtual` keyword is held on + `DataType::virtual_kw` separately by the parser so `ty.name` is the bare + interface name. Covered — this is literally the shape the interface + rename test exercises. + - **`parameter type` defaults** — a `type` parameter's default type value + parses as `ExprKind::Type`, reaching `bind_data_type` at line 1192. + Covered, per the dev's own comment there. + - **`struct packed` member types** — `TypedefKind::Struct`'s per-member + loop calls `bind_data_type` on `m.ty` at line 475 before declaring each + of the struct's declarators. Covered. + - **tf args** — `bind_tf_args` (line 656) calls `bind_data_type` on `a.ty` + for every task/function argument, called from both `bind_function` and + `bind_task`. Covered. + + I could not find a call site of `DataType` binding that bypasses + `bind_data_type`. **Verdict: the map is exhaustive** for the four probed + shapes and, as far as a full read of the file shows, for the language's + type positions generally. The "twelve" vs. eleven count is the only + inaccuracy found and it overstates rather than understates the coverage. + +**5. Corpus numbers — every figure in both READMEs re-derives to the digit, +independently.** Built a raw per-Resolution-variant counter (bypassing the +dev's `Tally` entirely — counts `Resolution::Resolved`/`ExternalCandidate`/ +`InheritedCandidate`/`NotFound` directly off `sem.references()`), ran it at +three states and popped/reapplied a `git stash` of the three `src` files +between them (`bind.rs`/`resolve.rs`/`model.rs`/`workspace.rs`), then removed +the probe: + +| bucket | `3bc61f9` (mine) | shipped (mine) | README | +|---|---:|---:|---:| +| `Resolved` | 69 274 | 69 274 | 69 274 / 69 274 | +| `ExternalCandidate` | 16 152 | 16 314 | 16 152 / 16 314 | +| `InheritedCandidate` | 7 841 | 7 841 | 7 841 / 7 841 | +| `NotFound` | 1 418 | 1 256 | 1 418 / 1 256 | + +Bit-for-bit match, both states, both non-`InheritedCandidate` claims (the +inherited bucket's bit-identical 7 841 reproduces independently) and the +arithmetic join (16 152 + 1 418 = 17 570 = the promote-everything external +count; 16 152 + 162 = 16 314; 1 418 − 162 = 1 256). + +Went further than the minimum bar and reproduced the **middle** "promote +everything" column too, by temporarily patching `resolve.rs`'s +`Target::Lexical` arm to pass `promote: true` (mechanically the same +behavior the first-cut round shipped, since `Target::Type` didn't exist yet +to distinguish them) — ran, recorded, reverted the one line from a saved +copy, and confirmed `git diff` showed zero net change to `resolve.rs` +afterward: + +| bucket | promote-everything (mine) | README | +|---|---:|---:| +| `ExternalCandidate` | 17 570 | 17 570 | +| `InheritedCandidate` | 7 841 | 7 841 | +| `NotFound` | 0 | 0 | + +Also re-ran `the_corpus_index_finishes_most_external_references` at all three +states (before/promote-everything/shipped) and matched every printed figure +to the README's workspace-index table: handed 16 152→18 090→16 717 (all +files), inherited-landed 0→520→403, nowhere-to-jump (all files) +10 992→10 431→10 572, nowhere-to-jump (clean files) 10 794→10 235→10 376. + +**The 141-given-back split (117 + 24), reproduced exactly.** Wrote a second +throwaway probe splitting `resolve_external`'s landed overlay entries by +`reference.is_inherited_candidate()`, ran at promote-everything and shipped: + +| | promote-everything | shipped | delta | +|---|---:|---:|---:| +| inherited-landed | 520 | 403 | **117** | +| external-landed | 14 460 | 14 436 | **24** | + +117 + 24 = 141, matching the README's split exactly, independently derived +(not by re-running the dev's own numbers, by counting landed overlay entries +directly). Both throwaway probes (`qa_probe_raw_resolution_bucket_counts`, +`qa_probe_landed_split_external_vs_inherited` in +`crates/vlog_semantic/tests/workspace.rs`, and three more in +`crates/vlog_refactor/tests/rename.rs` / `crates/lucisv_server/src/type_def.rs` +for items 2–3 above) were removed from the working tree after use — +diagnostic only, confirmed by `git diff --stat` returning to the dev's +original fix-round shape before this entry was written. + +**6. The six re-pointed assertions — all six checked against `3bc61f9`, not +just three.** `git diff crates/vlog_semantic/tests/{semantics,classes}.rs` +(default diff base is `3bc61f9`, since everything here is uncommitted on top +of it) shows, for all six the work log names (`set_name`, `UVM_LOW`, +`member_miss`, `held = 1`, the genvar `i`, `SOMETHING`): **either zero diff +at all** (`member_miss`'s test has no diff whatsoever against `3bc61f9`) **or +a comment-only diff** — the assertion lines themselves (`Resolution:: +InheritedCandidate { .. }`, `Resolution::NotFound`, the exact `paths` vectors) +are byte-identical to `3bc61f9` in every one of the six; only explanatory +comments were added, and in one case (`held = 1`) an assertion failure +message string. None of the six assertion *values* are new inventions — +every one is provably the pre-round value. + +**7. README honesty.** The struck Assumptions bullet reads as an honest +correction (strikethrough kept, correction inline, attributed to "QA finding +1, 2026-08-26") rather than a silent edit. Both measured READMEs' +resolution-bucket tables match my independent re-derivation to the digit +(item 5). The cast-binds-no-reference gap is recorded explicitly in the fix +round's work log ("Not a call site, worth recording: a cast's type...", +"Out of scope here, noted for whoever picks it up") — confirmed by reading +`bind.rs:1177`'s `ExprKind::Cast { expr, .. } => self.bind_expr(expr, scope)`, +which indeed binds only the operand, dropping the casting type with no +reference produced, unchanged by this round. + +**8. Minor finding, not fixed (out of scope, prose-only).** The work log's +call-site-map summary sentence says "exactly four `Target::Lexical` sites" +where the current tree has three (plus one `Target::Type` the fourth became) +— see item 4. Cosmetic; the per-site bullets underneath already say the +right thing, and the exhaustive-match property the claim is *for* holds +regardless. Left for the lead to wave through or ask for a one-word fix. + +**Verdict: committable.** Finding 1 is closed and dead from every angle +tested (assign RHS, if-condition, port-connection value, disable-label; both +`rename` and `nav::definition`/`type_definition`). No new regression found. +Every type-position win from the main round still resolves, including one +shape (ANSI port) no existing test exercised directly. The call-site map is +functionally exhaustive despite one prose miscount. Corpus arithmetic +reproduces to the digit across all three states and the full given-back +split. Gates are green with zero failing tests anywhere. + +## Review + +### 2026-08-26 — lead + +Reviewed both rounds' diffs, work logs and QA logs; re-ran all gates +myself, clean. This feature is the workflow's best argument for itself. +The main round delivered the Handshake and honestly re-measured stale +baselines — and QA's adversarial pass then found the one thing that +mattered: the promotion had quietly made rename, a write operation, +reachable from a value-position name coincidence, disproving the work +log's "same exposure as always" claim against the pre-round source. The +fix round's answer is the right kind: a `Target::Type` variant that +records where the fact "this is a type position" actually exists (one +line in `bind_data_type`), a four-line behavior delta, `miss` restored +verbatim, and the write path's refusal back — while every type-position +win survives, the corpus join shows 418 clean-file references gained a +target with none lost, and the 141 coincidence-answers given back are +exactly the ones no one should want. + +I read the promoted `lexical` and restored `miss` myself; the doc +comment now argues the value/type asymmetry better than either brief +did. QA's re-check killed the regression from three angles (assign, +expression context, disable label), verified the call-site map by +independent grep and caller reading, and reproduced every corpus figure +to the digit including the 117+24 split. I fixed the two prose +miscounts QA flagged (the four-Lexical-sites summary, twelve→eleven +callers) in the work log directly, and un-clobbered one QA quotation my +first fix had edited by mistake. The cast-binds-no-reference gap stays +filed as pre-existing. `indexed_type` is gone, its guard with it, and +the two handlers cannot drift because only one resolution path remains. +Accepted as shipped. diff --git a/docs/features/type-definition/README.md b/docs/features/type-definition/README.md index 7d6e60b..541af75 100644 --- a/docs/features/type-definition/README.md +++ b/docs/features/type-definition/README.md @@ -48,16 +48,17 @@ feature adds is *which offset to ask about*. anything to do with inheritance — so in a type window it means only "a base class *might* declare this type". `vlog_semantic` never chases a base chain (in this file or out of it: `lexical` walks `scope.parent`, which is lexical - nesting, and `miss` records the base's *name* and stops; `resolve_external` - only finishes an `ExternalCandidate`), so no layer can turn that into a - location, and the workspace's file-scope type of that name is the best - honest answer available. This is assumed, not enforced: a base class that - genuinely declares a nested type of the same name would be the better answer, - and nothing here can produce it — but nothing displaces it either, because - the fallback is consulted only after `nav::definition` came back empty. The - day `vlog_semantic` does chase a base, such a reference becomes - `Resolution::Resolved`, `definition` answers it, and the fallback is never - reached. Pinned by + nesting, and `miss` records the base's *name* and stops), so no layer can + turn that into a location, and the workspace's file-scope type of that name + is the best honest answer available. **Since 2026-08-26 that answer comes + from the overlay itself**, which tries the paths such a miss now carries + (`docs/features/overlay-promotion/README.md`) — the reasoning is unchanged, + only the layer that acts on it. This is assumed, not enforced: a base class + that genuinely declares a nested type of the same name would be the better + answer, and nothing here can produce it — but nothing displaces it either, + because a resolved name never reaches the sweep. The day `vlog_semantic` does + chase a base, such a reference becomes `Resolution::Resolved` and + `definition` answers it directly. Pinned by `an_in_file_bases_nested_typedef_does_not_beat_the_workspace_type_because_nothing_finds_it`. ## Handshakes @@ -68,9 +69,11 @@ Instantiation, GenIf, GenElse, GenBlock, Stmt, StmtKind}` and `TextRange`. Read-only; nothing was changed. **Consumed from `vlog_semantic`:** `Semantics::{references, reference_at, -symbol}`, `Reference::{name, name_span, resolved}`, `Resolution::NotFound`, -`SymbolKind`, and `WorkspaceIndex::{units, path}` for the one fallback below. -Read-only; nothing was changed. +symbol}`, `Reference::{name, name_span, resolved}` and `SymbolKind`. +Read-only; nothing was changed. (Until 2026-08-26 this also read +`Resolution::{NotFound, InheritedCandidate}` and `WorkspaceIndex::{units, +path}` for the `indexed_type` fallback; request 1 below landed and the +fallback is gone.) **Consumed from this crate:** `nav::definition` (the whole answer), `nav::symbol_at` — widened from private to `pub(crate)` so the two handlers @@ -82,11 +85,23 @@ serving `server.rs`'s `GotoTypeDefinition` arm. Same answer shape as to, every candidate where the workspace declares the name twice, and an empty array (not `null`) for a buffer the server was never sent. -**Requested of other modules** — neither blocked this round, and neither was -done here: +**Requested of other modules** — neither blocked the original round, and +neither was done there: -1. **`vlog_semantic`: report an unresolved *unqualified* name as an external - candidate, not as a bare lexical miss.** `resolve.rs`'s `lexical` miss ends +1. ~~**`vlog_semantic`: report an unresolved *unqualified* name as an external + candidate, not as a bare lexical miss.**~~ **Delivered 2026-08-26 by + `overlay-promotion`** (`docs/features/overlay-promotion/README.md`): a miss + on a name written in a **type** position — which is every name this feature + ever asks about — carries the bare name as its last candidate path in both + miss spellings, so the workspace overlay answers them. (A miss in a *value* + position does not, which is what keeps a bare expression identifier from + matching a unit on name alone.) `indexed_type` — its qualifier guard and + its kind filter with it — is deleted. `type_definition` is now literally + `nav::definition` of the type name's offset and nothing else. One test + changed behavior with it: a `package` of the type's name is now answered + exactly as `definition` answers it, because the shared overlay does not + filter by kind and the private fallback did (argued in that feature's + Assumptions). The original request read: `resolve.rs`'s `lexical` miss ends in `Resolution::NotFound` whenever the file collected no import paths on the way out — or, inside a class with an `extends`, in `Resolution::InheritedCandidate` — and neither reaches `resolve_external`, @@ -105,7 +120,8 @@ done here: **file-scope** declaration, and only for the kinds that can be a type (`Module`, `Class`, `Typedef` — a `package` of that name is not one). When the request above lands, that function is deleted and nothing else in this - module changes. + module changes. *(It landed; the function is gone and nothing else in this + module changed.)* 2. **`vlog_parser`: an ANSI header whose *first* port carries no direction does not parse.** `module m (bus_if bus, input logic clk);` becomes an `Error` item, while `module m (input logic clk, bus_if bus);` parses fine — the @@ -119,7 +135,7 @@ done here: ## Status / TODO - [x] `crates/lucisv_server/src/type_def.rs`: the offset redirection, the - declaration walk, and the index fallback. + declaration walk, and (until 2026-08-26) the index fallback. - [x] `type_definition_provider` advertised (`TypeDefinitionProviderCapability::Simple(true)`). - [x] `GotoTypeDefinition` dispatched in `server.rs`, on `GotoDefinition`'s conventions exactly. @@ -136,6 +152,13 @@ done here: finding below (a cross-file type used as a member of any `extends`-ing class — nearly every UVM class — answered nothing). 4 tests added, QA's regression test flipped, corpus spot-check assertions flipped positive. +- [x] **Fallback deleted (2026-08-26, `overlay-promotion`):** Handshake request + 1 landed in `vlog_semantic`, so `indexed_type` — fence, qualifier guard + and all — is gone and `type_definition` is `nav::definition` of the type + name's offset, nothing more. Every test in the suite still passes; two + were renamed and one changed behavior (a `package` of the type's name is + now answered as `definition` answers it), each argued in that feature's + work log. - [x] One e2e round trip: the capability in the real handshake, a cross-file package typedef, and a built-in answered with an empty array. - [x] TODO.md §9c checkbox; `docs/features/lucisv-server/README.md` capability @@ -300,6 +323,40 @@ done here: node editors/vscode/smoke.js target/debug/lucisv-server`: `smoke: OK`. No `git commit`, no `git push`. +### 2026-08-26 — overlay-promotion dev agent (the Handshake landing) + +- **`indexed_type` deleted whole**, its qualifier guard and its kind filter + with it, and `type_definition` is now three lines: find the type name's + offset, ask `nav::definition`, return. `Resolution` and + `crate::locate::location` are no longer imported by this module at all — the + handler builds no `Location` of its own, which is the delegation-honesty + property QA checked by reading, now true by absence. +- **The whole suite is the acceptance suite and it still passes** — 45 tests, + none added, none removed. 41 are untouched; one had an expectation updated + (below). Three were renamed because they named the deleted function or a + fence that moved, and one of those three — + `a_package_of_the_same_name_is_not_a_type` — also changed behavior; it is now + `a_package_of_the_same_name_answers_exactly_as_definition_answers_it`, + asserting literal equality with `nav::definition` at the same offset. The + reason it changed: the shared overlay does not filter the unit table by kind, + and the private fallback did. Keeping the old answer would mean rebuilding + the fourth resolution layer this round exists to delete, and the input it + concerns (`thing t;` where the workspace's only `thing` is a package) does + not compile either way. +- `a_plain_expression_use_of_a_workspace_module_name_is_never_a_type_site` kept + its name and got stronger, though not the way the round first wrote it. The + first cut had it assert that `nav::definition` *does* answer that offset + while `type_definition` does not; QA showed the same promotion made `rename` + rewrite an unrelated file on the same coincidence, so the promotion was + narrowed to type positions and the read side went back with the write side. + The test now asserts the reference is `NotFound` and that **neither** + handler answers it — pinning two independent fences (the model never offers + the coincidence; no `Site` is built for an expression statement) instead of + one. +- Everything else about this feature — the offset redirection, `site_at`, the + one-hop rule, the conventions — is unchanged. Full rationale, consumer audit + and corpus measurement: `docs/features/overlay-promotion/README.md`. + ## QA log ### 2026-08-26 — QA agent (continuation of an interrupted run) diff --git a/docs/features/vlog-semantic/README.md b/docs/features/vlog-semantic/README.md index 651bea7..116b39b 100644 --- a/docs/features/vlog-semantic/README.md +++ b/docs/features/vlog-semantic/README.md @@ -45,7 +45,12 @@ struct Reference{ name, name_span, scope: ScopeId, resolution: Resolution } struct Scope { kind: ScopeKind, parent, owner: Option, span, symbols: Vec, children, imports: Vec } -enum Resolution { Resolved(SymbolId), ExternalCandidate { paths: Vec }, NotFound } +enum Resolution { + Resolved(SymbolId), + ExternalCandidate { paths: Vec }, + InheritedCandidate { base: String, paths: Vec }, // class-semantics + NotFound, +} ``` `SymbolKind` is the list the task named: `Module`, `Package`, `Port`, `Net`, @@ -89,7 +94,19 @@ Verilog requires at module scope — and as an editor needs mid-edit anywhere. 1. **Lexical chain.** From the scope the use is written in, outward through parents to the file scope. In each scope: names declared there first, then - the packages that scope imports, then on to the parent. + the packages that scope imports, then on to the parent. A miss on a name + written in a **type** position leaves carrying **the use's own name as its + last path**, after any import paths collected on the way out: an unqualified + type nothing here binds is how a file-scope `interface`, a package-less + `class` or a cross-file `typedef` is written, and the workspace's unit table + is the only layer that can say (`docs/features/overlay-promotion/README.md`, + 2026-08-26). A miss on an identifier in a **value** position gets no such + path — nothing about a bare expression name claims a file-scope declaration, + and a mere collision with a workspace unit name is not a reason to rewrite + another file. Inside a class with an `extends` either miss is an + `InheritedCandidate` (carrying the base, and the paths it collected); + everywhere else an `ExternalCandidate`, or `NotFound` when it has no path at + all. 2. **Ports and parameters are module-scope names**, so a module body sees them; a `function`/`task`/block scope sees them through its parents. 3. **Enum variants land in the scope holding the enum**, per the LRM — not @@ -112,7 +129,12 @@ Verilog requires at module scope — and as an editor needs mid-edit anywhere. external candidates and the tail carries the full path `p::x`. If `p` *is* in this file but has no member `x`, the tail is `Resolution::NotFound` — not an external candidate, because the package is fully known locally and - no workspace index could change the answer. (QA find, lead-documented.) + no workspace index could change the answer. (QA find, lead-documented.) A + qualified miss is **never** given the bare name rule 1 gives an unqualified + one: `x` names something inside `p`, and sweeping the unit table for a bare + `x` would discard the qualifier and answer a different question. The same + holds for the class spelling — `c::x` where `c` is an in-file class with an + `extends` is an `InheritedCandidate` with *no* paths at all. 7. **Instantiations.** The module name is a reference to a file-scope module, else an external candidate naming the module. A named connection's `.port` resolves **against that module's scope** — so `.data_i(x)` jumps to @@ -233,7 +255,9 @@ rules): Empty ranges never match `contains`, so a query never returns one. - Every `Reference` whose `Resolution` is `ExternalCandidate` carries the workspace-level paths that could finish it; the workspace index may rewrite - those references and nothing else. + those references and nothing else. An `InheritedCandidate` carries paths too + and may be *answered* by the index without being rewritten — its `base` is + this crate's answer and stays (`docs/features/overlay-promotion/README.md`). **Requested of `vlog_parser`** (not done here — out of scope for this feature, and the crate works without it): @@ -262,13 +286,37 @@ feature, and the crate works without it): `.v`/`.sv`/`.svh` files in `corpus/` (Ibex, OpenTitan, PULP common_cells, picorv32), 2026-08-19: -| population | files | symbols | references | resolved in-file | external candidates | unresolved | -|---|---:|---:|---:|---:|---:|---:| -| every file | 860 | 21 485 | 73 708 | 73.4 % | 19.4 % | 7.2 % | -| files that parse with zero errors | 502 | 12 900 | 46 408 | 79.5 % | 19.6 % | **0.9 %** | +| population | files | symbols | references | resolved in-file | external candidates | inherited candidates | unresolved | +|---|---:|---:|---:|---:|---:|---:|---:| +| every file | 860 | 21 485 | 73 708 | 73.4 % | 19.4 % | — | 7.2 % | +| files that parse with zero errors | 502 | 12 900 | 46 408 | 79.5 % | 19.6 % | — | **0.9 %** | -No panics, and every one of the 95 193 name spans built across the corpus -slices back to exactly the name it claims (0 unplaced). +**Re-measured 2026-08-26** (`overlay-promotion`), same command, same corpus. +The table above had gone stale by several rounds — class support and the +parser rounds since moved both the reference count and the clean-file +population — so the "before" row is a fresh measurement of `3bc61f9`, not a +quote: + +| population | files | symbols | references | resolved in-file | external candidates | inherited candidates | unresolved | +|---|---:|---:|---:|---:|---:|---:|---:| +| every file, before | 860 | 26 812 | 94 685 | 73.2 % | 17.1 % (16 152) | 8.3 % (7 841) | 1.5 % (1 418) | +| every file, after | 860 | 26 812 | 94 685 | 73.2 % | **17.2 % (16 314)** | 8.3 % (7 841) | **1.33 % (1 256)** | +| clean files, before | 853 | 26 752 | 94 384 | 73.3 % | 17.1 % (16 133) | 8.3 % (7 841) | 1.3 % (1 224) | +| clean files, after | 853 | 26 752 | 94 384 | 73.3 % | **17.3 % (16 286)** | 8.3 % (7 841) | **1.13 % (1 071)** | + +The promotion fires on **type positions only** — a name written where a type +goes, which is every use that reaches `bind_data_type`. An identifier in a +value position keeps the spelling it always had. The round first promoted both +and had to give the value half back: an unbound expression identifier that +happens to match a workspace unit name is a coincidence, and `rename` acted on +it across files (`docs/features/overlay-promotion/README.md`, QA finding 1 and +the fix round under it). So 162 references over all files (153 on clean files) +moved `NotFound` → `ExternalCandidate`, not the 1 418 the unrestricted version +moved. **`InheritedCandidate` is 7 841 in every one of the three states** — the +promotion never reclassified a reference, it only lengthened `paths`. + +No panics, and every name span built across the corpus slices back to exactly +the name it claims (0 unplaced), before and after. Reading the numbers honestly: @@ -277,16 +325,23 @@ Reading the numbers honestly: declared elsewhere; those references are *supposed* to leave this crate unfinished. The workspace index converts this bucket, and it is the single biggest lever on perceived LSP quality. -- **0.9 % genuinely unresolved on clean files** is the interesting number. A - sample of what is in it: names a `` `define`` would have produced (`XLEN`, - `ENABLE_IRQ`), class/UVM constructs in files that parse only because their - broken parts became error nodes (`this`, `super`, `null`, `new`), and - hierarchical/member tails reached through a path this crate stops at. -- **The 7.2 % over *all* files is dominated by the 42 % of corpus files that - still hit a parse error** (classes, `bind`, queues — README's "not yet - supported" list): a declaration swallowed by an error node cannot bind, so - every use of it counts unresolved. That number will move when the parser - moves, not when this crate does. +- **The unresolved bucket shrank by a re-spelling, not a discovery.** The + references that left it are the ones written in a *type* position with + nothing in the file or its imports to bind them: a cross-file `interface`, + a package-less `class`, a file-scope `typedef`. Those really could be held by + the workspace, so they now say so. Moving a reference between buckets answers + nothing by itself — what the workspace layer actually gained is **418 + references on clean files that now have somewhere to jump, and none that lost + one** (`docs/features/workspace-index/README.md` reports the composite). +- **What is left under `NotFound` is what belongs there**: names a `` `define`` + would have produced (`XLEN`, `ENABLE_IRQ`), a genvar used outside its loop, + hierarchical/member tails reached through a path this crate stops at, members + of a locally-declared package, and `this.x` with no base. These are value + positions, and a value position is never swept through the unit table — a + one-letter `i` must not find a `module i` in another file, least of all when + `rename` is the caller. +- Only 7 of 860 corpus files still fail to parse cleanly, which is why the two + populations now barely differ. The test asserts the two properties, not the percentages: zero unplaced names anywhere, and under 3 % unresolved on cleanly-parsed files. @@ -310,6 +365,9 @@ anywhere, and under 3 % unresolved on cleanly-parsed files. - [x] `Error` nodes are opaque; tolerant trees analyze without panicking - [x] Tests: 19 behavior tests + 6 scanner unit tests + corpus smoke test - [x] TODO.md §6 `vlog_semantic` checkbox +- [x] 2026-08-26 (`overlay-promotion`): an unqualified **type**-position miss + carries the bare name to the workspace layer, in both spellings + (`Target::Type`); a value-position miss keeps the spelling it had - [ ] Deferred to the workspace index: resolving `ExternalCandidate`s - [ ] Deferred: interfaces/modports — the parser does not accept them. Classes delivered 2026-08-19 by `class-semantics` @@ -318,6 +376,19 @@ anywhere, and under 3 % unresolved on cleanly-parsed files. ## Work log +**2026-08-26 — overlay-promotion dev agent (lead-authorized, cross-module).** +`bind.rs` gains `Target::Type`, emitted by `bind_data_type`'s unqualified arm +and nowhere else, so pass two can tell a type window from an expression. +`resolve.rs::lexical` pushes the use's own name onto the candidate paths for +that target only, so a type-position miss reaches the workspace layer in both +its spellings while a value-position miss stays exactly what it was; +`workspace.rs::resolve_external` answers an `InheritedCandidate` from those +paths when one lands. Strictly additive to what a reference *says*: no target, +span, symbol or variant was removed, and `InheritedCandidate.base` is +untouched, which is why no consumer needed a change. Full rationale, the +consumer audit, the QA-found value-position regression and the before/after +corpus measurement: `docs/features/overlay-promotion/README.md`. + **2026-08-24 — refactor-rename dev agent (lead-authorized, cross-module).** End labels are now references. `bind.rs` gains `Target::Declaration(SymbolId)` and `Binder::use_end_label`, called from the module, package, class, function, diff --git a/docs/features/workspace-index/README.md b/docs/features/workspace-index/README.md index 6bf3d02..4c2e26c 100644 --- a/docs/features/workspace-index/README.md +++ b/docs/features/workspace-index/README.md @@ -83,10 +83,14 @@ implicitly. `Semantics::definition_of` still works alone, for a server with no workspace open. -The overlay holds an entry **only** for references the in-file layer left as -`ExternalCandidate`; a locally-resolved reference is absent from it entirely, -which is also how a caller tells "resolved locally" from "not an external -candidate at all" without re-reading the `Resolution`. +The overlay holds an entry for every reference the in-file layer left as +`ExternalCandidate`, and — since 2026-08-26, +`docs/features/overlay-promotion/README.md` — for an `InheritedCandidate` +**when one of its paths actually lands**. A locally-resolved reference is +absent from it entirely, and so is an inherited candidate nothing answered: +the base class is the in-file layer's answer and this layer does not overrule +it, it only adds a location when the unit table has one. So an entry still +means "the workspace had something to say about this name". ## Resolution rules @@ -101,7 +105,12 @@ with any hit wins: `import p::x` that only offers itself for the name `x`; the use's name is what is looked up, so the two spellings need no separate handling.) 2. A bare path is the **unit itself** when the use spells the unit's name — an - instantiated module, the `p` head of `p::x`, the package of an import. + instantiated module, the `p` head of `p::x`, the package of an import, and + (since `overlay-promotion`) the last path of an unqualified miss written in + a **type** position, which is how a cross-file `interface` or package-less + `class` used as a type is answered. A miss in a value position never gets + such a path, so this layer is never asked to match a bare expression + identifier against a unit name. 3. A bare path whose name differs from the use's is a **member of that unit**: the `.port` (or `.PARAM` override) of a connection to a module declared in another file. @@ -113,11 +122,16 @@ written"). Ambiguity means something else — see below. ### What is indexed -- **Units** (`units(name)`): every file-scope `module`, `package` and - `typedef`. File-scope typedefs are indexed for `workspace_symbols` and for a - future include-aware lookup; nothing resolves to them today, because a use of - a type declared in another file with no import path is `NotFound`, not an - external candidate, and so never reaches this layer. +- **Units** (`units(name)`): every file-scope `module`, `package`, `typedef` + and `class`. ~~File-scope typedefs are indexed for `workspace_symbols` and + for a future include-aware lookup; nothing resolves to them today, because a + use of a type declared in another file with no import path is `NotFound`, + not an external candidate, and so never reaches this layer.~~ **Since + 2026-08-26 they do resolve**, from a type position: such a use is an external + (or inherited) candidate carrying the bare name, so a file-scope `typedef`, + `class` or `interface` in another file is reachable from the declaration that + names it as a type (`docs/features/overlay-promotion/README.md`). Only from a + type position — the same name in an expression is not offered here. - **Package members**: everything declared at a package's top level — params, typedefs, enum variants, functions, tasks, nets and vars. This is what makes `import p::*` and `p::x` reach *into* the package's file. @@ -273,6 +287,49 @@ unresolved-external rate over *all* references falls **19.6 % → 2.6 %**, and "Ambiguous" counts as answered: it is a list of real locations, which is what LSP's definition request takes. +**Re-measured 2026-08-26** (`overlay-promotion`), same command, same corpus. +The table above had gone stale by several rounds, so the before column is a +fresh measurement of `3bc61f9`. The index itself did not change: 860 files in +0.78 s, 561 modules, 63 packages, 22 file-scope typedefs, 258 classes, 11 937 +exported members, 507 define directives, before and after, determinism +assertions green. + +The middle column is the round's first cut, which promoted **every** +unqualified lexical miss; the last is what shipped, promoting only misses +written in a *type* position. QA found that the first cut let `rename` rewrite +an unrelated file's declaration when an unbound expression identifier happened +to match a workspace unit name, so the value half was given back +(`docs/features/overlay-promotion/README.md`). Both are shown because the +difference between them is the honest price of that fix. + +| metric (clean files, 853 of 860, 94 384 references) | before | promote everything | **type positions only (shipped)** | +|---|---:|---:|---:| +| handed to the workspace layer | 16 133 (17.1 %) | 17 877 (18.9 %) | **16 689 (17.7 %)** | +| …of which inherited candidates | 0 | 520 | **403** | +| answered | 89.3 % | 83.7 % | **88.8 %** | +| one target / ambiguous | 83.9 % / 5.3 % | 78.9 % / 4.8 % | **83.6 % / 5.2 %** | +| still unresolved (of those handed) | 10.7 % | 16.3 % | **11.2 %** | +| **references with nowhere to jump, both layers** | **10 794 (11.4 %)** | 10 235 (10.8 %) | **10 376 (11.0 %)** | + +All files: nowhere to jump 10 992 (11.6 %) → 10 431 (11.0 %) → **10 572 +(11.2 %)**. + +**What survived and what was given back.** Against the `3bc61f9` baseline, +**418 references on clean files gained somewhere to jump and none lost one** +(420 over all files). The first cut gained 559 on clean files (561 over all), +so **141 gains were given back** — identical on both populations. They split +117 inherited-candidate answers (520 → 403) and 24 external-bucket answers, and +every one of them was a value-position identifier answered on nothing but a +name collision. That is the trade, stated plainly: a quarter of the round's +jump targets were coincidences, and a coincidence that `rename` can act on is +worth less than nothing. + +**The answer rate moving is a denominator, not a result.** This layer is now +handed 556 more references than before (153 that were spelled `NotFound` and +never offered, 403 inherited candidates), and some of them are names no +workspace could hold. The number that cannot move by re-spelling is the last +row, which is why the `Tally` in `tests/workspace.rs` prints it. + **Where the ambiguity comes from** — all of it real, none of it a defect. The top shapes are OpenTitan's technology libraries: `prim_buf`, `prim_flop`, `prim_xor2` and their ports/params are declared once in @@ -291,6 +348,12 @@ the whole corpus. | `SB_SPRAM256KA` | 44 | an iCE40 vendor primitive — no source anywhere | | `PLLE2_ADV` | 32 | a Xilinx vendor primitive — likewise | +After the 2026-08-26 re-measurement the same list reads `sail_ibexspec` (168), +`ibex_pkg::* | uvm_pkg::*` (83, e.g. `id_stage_i`), `ibex_pkg::*` (71, e.g. +`main_mode`), `clk_rst_gen` (60) and `SB_SPRAM256KA` (44) — the `picorv32` +entries are gone, closed by the parser rounds since. Every remaining one is +still a workspace that genuinely does not contain the definition. + Over all files the list also shows `uvm_pkg::*` (220) and `uart_reg_pkg::*` (214) — a verification library and a generated register package, neither checked into the corpus. Every one of these is a workspace that genuinely does @@ -313,6 +376,9 @@ and more than half of all external candidates answered on clean files. - [x] Per-file `` `define`` tables + workspace-wide `find_define` - [x] `resolve_external` → `ExternalResolutions` overlay keyed by `ReferenceId`, `Semantics` untouched +- [x] 2026-08-26 (`overlay-promotion`): the overlay also answers an + `InheritedCandidate` from its paths, recording an entry only when one + lands; `Tally` reports references with nowhere to jump - [x] Composed `definition_of`, `workspace_symbols`, `members_of` - [x] Unit tests: cross-file instantiation, cross-file port, wildcard and explicit import, package member, enum variant, duplicate → `Ambiguous`, @@ -326,6 +392,17 @@ and more than half of all external candidates answered on clean files. ## Work log +**2026-08-26 — overlay-promotion dev agent (lead-authorized, cross-module).** +`resolve_external` gained one arm: an `InheritedCandidate`'s paths are tried +like an external candidate's, and an entry is recorded only when one lands, so +a name this layer cannot answer stays exactly what the single-file layer made +it. `counts()`'s doc says what it counts now. `tests/workspace.rs`'s `Tally` +reports references with nowhere to jump after both layers, because a +re-spelled miss moves between the other columns without anything getting +better or worse. Corpus tables above re-measured before, after the first cut, +and after the fix round that narrowed the promotion to type positions. +Rationale and the full audit: `docs/features/overlay-promotion/README.md`. + **2026-08-19 — dev agent.** Built `workspace.rs` and `tests/workspace.rs`. Key decisions, all argued above: