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]>
This commit is contained in:
1 parent
3325905f21
commit
dc2181e1a2
9 files changed
+1531
-141
No files matched your search
@@ -99,9 +99,19 @@ pub enum ItemKind {
|
||||
pub struct Module {
|
||||
pub kw: String,
|
||||
pub name: String,
|
||||
pub imports: Vec<String>,
|
||||
pub param_ports: Vec<ParamPort>,
|
||||
/// One entry per `import` statement written in the header, each holding
|
||||
/// that statement's comma-separated paths. A header may write several
|
||||
/// (`module m import a::*; import b::t; (...)`), and merging them into one
|
||||
/// statement would replace a `;` with a `,`.
|
||||
pub imports: Vec<Vec<String>>,
|
||||
/// `None` when the header wrote no `#( ... )` at all; an empty `Some` is a
|
||||
/// written-but-empty `#()`, which must be printed back.
|
||||
pub param_ports: Option<Vec<ParamPort>>,
|
||||
/// Comments written after the last parameter port and before the `)`.
|
||||
pub param_dangling: Vec<Comment>,
|
||||
pub ports: PortList,
|
||||
/// Comments written after the last port and before the `)`.
|
||||
pub port_dangling: Vec<Comment>,
|
||||
pub items: Vec<Item>,
|
||||
pub dangling: Vec<Comment>,
|
||||
pub end_label: Option<String>,
|
||||
@@ -265,6 +275,9 @@ pub struct AssignPair {
|
||||
pub meta: Meta,
|
||||
pub lhs: Expr,
|
||||
pub rhs: Expr,
|
||||
/// Comments written between the `=` and the right-hand side. Kept here so
|
||||
/// they print on the `=`'s side of the value instead of drifting into it.
|
||||
pub rhs_comments: Vec<Comment>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -282,14 +295,30 @@ pub enum SensList {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SensItem {
|
||||
/// The separator written before this item; `None` on the first item.
|
||||
pub sep: Option<SensSep>,
|
||||
pub edge: Option<String>,
|
||||
pub expr: Expr,
|
||||
}
|
||||
|
||||
/// How two event-list items were separated in the source. Both spellings are
|
||||
/// legal and mean the same thing, but rewriting one as the other changes the
|
||||
/// token stream, so the formatter reproduces whichever was written.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SensSep {
|
||||
/// `@(posedge clk, negedge rst_n)`
|
||||
Comma,
|
||||
/// `@(posedge clk or negedge rst_n)`
|
||||
Or,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Instantiation {
|
||||
pub module: String,
|
||||
pub params: Vec<Connection>,
|
||||
/// The parameter override list, `None` when the source wrote no `#(...)`
|
||||
/// at all. An empty `Some` is a written-but-empty `#()`, which must be
|
||||
/// printed back: dropping it would lose two tokens.
|
||||
pub params: Option<Vec<Connection>>,
|
||||
pub instances: Vec<Instance>,
|
||||
}
|
||||
|
||||
@@ -370,8 +399,9 @@ pub struct GenCase {
|
||||
#[derive(Debug)]
|
||||
pub struct GenCaseItem {
|
||||
pub meta: Meta,
|
||||
/// Empty means `default`.
|
||||
pub labels: Vec<Expr>,
|
||||
/// Empty means `default`. Each label carries the comments written around
|
||||
/// it, so a comment between two labels stays between them.
|
||||
pub labels: Vec<ExprItem>,
|
||||
pub body: GenBlock,
|
||||
}
|
||||
|
||||
@@ -545,8 +575,9 @@ pub enum TimingControl {
|
||||
#[derive(Debug)]
|
||||
pub struct CaseItem {
|
||||
pub meta: Meta,
|
||||
/// Empty means `default`.
|
||||
pub labels: Vec<Expr>,
|
||||
/// Empty means `default`. Each label carries the comments written around
|
||||
/// it, so a comment between two labels stays between them.
|
||||
pub labels: Vec<ExprItem>,
|
||||
pub stmt: Stmt,
|
||||
}
|
||||
|
||||
@@ -575,8 +606,9 @@ pub enum Expr {
|
||||
Ident(String),
|
||||
Number(String),
|
||||
Str(String),
|
||||
/// Explicitly empty (used for `.port()` connections).
|
||||
Empty,
|
||||
/// Explicitly empty (used for `.port()` connections), carrying any
|
||||
/// comments written between the parens so they stay inside them.
|
||||
Empty(Vec<Comment>),
|
||||
Unary {
|
||||
op: String,
|
||||
expr: Box<Expr>,
|
||||
@@ -585,14 +617,16 @@ pub enum Expr {
|
||||
lhs: Box<Expr>,
|
||||
op: String,
|
||||
rhs: Box<Expr>,
|
||||
/// Comments written between the left operand and the operator. They
|
||||
/// force the chain to break, with the operator starting the new line.
|
||||
comments: Vec<Comment>,
|
||||
/// Boxed to keep `Expr` small, as for `TernaryComments`.
|
||||
comments: Box<BinaryComments>,
|
||||
},
|
||||
Ternary {
|
||||
cond: Box<Expr>,
|
||||
then: Box<Expr>,
|
||||
els: Box<Expr>,
|
||||
/// Boxed to keep `Expr` small: a ternary with comments in it is rare,
|
||||
/// but every `Expr` would otherwise carry four empty vectors.
|
||||
comments: Box<TernaryComments>,
|
||||
},
|
||||
Call {
|
||||
callee: Box<Expr>,
|
||||
@@ -658,6 +692,45 @@ pub enum Expr {
|
||||
},
|
||||
}
|
||||
|
||||
/// Comments written next to a binary operator. Kept per side so neither
|
||||
/// drifts across the operator: `a && // why` and `a // why` + `&& b` are
|
||||
/// different token streams.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct BinaryComments {
|
||||
/// Between the left operand and the operator. These force the chain to
|
||||
/// break, with the operator starting the new line.
|
||||
pub before: Vec<Comment>,
|
||||
/// Between the operator and the right operand. These force the chain to
|
||||
/// break, with the right operand starting the new line.
|
||||
pub after: Vec<Comment>,
|
||||
}
|
||||
|
||||
/// Comments written inside a `cond ? then : els`, kept per position so the
|
||||
/// formatter prints each back between the same two tokens it was written
|
||||
/// between. Anywhere else they would drift across `?` or `:`.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct TernaryComments {
|
||||
/// Between the condition and `?`.
|
||||
pub before_question: Vec<Comment>,
|
||||
/// Between `?` and the then-branch.
|
||||
pub after_question: Vec<Comment>,
|
||||
/// Between the then-branch and `:`.
|
||||
pub before_colon: Vec<Comment>,
|
||||
/// Between `:` and the else-branch.
|
||||
pub after_colon: Vec<Comment>,
|
||||
}
|
||||
|
||||
impl TernaryComments {
|
||||
/// True when nothing was written inside the `? :` — the common case, laid
|
||||
/// out without any comment handling.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.before_question.is_empty()
|
||||
&& self.after_question.is_empty()
|
||||
&& self.before_colon.is_empty()
|
||||
&& self.after_colon.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PatternItem {
|
||||
pub meta: Meta,
|
||||
|
||||
Reference in new issue
Block a user