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]>
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_spanis derived asname_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 dotteddisabletarget 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.rsfailed the same cases (itsfindmatches whole words, so it never found\a+bwith 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_startis only ever written by the parser. It ispub(crate)invlog_parser; no other crate builds aDataType(grep: the onlyDataType { … }literals in the workspace are the two invlog_parser/src/parser/).- opentitan is read-only. The before/after sweep used the server's scratch
index store (
docs/performance_take3.md§9) andgit -C ~/repo/opentitan status --porcelainreported 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 fromname_spanand the name's own text. Never rescans the construct.StmtKind::Disable { name, name_span }— wasDisable(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_spanat every construction site +segments(); size ruled (below) - 47.2
StmtKind::Disablename span - 47.3
scan.rsdeleted, itsmodremoved, binder reads the spans, census pin now covers type-name references - Consumers:
nav/hoveralready go throughReference::name_span(confirmed:nav.rsreads onlysymbol.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/:
parse_opt_data_type'ssequence/propertySVA-formal arm — the keyword token's start.parse_opt_data_type'svirtual bus_if.mparm — delegates to (5).parse_opt_data_type's type-keyword arm (logic,int, …) — the keyword token's start.parse_opt_data_type's user-type arm — now calls the existingparse_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 baremy_type_twhere a type is required) calls the same helper for the same reason.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— delivered 2026-09-05 by type-name-spans (TODO §47):DataType(andExprKind::Cast::tytails) — the last thing keepingvlog_semantic/src/scan.rsaliveDataType::name_span()(stored as au32start paired withname.len(), soExprstays inside its 96-byte pin) andDataType::segments()(the::/.split, derived from the span's own text);StmtKind::Disablecarries its target's span too.scan.rsis deleted — nothing invlog_semanticscans source text for a name any more.analyze'ssrcparameter stays, no longer as a scanner but asBinder::exact_or_empty's verification oracle. The corpus census pin now covers type-name references. | vlog-semantic (item 2); restated by class-semantics |vlog_parserdone | -
§1.3's
vlog_semanticlayout 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-semanticrow (line ~449) — the tail "shrinkingscan.rsto theDataTypecase (still open — §2.9)" becomes "…; type-name-spans (§47) delivered theDataTypecase and deletedscan.rs". -
crates/vlog_semantic/README.mddoes not exist (the crate has no top-level README;docs/features/vlog-semantic/README.mdis 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 plainTextRangefield before a line of it was written. See "The size ruling". DataTypegainedpub(crate) name_start: u32,pub fn name_span()andpub fn segments(), plus a freeseparator()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_nameis 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)becameDisable { name, name_span }. Theforkform spans theforkkeyword; the dotted form spans the wholea.bchain. Formatter (format/stmt.rs) and linter (rules/disable_statement.rs) match arms updated; neither reads the span, so no output moves.Binder::bind_data_typelost itswindowparameter and gainedbind_type_name, which walksty.segments()and records the head as aTarget::Unit(::) orTarget::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-segmenta::b::cused to bindaplus ab::cthat 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'sunplacedcounter — not a quieter resolution rate — is what a future join regression would move. Corpus-neutral (unplacedwas and is 0; no corpus file spells a type name with spaces around its separators). - Dropping
windowremoved the window computations at ten call sites, and with them the now-unusedspanparameters ofbind_data_decl,bind_declaratorsandbind_enum_body. crates/vlog_semantic/src/scan.rsdeleted along withmod 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()splitspkg::state_tandbus_if.mpand yields nothing for an implicit type; an escaped segment keeps its terminating space in both the span and the first segment; adisable's target has a span). The generic statement walker inspans.rsnow checksDisable's span instead of skipping the arm. Two inlucisv_server/src/nav.rs: F12 on the item half ofpkg::tand on both halves ofbus_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
-
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) exercisinganalyze()over: plainpkg::item, spacedpkg :: item, a/* c */-interruptedpkg :: item,pkg::/itemsplit 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_ifwith no modport,pkg::tused bare (parameterized-type source next to a typedef target lacking params — the plain scoped case), an inlineenum, an inlinestruct, three implicit-type shapes (input [7:0] x,parameter type T,wire w), a class-scopedcls::t, a castint'(x), a scoped castpkg::t'(x), and fivedisableshapes (fork, a plain label, a dotteda.b.c, an escaped label, and a spaced dotteda . b . c).For every reference
analyze()recorded across this whole battery,src[name_span] == nameheld, 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) —itemnot recorded (onlypkgis; the early-return inbind_type_namestops at the first segment whose derived span failsexact_or_empty, so everything after it, correct or not, is silently dropped rather than recorded empty).pkg /* c */ :: item(comment-interrupted) — same as above,itemdropped.pkg::/itemsplit across a line — same,itemdropped.disable a . b . c(spaced dotted) — 0 references recorded (the whole chain, sinceexact_or_emptychecks the joineda.b.cagainst the real, spaced span as one unit).disable forkrecorded 0 references, but this is pre-existing, unrelated behavior:Binder::use_memberfiltersis_keyword(name)andforkis a keyword; confirmed by readingbind/mod.rs:296-297and 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 dotteddisable a.b.clocated exactly, which is new (see next point). -
0.44.0 baseline comparison (built in a
git worktreeatv0.44.0, removed after). Ran the identical battery through the oldscan.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 matchpush_scope_segment's own join; new: both exact). Plaindisable a.b.c(old: empty —NameScanner::findonly 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, andpkg::/itemsplit across a line, the 0.44.0 scanner found bothpkganditemat their correct positions (whole-word search tokenizes past whitespace and comments, skipping them — seescan.rs'snext_word), while the new code dropsitementirely once its derived offset (computed from the tightly-joinednamestring, which does not reflect arbitrary inter-segment whitespace/comments) no longer covers real source bytes. This never mislocates —itemis simply absent froms.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 someReference(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 . mpspaced) 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 dotteddisabletarget, also disagrees and silently drops the affected reference — and, specific to the binder's new early-return inbind_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 aReferenceat all (0.44.0 always recorded one, with an empty span, viaNameScanner's always-recording callers). This means a future regression in the parser's own joining logic for these constructs would no longer surface asunplaced > 0in the corpus census (crates/vlog_semantic/tests/corpus.rs'scovers()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 thatbind_type_namerecord 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 thedisable/type-name-with-whitespace spellings are rare in real RTL. - Improvements over 0.44.0 (old code got these wrong, new code gets
them right):
-
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). Confirmedcovers()(tests/corpus.rs:69-80) assertssrc[span] == namefor 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. -
disablespans + formatter/linter round-trip. Confirmed via the parser's own new tests (a_disable_names_its_target_with_a_span,spans.rs) and independently vialucisv format --stdout/lucisv checkon a hand-writtenfork/label/dotted-label file: output is idempotent (format(format(x)) == format(x)) and byte-identical to thelucisv-0.44.0baseline binary, andlucisv check'sdisable-statementdiagnostic is identical old vs new. Confirms the formatter/linter genuinely ignore the new span (as the work log claims) — output moved nowhere. -
Size pins.
tools/guard.sh -- cargo test -p vlog_parser --lib size_pins:expr_stmt_and_stmt_kind_stay_within_their_pinned_sizespasses (Expr <= 96,StmtKind <= 392,Stmt <= 552), confirming thename_start: u32design keeps every pin where §36's protocol left it. -
Server: definition/hover/typeDefinition/rename, in-tree and over opentitan.
cargo test -p lucisv_server: the dev's two newnav.rstests 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]incrates/lucisv_server/src/rename.rs(removed before finishing;git diffon that file is empty now) that renames a package typedeftused aspkg::tfrom three files. Result: all three files edited, each edit's range slicing to exactlyt(verified by slicing the edit's ownTextEdit.rangeout of the source line) — neverpkg::t, confirming attack item 4's rename requirement directly rather than by inspection. lucisv_server/src/type_def.rsis untouched by this round (confirmed bygit diff --stat) and still locates a type site by its own from-scratch window/site()walk, independent ofDataType::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 usedaes/hmac/spi_device/uart/uart_agent/cip_lib/dv_lib), picking 200 positions over 43 files. Built the 0.44.0lucisv-serverin the samev0.44.0worktree used for the binder comparison, and ran bothtextDocument/definition,textDocument/hover, andtextDocument/typeDefinitionover all 200 positions with both servers (<scratchpad>/defcmp/run.py,run_hover_typedef.py— the latter is a QA-added twin of the dev'srun.pyadding hover/ typeDefinition, since the original only askeddefinition). 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 --porcelainreported 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.