Files
lucioandClaude Fable 5.1 4d59e80568
ci / checks (push) Successful in 1m3s
ci / corpus (push) Successful in 33s
Type-name spans on the AST; vlog_semantic/src/scan.rs retired
TODO §47 (docs/features/type-name-spans). Closes topo §2.9-2.

`DataType` carries `name_start` (a `u32` in its existing padding, so
`Expr` stays at its 96-byte pin) and derives `name_span()` and
`segments()` — the `::`/`.` split from the span's own text, with a
leading escaped identifier read to its terminator first. Five parser
construction sites set it; an implicit type gets the empty range at the
position its name would have had. `StmtKind::Disable { name, name_span }`.
The binder walks `ty.segments()` and verifies every segment's range
against the source before recording it (`exact_or_empty`); a segment that
does not read back is recorded with the empty range, never dropped, so
the census's `unplaced` counter is the alarm a join regression would
move (review rework of QA's MEDIUM). `scan.rs` deleted; `bind_data_type`
lost its `window` and ten call sites their window arithmetic.

Census unchanged in every field (860 files, 27 486 symbols, 103 870
references, 1 197 unresolved, 0 unplaced); 0 of 860 corpus files differ;
200/200 opentitan definition/hover/typeDefinition answers identical.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-05 09:24:19 -05:00
..

Type-name spans

Goal

TODO.md §47 / docs/topo.md §2.9-2. vlog_semantic/src/scan.rs (193 lines) recovered the byte range of a name the AST kept only as a String by scanning the construct's own source text. Every declared name got a real name_span from the parser in the 2026-08-19 name-spans round; two uses did not, and they were the module's only remaining callers — the type name of a declaration (DataType::name, split as pkg::item or iface.modport) and disable <label>.

This round puts both spans on the AST, deletes scan.rs, and has the binder read what the parser already knew. A type reference is now located by construction rather than by a text search that is only right in practice, and the corpus census pin (src[name_span] == name) covers type-name references for the first time.

Assumptions

  • A name's span slices back to the name. DataType::name_span is derived as name_start .. name_start + name.len(), so it is exact for every name the source spells the way the parser joined it. Any whitespace or comment around a :: or . separator (pkg :: item, pkg /* c */ :: item, a name split across a line, bus_if . mp), an escaped segment terminated by a newline rather than a space, and spacing inside a dotted disable target spell the name differently from the AST's join (QA's census of the spellings, 2026-09-05). The binder therefore checks every segment's span against the source (Binder::exact_or_empty) before it records a reference, which is the rule the modport tail has always followed: such a segment is recorded with the empty range at its start — never a wrong non-empty range, and never dropped, because an empty range is what the corpus census counts as unplaced, so a parser regression in the join trips that alarm (lead's rework of QA's MEDIUM). scan.rs failed the same cases (its find matches whole words, so it never found \a+b with its trailing space either), so this is parity, not a new gap.
  • The token text of a plain identifier is its source text. Pinned by the lexer (src[span] == text, an_escaped_identifier_ends_before_its_terminating_whitespace). Everything above rests on it.
  • DataType::name_start is only ever written by the parser. It is pub(crate) in vlog_parser; no other crate builds a DataType (grep: the only DataType { … } literals in the workspace are the two in vlog_parser/src/parser/).
  • opentitan is read-only. The before/after sweep used the server's scratch index store (docs/performance_take3.md §9) and git -C ~/repo/opentitan status --porcelain reported only the three pre-existing modified files before and after.

Handshakes

Consumed from vlog_parser:

  • DataType::name_span() -> TextRange — where the type name is written, the empty range at the would-be position when the type is implicit.
  • DataType::segments() -> impl Iterator<Item = (&str, TextRange)> — the ::/.-separated segments with their ranges, derived from name_span and the name's own text. Never rescans the construct.
  • StmtKind::Disable { name, name_span } — was Disable(String).

Promised to vlog_semantic's callers: analyze(file, src) keeps its src parameter. It is no longer used to find names — nothing in the crate scans source text any more — but it is still read by Binder::exact_or_empty, the "verify before recording" oracle used by eleven call sites (instance module names, class extends heads and tails, member tails, end labels, the type-name segments and the disable target). Removing it would remove that check, which is the opposite of what §47 is for. The vlog-semantic README's handshake item 2 ("a span for DataType") is delivered; the src half of item 1's promise ("this parameter goes away") is amended to "src stops being a scanner and becomes a verifier".

Not changed, and why: lucisv_server/src/type_def.rs still finds a type site by a window (site(&ty.name, TextRange::new(span.start, first))) rather than by DataType::name_span(). That is a textDocument/typeDefinition concern in another crate and outside §47's file set; it is a clean follow-up now that the span exists. Filed here rather than edited.

Status / TODO

  • 47.1 DataType::name_span at every construction site + segments(); size ruled (below)
  • 47.2 StmtKind::Disable name span
  • 47.3 scan.rs deleted, its mod removed, binder reads the spans, census pin now covers type-name references
  • Consumers: nav/hover already go through Reference::name_span (confirmed: nav.rs reads only symbol.name_span / reference.name_span); two definition tests added
  • Gates (guarded)

The size ruling

DataType rides in every Expr through ExprKind::Type, and size_pins holds Expr <= 96. Measured with a throwaway probe test on v0.44.0:

DataType ExprKind Expr StmtKind Stmt
before 88 88 96 392 552
pub name_span: TextRange 96 96 104 416 576
pub(crate) name_start: u32 88 88 96 392 552

A whole TextRange breaks the pin — and StmtKind/Stmt's pins with it. DataType's eight-byte-aligned fields total 80 bytes and virt is one more, so the struct already carries seven bytes of padding: a u32 fits in it for free, an eight-byte span does not.

So the span is stored as its start and paired with name.len() by DataType::name_span(). The plan offered two fallbacks — move the span into the already-boxed TypeExtra, or box it — and this is a third that is better than both: they would put a heap allocation on every DataType, because name_span is wanted for the implicit case too (the empty range at the would-be position), and an implicit type is the common one. The pin did not move. name_start is pub(crate), so the invariant end == start + len has exactly one writer, the parser.

Construction sites

Five, all in vlog_parser/src/parser/:

  1. parse_opt_data_type's sequence/property SVA-formal arm — the keyword token's start.
  2. parse_opt_data_type's virtual bus_if.mp arm — delegates to (5).
  3. parse_opt_data_type's type-keyword arm (logic, int, …) — the keyword token's start.
  4. parse_opt_data_type's user-type arm — now calls the existing parse_scoped_name, which already returned the joined text plus the whole chain's range, so the :: loop is no longer written twice. parse_type_ref (a bare my_type_t where a type is required) calls the same helper for the same reason.
  5. parse_modport_port_type — the head identifier's start.

The implicit case is spanned by Parser::implicit_type(): a DataType whose name_start is self.here(), the cursor before any of the type has been consumed. parse_opt_data_type starts from it, so an input [7:0] x whose type is nothing at all reports the empty range at the [; so does the parameter type T placeholder in parse_param_decl and in the parameter-port list, which write no data type at all. This is the convention name_span already used for an unnamed DPI formal.

Docs to apply at merge (lead)

Three places in docs/topo.md:

  • §2.9 row 2 (line ~618) — struck. Suggested replacement row:

    | 2 | A span for DataType (and ExprKind::Cast::ty tails) — the last thing keeping vlog_semantic/src/scan.rs alive — delivered 2026-09-05 by type-name-spans (TODO §47): DataType::name_span() (stored as a u32 start paired with name.len(), so Expr stays inside its 96-byte pin) and DataType::segments() (the ::/. split, derived from the span's own text); StmtKind::Disable carries its target's span too. scan.rs is deleted — nothing in vlog_semantic scans source text for a name any more. analyze's src parameter stays, no longer as a scanner but as Binder::exact_or_empty's verification oracle. The corpus census pin now covers type-name references. | vlog-semantic (item 2); restated by class-semantics | vlog_parser done |

  • §1.3's vlog_semantic layout paragraph (line ~201) — drop the `scan.rs` (residual text-scanning for the one span the parser doesn't carry — `DataType`; shrinks to zero when open handshake §2.9-2 lands); clause outright; the file is gone.

  • §1.2's name-spans ◀──▶ vlog-semantic row (line ~449) — the tail "shrinking scan.rs to the DataType case (still open — §2.9)" becomes "…; type-name-spans (§47) delivered the DataType case and deleted scan.rs".

  • crates/vlog_semantic/README.md does not exist (the crate has no top-level README; docs/features/vlog-semantic/README.md is the one the §47 brief means). Its Handshakes/Deviations text was edited in place by this lane — see the work log.

Work log

2026-09-05 — dev agent.

  • Measured the sizes first (throwaway tests/zz_size_probe.rs, deleted), which ruled out the plain TextRange field before a line of it was written. See "The size ruling".
  • DataType gained pub(crate) name_start: u32, pub fn name_span() and pub fn segments(), plus a free separator() that finds the first ::/. that is not inside a leading escaped identifier. segments() yields nothing for an implicit type.
  • Five parser construction sites set the start; parse_scoped_name is now reused by the two that had open-coded its :: loop, which is a small de-duplication that fell out of needing the range.
  • StmtKind::Disable(String) became Disable { name, name_span }. The fork form spans the fork keyword; the dotted form spans the whole a.b chain. Formatter (format/stmt.rs) and linter (rules/disable_statement.rs) match arms updated; neither reads the span, so no output moves.
  • Binder::bind_data_type lost its window parameter and gained bind_type_name, which walks ty.segments() and records the head as a Target::Unit (::) or Target::Type (. or bare) and each following segment as a member of the one before it. The old code split once and bound two halves; a three-segment a::b::c used to bind a plus a b::c that no scan could ever locate, and now binds all three.
  • Every span is passed through exact_or_empty; a segment that does not verify was, in the dev's version, the end of the chain (the reference dropped). Changed at review: every segment is recorded, a failing one with the empty range, so the census's unplaced counter — not a quieter resolution rate — is what a future join regression would move. Corpus-neutral (unplaced was and is 0; no corpus file spells a type name with spaces around its separators).
  • Dropping window removed the window computations at ten call sites, and with them the now-unused span parameters of bind_data_decl, bind_declarators and bind_enum_body.
  • crates/vlog_semantic/src/scan.rs deleted along with mod scan;. Its six unit tests went with it (they tested the scanner, not a behaviour).
  • Tests added: four in vlog_parser/tests/spans.rs (a type name slices back to the name as written across all five sites; segments() splits pkg::state_t and bus_if.mp and yields nothing for an implicit type; an escaped segment keeps its terminating space in both the span and the first segment; a disable's target has a span). The generic statement walker in spans.rs now checks Disable's span instead of skipping the arm. Two in lucisv_server/src/nav.rs: F12 on the item half of pkg::t and on both halves of bus_if.mp.

Gates (all through tools/guard.sh; no guard kill)

gate result
cargo fmt -p vlog_parser -p vlog_semantic -p vlog_formatter -p vlog_linter -p lucisv_server clean
cargo clippy --all-targets clean, no new #[allow]
cargo test --workspace 3 814 passed, 0 failed, 44 ignored — the 0.44.0 baseline exactly: six scan.rs unit tests left, six new ones arrived
tools/corpus_check.sh corpus 814/820 (99.3%), the same six parse errors; the per-file TSV is byte-identical to the committed corpus-check-results.tsv
formatter byte-identity format --stdout of all 860 corpus files, new vs ~/.cache/lucisv-baselines/lucisv-0.44.0: 0 differ
cargo build --release -p lucisv_server + smoke OK — F12 on pkg::t's head and item, on bus_if.mp's head and modport, and on a disable's target all answer the right ranges; hover and documentSymbol answer
semantic corpus census 860 files, 27 486 symbols, 103 870 references, 1 197 unresolved, 0 unplaced — byte-identical to the same test run in a v0.44.0 scratch worktree
opentitan definition sweep 200 type-name positions over 74 files (50 scoped heads, 36 scoped items, 105 bare _t/_e types, 9 virtual …_if), 0.44.0 server vs the new one: 200/200 identical, 180 of them non-empty answers. opentitan status --porcelain reported only the three pre-existing modified files after

The 0.44.0 baseline binary was built in a scratch git worktree at the tag (~/.cache/lucisv-baselines/lucisv-0.44.0, sha256 4d928238…, kept for the next round); the worktree was removed afterwards. Sweep scripts: <scratchpad>/defcmp/{lspclient,positions,run}.py.

Census: before and after

The plan asked for the new count. The corpus test's numbers are unchanged in every field — 27 486 / 103 870 / 1 197 / 0 unplaced on both sides — which is the strongest form of the answer: type-name references were already counted, they were merely located by a scan, and the parser's spans put them in exactly the same places. (The 21 485 the §47 brief quotes is the 2026-08-19 figure; the corpus and the crate have both grown a great deal since, and the vlog-semantic README's copy of it has been refreshed to today's numbers.)

QA log

2026-09-05 — QA agent.

Verdict: PASS. No hard-invariant violation, no mislocation, no formatter-output change, no corpus regression. One MEDIUM documentation/ observability finding below; recommend fixing at the lead's discretion (does not block merge).

What was verified, and how

  1. Attack battery on bind_type_name/exact_or_empty (never mislocate). Built a scratch integration test (crates/vlog_semantic/tests/zz_qa_type_name_spans.rs, removed before finishing) exercising analyze() over: plain pkg::item, spaced pkg :: item, a /* c */-interrupted pkg :: item, pkg:: / item split across a line, \my-pkg ::\state-t (escaped both sides, space terminator), \my-pkg\n::item (escaped, newline terminator), an escaped segment whose own text contains :: (\a::b ::c), bus_if.mp, bus_if . mp (spaced), virtual bus_if.mp, virtual interface bus_if with no modport, pkg::t used bare (parameterized-type source next to a typedef target lacking params — the plain scoped case), an inline enum, an inline struct, three implicit-type shapes (input [7:0] x, parameter type T, wire w), a class-scoped cls::t, a cast int'(x), a scoped cast pkg::t'(x), and five disable shapes (fork, a plain label, a dotted a.b.c, an escaped label, and a spaced dotted a . b . c).

    For every reference analyze() recorded across this whole battery, src[name_span] == name held, or the span was empty — zero non-empty-but-wrong spans ("MISMATCH") anywhere. The hard property the round is built on holds under adversarial input.

    Fallback / dropped-reference count — spellings where a reference either fell back to empty or was not recorded at all:

    • \my-pkg\n::item (escaped, newline-terminated) — 0 references recorded (both segments; documented in Assumptions as a known disagreement).
    • pkg :: item (spaced) — item not recorded (only pkg is; the early-return in bind_type_name stops at the first segment whose derived span fails exact_or_empty, so everything after it, correct or not, is silently dropped rather than recorded empty).
    • pkg /* c */ :: item (comment-interrupted) — same as above, item dropped.
    • pkg:: / item split across a line — same, item dropped.
    • disable a . b . c (spaced dotted) — 0 references recorded (the whole chain, since exact_or_empty checks the joined a.b.c against the real, spaced span as one unit).
    • disable fork recorded 0 references, but this is pre-existing, unrelated behavior: Binder::use_member filters is_keyword(name) and fork is a keyword; confirmed by reading bind/mod.rs:296-297 and by the fact the 0.44.0 baseline drops it identically (see below).

    No other spelling in the battery fell back to empty or was dropped — in particular, both escaped-with-space-terminator (\my-pkg ::\state-t) and plain dotted disable a.b.c located exactly, which is new (see next point).

  2. 0.44.0 baseline comparison (built in a git worktree at v0.44.0, removed after). Ran the identical battery through the old scan.rs-based binder to see what changed, not just what the README claims:

    • Improvements over 0.44.0 (old code got these wrong, new code gets them right): \my-pkg ::\state-t (old: both halves empty — the scanner's whole-word matcher never includes the escaped segment's trailing space, so it could never match push_scope_segment's own join; new: both exact). Plain disable a.b.c (old: empty — NameScanner::find only ever returns single-token words, so a dotted name can never match as one word; new: exact). These are real, verified accuracy wins from moving off text-scanning.
    • A narrower regression, corpus-neutral in practice: for pkg :: item, pkg /* c */ :: item, and pkg::/item split across a line, the 0.44.0 scanner found both pkg and item at their correct positions (whole-word search tokenizes past whitespace and comments, skipping them — see scan.rs's next_word), while the new code drops item entirely once its derived offset (computed from the tightly-joined name string, which does not reflect arbitrary inter-segment whitespace/comments) no longer covers real source bytes. This never mislocates — item is simply absent from s.references() rather than present with a wrong span — but it is a real loss of find-and-locate capability for these three SV-legal (if unusual) spellings, and the old code additionally always recorded some Reference (even an empty-span one) where the new code, for the type-name path specifically, now sometimes records nothing at all.
    • The disable/type-name modport-tail shapes (bus_if.mp, bus_if . mp spaced) are byte-for-byte identical old vs new, confirming the modport tail's own pre-existing "skip if empty" convention was carried over unchanged, as the work log claims.

    Finding (MEDIUM, doc/observability, not a correctness bug): the README's Assumptions section names only two "joins that can disagree" (an escaped segment's space, and the modport .). Empirically, any whitespace or comment between ::-separated segments, and any spacing in a dotted disable target, also disagrees and silently drops the affected reference — and, specific to the binder's new early-return in bind_type_name (crates/vlog_semantic/src/bind/decl.rs), a segment past the first divergence is not merely mislocated-and-caught but never recorded as a Reference at all (0.44.0 always recorded one, with an empty span, via NameScanner's always-recording callers). This means a future regression in the parser's own joining logic for these constructs would no longer surface as unplaced > 0 in the corpus census (crates/vlog_semantic/tests/corpus.rs's covers() only counts spans that exist; a dropped reference contributes nothing) — it would have to be caught by resolution-rate drift instead, which is a weaker signal. Recommend the Assumptions section name the fuller set of disagreeing spellings (whitespace/comments around any ::/., not only the escaped-segment case), and/or that bind_type_name record a trailing empty-span reference on early return the way the pre-round code did, so the census keeps its loud-failure property. Not a merge blocker: corpus-neutral (verified below), never mislocates, and the disable/type-name-with-whitespace spellings are rare in real RTL.

  3. Census pin. tools/guard.sh -- cargo test -p vlog_semantic --test corpus -- --nocapture: 860 files, 27 486 symbols, 103 870 references, 1 197 unresolved (1.15%), 0 unplaced — matches the README's claim exactly (re-derived independently, not read off the README). Confirmed covers() (tests/corpus.rs:69-80) asserts src[span] == name for every non-empty-span reference and symbol uniformly (not type-references-only, but type references are now part of that population for the first time, per the round's stated purpose) and that an empty span is counted as "unplaced" rather than exempted — so the 0-unplaced result is a real assertion, not a vacuous one, over the actual corpus.

  4. disable spans + formatter/linter round-trip. Confirmed via the parser's own new tests (a_disable_names_its_target_with_a_span, spans.rs) and independently via lucisv format --stdout / lucisv check on a hand-written fork/label/dotted-label file: output is idempotent (format(format(x)) == format(x)) and byte-identical to the lucisv-0.44.0 baseline binary, and lucisv check's disable-statement diagnostic is identical old vs new. Confirms the formatter/linter genuinely ignore the new span (as the work log claims) — output moved nowhere.

  5. Size pins. tools/guard.sh -- cargo test -p vlog_parser --lib size_pins: expr_stmt_and_stmt_kind_stay_within_their_pinned_sizes passes (Expr <= 96, StmtKind <= 392, Stmt <= 552), confirming the name_start: u32 design keeps every pin where §36's protocol left it.

  6. Server: definition/hover/typeDefinition/rename, in-tree and over opentitan.

    • cargo test -p lucisv_server: the dev's two new nav.rs tests pass (a_scoped_type_name_jumps_from_its_item_half, an_interface_port_type_jumps_from_its_head), as part of the full 3 814-test run below.
    • Added a temporary #[test] in crates/lucisv_server/src/rename.rs (removed before finishing; git diff on that file is empty now) that renames a package typedef t used as pkg::t from three files. Result: all three files edited, each edit's range slicing to exactly t (verified by slicing the edit's own TextEdit.range out of the source line) — never pkg::t, confirming attack item 4's rename requirement directly rather than by inspection.
    • lucisv_server/src/type_def.rs is untouched by this round (confirmed by git diff --stat) and still locates a type site by its own from-scratch window/site() walk, independent of DataType::name_span/segments() — exactly what the Handshakes section says. Verified it still answers correctly (see next point), so the "clean follow-up, not a regression" framing holds.
    • Opentitan sweep, independently re-derived (attack item 5): wrote a second position-picker (<scratchpad>/defcmp/qa_positions.py) targeting a disjoint set of directories from the dev's own script (hw/ip/otp_ctrl/rtl, hw/ip/flash_ctrl/rtl, hw/ip/i2c/rtl, hw/ip/rv_dm/rtl, hw/ip/spi_host/rtl, hw/dv/sv/tl_agent, hw/dv/sv/csr_utils — the dev used aes/hmac/spi_device/uart/ uart_agent/cip_lib/dv_lib), picking 200 positions over 43 files. Built the 0.44.0 lucisv-server in the same v0.44.0 worktree used for the binder comparison, and ran both textDocument/definition, textDocument/hover, and textDocument/typeDefinition over all 200 positions with both servers (<scratchpad>/defcmp/run.py, run_hover_typedef.py — the latter is a QA-added twin of the dev's run.py adding hover/ typeDefinition, since the original only asked definition). Results: definition 200/200 identical (149 non-empty), hover 200/200 identical (149 non-empty), typeDefinition 200/200 identical (63 non-empty). git -C ~/repo/opentitan status --porcelain reported only the three pre-existing modified files after every run (before, during, and after — checked three times).

Gates re-run independently (all guarded, all matched the dev's numbers)

gate result
cargo clippy --all-targets clean (fully cached; 0 warnings/errors)
tools/guard.sh -- cargo test --workspace 3 814 passed (3 815 with my scratch test counted, subtracted), 0 failed, 44 ignored — exact match
tools/guard.sh -- tools/corpus_check.sh corpus 814/820 (99.3%), same six parse errors, 0 verification errors, 0 crashes; git diff --stat -- corpus-check-results.tsv empty (byte-identical)
formatter byte-identity wrote an independent diff script; lucisv format --stdout on all 860 corpus files vs ~/.cache/lucisv-baselines/lucisv-0.44.0: 0 differ
census 860 files / 27 486 symbols / 103 870 references / 1 197 unresolved / 0 unplaced — re-derived, not copied
opentitan definition/hover/typeDefinition sweep 200/200/200 identical old vs new on an independently-chosen position set; opentitan status --porcelain clean (only the three pre-existing files) throughout

No guard kill anywhere.

Cleanup

Removed: crates/vlog_semantic/tests/zz_qa_type_name_spans.rs (scratch test), the temporary #[test] in crates/lucisv_server/src/rename.rs (confirmed git diff on that file is now empty), the v0.44.0 scratch git worktree (git worktree remove, confirmed gone from git worktree list), and both scratch server storage directories. Left in the scratchpad (not the repo) for the lead's reference: <scratchpad>/defcmp/qa_positions.py, qa_positions.json, qa_old.json/qa_new.json (definition), qa_old_ht.json/qa_new_ht.json (hover/typeDefinition), run_hover_typedef.py, byte_identity_check.sh.

Review

Review

2026-09-05 — lead. Accepted with one rework; ships in 0.45.0 with §48 and §49. The size ruling is the right one: a u32 start in the padding DataType already had keeps Expr at 96 with no allocation on the common implicit case, and the derived end is verified against the source before any reference is recorded, so the "never mislocate" invariant held under QA's whole battery. QA's MEDIUM was fair — a dropped reference silences the census alarm the pin exists for — and is fixed by recording the empty-range placeholder instead of returning early; the README's list of disagreeing spellings is now the full one QA found. Two shapes the old scanner always failed (an escaped segment with a space terminator, a dotted disable target) are now exact. Census unchanged in every field, 0 of 860 corpus files differ, 200/200 opentitan answers identical for definition, hover and typeDefinition. The type_def.rs window lookup is filed as a follow-up in Handshakes, not a regression.