Files
lucisv/docs/features/semantic-refactor-r8/README.md
T
Guoliang ChenandClaude Mythos 5.2 532a64546c Round 8: semantic and refactor edge cases (#12, #31, #32, L-5/L-6/L-10)
DPI-export names are semantic references. verify_move reconstructs the
result independently and checks equation 3 per edit, with 16 attack tests.
Interface generate-block members are reachable through a port or virtual
interface; bind to a bare instance name is found; nested struct members
get their container key. Escaped identifiers join FileFacts::words
(FACTS_FORMAT 23); generate-scoped bind shorthand resolves. Scope reuses
index_order. Files topo #68-#70.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-26 17:18:59 -08:00

27 KiB
Raw Blame History

semantic & refactor edge cases (Round 8)

Goal

Close docs/topo.md §2.9 rows 12, 31 and 32 and oct_review.md L-5, L-6 and L-10, plus the two parked edge cases the Round 7–12 handoff names: an escaped identifier missing from FileFacts::words (so a census pre-filter never opened a file that only wrote the escaped spelling — lucisv_mcp qa_m7.rs R2) and a generate-scoped instance mistaken for the enclosing module's own by a bind u shorthand rename (vlog_refactor qa_rename_implicit.rs QA note 1). A bug-fix round: no features beyond the six items. The persisted census changes three ways, so FACTS_FORMAT goes 22 → 23 once for all of them.

Assumptions

  • #12. index_order sorts with Path's Ord and keeps the first copy of a repeated path. Making it generic in the path type (P: AsRef<Path>) orders a &Path exactly as the PathBuf it borrows from, so Scope's sources are byte-identical to before.
  • #31. A DPI export's subroutine is declared in the scope the export is written in (IEEE 1800 §35.5.4), so the name is bound Target::InScope — a miss records nothing rather than an unresolved use to warn about. The c_name = half is a C linkage name and is never a reference. *::* package exports are unchanged.
  • #32. Every real move today (extract_module to a new file, inline_module) writes one edit per file it names in moving, so the per-edit rule cannot refuse a real plan; the same-file extraction passes no moving and keeps the per-file contract. A refactoring that stays in one file may still carry a comment from one edit to another (the ANSI conversion does), so the per-edit rule applies only to files a move names.
  • #32. A piece is inside an edit's window only when it lies wholly inside it; a piece straddling a window edge counts nowhere and so fails the rule — the conservative direction.
  • L-5. Hierarchical references through an interface port and through a virtual interface into a named generate block of the interface are legal; only blocks move to the interface's connection surface — its instances stay hierarchical, as before.
  • L-5 (fix round 1). Only an interface's named blocks (and blocks nested in them) export their members on the connection surface (hierarchy::surface_in, rooted at the unit the block chain hangs off). A module's block members stay hierarchical-only, exactly as on trunk. The first cut filed every block's members on the connection table, which leaked module generate-block internals into the workspace-symbol listing (QA-R8-1).
  • L-6. The bare-instance shape is recognised lexically, in the text that holds the bind: unit name or unit #(…) name. A bare target naming an instance declared in another file (upward resolution past the file) is not recognised — the same scope as every other lexical H3 scan; such a bind is still covered by the engine's connections.rs walk, which resolves instances through the index.
  • L-10. member_key of a scope owned by a StructMember is its container's key, ., its name — record::nested_key's spelling. Only a struct member that opens a scope owns one, which is exactly the set nested_key keys.
  • Escaped words. An escaped identifier is spelled in the census as its token is: backslash included, terminating whitespace not (\my.sig), the spelling every symbol and pre-filter uses. Completion — the one reader that inserts a word — filters escaped words out of its table.
  • Generate-scoped bind u. "The enclosing module's own instance" is the declaration upward lookup from the bind finds (sites::nearest). An instance in a generate block is not found from outside the block, and is found from inside it.

Handshakes

  • vlog_semantic::index_order is now generic in the path: index_order<P: AsRef<Path>, T>(impl IntoIterator<Item = (P, T)>) -> Vec<(P, T)>. Source-compatible for every existing caller (PathBuf infers as before); vlog_refactor::Scope::assemble calls it with &Path.
  • FACTS_FORMAT 22 → 23. No field changes; three census changes: the W group holds escaped identifiers; a DPI export's name is a reference; an interface's named generate block, and the members of blocks inside an interface, are filed on the connection surface (a module's blocks are unchanged). Fix round 1 changed which records carry which surface tag relative to the first cut; nothing was ever committed or released at 23, so 23 names exactly one layout — this one — and needs no second bump. Every store written by 0.66.x is discarded whole by the header check (lucisv_server::index_cache, lucisv_mcp::cache); the existing "every other format" loops (index_cache.rs 1..FACTS_FORMAT, qa_m6.rs FACTS_FORMAT - 1) now cover 22.
  • FileFacts::words / words::harvest now include escaped identifiers. Readers: lucisv_mcp declared.rs and diagnostics.rs (pre-filter and census — wanted), lucisv_server::rename_trace (census — wanted), the semantic-lint mention guard in lucisv and lucisv_server (an escaped name another file writes is now seen as mentioned — fewer false positives), and completion. Out-of-scope edit, flagged: lucisv_server/src/candidates.rs gains insertable, applied in from_words and set_words, so completion never offers an escaped word, plus one test.
  • Semantics::member_key now answers reg2hw_t.ctrl for an inline nested struct member's scope (was ctrl). Consumers: lucisv_server nav.rs, same_file.rs, completion/related.rs — each passes the key to member_in, which now finds what the index filed.
  • Interface block members in the symbol listings (fix round 1, deliberate). An interface's own signals are connection members and so workspace_symbols entries, declared_names, part of symbol_view, and exported references. An interface's block members are now the same kind of member and are treated the same way: seen of bus_if.g_mon is listed with container bus_if.g_mon, g_mon with container bus_if, and neither is in hierarchical_declarations. A module's block members are unchanged from trunk on all four queries (pinned in tests/semantic_r8.rs). OpenTitan hw/ip workspace-symbol count: see the fix-round-1 work log.
  • Key collision (QA LOW). A typedef m with an inline nested member g_lane and a module m with block g_lane share the key m.g_lane, as on trunk; the module's block members are again on the hierarchical table only, so member_in("m.g_lane", "lane_q", Connection) is empty as on trunk. An interface m with a block g_lane beside such a typedef would merge both on the connection table — the same by-name merge the member table already has for every unit name, not new.
  • Pre-existing OpenTitan test failures, for the lead (identical on trunk e229ff9, not fixed here): see the fix-round-1 work log for each one's outcome on this tree against trunk.
  • check::verify_move (and so verify_splice) refuses edits that are out of order, overlap, run past the end or split a character; no caller in the workspace produces such a plan (the full vlog_refactor suite is green).
  • Sync points touched for the number: crates/vlog_semantic/src/facts.rs, docs/topo.md (lines stating the number only: the header paragraph, the vlog_semantic module note, the package-reexports row's "codec is N now", the ownership table, the workspace contract row), docs/site/src/content/docs/reference/rust-api.md, docs/repository-analysis.md (current-state lines; the historical "top-rooted … = 22" left alone), crates/vlog_semantic/src/words.rs, crates/lucisv_server/src/candidates.rs (doc). Tests assert the number via the constant everywhere; tests/semantic_r8.rs pins 23.

Status / TODO

  • #12 Scope::assemble uses index_order (pure refactor).
  • #32 independent reconstruction + per-edit equation 3 for move-named files; Finding QA-1 pair proven accepted before, refused after.
  • L-6 bare-instance bind target in scoped::binds_into.
  • Generate-scoped bind u shorthand (connections.rs); test un-ignored.
  • #31 DPI-export names bound as InScope references.
  • L-5 interface generate blocks on the connection surface.
  • L-10 member_key for inline nested struct members.
  • Escaped identifiers in the word census; completion filters them; qa_m7.rs test un-ignored.
  • FACTS_FORMAT 22 → 23 and every sync point.
  • Gates (fmt, clippy, guarded crate tests, OpenTitan ignored tests, stamp) — see Work log.
  • Fix round 1: QA-R8-1 (module blocks back to trunk, interface blocks only), architecture.md codec, article, QA's attack shapes as tests, real OpenTitan runs compared with trunk.

Work log

2026-11-26 — dev. Order: the vlog_refactor-only items first (#12, #32, L-6, generate-scoped bind u), then every vlog_semantic census change together so FACTS_FORMAT moved once.

  • #12. index_order made generic in the path type; Scope::assemble replaces its hand-written sort/dedup with it. No new test (pure move); the vlog_refactor suite is unchanged and green.
  • #32. New check/ledger/windows.rs. reconstruct splices the edits in from the last backwards and refuses out-of-order, overlapping, out-of-range or mid-character edits — apply skips such an edit silently, so the two disagreeing is now a refusal (unplaceable). The ledger reads the reconstructed text. Split::windows_match holds equation 3 per edit in a file the move names: each edit's window is located in the reconstructed text by offsets alone, and the never-dropped pieces the re-lexed file holds there must equal what the edit deleted outside the region (sender; >= for generated text) or at least that (receiver). It is asked after Transit::check, so every existing refusal keeps its sentence. Attack module check/in_place_attacks.rs (8 tests): the QA-1 pair, a destination relocation, a sender inventing a comment, overlapping and past-the-end edits, and three accept controls (the real extraction, an edit rewriting around its own comment, a one-file splice carrying a comment between edits). Proof of tightening: with in_place? and the reconstruction disabled, four of the eight fail (both relocations, overlap, past-end). No check loosened.
  • L-6. scoped::binds_into also counts a bind whose bare target the same text instantiates as unit (instantiates_as, past_parens). Test qa_warning_scope::l6_… (failed first: no warning; also pins that a bind onto another module's instance stays silent).
  • Generate-scoped bind u. connections.rs asks visible_target — the declaration sites::nearest finds from the bind — and counts an enclosing-module instance as the bind's own only when it is that one. qa_rename_implicit::qa_b_a_generate_scoped_instance_is_not_the_enclosing_modules_own un-ignored (failed first); added a_bind_inside_the_generate_block_sees_the_blocks_own_instance.
  • #31. bind/item.rs: ExportDecl::Dpi binds dpi.name as Target::InScope. Tests in vlog_semantic/tests/semantic_r8.rs (resolution, task with c_name =, package scope, no outward reach) and vlog_refactor/tests/rename_dpi_export.rs (rename from either end, the C name untouched, find_references includes the export).
  • L-5. hierarchy::surface_of: Interface → Block is Connection; Block → members are Connection (the second hop failed without it — a block has one surface). Tests: resolution through an interface port and a virtual interface, a module's block still off the connection surface, and qa_warning_scope::l5_… (the rename edits both paths, no "could not be resolved").
  • L-10. Semantics::member_key keys a StructMember-owned scope as {container key}.{name}. Test: reg2hw_t.ctrl, and member_in finds q.
  • Escaped words. words::harvest keeps escaped identifiers; words.rs's own test flipped to the new contract; lucisv_server::candidates::insertable keeps them out of completion (test an_escaped_identifier_is_never_offered_as_a_word). qa_m7::qa_rework_an_escaped_local_outline_lists_is_found un-ignored.
  • FACTS_FORMAT 23 with its history entry in facts.rs; sync points as listed in Handshakes.

2026-11-26 — dev, fix round 1 (QA-R8-1 and the lead's rulings).

  • QA-R8-1. Block → members are back to Hierarchical in hierarchy::surface_of. New hierarchy::surface_in(root, unit, member) puts a block's members on the connection surface only when the block chain hangs off an interface; record::collect_members carries that root (the unit itself, kept through nested blocks and inline struct members, reset at a nested class/typedef/covergroup). Tests in tests/semantic_r8.rs, three of which fail against the first cut: a_modules_block_internals_are_not_workspace_symbols (workspace_symbols empty, hierarchical_declarations = m.g_lane), …_not_declared_names_or_in_the_symbol_view (declared_names, and declares_the_same across a block-internal rename), a_typedef_named_like_a_module_does_not_share_its_blocks_connection_key (QA's LOW collision: member_in("m.g_lane","lane_q",Connection) empty), and an_interfaces_block_members_are_listed_like_its_own_signals (the deliberate choice, see Handshakes). bus.g_mon.seen / vif.g_mon.seen still resolve (semantic tests) and rename (qa_warning_scope::l5_…).
  • OpenTitan hw/ip workspace symbols (temporary probe, removed after measuring: WorkspaceIndex::build over every .sv/.v/.svh/.vh under hw/ip, 1,870 files, workspace_symbols("").len(), release, guarded): trunk e229ff9 41,621 (QA's number), this tree 41,684, first cut 43,670. The 63 extra entries were diffed by (name, container, kind): none removed, and every addition belongs to one of nine interfaces (adc_ctrl_fsm_sva_if, csrng_cov_if, edn_cov_if, keymgr_dpe_if, lc_tx_cov_array_if, otbn_trace_if, rom_ctrl_{,compare_,fsm_}bound_if): 26 blocks (container the interface) and 37 block members (33 variables, 4 instances; container iface.block). That is exactly the L-5 change with the listing rule an interface's own signals already follow.
  • FACTS_FORMAT 23 still names one layout: this one. Nothing was committed or released at 23, so the first cut's layout was never stored by anything the lead ships.
  • LOW: architecture.md current-state sentence → codec 23 (its v0.61–0.66 history line keeps 22); windows.rs refusal no longer says "take a attribute" (pinned by an_attribute_relocated_between_two_edits_is_rejected).
  • Test quality. a_sender_edit_that_invents_a_comment_is_rejected renamed control_…_keeps_its_old_refusal and documented as a control (it also asserts the new rule's sentence does not replace the old one). Added QA's uncovered shapes as permanent tests: relocation into the receiver's own insertion (two receiver edits), a dropped comment replaced by an identical-text copy, the same laundered through the other copy's edit, an attribute relocation, a swap of two comments between two edits, and the unplaceable shapes (out of order, mid-character, reversed range; overlap and past-end were already there). With reconstruct and windows_match disabled, 12 of 16 fail; the other 4 are the three accept controls and the old-refusal control. (The first identical-copy draft put the copy on the same line, where // dup // dup lexes as one comment and the old checks already refused it; moved to its own line.)
  • OpenTitan ignored tests, run for real (LUCISV_OPENTITAN / LUCISV_BIND_ROOT = /Users/lucio/repo/opentitan, guard -t 1200 because these index all of OpenTitan; none was killed), each also run on a detached trunk worktree (e229ff9, separate target dir, removed afterwards) and diffed (test names, panics, assertion text, warnings; thread ids and timings masked):
    • lucisv_server --test opentitan_references: 2/2 pass, as on trunk.
    • vlog_refactor --test opentitan_top_rooted: 1 pass, assertion failure at line 110, stack overflow in the_whole_tree_… — identical to trunk (warnings included).
    • lucisv_mcp --test opentitan: 1 pass, 2 failures (:209 earlgrey instance set, :122 navigation entropy_src_core.sv:3092) — identical to trunk.
    • vlog_refactor --test rename_bind (ignored test): stack overflow — identical to trunk. All four are pre-existing and not fixed here (lead ruling).

QA log

2026-11-26 — QA (Opus 5.5). Verdict: FAIL (one blocking finding, QA-R8-1; everything else passes). Experiments ran in a scratch copy of the working tree and in a detached trunk worktree (e229ff9), each with its own target dir. Nothing experimental was left in this tree, and OpenTitan status --porcelain was empty at the end.

Gates: cargo fmt --all -- --check clean; cargo clippy --workspace --all-targets clean; guarded cargo test -p all green: vlog_semantic 449/0 (4 ignored), vlog_refactor 785/0 (5), vlog_linter 711/0, lucisv 162/0, lucisv_server 2196/0 (52), lucisv_mcp 400/0 (3). stamp_author.py --check clean. Release lucisv check opentitan/hw: 1,178, and the output is byte-identical to trunk's (the mention guard did not move any rule). lucisv --check --no-cache opentitan/hw: 3,967 would reformat + 72 unchanged = 4,039 / 4,046 (7 parse failures), 0 verification failures.

OpenTitan ignored tests, run with LUCISV_OPENTITAN set (without it, opentitan_top_rooted and opentitan_references skip silently in 0.00 s): opentitan_references 2/2 pass. opentitan_top_rooted (1 assertion failure plus 1 stack overflow), lucisv_mcp --test opentitan (2 failures) and rename_bind (stack overflow) fail identically on trunk. They are pre-existing, not this round's.

#32 verifier: compared every check before and after. Nothing is loosened. The same refusals run in the same order, reconstruct must equal apply's text, and in_place? only adds a refusal. Re-attack: 16 new pairs in a scratch module. Ten of them are relocations: across two receiver edits, into the receiver's insertion, a dropped // dup "replaced" by an identical-text copy, the same thing laundered through the other dup's edit, an attribute, a line comment, a generated /* TODO: connect */, a move into the region's replacement text, and a swap of two comments between two edits. With the pieces-match cases and the unplaceable shapes (unsorted, mid-character, reversed), that is 11 refused that the new checks catch: all 11 are accepted with reconstruct and windows_match disabled. Five more were already refused by the old rules: duplicated transit (×2), moving naming only one file (×2), and generated text laundering a moved comment. The dev's 8 tests were confirmed the same way: 4 fail without the new code, 3 are accept controls, and a_sender_edit_that_invents_a_comment_is_rejected was refused before too. A directive relocated between two edits is still accepted, the same as trunk: a directive is not a never-dropped piece. No false refusals: all 13 public planners over LF / CRLF / non-ASCII / CRLF+non-ASCII (add/remove port, propagate, expand .*, ANSI, organize imports including offset 0, extract NewFile/SameFile ending at EOF, inline, rename) give the same outcome as trunk. Hand-built splices with two inserts at one offset, an edit at offset 0, an edit at EOF and adjacent edits verify. Plan::settle sorts by (start, end), and extract/inline write one edit per moved file.

#31: function and task, export before and after the declaration, exported twice, c_name = (including a c_name spelled like a signal in scope), interface, package and generate block, an undeclared name (records nothing, rename at it refused), DPI imports unchanged, *::* unchanged. OpenTitan otbn_* exports: 1 → 2 references and a clean rename (trunk 1 + warning). L-10: nested-in-nested, union, interface typedef, and a same-named outer typedef ctrl (trunk resolved the inner q to it) all improve; enum unchanged. Generate-scoped bind u: nested, sibling, same name in the block and the module (each side), and for-generate all behave per upward lookup. A format-22 index-cache-mcp written by the trunk binary is discarded and rebuilt by the new binary; the escaped find succeeds, and warm reuse works.

Findings:

  • QA-R8-1 (MEDIUM, blocking, this round) — workspace/hierarchy.rs:133 (Block → members Connection) files the members of every module's named block on the connection table. That puts them in workspace_symbols, declared_names and symbol_view. Input: module m; if (1) begin : g_lane logic lane_q; end endmodule. Expected (trunk, and index.rs:139-147: "A module's internal net is not a workspace symbol"): workspace_symbols("lane_q") empty and lane_q in hierarchical_declarations. Actual: [email protected]_lane listed and hierarchical_declarations empty. On OpenTitan hw/ip the listing grows 41,621 → 43,670. The Handshakes section names no workspace/symbol consumer.
  • LOW (this round): docs/site/.../reference/architecture.md:55 still says "codec 22" in a current-state sentence. docs/topo.md:376 still says "DPI-export names remain unbound" (the lead's file).
  • LOW (this round): ledger/windows.rs:122 produces "take a attribute".
  • LOW (this round): a typedef m with an inline nested member g_lane and a module m with block g_lane now share the Connection key m.g_lane (trunk merged them on the Hierarchical surface only).
  • INFO (pre-existing): \foo and foo are not one identifier anywhere. A rename of foo silently misses u.\foo in another file. The MCP log calls a format-22 store "not written by lucisv 0.66.2". verify_move is 115 lines (99 on trunk).
  • Largest changed production files: rename/connections.rs 503, facts.rs 467, check/mod.rs 444, candidates.rs 440, bind/item.rs 408. None of them is over 600.

2026-11-26 — QA re-check of fix round 1 (Opus 5.5). Verdict: PASS. QA-R8-1 is closed, and every lesser item is fixed or accepted. A detached trunk worktree (e229ff9) and a scratch copy of the tree were used, each with its own target dir, and both were removed afterwards. OpenTitan status --porcelain is empty.

  • QA-R8-1 closed. The module-block input matches trunk on workspace_symbols, hierarchical_declarations, member_in on both surfaces and the in-file postings (posts [0], as on trunk), so nav.rs hierarchical_only takes the trunk path for a module block. The typedef-m / module-m key collision is back to trunk.

  • root threading. 13 shapes were diffed against trunk: a block inside a for-generate in an interface, blocks nested two deep, a module instantiated inside an interface block, a class / typedef / covergroup / localparam / procedural block inside an interface block, an interface nested in a module, a program, an interface instance inside a module's block, modport and virtual-interface paths, a bind into an interface block, and a direct interface instance next to one inside a block.

    • Every difference is an interface block or an interface block's member.
    • The internals of leaf (inner, leaf.lg.leaf_blk) are unchanged.
    • Class, typedef and covergroup members are unchanged, as on trunk.
    • Program and module-with-class cases are identical to trunk.
  • OpenTitan hw/ip. Workspace symbols go from 41,621 to 41,684. The diff is additions only, all in nine interfaces: 26 blocks, 33 vars and 4 instances.

  • L-5. bus.g_mon.seen and vif.g_mon.seen are posted (2 uses). Connection listings are sane: bus_if lists [d, g_mon, mp], and bus_if.g_mon lists [seen]. qa_warning_scope::l5_… (rename edits both paths, no "could not be resolved") is green.

  • LOW items. architecture.md:55 now says codec 23 (:89 is historical). The windows.rs refusal now reads "take one elsewhere". The collision is back to trunk. With reconstruct and windows_match disabled in the scratch copy, 12 of in_place_attacks.rs's 16 tests fail and the 4 labelled controls pass, as claimed.

  • Gates. fmt clean, clippy 0 warnings, stamp clean. Guarded cargo test -p, all green:

    crate passed ignored
    vlog_semantic 453 4
    vlog_refactor 793 5
    lucisv_server 2196 52
    lucisv_mcp 400 3
    lucisv 162 0
    vlog_linter 711 0
  • OpenTitan sweeps. lucisv check gives 1,178 findings, byte-identical to trunk. --check --no-cache gives 3,967 + 72 = 4,039 / 4,046 with 0 verification failures.

  • OpenTitan ignored tests (LUCISV_OPENTITAN set). opentitan_references passes 2/2. opentitan_top_rooted, lucisv_mcp --test opentitan and rename_bind fail identically to trunk. guard -t 1200 killed nothing.

  • LOW (this round). An instance inside an interface's block goes on the connection surface and is listed as a workspace symbol (bus_if.g.u_inblk; 4 on OpenTitan). The interface's direct instances stay hierarchical-only and unlisted (u_direct). So the claim "listed like the interface's own signals" holds for signals and parameters, but not for instances. This is not a regression: a block instance is only reachable through a connection read that trunk could not make at all.

  • INFO (pre-existing). bus.mp.g_mon.seen is not posted (a modport is not a path scope). A modport does not restrict which block members a bus_if.mp port reaches, just as it does not restrict the interface's signals.

Review

2026-11-26 — lead: accepted after two QA passes.

  • Delivered: §2.9 #12, #31 and #32 (closed in docs/topo.md), oct_review.md L-5, L-6 and L-10, escaped identifiers in FileFacts::words (FACTS_FORMAT 23), and the generate-scoped bind shorthand; both previously ignored tests are un-ignored and pass.
  • #32 tightens the verifier and loosens nothing: QA compared every check against trunk, ran 13 real planners over LF/CRLF/non-ASCII text with identical outcomes, and wrote 16 attack pairs of its own, 11 of which trunk accepted.
  • The first cut of L-5 moved every module's block members onto the connection surface (QA-R8-1); fix round 1 restricted it to interface blocks. OpenTitan hw/ip workspace symbols: 41,621 → 41,684, additions only, all under nine interfaces.
  • Out-of-lane edit accepted: lucisv_server/src/candidates.rs keeps escaped words out of the completion table, forced by the shared word census.
  • Filed for later: §2.9 #68 (three ignored OpenTitan tests that fail on trunk once LUCISV_OPENTITAN is set — the dev's first report counted their silent skip as a pass), #69 (instances inside interface blocks are listed, direct ones are not), #70 (\\foo vs foo across files).
  • OpenTitan: lucisv check hw byte-identical to trunk (1,178); format 4,039/4,046 with 0 verification failures.