21 KiB
refactor-correctness-r1
Goal
Fix five correctness, panic, and determinism issues in vlog_refactor:
- UTF-8 char-boundary panic in
skip_string& callers (rename/home.rs,rename/carry.rs): advancing past a backslash escape in"\\é"or"\\中"withi += 2lands mid-codepoint and panics subsequent string slices. - SipHash nondeterminism and cycle-memoization bug in
carry.rs:HashMap/HashSetiteration order combined with memoizing cycle-taintedfalseresults inWalk::is_binder(and order-sensitive recursion inWalk::formals_of) produces non-deterministic carrier sets for mutually recursive macros. - Duplicate-unit member rename ambiguity (
#53) (rename/mod.rs):renameable_hereandScope::declarationpreviously checkedindex.units(&name).len() > 1only forfile_scopesymbols; renaming a member/port/block declared inside a file-scope unit (module/interface/package/class/typedef) whose unit name appears more than once inindex.units(matching kind) must refuse unambiguously withambiguous(unit_name). - Cross-module same-file
.port(...)false body-use hit (#38) (ports/remove.rs):body_uses_inpreviously treated allsemantics.references_of(id)in the file as body uses of the target module, including.port(...)connections on instances in another module in the same file. - CRLF preservation in
extract(#39) (extract/render.rs,extract/mod.rs): preserve\r\nvs\nfrom the source file across the extracted module, replacement instantiation, and\r\n\r\nsame-file insertion.
Assumptions
Semantics::file_scope()owns all units indexed byWorkspaceIndex::units(name)(Module,Interface,Package,Typedef,Class), matchingvlog_semantic/src/workspace/record.rs::is_unit.- Unit-kind matching treats
Module/Interface(is_instantiable()) as sharing the instantiable namespace (matchingports/find.rs:52) while keepingPackage,Class, andTypedefdistinct bySymbolKind, so apackage pkandmodule pkin the same workspace (top_rooted_paths::qa_f1_*) are not treated as duplicate declarations of one unit, and two non-duplicated packagespkg1/pkg2with identically named classes/members remain renameable. - Source files using CRLF consistently contain
\r\n; mixed line-ending files default to\r\nwhen any\r\nis present (matchingrename/layout.rs), and instantiation line endings are normalized inextract/render.rsbecauseinstantiate::InstantiationPlan::render_withis outside this task's file ownership.
Handshakes
rename/preflight.rs(declared_here) (implemented in Round 1 Lane 1A QA-fix pass):- Shares
super::enclosing_unitwithScope::declaration(rename/mod.rs) sodeclared_heredefers (Ok(())) beforealready_namedwheneverenclosing_unit(semantics, declaration).is_some()(both file-scope declarations and declarations inside file-scope units). This keepsrename_preflightone-directionally consistent withrenameon duplicate-unit members (qa_correctness_r1::qa_preflight_same_name_inside_duplicate_unit_matches_rename).crates/vlog_refactor/tests/preflight_oracle.rs::renaming_a_symbol_to_the_name_it_already_has_is_refused_from_the_bufferwas updated to test buffer-onlyalready_namedoutside file-scope units (a$unitfunction local) and deferral inside file-scope units (module sub).
- Shares
lucisv_server/src/same_file.rs(renamed_here) (assigned to Lane 1B — untouched here):same_file.rs:179-197treats symbols withsymbol.scope != file_scope()as eligible for single-file fast-pathprepareRenamewhen the workspace index is not consulted. Lane 1B owns updatingsame_file.rsfor QA finding F2b so single-fileprepareRenamedefers members inside file-scope units to match settledprepare_rename_here.
lucisv_mcp/src/tools/find.rs(engine_refusal):- Translates
"which declaration this rename means"to"which declaration this position means". Reusingambiguous(enclosing_unit)preserves exact parity acrossrename::prepare_rename,rename::prepare_rename_here,Scope::declaration, andlucisv_mcp'sfind_references.
- Translates
crates/vlog_refactor/tests/qa_rename_implicit.rs(qa_a_port_rename_into_a_module_declared_twice_is_refused):- Previously, renaming a port inside duplicated
module leafpassedScope::declarationand failed downstream inconnections.rswith"`u_leaf` at top.sv:2 connects with `.*` to `leaf`, which lucisv cannot read...". With#53fixed,Scope::declarationnow refuses upfront with"`leaf` is declared in more than one indexed file; lucisv will not guess which declaration this rename means."; the test assertion was updated accordingly (whilerename_implicit::a_wildcard_into_a_module_declared_twice_is_refused, which renames intop.svrather thanleaf.sv, still exercises theu_leafwildcard refusal unchanged).
- Previously, renaming a port inside duplicated
crates/vlog_refactor/src/instantiate.rs:InstantiationPlan::render_withemits\n.extract/render.rs::instantiationconverts emitted\nto\r\nwhen the source uses CRLF soinstantiate.rsstays untouched.
Status / TODO
- Fix UTF-8 char-boundary handling in
rename/home.rsandrename/carry.rs - Replace
HashMap/HashSetand cycle-tainted memoization inrename/carry.rswithBTreeMap/BTreeSet+ monotonic fixed-point computation - Refuse renames inside duplicated file-scope units in
rename/mod.rs(renameable_hereandScope::declaration) - Filter
ports/remove.rs::body_uses_inreferences tomodule_span(module) - Preserve source line endings (
\r\nvs\n) inextract/render.rsandextract/mod.rs - Add/update regression tests in
crates/vlog_refactor/tests/and inline unit tests - Fix QA F1 (
ports/remove.rs,ports/offer.rs): passfind_module's fullmodule ... endmodulespan intobody_uses_inso empty-body modules check header port default expressions - Fix QA F2a (
rename/preflight.rs,rename/mod.rs): shareenclosing_unitindeclared_hereso same-name renames inside file-scope units defer to the ambiguity check - Pass formatting, clippy, full test suite, and author-stamp check
Work log
- Changed
rename/home.rs::skip_stringto accept&strand step past escaped multi-byte UTF-8 characters (1 + char::len_utf8), and guarded string/slice indexing inhome.rs(includes_in,macro_names,skip_string) andcarry.rs(invocations,split_arguments) with.get(..)and UTF-8 character stepping. - Changed
carry::Defs,Carriers::formals, andCarriers::bindersfromHashMap/HashSettoBTreeMap/BTreeSet; replacedWalk::is_binderandWalk::formals_ofwith order-independent monotonic fixed-point loops (find_bindersleast fixed point andcompute_formalsgreatest fixed point so cycles remain carried/true). - Added
enclosing_unitandis_duplicate_unitinrename/mod.rs, shared betweenrenameable_hereandScope::declaration, refusing members/ports/blocks inside duplicated same-kind file-scope units withambiguous(unit). - Filtered
ports/remove.rs::body_uses_inreferences tomodule_span(module)so.port(...)connections in other modules within the same file are ignored. - Threaded
line_ending(text)(\r\nvs\n) throughextract/mod.rs(ensure_newline,module_text,instantiation, and{eol}{eol}{module_text}same-file insertion) andextract/render.rs(new_module,instantiation). - Added regression unit and integration tests in
rename/home.rs,rename/carry.rs,tests/rename_macro_carry.rs,tests/rename.rs,tests/ports.rs, andtests/extract.rs, and updatedtests/qa_rename_implicit.rs. - Production non-blank non-comment line counts (
<= 600limit):crates/vlog_refactor/src/rename/home.rs: 211 linescrates/vlog_refactor/src/rename/carry.rs: 233 linescrates/vlog_refactor/src/rename/mod.rs: 495 linescrates/vlog_refactor/src/ports/remove.rs: 288 linescrates/vlog_refactor/src/extract/render.rs: 322 linescrates/vlog_refactor/src/extract/mod.rs: 409 lines
2026-11-26 — Round 1 Lane 1A QA-fix pass (F1 & F2a)
- QA F1 (
crates/vlog_refactor/src/ports/remove.rs,crates/vlog_refactor/src/ports/offer.rs): Removedmodule_span(module)and updatedbody_uses_into takemodule_range: TextRangedirectly fromfind_module'sitem.span(which covers the entiremodule ... endmoduledeclaration including header ports and default expressions while excluding sibling modules in the same file). Updated bothplan_remove(ports/remove.rs) andremoval(ports/offer.rs) to pass that range. - QA F2a (
crates/vlog_refactor/src/rename/mod.rs,crates/vlog_refactor/src/rename/preflight.rs): Promotedenclosing_unittopub(super) fninrename/mod.rsand updateddeclared_hereinrename/preflight.rsto defer (Ok(())) wheneverenclosing_unit(semantics, declaration).is_some(), matchingScope::declaration's ambiguity-before-already_namedordering without duplicating logic. - Updated
crates/vlog_refactor/tests/preflight_oracle.rs::renaming_a_symbol_to_the_name_it_already_has_is_refused_from_the_bufferto verifyalready_namedstill refuses from buffer outside file-scope units ($unitfunction local) and defers for declarations inside file-scope units (module sub). - Un-ignored and expanded
crates/vlog_refactor/tests/qa_correctness_r1.rs::qa_remove_port_empty_body_module_with_default_expr_using_removed_portandqa_preflight_same_name_inside_duplicate_unit_matches_rename. - Updated production non-blank non-comment line counts (
<= 600limit):crates/vlog_refactor/src/rename/home.rs: 211 linescrates/vlog_refactor/src/rename/carry.rs: 233 linescrates/vlog_refactor/src/rename/mod.rs: 495 linescrates/vlog_refactor/src/rename/preflight.rs: 33 linescrates/vlog_refactor/src/ports/remove.rs: 283 linescrates/vlog_refactor/src/ports/offer.rs: 286 linescrates/vlog_refactor/src/extract/render.rs: 322 linescrates/vlog_refactor/src/extract/mod.rs: 409 lines
QA log
2026-11-26 — QA agent: FAIL — core fixes 1/2/5 hold, two concrete findings on #38 (module_span) and #53 (preflight / same_file handshakes)
Verdict: FAIL. Two concrete findings (F1 inside owned ports/remove.rs, F2 in the #53 handshakes noted as untouched by DEV). Fixes 1 (UTF-8 skip_string), 2 (carry.rs determinism), and 5 (extract CRLF) survived every adversarial attack.
Findings
-
F1 (BLOCKING —
crates/vlog_refactor/src/ports/remove.rs:248-251):module_span(module)computesend = module.items.last().map_or(module.name_span.end, |item| item.span.end)and returnsTextRange::new(module.name_span.start, end.max(module.name_span.end)). Whenmodule.itemsis empty (e.g.,module leaf (\n input logic a,\n input logic b = a\n);\nendmodule\n),module_spancovers onlyleaf(name_span), excluding the port header. As a result,body_uses_in(ports/remove.rs:223-227) fails to find porta(module_range.contains(s.name_span.start)isfalse) and returnsVec::new():port_offers(crates/vlog_refactor/src/ports/offer.rs:302) falsely offers"lucisv: remove porta(no instantiation in scope)"despiteb = ausinga.remove_portbypasses the"is still used inside ..."refusal and fails later inverify_splicewith"removing portafromleafwould change whatameans in leaf.sv; no edits were made."instead of"`a` is still used inside `leaf` at leaf.sv:3; remove those uses first.".- Reproduction:
crates/vlog_refactor/tests/qa_correctness_r1.rs::qa_remove_port_empty_body_module_with_default_expr_using_removed_port(#[ignore = "QA finding 1..."];find_moduleatports/find.rs:95already returns the fullitem.spancoveringmodule ... endmodule, whichports/remove.rs:99andports/offer.rs:298currently discard).
-
F2 (BLOCKING —
#53parity breaks incrates/vlog_refactor/src/rename/preflight.rs:79-81andcrates/lucisv_server/src/same_file.rs:196): Both files were left untouched by DEV under strict file ownership and documented in## Handshakes, but#53breaks their invariants with concrete user-visible mismatches:- F2a (
crates/vlog_refactor/src/rename/preflight.rs:79-81):declared_hereonly skipsalready_namedwhendeclaration.scope == semantics.file_scope(). WithScope::declarationnow rejecting members inside duplicated file-scope units beforealready_named, renaming a membersigto"sig"inside duplicatedmodule dupreturnsErr("sigis the name it already has.")fromrename_preflightwhilerenamereturnsErr("dupis declared in more than one indexed file; lucisv will not guess which declaration this rename means."). Sincecrates/lucisv_server/src/rename.rs:85callsrename_preflightfirst, the LSP server returns the wrong refusal.- Reproduction:
crates/vlog_refactor/tests/qa_correctness_r1.rs::qa_preflight_same_name_inside_duplicate_unit_matches_rename(#[ignore = "QA finding 2..."]).
- Reproduction:
- F2b (
crates/lucisv_server/src/same_file.rs:196):renamed_hereonly defers to the workspace index whensymbol.scope == doc.semantics.file_scope(). Withprepare_rename_herenow readingindex.units(...)for members inside file-scope units, an early/mid-scantextDocument/prepareRename(ahead.rs) onlogic d;indup_b.sv(module dup; logic d; endmodule) answersOk({"placeholder": "d", ...})while the settled server refuses with"lucisv:dupis declared in more than one indexed file; lucisv will not guess which declaration this rename means.".- Reproduction: Adding
"dup_b.sv"(already written inshapesatcrates/lucisv_server/src/server/tests/fast_actions_differential.rs:245) to the loop at line 272 failsearly_answers_equal_settled_over_the_locality_shapeswithdiffered=3ondup_b.svline 1 cols 8–9 (lucisv_serverwas immediately reverted so no unowned files remain modified).
- Reproduction: Adding
- F2a (
Verification Summary
- Diff / Ownership / Standards:
- Modified/added files confined to
crates/vlog_refactor/(6 prod files, 5 existing test files, newtests/qa_correctness_r1.rs) anddocs/features/refactor-correctness-r1/README.md. - Production non-blank, non-comment line counts before
mod tests:home.rs211,carry.rs233,rename/mod.rs495,ports/remove.rs288,extract/render.rs322,extract/mod.rs409 (all<= 600). - Zero
unwrap(),expect(),panic!, orunsafein modified production code. python3 tools/stamp_author.py --check: pass (would stamp 0 files; left 249 untouched).
- Modified/added files confined to
- Adversarial Checks (
crates/vlog_refactor/src/rename/{home,carry}.rs+crates/vlog_refactor/tests/qa_correctness_r1.rs):- UTF-8
skip_string(home.rs,carry.rs): tested"\\\\","\\\\\\","\\é","\\🚀","\\at EOF, multi-line strings ininvocations/split_arguments, and non-ASCII comments/identifiers near strings — all passed without panic. - Determinism (
carry.rs): tested 3-cycles (M1 -> M2 -> M3 -> M1with binder and cross-position forwarding), reversed key names (Z3/Z2/Z1), and reversed definition order across 10 iterations — identical deterministic carrier/warning behavior. - Duplicate-unit member rename (
rename/mod.rs): same-namedmodule m+package mdo not collide; twointerface bus_iffiles refuse ports/signals/modports;module bus+interface buscollide; nestedgenerate/for/ifinsideduprefuses; non-duplicatedunique_min the same file renames cleanly; duplicate file-scopetypedef structandclassrefuse; byte-for-byteprepare_renamevsprepare_rename_hereparity holds onmixed.sv. #38(ports/remove.rs): same-file.p(sig)in another module + body use ofpstill refuses; same-file positional refuses; same-file.*warns; non-ANSI port and nested same-named port succeed; fails F1 on empty-body module withb = aport default.#39(extract/render.rs,extract/mod.rs): CRLF with imports + params + ports +//and/* */comments + no trailing EOL (SameFile&NewFile) and zero-port/zero-param CRLF emit zero bare\n; LF control emits zero\r.
- UTF-8
- Gates (post-final-edit):
cargo fmt -p vlog_refactor -- --check: pass../tools/guard.sh -m 6 -t 600 -- cargo clippy -p vlog_refactor -p lucisv_server -p lucisv_mcp --all-targets -- -D warnings: pass../tools/guard.sh -m 6 -t 600 -- cargo test -p vlog_refactor --all-targets: pass (qa_correctness_r1: 7 passed, 0 failed, 2 ignored for F1/F2a; fullvlog_refactorsuite green)../tools/guard.sh -m 6 -t 600 -- cargo test -p lucisv_mcp --all-targets: pass../tools/guard.sh -m 6 -t 600 -- cargo test -p lucisv_server --all-targets: pass.
2026-11-26 — QA re-check (post DEV fix pass): PASS (Lane 1A F1 & F2a resolved; F2b remains with Lane 1B)
Verdict: PASS. Re-verified Round 1, Lane 1A after the DEV fix pass. Both Lane 1A findings (F1 in ports/remove.rs & ports/offer.rs, F2a in rename/preflight.rs & rename/mod.rs) are fixed and survived expanded adversarial attacks; F2b (crates/lucisv_server/src/same_file.rs) remains tracked under Lane 1B per ## Handshakes.
Re-Verification Summary
- Diff / Ownership / Standards:
git status/git diff: onlycrates/vlog_refactor/(8 modified prod files, 6 modified test files,tests/qa_correctness_r1.rs) anddocs/features/refactor-correctness-r1/README.mdare modified/untracked.- Non-blank, non-comment prod lines before
mod tests(<= 600):extract/mod.rs409,extract/render.rs322,ports/offer.rs286,ports/remove.rs283,rename/carry.rs234,rename/home.rs212,rename/mod.rs495,rename/preflight.rs33. - Zero
unwrap(),expect(),panic!, orunsafein modified production code. python3 tools/stamp_author.py --check: exit 0 (would stamp 0 files; left 249 untouched).
- F1 Attack (
crates/vlog_refactor/src/ports/{remove,offer}.rs):qa_correctness_r1::qa_remove_port_empty_body_module_with_default_expr_using_removed_portruns un-ignored and passes.- Added
qa_correctness_r1::qa_remove_port_non_ansi_param_default_and_sibling_before_target_edge_cases: passes across siblingmodule top (input logic a)placed beforeleafwith parameter defaultsP = 8, Q = P + 1andb = a(refusesainremove_port& emptyport_offers, offers & removesbwhile ignoring sibling.b(y)in body checks), non-ANSI(a, b); input logic a; input logic b = a;+ sibling.a(x), .b(y), shared non-ANSIinput logic a, b;withport_offers(PortOfferKind::Remove), and sibling parameteraalongside target parameter defaultQ = P.
- F2a Attack (
crates/vlog_refactor/src/rename/{preflight,mod}.rs):qa_correctness_r1::qa_preflight_same_name_inside_duplicate_unit_matches_renameruns un-ignored and passes; all 11 tests intests/preflight_oracle.rspass.- Added
qa_correctness_r1::qa_preflight_parity_sweep_unit_local_vs_duplicate_module_nested_members: passes for$unitfunction local/arg renamed to itself (immediatealready_named), duplicatedmodule dupnestedgenerate/function/classmembers renamed to themselves (rename_preflightdefers withOk(())toambiguous("dup")), and full byte-by-byte parity sweeps forprepare_renamevsprepare_rename_hereandrename_preflightvsrenameon both shapes.
- Guarded Gates (post-final-code-edit):
cargo fmt -p vlog_refactor -- --check: pass../tools/guard.sh -m 6 -t 600 -- cargo clippy -p vlog_refactor -p lucisv_server -p lucisv_mcp --all-targets -- -D warnings: pass (0 warnings in crates)../tools/guard.sh -m 6 -t 600 -- cargo test -p vlog_refactor --all-targets: pass (qa_correctness_r1: 11 passed, 0 failed, 0 ignored;preflight_oracle: 11 passed, 0 failed; total 765 passed, 0 failed, 6 pre-existing ignored acrosscorpus/opentitan_top_rooted/qa_rename_implicit/rename_bind)../tools/guard.sh -m 6 -t 600 -- cargo test -p lucisv_mcp --all-targets: pass (388 passed, 0 failed, 4 pre-existing ignored)../tools/guard.sh -m 6 -t 600 -- cargo test -p lucisv_server --all-targets: pass (2139 passed, 0 failed, 52 pre-existing ignored).
Review
2026-11-26 — Lead review: PASS (merged with Lane 1B in Round 1)
- Inspected combined diff across
vlog_refactorandlucisv_server; cross-lane handshake F2b (same_file::renamed_here+dup_b.svdifferential check) landed cleanly in Lane 1B and passes together with Lane 1A on trunk. - Removed stray duplicate
// Author:line at line 3 of this README. - Handshakes closed in
docs/topo.md:#38,#39,#53(engine half). Fulltools/gates.shverified green on mergedmaster.