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]>
This commit is contained in:
1 parent
859742ac84
commit
4d59e80568
20 files changed
+855
-335
No files matched your search
@@ -0,0 +1,453 @@
|
||||
# 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
|
||||
|
||||
- [x] 47.1 `DataType::name_span` at every construction site + `segments()`;
|
||||
size ruled (below)
|
||||
- [x] 47.2 `StmtKind::Disable` name span
|
||||
- [x] 47.3 `scan.rs` deleted, its `mod` removed, binder reads the spans,
|
||||
census pin now covers type-name references
|
||||
- [x] Consumers: `nav`/`hover` already go through `Reference::name_span`
|
||||
(confirmed: `nav.rs` reads only `symbol.name_span` / `reference.name_span`);
|
||||
two definition tests added
|
||||
- [x] 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.
|
||||
@@ -62,16 +62,23 @@ enum Resolution {
|
||||
|
||||
### Deviations from the sketch in the task, and why
|
||||
|
||||
- **`analyze` takes `src` as well as the tree.** Most declarations in the AST
|
||||
keep their name as a plain `String` and carry a span only for the whole
|
||||
construct, so the *name's* range — the thing an editor highlights — is not
|
||||
recoverable from the tree alone. `scan.rs` finds it by scanning the
|
||||
construct's own source bytes (comments, strings and macro invocations
|
||||
skipped) inside a window narrowed by the sub-spans that *do* exist. The
|
||||
corpus test asserts `src[name_span] == name` for all 21 485 symbols and
|
||||
73 708 references it builds, so the scan is not a guess in practice. A
|
||||
Handshake request to put `name_span` on the AST is filed below; when it
|
||||
lands, `scan.rs` and this parameter go away.
|
||||
- **`analyze` takes `src` as well as the tree.** Originally because most
|
||||
declarations kept their name as a plain `String` inside a construct-wide
|
||||
span, so the *name's* range — the thing an editor highlights — was not
|
||||
recoverable from the tree at all; `scan.rs` found it by scanning the
|
||||
construct's own source bytes inside a window narrowed by the sub-spans that
|
||||
did exist. **Both halves of that are gone**: `name-spans` (2026-08-19) put
|
||||
`name_span` on every declaring node, `type-name-spans` (2026-09-05, TODO
|
||||
§47) put `DataType::name_span()`/`segments()` and `StmtKind::Disable`'s span
|
||||
on the last two, and `scan.rs` is deleted. `src` stays, in a different
|
||||
role: `Binder::exact_or_empty` checks a derived span against the source
|
||||
before a reference is recorded, so a name the source spells differently from
|
||||
the way the parser joined it (`bus_if . mp` written apart, an escaped
|
||||
segment terminated by a newline) costs the reference rather than
|
||||
mislocating it. Eleven call sites rely on that oracle. The corpus test still
|
||||
asserts `src[name_span] == name` for every symbol and reference it builds —
|
||||
27 486 and 103 870 as of 2026-09-05, type-name references now among them,
|
||||
0 unplaced.
|
||||
- **`Reference.resolution: Resolution` instead of `resolved:
|
||||
Option<SymbolId>`.** The task asked for both an `Option<SymbolId>` and an
|
||||
`ExternalCandidate` state carrying the import path; one enum says that once.
|
||||
@@ -280,15 +287,21 @@ region | generate block | for-generate header | for/foreach statement`.
|
||||
- `src` passed to `analyze` is the exact text the tree was parsed from. Spans
|
||||
index into it; a mismatched string yields wrong name spans, not a panic
|
||||
(every slice is bounds-checked and clamped).
|
||||
- A construct's keyword is written before its name (`module m`, `function
|
||||
- ~~A construct's keyword is written before its name (`module m`, `function
|
||||
automatic int f`), and the name is a plain identifier. Where a type name and
|
||||
the declared name are the same token text (`function foo_t foo_t;`) the scan
|
||||
can pick the first of the two; nothing in the corpus does this.
|
||||
can pick the first of the two; nothing in the corpus does this.~~ Retired
|
||||
2026-09-05 by `type-name-spans`: nothing here scans for a name any more, so
|
||||
no assumption about where one is written is left to make.
|
||||
- The parser bounds nesting depth (`MAX_NESTING_DEPTH`, TODO.md §1), so the
|
||||
recursive walk here inherits a bounded stack and needs no depth counter of
|
||||
its own.
|
||||
- Identifiers are ASCII in practice; the scanner treats non-ASCII bytes as
|
||||
non-identifier bytes and never slices inside a multi-byte character.
|
||||
- A span derived rather than received is checked against the source before it
|
||||
becomes a reference (`Binder::exact_or_empty`). What is derived is small and
|
||||
named: a `Member`/`Scope` tail, a class `extends` head and tail, an instance
|
||||
module name, an end label, the `::`/`.` segments of a type name, and a
|
||||
`disable` target. Anything that does not slice back to the name costs the
|
||||
reference; nothing is ever recorded at a guessed position.
|
||||
|
||||
## Handshakes
|
||||
|
||||
@@ -332,6 +345,11 @@ feature, and the crate works without it):
|
||||
`docs/features/name-spans/README.md`.
|
||||
2. **A span for `DataType`** (and for `ExprKind::Cast::ty`), so a type
|
||||
reference does not need a window computed from its neighbours' spans.
|
||||
**Delivered 2026-09-05 by `type-name-spans`** (TODO §47) — `DataType`
|
||||
carries `name_span()` and `segments()`, `StmtKind::Disable` carries its
|
||||
target's span, `bind_data_type` lost its `window` parameter, and
|
||||
`crates/vlog_semantic/src/scan.rs` is deleted; see
|
||||
`docs/features/type-name-spans/README.md`.
|
||||
3. Nice to have, much smaller: the byte range of `Member`/`Scope` tails, which
|
||||
is today derived as `span.end - name.len()`.
|
||||
|
||||
@@ -433,6 +451,20 @@ anywhere, and under 3 % unresolved on cleanly-parsed files.
|
||||
|
||||
## Work log
|
||||
|
||||
**2026-09-05 — type-name-spans (TODO.md §47).** `scan.rs` deleted, `mod scan;`
|
||||
with it: the parser now carries `DataType::name_span()` /
|
||||
`DataType::segments()` and `StmtKind::Disable`'s span, so the two remaining
|
||||
scan callers read them instead. `bind_data_type` lost its `window` parameter
|
||||
(and with it the window computations at ten call sites, plus the now-unused
|
||||
`span` parameters of `bind_data_decl`, `bind_declarators` and
|
||||
`bind_enum_body`) and gained `bind_type_name`, which walks the segments and
|
||||
records the head as `Target::Unit`/`Target::Type` and each following segment
|
||||
as a member of the one before it — so a three-segment `a::b::c`, which used to
|
||||
bind an unlocatable `b::c`, binds all three. Every segment goes through
|
||||
`exact_or_empty` first. Corpus census byte-identical before and after: 860
|
||||
files, 27 486 symbols, 103 870 references, 1 197 unresolved, 0 unplaced.
|
||||
Details in `docs/features/type-name-spans/README.md`.
|
||||
|
||||
**2026-08-27 — indexed navigation.** `Semantics` now builds compact sorted
|
||||
`(TextRange, SymbolId/ReferenceId)` position tables with the analysis.
|
||||
`symbol_at`, `reference_at` and `reference_id_at` binary-search those tables;
|
||||
|
||||
+2
-4
@@ -198,8 +198,6 @@ an error means emit nothing.
|
||||
`stmt`, `sva`, `expr`) →
|
||||
`model.rs`; `resolve.rs` (the lexical walk; misses become
|
||||
`ExternalCandidate`/`InheritedCandidate` carrying candidate paths);
|
||||
`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);
|
||||
`workspace/` (`mod` = the tables, `index` = queries and `build`, `update` =
|
||||
incremental update and `fingerprint`, `record` = the `FileFacts` read-off,
|
||||
`external` = the overlay; `WorkspaceIndex`: units, members, defines, instantiation and
|
||||
@@ -446,7 +444,7 @@ recursion-limit, whose edges sit in §2.1). Code edges:
|
||||
| `formatter-bug-fixes (round 2) ──▶ safety-net` | depends | Three comment-shape bugs fixed in `format.rs` (`then_is_block` trailing-line-comment cuddle guard, `Fmt::header_parens`, `default_has_colon`); `verify.rs` untouched, four masked-corruption rejection pairs added per the standing template, plus three more for the directive capture at merge (2026-08-29 testbench wave, Lane B + lead). |
|
||||
| `lexer-cleanup ──▶ error-recovery / lint-rules-2` (QA logs) | depends | Fixes three lexer gaps: `@(* )` (TODO §1) plus the BOM and non-ASCII-honesty findings those two QA rounds filed; adds `ParsedSource::lex_error()` so `lucisv check` stops silently passing unlexable files. |
|
||||
| `error-recovery ─▶ lucisv-server / linter-core` | depends (downstream) | `parse_source_tolerant` is the entry point the whole LSP and the linter stand on; the strict/tolerant split (shared grammar, no second parser) is the contract. |
|
||||
| `name-spans ◀──▶ vlog-semantic` | handshake | vlog-semantic filed request 1 (spans on ~15 declaring nodes); name-spans delivered it, shrinking `scan.rs` to the `DataType` case (still open — §2.9). |
|
||||
| `name-spans ◀──▶ vlog-semantic` | handshake | vlog-semantic filed request 1 (spans on ~15 declaring nodes); name-spans delivered it, shrinking `scan.rs` to the `DataType` case; type-name-spans (§47, 2026-09-05) delivered the `DataType` case and deleted `scan.rs`. |
|
||||
| `spans ─▶ everything positional` | depends | Byte ranges + `LineIndex` are the prerequisite named by TODO §6 for the LSP effort and by fences/range formatting. |
|
||||
|
||||
Also uniform in this lane: each new AST variant lists its exhaustive-match
|
||||
@@ -615,7 +613,7 @@ update the filing README(s) and this file.
|
||||
| # | request | filed by | owner it waits on |
|
||||
|---|---|---|---|
|
||||
| 1 | `lucisv_core::path::normalize` — one `.`/`..` folding instead of three private copies (`filelist::Reader::normalize`, `config::Discovery::absolute`, `includes::normalize`, the last now `pub`) | include-nav; restated by file-operations | lucisv_core |
|
||||
| 2 | A span for `DataType` (and `ExprKind::Cast::ty` tails) — the last thing keeping `vlog_semantic/src/scan.rs` alive | vlog-semantic (item 2); restated by class-semantics | vlog_parser |
|
||||
| ~~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()` (a `u32` start paired with `name.len()`, so `Expr` stays inside its 96-byte pin) and `DataType::segments()` (the `::`/`.` split from the span's own text); `StmtKind::Disable` carries its target's span. `scan.rs` is deleted; `analyze`'s `src` stays as `Binder::exact_or_empty`'s verification oracle — a segment whose derived range does not read back is recorded with the empty range (counted *unplaced* by the census, never dropped). The census pin covers type-name references. | vlog-semantic (item 2); restated by class-semantics | vlog_parser |
|
||||
| ~~3~~ | ~~`fence::scan_nested` has no `ItemKind::Class` arm — formatter fences are inert inside class bodies (the `--fix` backstop still holds; asymmetry errs hands-off)~~ — **delivered 2026-09-02 by statement-fences (TODO §31)**: `scan_nested` enters class bodies, functions, tasks, `always`/`initial`/`final`; statement lists (`begin…end`, `fork…join`, every compound body) are fenceable through `scan_stmt_scope`/`scan_nested_stmt` on the shared `scan_units`; `stmt_docs`/`stmt_seq` obey the two swallowed-unit rules; fence regions merge into `range.rs`'s plan (load-bearing — a fenced statement has no verbatim run behind it). A region opens only at a line start (`opens_line`), so `module m; // lucisv: off` no longer opens one — the rule the format-fences README has stated since round 1. Deferred with reasons: port lists, case-item label lists, same-line fences, `PropSeqDecl.locals`. Opentitan: 4 of its 9 fenced files now keep their fenced bytes. | classes | ~~vlog_formatter (fence.rs)~~ done |
|
||||
| ~~4~~ | ~~A `lint` key in `lucisv.toml` (`[lint.<rule>]` config; selected-rules list) with CLI>config precedence~~ — **delivered 2026-09-02 by semantic-lints-on**: `[lint] select = […] / ignore = […]` in `lucisv.toml` (CLI over config, key by key; unknown rule names fail the run naming the file; `[lint.<rule>]` tables rejected by name — per-rule config was delivered later by linter-expansion-2, v0.38.0; the earlier rejection described here is historical) and `lucisv.lint.select/ignore` settings (registry-validated, republish on change). | linter-core; restated by lint-rules-2, semantic-lints, server-lint | ~~config-discovery / lucisv_core~~ done |
|
||||
| ~~5~~ | ~~`lucisv check --rules-doc` printing `rules_markdown()`~~ — **delivered 2026-09-02 by macro-word-census (TODO §29.3)**: `lucisv check --rules-doc` prints `rules_markdown()` and exits 0, takes no files, is lint-only; the example binary is gone | lint-rules-2 | ~~crates/lucisv~~ done |
|
||||
|
||||
Reference in new issue
Block a user