From 7f65a2449a2c32ce856d19010e885288ef3c6f07 Mon Sep 17 00:00:00 2001 From: Guoliang Chen Date: Sat, 29 Aug 2026 13:43:24 -0700 Subject: [PATCH] The merged-tree pins both lanes promised each other MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The refusal pin a_comment_before_a_call_in_a_condition_is_still_refused flips exactly as Lane B's Handshake said it should now that take_gap and header_parens share a tree: the shape formats, the comment stays inside the parens, fixed point asserted, plus the keymgr .cases entry. And the standing invariant-4 template applied to the directive capture: three (input, corrupted output) pairs — a dropped `else arm, swapped arms, a lost `endif — each asserted rejected by the safety net. Both were flagged by the serial round as the lead's first post-merge task; done by the lead. Co-Authored-By: Claude Fable 5 --- .../tests/cases/directive_in_statements.cases | 24 ++++++++++ crates/vlog_formatter/tests/verification.rs | 47 +++++++++++++++---- 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/crates/vlog_formatter/tests/cases/directive_in_statements.cases b/crates/vlog_formatter/tests/cases/directive_in_statements.cases index a4a1494..c7eb8e3 100644 --- a/crates/vlog_formatter/tests/cases/directive_in_statements.cases +++ b/crates/vlog_formatter/tests/cases/directive_in_statements.cases @@ -237,3 +237,27 @@ module m; // after the block wire after; endmodule +==== +# the keymgr shape: the take_gap parser fix and header_parens in one tree — +# the comment written after `if (` stays inside the parens (the last of +# bucket 2's 12; merged-tree pin the serial round could not add itself) +module m; + function automatic int f(); + if (// why + !en() || b + ) begin + return 1; + end + endfunction +endmodule +---- +module m; + function automatic int f(); + if ( + // why + !en() || b + ) begin + return 1; + end + endfunction +endmodule diff --git a/crates/vlog_formatter/tests/verification.rs b/crates/vlog_formatter/tests/verification.rs index 8171435..c11e153 100644 --- a/crates/vlog_formatter/tests/verification.rs +++ b/crates/vlog_formatter/tests/verification.rs @@ -1344,16 +1344,45 @@ fn the_bucket_two_corruptions_are_still_rejected() { /// A comment written just after a statement header's `(` is queued by the /// parser and drained onto the first bracket it meets — so when the condition -/// starts with a call, `CallComments::before_open` swallows it and the -/// comment prints between the callee and its `(`. `header_parens` cannot take -/// it back: it never reaches the body's leading comments. Pinned as a refusal -/// (the file is left alone); the fix belongs in the parser's -/// `take_before_open`, which drains the whole pending queue instead of the -/// comments actually written in front of the bracket. +/// started with a call, `CallComments::before_open` swallowed it and the +/// comment printed between the callee and its `(`. This was pinned as a +/// refusal until the directive-in-statements round delivered the parser's +/// `take_gap` fix (2026-08-29); the pin flips exactly as the Handshake said +/// it should: the shape now formats, the comment keeps its place inside the +/// parens, and the round trip is a fixed point. The last of bucket 2's 12. #[test] -fn a_comment_before_a_call_in_a_condition_is_still_refused() { - expect_refusal( - "module m;\n function automatic int f();\n if (// why\n !en() || b\n ) begin\n return 1;\n end\n endfunction\nendmodule\n", +fn a_comment_before_a_call_in_a_condition_now_formats() { + let input = "module m;\n function automatic int f();\n if (// why\n !en() || b\n ) begin\n return 1;\n end\n endfunction\nendmodule\n"; + let expected = "module m;\n function automatic int f();\n if (\n // why\n !en() || b\n ) begin\n return 1;\n end\n endfunction\nendmodule\n"; + let config = Config::default(); + let once = format_source(input, &config).expect("the delivered handshake formats this"); + assert_eq!(once, expected, "the comment stays inside the parens"); + let twice = format_source(&once, &config).expect("and the result still formats"); + assert_eq!(twice, once, "fixed point"); +} + +/// The standing template applied to directive-in-statements' verbatim +/// capture (the round could not add these itself — this file was Lane B's +/// during the wave): crafted (input, corrupted output) pairs the capture +/// could plausibly produce if its extent scan slipped, each asserted +/// rejected. An `` `else `` arm dropped, the arms swapped, and the +/// `` `endif `` lost — every one is a divergence the safety net must see. +#[test] +fn a_corrupted_directive_capture_is_rejected() { + // The `` `else `` arm dropped from the captured region. + expect_divergence( + "module m;\n assign x =\n`ifdef A\n a;\n`else\n b;\n`endif\nendmodule\n", + "module m;\n assign x =\n`ifdef A\n a;\n`endif\nendmodule\n", + ); + // The two arms swapped. + expect_divergence( + "module m;\n assign x =\n`ifdef A\n a;\n`else\n b;\n`endif\nendmodule\n", + "module m;\n assign x =\n`ifdef A\n b;\n`else\n a;\n`endif\nendmodule\n", + ); + // The `` `endif `` lost, leaking the region into the module tail. + expect_divergence( + "module m;\n assign x =\n`ifdef A\n a;\n`else\n b;\n`endif\nendmodule\n", + "module m;\n assign x =\n`ifdef A\n a;\n`else\n b;\nendmodule\n", ); }