Files
lucisv/crates/vlog_formatter/tests/cases/alignment.cases
T
lucioandClaude Fable 5 003e0766e9 Add alignment inference and the format cache (round 17)
alignment: Verible-style alignment-intent inference for ANSI ports
(name column), named connections (paren column) and parameter items
(name and = columns). A group aligns iff the author asked: >=4
excess spaces somewhere, or the group already sits consistently at
one column -- single-space code keeps today's bytes exactly (zero
churn across all 397 pre-existing cases; corpus outcome TSV
byte-identical while 291/578 formattable files change content).
Fixed-point by construction: aligned output re-infers the same
targets, flush re-infers flush; the whole verdict is decided at
document-build time (a printer-side split diverged ibex_core.sv at
width 60 during development -- caught by a 2312-run config sweep and
redesigned). Groups break at comments/attributes/directives/blank
lines; a group that cannot fit falls back to flush whole, never
mixed. No lexer changes: name_span plus the source answers every
spacing question. QA's sabotage confirmed the runtime convergence
check catches the predicted flip-flop even with the unit test gone.

format-cache: warm runs skip verified-clean files. Key = (FNV-1a 64
content hash, resolved config values, vfmt version), path-keyed;
only the fixed-point verdict is ever cached, so --check/--diff can
never go stale and a hit can only skip work, never produce output.
One atomic text file in self-gitignoring .vfmt_cache/; --no-cache /
--cache-dir; 8-process concurrency clean. Warm corpus check: 2x at
default threads, 7.7x single-threaded.

655 workspace tests. Dev: 2 Opus agents (both isolated their gates
from the other's churn via HEAD-reverted scratchpad copies); QA: 2
Sonnet agents; reviews in docs/features/{alignment,format-cache}/
README.md.

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

554 lines
11 KiB
Plaintext

# ports: a hand-aligned group stays aligned
module m (
input wire clk,
input wire [WIDTH-1:0] data,
output logic valid
);
endmodule
----
module m (
input wire clk,
input wire [WIDTH-1:0] data,
output logic valid
);
endmodule
====
# ports: single spaces stay flush, and a list that fits collapses
module m (
input wire clk,
input wire [WIDTH-1:0] data,
output logic valid
);
endmodule
----
module m (input wire clk, input wire [WIDTH-1:0] data, output logic valid);
endmodule
====
# ports: four excess spaces on one line converge the group to aligned
module m (
input wire clk,
input wire [WIDTH-1:0] data,
output logic valid
);
endmodule
----
module m (
input wire clk,
input wire [WIDTH-1:0] data,
output logic valid
);
endmodule
====
# ports: three excess spaces are below the threshold
module m (
input wire clk,
input wire [WIDTH-1:0] data,
output logic valid
);
endmodule
----
module m (input wire clk, input wire [WIDTH-1:0] data, output logic valid);
endmodule
====
# ports: equal prefixes have nothing to align, so the padding collapses
module m (
input wire clk,
input wire rst,
input wire ena
);
endmodule
----
module m (input wire clk, input wire rst, input wire ena);
endmodule
====
# ports: a standalone comment splits the group in two
module m (
input wire clk,
input wire [WIDTH-1:0] data,
// the outputs
output logic valid,
output logic [7:0] count
);
endmodule
----
module m (
input wire clk,
input wire [WIDTH-1:0] data,
// the outputs
output logic valid,
output logic [7:0] count
);
endmodule
====
# ports: a compiler directive splits the group in two
module m (
input wire clk,
input wire [WIDTH-1:0] data,
`ifdef DEBUG
output logic valid,
output logic [7:0] count
`endif
);
endmodule
----
module m (
input wire clk,
input wire [WIDTH-1:0] data,
`ifdef DEBUG
output logic valid,
output logic [7:0] count
`endif
);
endmodule
====
# ports: an aligned line past the limit takes the whole group back to flush
module m (
input wire [SOME_REALLY_LONG_PARAMETER_NAME_XXXXXXXXXXXXXXXXXXXX-1:0] b,
input wire a_very_long_signal_name_here_that_is_quite_long_indeed_yes,
output logic c
);
endmodule
----
module m (
input wire [SOME_REALLY_LONG_PARAMETER_NAME_XXXXXXXXXXXXXXXXXXXX-1:0] b,
input wire a_very_long_signal_name_here_that_is_quite_long_indeed_yes,
output logic c
);
endmodule
====
# ports: a continuation port has no prefix to pad, so the run ends at it
module m (
input wire clk,
input wire [3:0] sel, more,
output logic valid
);
endmodule
----
module m (
input wire clk,
input wire [3:0] sel,
more,
output logic valid
);
endmodule
====
# ports: an aligned group keeps its trailing comments
module m (
input wire clk, // the clock
input wire [WIDTH-1:0] data,
output logic valid // high for one cycle
);
endmodule
----
module m (
input wire clk, // the clock
input wire [WIDTH-1:0] data,
output logic valid // high for one cycle
);
endmodule
====
# ports: alignment holds a list open that would otherwise fit on one line
module m (
input wire clk,
output logic q
);
endmodule
----
module m (
input wire clk,
output logic q
);
endmodule
====
# connections: a hand-aligned group stays aligned
module m;
sub u (
.clk (clk),
.reset_n (rst_n),
.data_valid (dv)
);
endmodule
----
module m;
sub u (
.clk (clk),
.reset_n (rst_n),
.data_valid (dv)
);
endmodule
====
# connections: tight parens stay tight and the list collapses
module m;
sub u (
.clk(clk),
.reset_n(rst_n),
.data_valid(dv)
);
endmodule
----
module m;
sub u (.clk(clk), .reset_n(rst_n), .data_valid(dv));
endmodule
====
# connections: four spaces before one `(` converge the group to aligned
module m;
sub u (
.clk (clk),
.reset_n(rst_n),
.data_valid(dv)
);
endmodule
----
module m;
sub u (
.clk (clk),
.reset_n (rst_n),
.data_valid (dv)
);
endmodule
====
# connections: one space each is not a hint
module m;
sub u (
.clk (clk),
.reset_n (rst_n),
.data_valid (dv)
);
endmodule
----
module m;
sub u (.clk(clk), .reset_n(rst_n), .data_valid(dv));
endmodule
====
# connections: an author who over-padded gets the computed column
module m;
sub u (
.clk (clk),
.reset_n (rst_n),
.data_valid (dv)
);
endmodule
----
module m;
sub u (
.clk (clk),
.reset_n (rst_n),
.data_valid (dv)
);
endmodule
====
# connections: `.*` and an implicit `.name` are not alignable and split the group
module m;
sub u (
.clk (clk),
.reset_n (rst_n),
.data_valid,
.ready (rdy),
.last_thing (lt)
);
endmodule
----
module m;
sub u (
.clk (clk),
.reset_n (rst_n),
.data_valid,
.ready (rdy),
.last_thing (lt)
);
endmodule
====
# connections: a standalone comment splits the group
module m;
sub u (
.clk (clk),
.reset_n (rst_n),
// the data side
.data_valid (dv),
.ready (rdy)
);
endmodule
----
module m;
sub u (
.clk (clk),
.reset_n (rst_n),
// the data side
.data_valid (dv),
.ready (rdy)
);
endmodule
====
# connections: equal-width names have nothing to align
module m;
sub u (
.clk_a (a),
.clk_b (b),
.clk_c (c)
);
endmodule
----
module m;
sub u (.clk_a(a), .clk_b(b), .clk_c(c));
endmodule
====
# params: a hand-aligned `=` column stays aligned
module m;
localparam int A = 1;
localparam int LONGER = 22;
endmodule
----
module m;
localparam int A = 1;
localparam int LONGER = 22;
endmodule
====
# params: single spaces stay flush
module m;
localparam int A = 1;
localparam int LONGER = 22;
endmodule
----
module m;
localparam int A = 1;
localparam int LONGER = 22;
endmodule
====
# params: four excess spaces before one `=` converge the group
module m;
localparam int A = 1;
localparam int LONGER = 22;
endmodule
----
module m;
localparam int A = 1;
localparam int LONGER = 22;
endmodule
====
# params: the name column aligns too when the types differ
module m;
localparam int A = 1;
localparam logic [31:0] LONGER = 32'hDEAD;
endmodule
----
module m;
localparam int A = 1;
localparam logic [31:0] LONGER = 32'hDEAD;
endmodule
====
# params: a blank line splits the group
module m;
localparam int A = 1;
localparam int LONGER = 22;
localparam int B = 3;
localparam int OTHER = 44;
endmodule
----
module m;
localparam int A = 1;
localparam int LONGER = 22;
localparam int B = 3;
localparam int OTHER = 44;
endmodule
====
# params: a standalone comment splits the group
module m;
localparam int A = 1;
localparam int LONGER = 22;
// a second table
localparam int B = 3;
localparam int OTHER = 44;
endmodule
----
module m;
localparam int A = 1;
localparam int LONGER = 22;
// a second table
localparam int B = 3;
localparam int OTHER = 44;
endmodule
====
# params: an unrelated item between two parameters splits the group
module m;
localparam int A = 1;
wire w;
localparam int LONGER = 22;
endmodule
----
module m;
localparam int A = 1;
wire w;
localparam int LONGER = 22;
endmodule
====
# params: a declaration without a value is not a row and splits the group
module m;
localparam int A = 1;
parameter P;
localparam int LONGER = 22;
endmodule
----
module m;
localparam int A = 1;
parameter P;
localparam int LONGER = 22;
endmodule
====
# params: two declarators in one statement are not a row
module m;
localparam int A = 1, B = 2;
localparam int LONGER = 22;
endmodule
----
module m;
localparam int A = 1, B = 2;
localparam int LONGER = 22;
endmodule
====
# params: an author who over-padded gets the computed column
module m;
localparam int A = 1;
localparam int LONGER = 22;
localparam int LONGEST_YET = 333;
endmodule
----
module m;
localparam int A = 1;
localparam int LONGER = 22;
localparam int LONGEST_YET = 333;
endmodule
====
# params: an aligned line past the limit takes the group back to flush
module m;
localparam int SHORT = 1;
localparam logic [31:0] A_MUCH_LONGER_PARAMETER_NAME_GOES_HERE_OK_LONGER = 32'hDEADBEEF + SOME_XYZ;
endmodule
----
module m;
localparam int SHORT = 1;
localparam logic [31:0] A_MUCH_LONGER_PARAMETER_NAME_GOES_HERE_OK_LONGER =
32'hDEADBEEF + SOME_XYZ;
endmodule
====
# params: one parameter is a group of one and never aligns
module m;
localparam int A = 1;
wire w;
endmodule
----
module m;
localparam int A = 1;
wire w;
endmodule
====
# params: a trailing comment rides along with an aligned row
module m;
localparam int A = 1; // the first
localparam int LONGER = 22; // the second
endmodule
----
module m;
localparam int A = 1; // the first
localparam int LONGER = 22; // the second
endmodule
====
# params: a fenced parameter is emitted verbatim and splits the group
module m;
localparam int A = 1;
// verilog_format: off
localparam int MID = 2;
// verilog_format: on
localparam int LONGER = 22;
endmodule
----
module m;
localparam int A = 1;
// verilog_format: off
localparam int MID = 2;
// verilog_format: on
localparam int LONGER = 22;
endmodule
====
# alignment applies inside a generate block at its own indentation
module m;
generate
if (X) begin : g
sub u (
.clk (clk),
.reset_n (rst_n),
.data_valid (dv)
);
end
endgenerate
endmodule
----
module m;
generate
if (X) begin : g
sub u (
.clk (clk),
.reset_n (rst_n),
.data_valid (dv)
);
end
endgenerate
endmodule
====
# a comment written before an element's comma does not split the group
module m;
sub u (
.clk (clk) /* c */,
.reset_n (rst_n),
.data_valid (dv)
);
endmodule
----
module m;
sub u (
.clk (clk) /* c */,
.reset_n (rst_n),
.data_valid (dv)
);
endmodule
====
# alignment in a package body: parameters align, the fence does not move
package p;
localparam int WIDTH = 8;
localparam int DEPTHXX = 16;
endpackage
----
package p;
localparam int WIDTH = 8;
localparam int DEPTHXX = 16;
endpackage
====
# a class body's parameters align the same way
class c;
localparam int WIDTH = 8;
localparam int DEPTHXX = 16;
endclass
----
class c;
localparam int WIDTH = 8;
localparam int DEPTHXX = 16;
endclass
====
# a hint on a list that would fit on one line still opens and aligns it
module m (input wire a, output logic b);
endmodule
----
module m (
input wire a,
output logic b
);
endmodule
====
# the same list without differing widths has nothing to align
module m (input wire a, input wire b);
endmodule
----
module m (input wire a, input wire b);
endmodule