Files
lucisv/crates/vlog_formatter/tests/cases/comments.cases
T
lucioandClaude Fable 5 dc2181e1a2 Fix the four corpus-found formatter bugs: 46 verification errors -> 0
Every fix makes the AST carry a fact the formatter used to invent or
discard: SensSep preserves each event-list separator as written
(, stays , / or stays or, mixed lists round-trip); module-header
imports keep one statement per import; Instantiation::params and
Module::param_ports become Option<Vec> so empty #() survives; and
seven distinct comment-motion shapes (closing paren, empty
connection, declarator-to-;, after binary operator, case labels,
ternary, assign-to-value) keep comments where the source put them,
with Fmt::inline_comments as the single comment-run printer.

verify.rs is byte-identical: the net was right on all 46 refusing
files. Seven new rejection tests pin that judgment (sabotage-checked
by QA). Also removes a latent split_off underflow panic
(Parser::take_around) that QA reproduced on the pre-fix binary, and
fixes the ternary comment refusal from the earlier bug round.

Corpus after: 468/820 parse, 0 verification errors, 0 crashes —
corpus_check.sh exits 0 for the first time. Exactly 46 files moved
verification-error -> would-reformat by path diff; nothing else
changed. 111 workspace tests (was 98), case table 237 entries,
clippy silent.

Dev: Opus agent; QA: Sonnet agent (all claims independently
reproduced); review in docs/features/corpus-bugs/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-19 04:07:58 -07:00

702 lines
11 KiB
Plaintext

# leading line comment on a module
// top level comment
module m;
endmodule
----
// top level comment
module m;
endmodule
====
# leading comment on a declaration
module m;
// the data bus
wire [7:0] bus;
endmodule
----
module m;
// the data bus
wire [7:0] bus;
endmodule
====
# trailing comment on a declaration
module m;
wire [7:0] bus; // the data bus
endmodule
----
module m;
wire [7:0] bus; // the data bus
endmodule
====
# block comment before a module
/* a block comment */
module m;
endmodule
----
/* a block comment */
module m;
endmodule
====
# multi-line block comment keeps its shape relative to its own opening column
module m;
/*
* doc block
*/
wire w;
endmodule
----
module m;
/*
* doc block
*/
wire w;
endmodule
====
# comment between statements inside a block
module m;
always_comb begin
a = 1;
// separator
b = 2;
end
endmodule
----
module m;
always_comb begin
a = 1;
// separator
b = 2;
end
endmodule
====
# trailing comment on a statement
module m;
always_comb begin
a = 1; // set a
end
endmodule
----
module m;
always_comb begin
a = 1; // set a
end
endmodule
====
# comment inside a port list forces the list to break
module m(
input a, // first
input b
);
endmodule
----
module m (
input a, // first
input b
);
endmodule
====
# comment inside a connection list forces the list to break
module m;
sub u0(
.a(x), // hook up x
.b(y)
);
endmodule
----
module m;
sub u0 (
.a(x), // hook up x
.b(y)
);
endmodule
====
# comment on a case item
module m;
always_comb begin
case (sel)
// the zero case
2'd0: y = a;
2'd1: y = b; // the one case
default: y = 0;
endcase
end
endmodule
----
module m;
always_comb begin
case (sel)
// the zero case
2'd0: y = a;
2'd1: y = b; // the one case
default: y = 0;
endcase
end
endmodule
====
# several consecutive comment lines are kept together
module m;
// line one
// line two
// line three
wire w;
endmodule
----
module m;
// line one
// line two
// line three
wire w;
endmodule
====
# blank lines around comments are collapsed to one
module m;
wire a;
// a comment after several blank lines
wire b;
endmodule
----
module m;
wire a;
// a comment after several blank lines
wire b;
endmodule
====
# comment at the very end of a module body
module m;
wire w;
// trailing note
endmodule
----
module m;
wire w;
// trailing note
endmodule
====
# comment after endmodule
module m;
endmodule
// after the module
----
module m;
endmodule
// after the module
====
# comment between two modules
module a;
endmodule
// between
module b;
endmodule
----
module a;
endmodule
// between
module b;
endmodule
====
# comment before else
module m;
always_comb begin
if (a) begin
y = 0;
// explain the else
end else begin
y = 1;
end
end
endmodule
----
module m;
always_comb begin
if (a) begin
y = 0;
// explain the else
end else begin
y = 1;
end
end
endmodule
====
# comment on a parameter port
module m #(
// the width
parameter WIDTH = 8
) ();
endmodule
----
module m #(
// the width
parameter WIDTH = 8
) ();
endmodule
====
# comment inside a concatenation forces the group to break
module m;
assign y = {
a, // high
b
};
endmodule
----
module m;
assign y = {
a, // high
b
};
endmodule
====
# leading comment on an instance
module m;
// instantiate the submodule
sub u0(.a(x));
endmodule
----
module m;
// instantiate the submodule
sub u0 (.a(x));
endmodule
====
# comment in an empty module body
module m;
// nothing here yet
endmodule
----
module m;
// nothing here yet
endmodule
====
# preprocessor directives are passed through verbatim
`include "defs.svh"
`define WIDTH 8
module m;
`ifdef FAST
wire fast;
`else
wire slow;
`endif
endmodule
----
`include "defs.svh"
`define WIDTH 8
module m;
`ifdef FAST
wire fast;
`else
wire slow;
`endif
endmodule
====
# attribute instances are passed through
(* keep = "true" *)
module m;
(* dont_touch *)
wire w;
endmodule
----
(* keep = "true" *)
module m;
(* dont_touch *)
wire w;
endmodule
====
# multi-line block comment already indented inside a block
module m;
initial begin
/* banner
line two
line three */
x = 1;
end
endmodule
----
module m;
initial begin
/* banner
line two
line three */
x = 1;
end
endmodule
====
# continuation lines left of the opening column land on the new indent
module m;
/* opener
one
two */
wire w;
endmodule
----
module m;
/* opener
one
two */
wire w;
endmodule
====
# block comment inside the parens of an implicit sensitivity list
module m;
always @( /* everything */ * ) y = a;
endmodule
----
module m;
always @(/* everything */ *) y = a;
endmodule
====
# comment after the star of an implicit sensitivity list
module m;
always @( * /* everything */ ) y = a;
endmodule
----
module m;
always @( * /* everything */) y = a;
endmodule
====
# a continued `define inside a module keeps its continuation indent
module m;
`define FOO(a) \
do_something(a)
wire w;
endmodule
----
module m;
`define FOO(a) \
do_something(a)
wire w;
endmodule
====
# comment inside a call argument list forces it to break
module m;
assign z = f(a, // first
b);
endmodule
----
module m;
assign z = f(
a, // first
b
);
endmodule
====
# comment inside an assignment pattern forces it to break
module m;
assign w = '{a: 1, // one
b: 2};
endmodule
----
module m;
assign w = '{
a: 1, // one
b: 2
};
endmodule
====
# comment just inside a parenthesized expression forces it to break
module m;
assign v = ( // why
a + b);
endmodule
----
module m;
assign v = (
// why
a + b
);
endmodule
====
# comment between the operands of a binary expression
module m;
assign y = (a // hi
+ b);
endmodule
----
module m;
assign y = (
a // hi
+ b
);
endmodule
====
# comment before the operator of a long operator chain
module m;
assign ready = first
// wait for the second one too
&& second;
endmodule
----
module m;
assign ready = first // wait for the second one too
&& second;
endmodule
====
# comment after a binary operator stays on the operator's line
module m;
assign fetch_addr_d = (branch_i ? addr_i : {fetch_addr_q[31:2], 2'b00}) +
// Current address + 4
{{29{1'b0}}, (valid_new_req & ~valid_req_q), 2'b00};
endmodule
----
module m;
assign fetch_addr_d = (branch_i ? addr_i : {fetch_addr_q[31:2], 2'b00}) + // Current address + 4
{{29{1'b0}}, (valid_new_req & ~valid_req_q), 2'b00};
endmodule
====
# comments on both sides of a binary operator
module m;
assign y = a // pre
&& // post
b;
endmodule
----
module m;
assign y = a // pre
&& // post
b;
endmodule
====
# a block comment after an operator stays on its line
module m;
assign y = a && /* still true */ b;
endmodule
----
module m;
assign y = a && /* still true */ b;
endmodule
====
# two line comments after an operator each keep their own line
module m;
assign y = a && // one
// two
b;
endmodule
----
module m;
assign y = a && // one
// two
b;
endmodule
====
# comment between `=` and the value it assigns
module m;
assign skid_valid_d =
// Branches invalidate the skid buffer
branch_i;
endmodule
----
module m;
assign skid_valid_d = // Branches invalidate the skid buffer
branch_i;
endmodule
====
# several comments between `=` and the value
module m;
assign rx_timeout_count_d =
// don't count if timeout feature not enabled
// will never reach timeout val
(uart_rxto_en == 1'b0) ? 24'd0 : count_q;
endmodule
----
module m;
assign rx_timeout_count_d = // don't count if timeout feature not enabled
// will never reach timeout val
(uart_rxto_en == 1'b0) ? 24'd0 : count_q;
endmodule
====
# comment after the `?` of a ternary
module m;
assign y = cond ?
// take the fast path
a : b;
endmodule
----
module m;
assign y = cond
? // take the fast path
a
: b;
endmodule
====
# comment after the `:` of a ternary
module m;
assign y = cond ? a : // otherwise
b;
endmodule
----
module m;
assign y = cond
? a
: // otherwise
b;
endmodule
====
# comments in every position inside a ternary
module m;
assign y = cond /* c1 */ ? /* c2 */ a /* c3 */ : /* c4 */ b;
endmodule
----
module m;
assign y = cond /* c1 */ ? /* c2 */ a /* c3 */ : /* c4 */ b;
endmodule
====
# comment between two case labels
module m;
always_comb begin
case (operator_i)
// Adder OPs
ALU_SUB,
// Comparator OPs
ALU_EQ, ALU_NE,
ALU_GE: y = 1'b1;
default: y = 1'b0;
endcase
end
endmodule
----
module m;
always_comb begin
case (operator_i)
// Adder OPs
ALU_SUB,
// Comparator OPs
ALU_EQ,
ALU_NE,
ALU_GE:
y = 1'b1;
default: y = 1'b0;
endcase
end
endmodule
====
# trailing comment on a case label
module m;
always_comb begin
case (s)
A, // first
B: y = 1'b1;
default: y = 1'b0;
endcase
end
endmodule
----
module m;
always_comb begin
case (s)
A, // first
B:
y = 1'b1;
default: y = 1'b0;
endcase
end
endmodule
====
# comments before the closing paren of a parameter port list
module prim_clock_buf #(
// Turning off these verilator lints because keeping these parameters makes it
/* verilator lint_off UNUSED */
parameter bit NoFpgaBuf = 1'b0, // serves no function in generic
parameter bit RegionSel = 1'b0 // serves no function in generic
/* verilator lint_on UNUSED */
) (
input clk_i,
output logic clk_o
);
endmodule
----
module prim_clock_buf #(
// Turning off these verilator lints because keeping these parameters makes it
/* verilator lint_off UNUSED */
parameter bit NoFpgaBuf = 1'b0, // serves no function in generic
parameter bit RegionSel = 1'b0 // serves no function in generic
/* verilator lint_on UNUSED */
) (input clk_i, output logic clk_o);
endmodule
====
# a continued trailing comment before the closing paren of a port list
module m (
input logic a,
output logic b // we are executing a taken branch
// instruction
);
endmodule
----
module m (
input logic a,
output logic b // we are executing a taken branch
// instruction
);
endmodule
====
# comment inside an otherwise empty parameter port list
module m #(
/* nothing to override */
) (input a);
endmodule
----
module m #(
/* nothing to override */
) (input a);
endmodule
====
# comment inside an otherwise empty port list
module m (
/* no ports */
);
endmodule
----
module m (
/* no ports */
);
endmodule
====
# comment inside an empty connection
module m;
edge_propagator_ack i_ack (
.clk_tx_i,
.ack_tx_o (/* unused */),
.edge_o
);
endmodule
----
module m;
edge_propagator_ack i_ack (.clk_tx_i, .ack_tx_o(/* unused */), .edge_o);
endmodule
====
# block comment between a declarator and its semicolon
module m;
logic [7:0] data_state /* verilator split_var */;
logic en_latch /* verilator clock_enable */;
endmodule
----
module m;
logic [7:0] data_state /* verilator split_var */;
logic en_latch /* verilator clock_enable */;
endmodule
====
# comment before the semicolon plus one after it
module m;
idx_t [7:0] index_nodes /* verilator split_var */; // propagates indices
endmodule
----
module m;
idx_t [7:0] index_nodes /* verilator split_var */; // propagates indices
endmodule
====
# comment before the semicolon of a parameter and a port declaration
module m (a);
input a /* async */;
parameter int W = 8 /* width */;
endmodule
----
module m (a);
input a /* async */;
parameter int W = 8 /* width */;
endmodule