TODO section 20 round 1, coverage_gaps C1 for constraints. A constraint
declaration was opaque text with no name span; renaming a rand field
left constraint c { user_id < 5; } as non-compiling code. Now
ItemKind::Constraint with a structured ConstraintSet (Expr{soft},
Implication, If, Foreach, SolveBefore, Unique, DisableSoft, Directive,
Empty), ExprKind::Dist, and randomize() with bodies as
ConstraintBody::{Items, Verbatim}. The parser attempts the structured
body behind a Rewind snapshot - cursor, both pending-comment buckets,
depth, links, open_conds, diagnostics - and on any error re-runs
v0.26.0's verbatim capture character for character, so an unknown body
IS the old behavior. No keywords reserved: soft/dist/solve/before are
matched by text, so logic before; keeps working and token.rs, pairs.rs
and the editor grammar are untouched. Canonical layout, verify.rs
untouched, attack pairs re-derived and extended. Every operand binds to
the class's properties (foreach vars nest; a with block resolves against
the randomized object's class first), so hover, definition, references
and rename reach inside. FACTS_FORMAT 10 -> 11. Lint rules read
constraint operands.
QA's finding - comments after the round's own words were dropped and
the safety net refused the file - answered with an exhaustive gap fuzzer
(358 gaps, format and idempotency demanded) and fourteen named comment
fields; the forty gaps that remain are shared machinery that fails
identically outside a constraint, filed as topo 2.9-22. Opentitan: 1993
of 2009 bodies structured, sweep unchanged, 48 DV files idempotent with
comment streams byte-identical, per-file diagnostics identical.
docs/features/constraint-bodies/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
323 lines
5.5 KiB
Plaintext
323 lines
5.5 KiB
Plaintext
# alternative declaration heads sharing one body: the whole construct is one
|
|
# verbatim block, so it comes back byte for byte
|
|
# corpus/ibex/vendor/google_riscv-dv/target/rv32imc/riscv_core_setting.sv:98
|
|
`ifdef DSIM
|
|
privileged_reg_t implemented_csr[] = {
|
|
`else
|
|
const privileged_reg_t implemented_csr[] = {
|
|
`endif
|
|
MVENDORID, // Vendor ID
|
|
MARCHID // Architecture ID
|
|
};
|
|
|
|
parameter int AFTER = 1;
|
|
----
|
|
`ifdef DSIM
|
|
privileged_reg_t implemented_csr[] = {
|
|
`else
|
|
const privileged_reg_t implemented_csr[] = {
|
|
`endif
|
|
MVENDORID, // Vendor ID
|
|
MARCHID // Architecture ID
|
|
};
|
|
|
|
parameter int AFTER = 1;
|
|
====
|
|
# alternative struct bodies sharing one closing brace, inside a package
|
|
# corpus/ibex/vendor/google_riscv-dv/src/riscv_instr_pkg.sv:1236
|
|
package p;
|
|
`ifdef _VCP
|
|
typedef struct packed {
|
|
bit l;
|
|
`else
|
|
typedef struct{
|
|
rand bit l;
|
|
`endif
|
|
} pmp_cfg_reg_t;
|
|
|
|
parameter int AFTER = 1;
|
|
endpackage
|
|
----
|
|
package p;
|
|
`ifdef _VCP
|
|
typedef struct packed {
|
|
bit l;
|
|
`else
|
|
typedef struct{
|
|
rand bit l;
|
|
`endif
|
|
} pmp_cfg_reg_t;
|
|
|
|
parameter int AFTER = 1;
|
|
endpackage
|
|
====
|
|
# the block's *relative* layout is what survives: only the first line is
|
|
# re-indented to the item's level, the rest is dedented by the block's start
|
|
# column and indented back -- the fixed-point trick `constraint` uses
|
|
module m;
|
|
`ifdef A
|
|
logic [3:0] x[] = {
|
|
`else
|
|
const logic [3:0] x[] = {
|
|
`endif
|
|
4'h1,
|
|
4'h2
|
|
};
|
|
assign y = 1;
|
|
endmodule
|
|
----
|
|
module m;
|
|
`ifdef A
|
|
logic [3:0] x[] = {
|
|
`else
|
|
const logic [3:0] x[] = {
|
|
`endif
|
|
4'h1,
|
|
4'h2
|
|
};
|
|
assign y = 1;
|
|
endmodule
|
|
====
|
|
# `ifndef and an `elsif chain: three rival spellings of one head, one body.
|
|
# Only the first arm's `{` is counted, so the scan does not go looking for
|
|
# two more closing braces.
|
|
`ifndef A
|
|
int x[] = {
|
|
`elsif B
|
|
const int x[] = {
|
|
`else
|
|
static int x[] = {
|
|
`endif
|
|
1
|
|
};
|
|
----
|
|
`ifndef A
|
|
int x[] = {
|
|
`elsif B
|
|
const int x[] = {
|
|
`else
|
|
static int x[] = {
|
|
`endif
|
|
1
|
|
};
|
|
====
|
|
# a *balanced* region inside the shared tail is ordinary conditional text and
|
|
# does not end the block early -- the item after it is still its own item
|
|
`ifdef A
|
|
int x[] = {
|
|
`else
|
|
const int x[] = {
|
|
`endif
|
|
1,
|
|
`ifdef B
|
|
2,
|
|
`endif
|
|
3
|
|
};
|
|
|
|
parameter int AFTER=1;
|
|
----
|
|
`ifdef A
|
|
int x[] = {
|
|
`else
|
|
const int x[] = {
|
|
`endif
|
|
1,
|
|
`ifdef B
|
|
2,
|
|
`endif
|
|
3
|
|
};
|
|
|
|
parameter int AFTER = 1;
|
|
====
|
|
# comments: the one before the region leads the `ifdef, the ones written on
|
|
# the directives and inside the arms are part of the verbatim bytes, and the
|
|
# one after the terminating `;` stays outside the block and trails it
|
|
// head
|
|
`ifdef A // which
|
|
int x[] = { // open
|
|
`else // other
|
|
const int x[] = {
|
|
`endif
|
|
// why
|
|
1
|
|
}; // done
|
|
int y;
|
|
----
|
|
// head
|
|
`ifdef A // which
|
|
int x[] = { // open
|
|
`else // other
|
|
const int x[] = {
|
|
`endif
|
|
// why
|
|
1
|
|
}; // done
|
|
int y;
|
|
====
|
|
# NEGATIVE: a region whose arms are each a whole item is not a split -- both
|
|
# arms are parsed and laid out normally, as they always were
|
|
`ifdef A
|
|
wire x;
|
|
`else
|
|
wire y ;
|
|
`endif
|
|
----
|
|
`ifdef A
|
|
wire x;
|
|
`else
|
|
wire y;
|
|
`endif
|
|
====
|
|
# NEGATIVE: a bracket that opens *and closes* inside one arm leaves nothing
|
|
# open, so the region is ordinary text around ordinary items
|
|
`ifdef A
|
|
int x[] = {1, 2};
|
|
`else
|
|
int x[] = {3, 4};
|
|
`endif
|
|
----
|
|
`ifdef A
|
|
int x [] = {1, 2};
|
|
`else
|
|
int x [] = {3, 4};
|
|
`endif
|
|
====
|
|
# a genuine split nested INSIDE a legitimately-open outer region: the guard
|
|
# added for QA's stray-`endif finding is "a region is live", not "exactly one
|
|
# region is live", so this still recovers
|
|
`ifdef OUTER
|
|
`ifdef DSIM
|
|
privileged_reg_t csr[] = {
|
|
`else
|
|
const privileged_reg_t csr[] = {
|
|
`endif
|
|
MVENDORID
|
|
};
|
|
`endif
|
|
parameter int AFTER = 1;
|
|
----
|
|
`ifdef OUTER
|
|
`ifdef DSIM
|
|
privileged_reg_t csr[] = {
|
|
`else
|
|
const privileged_reg_t csr[] = {
|
|
`endif
|
|
MVENDORID
|
|
};
|
|
`endif
|
|
parameter int AFTER = 1;
|
|
====
|
|
# the same, shape B, inside a package inside an outer region
|
|
package p;
|
|
`ifdef OUTER
|
|
`ifdef _VCP
|
|
typedef struct packed {
|
|
bit l;
|
|
`else
|
|
typedef struct{
|
|
rand bit l;
|
|
`endif
|
|
} pmp_cfg_reg_t;
|
|
`endif
|
|
parameter int AFTER = 1;
|
|
endpackage
|
|
----
|
|
package p;
|
|
`ifdef OUTER
|
|
`ifdef _VCP
|
|
typedef struct packed {
|
|
bit l;
|
|
`else
|
|
typedef struct{
|
|
rand bit l;
|
|
`endif
|
|
} pmp_cfg_reg_t;
|
|
`endif
|
|
parameter int AFTER = 1;
|
|
endpackage
|
|
====
|
|
# NEGATIVE: a stray `endif closes nothing, so the declaration next to it is
|
|
# not a split -- and, since neither is a parse error on its own, both stay
|
|
# ordinary items (lucisv does not validate directive nesting, and did not
|
|
# before this work either)
|
|
wire a;
|
|
`endif
|
|
int x[] = {1};
|
|
----
|
|
wire a;
|
|
`endif
|
|
int x [] = {1};
|
|
====
|
|
# over-suppression guard: directives written inside a `constraint` body are
|
|
# constraint items, not item-scope nesting, but the region around the body
|
|
# still counts, so a genuine split after it still recovers
|
|
class c;
|
|
constraint co {
|
|
`ifdef X
|
|
x < 10;
|
|
`endif
|
|
}
|
|
endclass
|
|
|
|
`ifdef DSIM
|
|
int y[] = {
|
|
`else
|
|
const int y[] = {
|
|
`endif
|
|
1
|
|
};
|
|
parameter int AFTER = 1;
|
|
----
|
|
class c;
|
|
constraint co {
|
|
`ifdef X
|
|
x < 10;
|
|
`endif
|
|
}
|
|
endclass
|
|
|
|
`ifdef DSIM
|
|
int y[] = {
|
|
`else
|
|
const int y[] = {
|
|
`endif
|
|
1
|
|
};
|
|
parameter int AFTER = 1;
|
|
====
|
|
# under-suppression guard: an earlier constraint item inside the very region
|
|
# the split sits in -- the outer `ifdef must still be counted
|
|
`ifdef OUTER
|
|
class c;
|
|
constraint co {x < 10;}
|
|
endclass
|
|
|
|
`ifdef DSIM
|
|
int y[] = {
|
|
`else
|
|
const int y[] = {
|
|
`endif
|
|
1
|
|
};
|
|
`endif
|
|
parameter int AFTER = 1;
|
|
----
|
|
`ifdef OUTER
|
|
class c;
|
|
constraint co {
|
|
x < 10;
|
|
}
|
|
endclass
|
|
|
|
`ifdef DSIM
|
|
int y[] = {
|
|
`else
|
|
const int y[] = {
|
|
`endif
|
|
1
|
|
};
|
|
`endif
|
|
parameter int AFTER = 1;
|