From 132f6e918603d6309c60e84d84b4f5281b41d94e Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Wed, 2 Sep 2026 22:17:28 -0700 Subject: [PATCH] =?UTF-8?q?TODO=20=C2=A731=20planned:=20format=20fences=20?= =?UTF-8?q?at=20statement=20level=20and=20inside=20class=20bodies=20(M9,?= =?UTF-8?q?=20=C2=A72.9-3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- TODO.md | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/TODO.md b/TODO.md index e9aed90..2aaecd7 100644 --- a/TODO.md +++ b/TODO.md @@ -3211,3 +3211,104 @@ parallel with §29. - [ ] QA: hand-written interface + DPI files in every listed shape, idempotent, comments kept; the negative pin; sweep unchanged +## 31. Format fences at statement level and inside class bodies (planned 2026-09-02) — M9, §2.9-3 + +Mapped (read-only exploration, file:line in the feature README to be): +fences are an exact-match `//` comment (`verilog_format: off|on`, +`lucisv: off|on`, `fence.rs::fence_of`) turned into `Region { fence, +start, end }` by `fence::collect`, a **comment scan over item scopes** +(`scan_scope` walks one `Vec` plus its `dangling`; `scan_nested` +enters Module/Package/GenerateRegion/GenIf/GenFor/GenCase and nothing +else — `_ => {}` is why a fence inside a class body, an `always` +block, a case item or a port list is inert). The formatter asks three +questions of the list (`verbatim.rs`: `slot`, `is_verbatim`, +`opens_at`) and splices `Doc::Verbatim(src[start..end])`, a column-0, +break-forcing leaf that must follow a line break; `region_at` is a +`partition_point` binary search that needs the list sorted by both +ends. `protected_regions` (the `--fix`/quick-fix backstop) is already +the union with a line scan, so it sees class-body and statement fences +today — this round closes that asymmetry, it does not open one. The +corpus holds zero fences (any output movement is a bug). Dev Opus 5, +QA Sonnet 5. Feature README: `docs/features/statement-fences/README.md`. + +**31.1 Class bodies — one arm.** `ClassDecl` holds `items: Vec` + +`dangling` and the formatter already prints them through the +fence-aware `item_seq`/`dangling`; add `ItemKind::Class(c) => +scan_scope(src, &c.items, &c.dangling, out)` in `scan_nested` (and the +same for any other item that carries an item list and is printed by +`item_seq` — check `Interface`/`Program`/`Checker`, say which). Cases: +a fence around one class item, around a nested class, an unmatched +`off` running to `endclass` only (not past it), comments before the +`off`. Closes §2.9-3; the classes README's handshake ticked; the QA-log +probe in that README re-run. + +**31.2 Statement lists.** A `Stmt` is fence-ready (`meta.leading` with +spans; `span` = code extent, comments out). Add `scan_stmt_scope(src, +stmts, dangling, out)` mirroring `scan_scope` (leading comments as +units, `scope_end` = last statement's `span.end` extended by +`with_trailing_comments`, an unmatched `off` runs to the list's end +only), and `scan_nested_stmt` entering `StmtKind::{Block, ForkJoin, +If (both arms), For, Foreach, While, DoWhile, Forever, Repeat, Case +(each item's body), Timing/Wait bodies}` — **statement lists only**: +`begin … end`, `fork … join*`, function/task bodies, `initial`/`always` +bodies reached from the item (`ItemKind::{Always, Initial, Final, +Function, Task}` and a class method); a bodyless `if (x) y = 1;` is not +a scope, for the reason `scan_gen_block` refuses `!is_block`. Merge +statement regions into `collect`'s output through the same global sort ++ "drop a region whose `fence` precedes the previous `end`" filter so +`region_at`'s precondition holds; `range.rs` manufactures regions into +the same list — re-check its planner with a statement region inside a +selected range (a fence outranks a range, as today). Formatter: +`stmt_seq` gains `item_seq`'s two rules (a swallowed statement emits +nothing and contributes no separator); `Fmt::stmt` checks `opens_at`/ +`is_verbatim` before `with_meta` and drops the dangling `HardLine` the +way `item_docs` does; `block_doc`'s `dangling` already goes through the +fence-aware path. Idempotency gate: a region may only open at a +`line_start` (a fence written after `begin` on the same line is an +ordinary comment — pin it); comment preservation: a statement scope's +end includes the last statement's trailing comment and never leaks past +the enclosing `end`/`endfunction`/`join`. + +**31.3 Not this round, written down**: port lists and case-item label +lists (elements printed inside a `Group` mid-line; `Doc::Verbatim` is +column-0 and `Doc::Inline` carries no region indentation — a different +primitive), same-line fences (trailing trivia; unblocked since `Meta. +trailing` carries a span, still deferred). The cross-level pairing rule +stays: an item-level `off` closed by a statement-level `on` is an +unmatched `off` today and becomes a stray `on` in another scope — +behaviour unchanged, the fences.cases entry "a statement-level fence has +no effect this round" inverts, and `docs/features/format-fences/ +README.md` §"Out of scope" plus `README.md` "Turning the formatter off" +are rewritten in the same change. + +Proof: the `tests/fences.rs` triple (byte-exact + `verify_equivalence` ++ second-pass fixed point) for every new scope; corrupted-region attack +pairs for a statement region and a class-body region (the five in +`fences.rs` as the model; `verify.rs` untouched — a region is source +bytes, equivalence holds by construction); `protected_regions` and +`is_protected` signatures untouched so `lucisv/src/lint.rs` and +`lucisv_server/src/lint.rs` are byte-identical; corpus 814/820 and +byte-identical to 0.33.0 (zero fences); opentitan sweep unchanged +(grep its fence count first; if any exist inside statements, their +files may now move — list them). +Files: crates/vlog_formatter/src/{fence.rs, format/{stmt.rs, item.rs, +verbatim.rs, class.rs}, range.rs (planner check)}, tests/{fences.rs, +cases/fences.cases, ranges.rs}, docs/features/statement-fences/README.md +(new), amendments in format-fences / classes / shared-fence-filter +READMEs, README.md "Turning the formatter off", docs/topo.md §2.9-3 +struck (lead), TODO §31. Runs after §29/§30 merge (format/ collides +with §30's routine.rs only at merge; disjoint files otherwise — the +lead may start it in parallel if §30's files are settled). +- [ ] 31.1 class bodies (+ any other item-list carrier), cases, §2.9-3 +- [ ] 31.2 statement lists: scan, merge, `stmt_seq`/`stmt` rules, + line-start gate, trailing-comment end, range planner re-check +- [ ] 31.3 docs rewritten (format-fences README, README.md, the + inverted case), deferrals listed with reasons +- [ ] Attack pairs + the fences.rs triple per scope; verify.rs untouched +- [ ] Gates: fmt/clippy/`cargo test --workspace`; corpus 814/820 + byte-identical; opentitan fence census + sweep +- [ ] QA: fences in every statement scope listed and in the three + deferred places (must be inert, never corrupt); an `off` with no + `on` in each scope (runs to the scope end only); nested fences; + `--lines` over a fenced statement; `--fix` still declines inside +