Files
lucisv/crates/vlog_formatter/tests/cases/fences.cases
T
lucioandClaude Fable 5 a0ae5e5fa8 Format fences at statement level and inside class bodies
TODO section 31 (coverage_gaps M9, docs/topo.md 2.9-3).
fence::collect enters class bodies, functions, tasks and always/
initial/final blocks, and statement lists - begin/end, fork/join and
every compound body - through scan_stmt_scope/scan_nested_stmt on the
one scan_units both scope kinds share; stmt_docs/stmt_seq obey the two
swallowed-unit rules item_docs/item_seq had; fence regions merge into
range.rs's plan, which was load-bearing (a fenced statement has no
verbatim run behind it; proved by disabling it). A region opens only at
a line start (opens_line) - the rule the format-fences README has
stated since round 1 - so a fence after code on the same line is an
ordinary comment everywhere, which narrows one accidental item-level
shape (module m; // lucisv: off) and is ruled a drift fix. Deferred
with reasons: port lists, case-item label lists, same-line fences, a
property's locals. verify.rs, lucisv/src/lint.rs and
lucisv_server/src/lint.rs untouched.
Proof: 3 244 tests / 48 binaries, fences.cases 25 -> 38 with the
statement-level entry inverted, corpus 814/820 and 860 files byte-
identical to 0.34.0, opentitan: 4 of its 9 fenced files now keep their
fenced bytes and are fixed points, --check counts identical; 3 348
fence-injection trials with no new refusals.

docs/features/statement-fences/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-09-03 03:40:12 -07:00

670 lines
9.8 KiB
Plaintext

# a fenced region comes out byte-exact, weird spacing and all
module m;
// verilog_format: off
wire [3:0] a = 4'h1;
wire [31:0] bb= 32'h2;
// verilog_format: on
wire c;
endmodule
----
module m;
// verilog_format: off
wire [3:0] a = 4'h1;
wire [31:0] bb= 32'h2;
// verilog_format: on
wire c;
endmodule
====
# the lucisv alias fences the same region
module m;
// lucisv: off
wire [3:0] a;
// lucisv: on
wire b;
endmodule
----
module m;
// lucisv: off
wire [3:0] a;
// lucisv: on
wire b;
endmodule
====
# the two spellings are interchangeable across one region
module m;
// verilog_format: off
wire a;
// lucisv: on
wire b;
endmodule
----
module m;
// verilog_format: off
wire a;
// lucisv: on
wire b;
endmodule
====
# a region keeps its own indentation, first line included
module m;
// lucisv: off
wire a;
wire b;
// lucisv: on
wire c;
endmodule
----
module m;
// lucisv: off
wire a;
wire b;
// lucisv: on
wire c;
endmodule
====
# a fence at the top of the file
// lucisv: off
module m; endmodule
// lucisv: on
module n;
wire a;
endmodule
----
// lucisv: off
module m; endmodule
// lucisv: on
module n;
wire a;
endmodule
====
# an unmatched off runs to the end of the file
module m;
wire a;
endmodule
// lucisv: off
module n; wire b; endmodule
----
module m;
wire a;
endmodule
// lucisv: off
module n; wire b; endmodule
====
# an unmatched off runs to the end of the module body, not past endmodule
module m;
wire a;
// lucisv: off
wire b;
wire c;
endmodule
module n;
wire d;
endmodule
----
module m;
wire a;
// lucisv: off
wire b;
wire c;
endmodule
module n;
wire d;
endmodule
====
# an unmatched off keeps the comment trailing its last item
module m;
// lucisv: off
wire a; // note
endmodule
----
module m;
// lucisv: off
wire a; // note
endmodule
====
# an unmatched off swallows the scope's dangling comments too
module m;
// lucisv: off
wire a;
// dangling one
// dangling two
endmodule
----
module m;
// lucisv: off
wire a;
// dangling one
// dangling two
endmodule
====
# an on written after endmodule cannot close an off inside the module
module m;
// lucisv: off
wire a;
endmodule
// lucisv: on
module n;
wire b;
endmodule
----
module m;
// lucisv: off
wire a;
endmodule
// lucisv: on
module n;
wire b;
endmodule
====
# two regions in one file
module m;
// lucisv: off
wire a;
// lucisv: on
wire b;
// lucisv: off
wire c;
// lucisv: on
wire d;
endmodule
----
module m;
// lucisv: off
wire a;
// lucisv: on
wire b;
// lucisv: off
wire c;
// lucisv: on
wire d;
endmodule
====
# a fence with trailing text is not a fence
module m;
// lucisv: off (just for now)
wire a;
// lucisv: on
wire b;
endmodule
----
module m;
// lucisv: off (just for now)
wire a;
// lucisv: on
wire b;
endmodule
====
# a block comment is not a fence
module m;
/* lucisv: off */
wire a;
/* lucisv: on */
wire b;
endmodule
----
module m;
/* lucisv: off */
wire a;
/* lucisv: on */
wire b;
endmodule
====
# a fence written after code on the same line is not a fence
module m;
wire z; // lucisv: off
wire a;
endmodule
----
module m;
wire z; // lucisv: off
wire a;
endmodule
====
# an on with no open off is an ordinary comment
module m;
// lucisv: on
wire a;
endmodule
----
module m;
// lucisv: on
wire a;
endmodule
====
# a second off inside an open region is just text, the first on closes
module m;
// lucisv: off
wire a;
// lucisv: off
wire b;
// lucisv: on
wire c;
// lucisv: on
wire d;
endmodule
----
module m;
// lucisv: off
wire a;
// lucisv: off
wire b;
// lucisv: on
wire c;
// lucisv: on
wire d;
endmodule
====
# a region of nothing but comments
module m;
// lucisv: off
// +-------+
// | ascii |
// +-------+
// lucisv: on
wire a;
endmodule
----
module m;
// lucisv: off
// +-------+
// | ascii |
// +-------+
// lucisv: on
wire a;
endmodule
====
# comments before the off fence are still formatted, and never dropped
module m;
wire z;
// doc for the table
// lucisv: off
wire a;
// lucisv: on
wire b;
endmodule
----
module m;
wire z;
// doc for the table
// lucisv: off
wire a;
// lucisv: on
wire b;
endmodule
====
# valid-but-ugly code inside a region is left exactly as written
module m;
// lucisv: off
always@(posedge clk)if(en)q<=d;else q <= 1'b0;
assign y = {a,b , c} ;
// lucisv: on
assign z = a + b;
endmodule
----
module m;
// lucisv: off
always@(posedge clk)if(en)q<=d;else q <= 1'b0;
assign y = {a,b , c} ;
// lucisv: on
assign z = a + b;
endmodule
====
# attributes and directives inside a region are source bytes like anything else
module m;
// lucisv: off
(* keep *) wire a;
`ifdef FOO
wire b;
`endif
// lucisv: on
wire c;
endmodule
----
module m;
// lucisv: off
(* keep *) wire a;
`ifdef FOO
wire b;
`endif
// lucisv: on
wire c;
endmodule
====
# fences work in a package body
package p;
// lucisv: off
localparam int A =1;
// lucisv: on
localparam int B =2;
endpackage
----
package p;
// lucisv: off
localparam int A =1;
// lucisv: on
localparam int B = 2;
endpackage
====
# fences work inside a generate begin..end block
module m;
generate
if (X) begin : g
// lucisv: off
wire a;
// lucisv: on
wire b;
end
endgenerate
endmodule
----
module m;
generate
if (X) begin : g
// lucisv: off
wire a;
// lucisv: on
wire b;
end
endgenerate
endmodule
====
# a statement-level fence fences the statements between it and the on
module m;
always @(*) begin
// lucisv: off
x = 1;
// lucisv: on
y = 2;
end
endmodule
----
module m;
always @(*) begin
// lucisv: off
x = 1;
// lucisv: on
y = 2;
end
endmodule
====
# a statement region keeps its own indentation, first line included
module m;
initial begin
// lucisv: off
x <= 8'h0a;
yy <= 8'h0b;
// lucisv: on
z <= 1;
end
endmodule
----
module m;
initial begin
// lucisv: off
x <= 8'h0a;
yy <= 8'h0b;
// lucisv: on
z <= 1;
end
endmodule
====
# an unmatched off runs to the end of the block, not past its end
module m;
initial begin
// lucisv: off
x = 1;
y = 2; // note
end
initial begin
z = 3;
end
endmodule
----
module m;
initial begin
// lucisv: off
x = 1;
y = 2; // note
end
initial begin
z = 3;
end
endmodule
====
# an unmatched off in a fork body stops at the join
module m;
initial fork
// lucisv: off
p1 ();
p2 ();
join_none
endmodule
----
module m;
initial
fork
// lucisv: off
p1 ();
p2 ();
join_none
endmodule
====
# fences work in a function body and stop at endfunction
module m;
function int f();
// lucisv: off
int a =1;
// lucisv: on
return a;
endfunction
endmodule
----
module m;
function int f();
// lucisv: off
int a =1;
// lucisv: on
return a;
endfunction
endmodule
====
# a fence inside a case item's block body fences that block only
module m;
always @(*) begin
case (s)
2'b00: begin
// lucisv: off
a = 1;
// lucisv: on
b = 2;
end
default: c = 3;
endcase
end
endmodule
----
module m;
always @(*) begin
case (s)
2'b00: begin
// lucisv: off
a = 1;
// lucisv: on
b = 2;
end
default: c = 3;
endcase
end
endmodule
====
# a fence written after begin on the same line is an ordinary comment
module m;
always @(*) begin // lucisv: off
x = 1;
y = 2;
end
endmodule
----
module m;
always @(*) begin
// lucisv: off
x = 1;
y = 2;
end
endmodule
====
# a fence written after a module header on the same line is an ordinary comment
module m; // lucisv: off
wire a;
wire b;
endmodule
----
module m;
// lucisv: off
wire a;
wire b;
endmodule
====
# a fence inside a bodyless if is an ordinary comment
module m;
always @(*)
// lucisv: off
if (c) x = 1;
endmodule
----
module m;
always @(*)
// lucisv: off
if (c) x = 1;
endmodule
====
# fences work inside a class body
class c;
int a;
// lucisv: off
int b =2;
int cc =3;
// lucisv: on
int d;
endclass
----
class c;
int a;
// lucisv: off
int b =2;
int cc =3;
// lucisv: on
int d;
endclass
====
# an unmatched off in a class body stops at endclass
class c;
// lucisv: off
int a;
endclass
class d;
int b;
endclass
----
class c;
// lucisv: off
int a;
endclass
class d;
int b;
endclass
====
# a fence around a nested class fences the whole nested class
class outer;
// lucisv: off
class inner;
int x;
endclass
// lucisv: on
int y;
endclass
----
class outer;
// lucisv: off
class inner;
int x;
endclass
// lucisv: on
int y;
endclass
====
# a port-list fence is an ordinary comment, and the port list still formats
module m (
// lucisv: off
input logic a,
output logic b
);
endmodule
----
module m (
// lucisv: off
input logic a,
output logic b
);
endmodule
====
# a case-item label fence is an ordinary comment
module m;
always @(*) begin
case (s)
// lucisv: off
2'b00: a = 1;
2'b01: a = 2;
endcase
end
endmodule
----
module m;
always @(*) begin
case (s)
// lucisv: off
2'b00: a = 1;
2'b01: a = 2;
endcase
end
endmodule
====
# a blank line before the off fence survives, collapsed to one
module m;
wire z;
// lucisv: off
wire a;
// lucisv: on
endmodule
----
module m;
wire z;
// lucisv: off
wire a;
// lucisv: on
endmodule
====
# a region ending the file keeps exactly one final newline
module m;
wire a;
endmodule
// lucisv: off
`define WIDTH 8
----
module m;
wire a;
endmodule
// lucisv: off
`define WIDTH 8
====