Files
lucisv/crates/vlog_formatter/tests/cases/comments.cases
T
lucioandClaude Fable 5 3a503e1cf7 Fix comment drops before brackets and attribute/comment reordering
Resolves the owner's comment-drop report (comments-round-2). Three
root causes: (1) a comment between a module header's imports and its
#( landed as the first parameter port's leading comment, printed
inside the brackets -- fixed by take_before_open (the opening-bracket
twin of take_before_sep, no-op unless the cursor is on the bracket)
feeding new bracket-comment slots on Module/Instantiation/Instance;
(2) Meta kept attributes and leading comments in two lists and the
formatter emitted list order, swapping (* attr *) with an adjacent
comment -- fixed by merging on span.start, with the fence check
hoisted so fenced items still emit attrs as source bytes only;
(3) found in the sweep survivors: a lone instance's leading comments
were parsed and never printed (latent invariant-#3 violation).

Acceptance: the reported 14 corpus insertion failures -> 0; the
exhaustive 62k-trial per-line sweep fixed 95 positions with 0 newly
refusing; all 240 survivors are in families already parked by
comments-round and refuse on HEAD too. verify.rs byte-identical
(8 new rejection tests, sabotage-verified); corpus TSV md5
unchanged; fences suite untouched and green. 524 workspace tests.

Dev: Opus agent; QA: Sonnet agent (14/14 reproduced, HEAD-diffed
sweep, attack pass on every new slot); review in
docs/features/comments-round-2/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-19 10:47:20 -07:00

1194 lines
20 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
====
# a comment before the comma of a port list stays before it
module m (input logic a /* first */, input logic b);
endmodule
----
module m (input logic a /* first */, input logic b);
endmodule
====
# a line comment before the comma of a port list puts the comma on the next line
module m (input logic aaa // why
, input logic b);
endmodule
----
module m (
input logic aaa // why
,
input logic b
);
endmodule
====
# a comment before the comma of a parameter port list stays before it
module m #(parameter int A = 1 /* lo */, parameter int B = 2) ();
endmodule
----
module m #(parameter int A = 1 /* lo */, parameter int B = 2) ();
endmodule
====
# a comment before the comma of a named connection list stays before it
module m;
sub u (.a(x) /* one */, .b(y));
endmodule
----
module m;
sub u (.a(x) /* one */, .b(y));
endmodule
====
# a comment before the comma of an ordered connection list stays before it
module m;
sub u (x /* one */, y);
endmodule
----
module m;
sub u (x /* one */, y);
endmodule
====
# a comment before the closing paren of an ordered connection list stays inside it
module m;
sub u (x, y /* last */);
endmodule
----
module m;
sub u (
x,
y /* last */
);
endmodule
====
# a comment inside a connection's own parens stays inside them
module m;
sub u (.a(x /* verilator lint_off */), .b(y));
endmodule
----
module m;
sub u (.a(x /* verilator lint_off */), .b(y));
endmodule
====
# a comment before the comma of an assignment pattern stays before it
module m;
localparam logic [1:0] P = '{1'b0 /* lo */, 1'b1};
endmodule
----
module m;
localparam logic [1:0] P = '{1'b0 /* lo */, 1'b1};
endmodule
====
# a comment before the comma of a concatenation stays before it
module m;
assign y = {a /* hi */, b};
endmodule
----
module m;
assign y = {a /* hi */, b};
endmodule
====
# a comment before the comma of a declarator list stays before it
module m;
logic a /* one */, b;
endmodule
----
module m;
logic a /* one */, b;
endmodule
====
# a comment before the comma of an enum member list stays before it
module m;
typedef enum logic {A /* zero */, B} e_t;
endmodule
----
module m;
typedef enum logic {A /* zero */, B} e_t;
endmodule
====
# a comment before the closing brace of an enum member list stays inside it
module m;
typedef enum logic {A, B
// that is all
} e_t;
endmodule
----
module m;
typedef enum logic {
A,
B
// that is all
} e_t;
endmodule
====
# a comment before the comma of a function argument list stays before it
module m;
function int f(input int a /* lhs */, input int b);
return a + b;
endfunction
endmodule
----
module m;
function int f(input int a /* lhs */, input int b);
return a + b;
endfunction
endmodule
====
# two leading comments separated by one blank line keep exactly one
module m;
// first
// second
wire a;
endmodule
----
module m;
// first
// second
wire a;
endmodule
====
# several blank lines between leading comments still collapse to one
module m;
// a
// b
wire x;
endmodule
----
module m;
// a
// b
wire x;
endmodule
====
# a comment inside a replication stays inside it
module m;
assign y = {2{a /* why */, b}};
endmodule
----
module m;
assign y = {2{a /* why */, b}};
endmodule
====
# a comment inside a gate instance argument list stays inside it
module m;
and g1 (y /* out */, a, b);
endmodule
----
module m;
and g1 (y /* out */, a, b);
endmodule
====
# a comment between a continuous assignment's value and its semicolon stays before it
module m;
assign y = a /* verilator split_var */ ;
endmodule
----
module m;
assign y = a /* verilator split_var */;
endmodule
====
# a comment next to an operator inside a bracket expression stays next to it
module m;
assign y = x[a /* plus */ + b];
endmodule
----
module m;
assign y = x[a /* plus */ + b];
endmodule
====
# a comment between two header imports stays between them
module m import a::*;
// then the other one
import b::t;
(input x);
endmodule
----
module m
import a::*;
// then the other one
import b::t;
(input x);
endmodule
====
# a trailing comment on a header import stays on its line
module m import a::*; // the first
import b::t; (input x);
endmodule
----
module m
import a::*; // the first
import b::t;
(input x);
endmodule
====
# a comment inside an event list stays on its side of the separator
module m;
always @(posedge clk /* the clock */ or negedge rst_n) q <= d;
endmodule
----
module m;
always @(posedge clk /* the clock */ or negedge rst_n) q <= d;
endmodule
====
# a comment after an event list separator stays after it
module m;
always @(posedge clk, /* and */ negedge rst_n) q <= d;
endmodule
----
module m;
always @(posedge clk, /* and */ negedge rst_n) q <= d;
endmodule
====
# a comment before the closing paren of a parameter override list stays inside it
module m;
sub #(.A(1), .B(2)
// no more
) u (.c(z));
endmodule
----
module m;
sub #(
.A(1),
.B(2) // no more
) u (.c(z));
endmodule
====
# a comment between two case labels stays between them
module m;
always_comb case (x)
A /* first */, B: y = 1;
default: y = 0;
endcase
endmodule
----
module m;
always_comb
case (x)
A /* first */,
B:
y = 1;
default: y = 0;
endcase
endmodule
====
# a comment inside an inside-set stays inside it
module m;
assign y = a inside {1 /* one */, 2};
endmodule
----
module m;
assign y = a inside {1 /* one */, 2};
endmodule
====
# a comment before a module header's #( stays before it
module m
// why these defaults
#(parameter int P = 1) (input a);
endmodule
----
module m // why these defaults
#(parameter int P = 1) (input a);
endmodule
====
# a block comment before a module header's #( keeps the header on one line
module m /* generic */ #(parameter int P = 1) (input a);
endmodule
----
module m /* generic */ #(parameter int P = 1) (input a);
endmodule
====
# a comment before a module header's port list stays before it
module m
import p::*;
// the ports
(input a);
endmodule
----
module m
import p::*;
// the ports
(input a);
endmodule
====
# a comment before an instantiation's #( stays before it
module m;
sub
// override the width
#(.WIDTH(8)) u (.a(b));
endmodule
----
module m;
sub // override the width
#(.WIDTH(8)) u (.a(b));
endmodule
====
# a comment before an instantiation's #( survives the override list breaking
module m;
sub
// the long way round
#(.AAAAAAAAAAAAAAAA(1), .BBBBBBBBBBBBBBBB(2), .CCCCCCCCCCCCCCCC(3), .DDDDDDDDDDDDDDDD(4)) u (.a(b));
endmodule
----
module m;
sub // the long way round
#(
.AAAAAAAAAAAAAAAA(1),
.BBBBBBBBBBBBBBBB(2),
.CCCCCCCCCCCCCCCC(3),
.DDDDDDDDDDDDDDDD(4)
) u (.a(b));
endmodule
====
# a comment before an instance's connection list stays before it
module m;
sub u
// hook it up
(.a(b));
endmodule
----
module m;
sub u // hook it up
(.a(b));
endmodule
====
# a comment before an instantiation's #( inside a generate block
module m;
for (genvar i = 0; i < 4; i++) begin : g
sub
// per bit
#(.W(i)) u (.a(b));
end
endmodule
----
module m;
for (genvar i = 0; i < 4; i++) begin : g
sub // per bit
#(.W(i)) u (.a(b));
end
endmodule
====
# a comment written after an attribute stays after it
(* DONT_TOUCH = "yes" *)
// keep the tool honest
module m (input a);
endmodule
----
(* DONT_TOUCH = "yes" *)
// keep the tool honest
module m (input a);
endmodule
====
# an attribute written between two comments stays between them
// before
(* keep *)
// after
module m;
wire x;
endmodule
----
// before
(* keep *)
// after
module m;
wire x;
endmodule
====
# an attribute between two comments on a declaration
module m;
// before
(* keep *)
// after
logic x;
endmodule
----
module m;
// before
(* keep *)
// after
logic x;
endmodule
====
# a comment between two attributes stays between them
module m;
(* a *)
// between
(* b *)
logic x;
endmodule
----
module m;
(* a *)
// between
(* b *)
logic x;
endmodule
====
# a comment after a statement's attribute stays after it
module m;
initial begin
(* keep *)
// after
x = 1;
end
endmodule
----
module m;
initial begin
(* keep *)
// after
x = 1;
end
endmodule
====
# a comment after an attribute inside a generate block stays after it
module m;
if (1) begin : g
(* keep *)
// after
logic x;
end
endmodule
----
module m;
if (1) begin : g
(* keep *)
// after
logic x;
end
endmodule
====
# a blank line between an attribute and the comment after it survives
(* keep *)
// after a blank
module m;
endmodule
----
(* keep *)
// after a blank
module m;
endmodule
====
# a comment before a lone instance's name stays before it
module m;
sub #(.W(1))
// the instance
u (.a(b));
endmodule
----
module m;
sub #(.W(1)) // the instance
u (.a(b));
endmodule
====
# a block comment before a lone instance's name keeps it on one line
module m;
sub /* the one */ u (.a(b));
endmodule
----
module m;
sub /* the one */ u (.a(b));
endmodule