WIP checkpoint, §32 paused 2026-09-03 — runaway root cause fixed (list_ends on an unmoved cursor), strict parity restored; 32.1–32.5 done, 32.6 half, 32.7 + gates not run

Root cause of the 100 GB crash: a non-ANSI port loop took its trailing
comma from the element, an error element never got that far, the next
iteration failed on the same comma, consumed nothing and pushed another
empty error element - an allocating spin. Fix is structural: list_ends
ends the list whenever the cursor has not moved since the iteration
began; the two loops that read their own separator also eat it after an
error element. Truncate-anywhere + delete-any-character pass under
tools/guard.sh -m 4. Strict parity: element_or_recover declines on a
conditional-compilation directive so split.rs's verbatim rescue still
runs. cargo test -p vlog_parser 365 + 26 + 31 / 0 failed; workspace
suite NOT re-run since the last fixes. Not done: completion pin + the
three validity probes (32.6), measurements (32.7), README amendments,
coverage_gaps M10, TODO ticks, every gate. Handshake: three
vlog_linter arms (visit.rs walk_param_ports, signals.rs connection
loops) live in the earlier commit 6a15594.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
lucioandClaude Fable 5 committed 2026-09-03 18:28:33 -07:00
1 parent 6a15594ae8
commit f1d44a2a0c
12 files changed
+639 -82

No files matched your search

+186 -5
View File
@@ -490,18 +490,199 @@ fn a_half_typed_declaration_is_one_error_node() {
assert!(m.end_label.is_none());
}
/// **Inverted by header recovery (TODO §32).** Until 2026-09-03 the unclosed
/// `(` swallowed everything up to the next `;` and the whole instantiation was
/// one `ItemKind::Error`, `wire w;` included. Now the instantiation keeps its
/// name and the connection that was typed, the half-typed one is an error
/// *element*, and the declaration under it is an item of the module again.
#[test]
fn a_half_typed_instantiation_is_one_error_node() {
fn a_half_typed_instantiation_costs_one_connection() {
let src = "module m;\n sub u0 (.a(\n wire w;\nendmodule\n";
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 1);
assert_eq!(diags.len(), 1, "{diags:?}");
let m = module_named(&file, "m");
// The unclosed `(` swallows what follows it up to the sync point: a
// bracket the skip did not open ends it, otherwise the `;`.
assert!(matches!(&m.items[0].kind, ItemKind::Error(_)), "{}", kind_name(&m.items[0]));
assert_eq!(m.items.len(), 2, "{:?}", m.items.iter().map(kind_name).collect::<Vec<_>>());
let ItemKind::Instantiation(inst) = &m.items[0].kind else {
panic!("expected an instantiation, got {}", kind_name(&m.items[0]))
};
assert_eq!(inst.module, "sub");
assert_eq!(inst.instances[0].name, "u0");
let Connections::Named(conns) = &inst.instances[0].conns else { panic!("named connections") };
assert_eq!(conns.len(), 1);
assert_eq!(conns[0].error().map(|r| r.text.as_str()), Some(".a("));
// The line under the broken connection is the module's again, not part of
// the list: `wire w;` is a sibling item.
assert!(matches!(&m.items[1].kind, ItemKind::DataDecl(_)), "{}", kind_name(&m.items[1]));
assert_eq!(error_nodes(&file).len(), 1);
}
// ----------------------------------------------------------------------
// Header recovery (TODO §32): one test per shape, with exact counts
// ----------------------------------------------------------------------
/// (a) The QA shape this round was written for: a parameter with no value.
/// One diagnostic, one item, and a module that still holds its body.
#[test]
fn a_half_typed_parameter_costs_one_parameter() {
let src = "module m #(parameter W = , parameter X = 4) (input a); wire ok; endmodule\n";
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 1, "{diags:?}");
assert_eq!(file.items.len(), 1, "{:?}", file.items.iter().map(kind_name).collect::<Vec<_>>());
let m = module_named(&file, "m");
let params = m.param_ports.as_ref().expect("a parameter port list");
assert_eq!(params.len(), 2);
assert_eq!(params[0].error().map(|r| r.text.as_str()), Some("parameter W ="));
assert_eq!(params[1].ok().map(|p| p.name.as_str()), Some("X"));
let PortList::Ansi(ports) = &m.ports else { panic!("expected ANSI ports") };
assert_eq!(ports.len(), 1);
assert_eq!(ports[0].ok().map(|p| p.name.as_str()), Some("a"));
assert_eq!(m.items.len(), 1, "the body survives the header");
assert!(matches!(&m.items[0].kind, ItemKind::DataDecl(_)), "{}", kind_name(&m.items[0]));
}
/// (b) The missing comma of a port half typed on the line above: the list
/// reads on to the ports after it, and says once that the `,` is missing.
#[test]
fn a_missing_comma_in_a_port_list_keeps_the_ports_after_it() {
let src = "module m (input logic a, inp\n output b);\nendmodule\n";
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 1, "{diags:?}");
assert!(diags[0].message.starts_with("expected `,`"), "{}", diags[0]);
let PortList::Ansi(ports) = &module_named(&file, "m").ports else { panic!("ANSI ports") };
let names: Vec<&str> = ports.iter().filter_map(|p| p.ok()).map(|p| p.name.as_str()).collect();
assert_eq!(names, ["a", "inp", "b"], "the port after the typo survives");
assert_eq!(error_nodes(&file).len(), 0, "a missing comma costs no element");
}
/// (c) A parameter list truncated at end of file — the mid-edit state itself.
/// The module keeps the parameter that was typed; the two diagnostics are the
/// unclosed `)` and the unclosed module, one each.
#[test]
fn a_parameter_list_truncated_at_eof_keeps_its_module() {
let src = "module m #(parameter W = 8,\n";
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 2, "{diags:?}");
assert!(diags[0].message.starts_with("expected `)`"), "{}", diags[0]);
assert!(diags[1].message.starts_with("expected `endmodule`"), "{}", diags[1]);
let m = module_named(&file, "m");
let params = m.param_ports.as_ref().expect("a parameter port list");
assert_eq!(params.len(), 1);
assert_eq!(params[0].ok().map(|p| p.name.as_str()), Some("W"));
}
/// (d) The `for` header the error-recovery README documented as costing two
/// diagnostics: the `;`s inside it are invisible to the skip now, so it costs
/// one, and the loop keeps its body.
#[test]
fn a_half_typed_for_header_keeps_the_loop_and_its_body() {
let src = "module m;\n initial begin\n for (i = 0; i < ; i = i + 1) x = 1;\n y = 2;\n end\nendmodule\n";
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 1, "{diags:?}");
let m = module_named(&file, "m");
let ItemKind::Initial(stmt) = &m.items[0].kind else { panic!("expected an initial") };
let StmtKind::Block { stmts, .. } = &stmt.kind else { panic!("expected a block") };
assert_eq!(stmts.len(), 2, "the statement after the loop is untouched");
let StmtKind::For { cond, body, .. } = &stmts[0].kind else { panic!("expected a for") };
let Some(Expr { kind: ExprKind::Error(raw), .. }) = cond else {
panic!("expected an error condition")
};
assert_eq!(raw.text, "i = 0; i < ; i = i + 1");
assert!(matches!(body.kind, StmtKind::Assign { .. }), "the body is the `x = 1;`");
assert!(matches!(stmts[1].kind, StmtKind::Assign { .. }));
}
/// (d′) The same header truncated mid-condition, where the block ends right
/// under it: the loop survives with an empty body rather than eating the
/// `end` its block is waiting for.
#[test]
fn a_for_header_truncated_mid_condition_does_not_eat_the_end() {
let src = "module m;\n initial begin\n for (int i = 0; i <\n end\nendmodule\n";
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 1, "{diags:?}");
let m = module_named(&file, "m");
let ItemKind::Initial(stmt) = &m.items[0].kind else { panic!("expected an initial") };
let StmtKind::Block { stmts, .. } = &stmt.kind else { panic!("expected a block") };
assert_eq!(stmts.len(), 1);
let StmtKind::For { cond, body, .. } = &stmts[0].kind else { panic!("expected a for") };
assert!(matches!(cond, Some(Expr { kind: ExprKind::Error(_), .. })));
let StmtKind::Error(raw) = &body.kind else { panic!("expected an empty body") };
assert_eq!(raw.text, "", "nothing was typed there, and nothing is invented");
}
/// (f) A formal list left open, with the body under it: the function and the
/// module around it both survive.
#[test]
fn a_half_typed_formal_list_keeps_its_function() {
let src = "module m;\n function int f(input int a,\n f = a;\n endfunction\nendmodule\n";
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 1, "{diags:?}");
let m = module_named(&file, "m");
assert_eq!(m.items.len(), 1);
let ItemKind::Function(f) = &m.items[0].kind else {
panic!("expected a function, got {}", kind_name(&m.items[0]))
};
assert_eq!(f.name, "f");
assert_eq!(f.args.first().and_then(|a| a.ok()).map(|a| a.name.as_str()), Some("a"));
}
/// (g) A condition left open, with the statements under it: the `if` keeps
/// its shape and its then-branch.
#[test]
fn a_half_typed_if_condition_keeps_its_branch() {
let src = "module m;\n initial begin\n if (a &&\n x = 1;\n y = 2;\n end\nendmodule\n";
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 1, "{diags:?}");
let m = module_named(&file, "m");
let ItemKind::Initial(stmt) = &m.items[0].kind else { panic!("expected an initial") };
let StmtKind::Block { stmts, .. } = &stmt.kind else { panic!("expected a block") };
assert_eq!(stmts.len(), 1);
let StmtKind::If { cond, then, els, .. } = &stmts[0].kind else { panic!("expected an if") };
assert!(matches!(cond.kind, ExprKind::Error(_)), "{:?}", cond.kind);
assert!(els.is_none());
assert!(matches!(then.kind, StmtKind::Assign { .. }), "the branch is the `y = 2;`");
}
/// The other statement headers recover through the same helper, so one test
/// covers them: each keeps its node, its body and exactly one diagnostic.
#[test]
fn the_other_statement_headers_recover_the_same_way() {
let shapes: &[(&str, &str)] = &[
("while", "module m;\n initial begin\n while (a &&\n x = 1;\n end\nendmodule\n"),
("repeat", "module m;\n initial begin\n repeat (a &&\n x = 1;\n end\nendmodule\n"),
("case", "module m;\n initial begin\n case (a &&\n x = 1;\n endcase\n end\nendmodule\n"),
];
for (name, src) in shapes {
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 1, "{name}: {diags:?}");
let m = module_named(&file, "m");
let ItemKind::Initial(stmt) = &m.items[0].kind else { panic!("{name}: expected initial") };
let StmtKind::Block { stmts, .. } = &stmt.kind else { panic!("{name}: expected a block") };
let kind = &stmts[0].kind;
let cond = match kind {
StmtKind::While { cond, .. } => cond,
StmtKind::Repeat { count, .. } => count,
StmtKind::Case { expr, .. } => expr,
other => panic!("{name}: {:?}", std::mem::discriminant(other)),
};
assert!(matches!(cond.kind, ExprKind::Error(_)), "{name}: {:?}", cond.kind);
}
}
/// The whole point, stated once: a broken header no longer costs the module.
/// This is the shape the error-recovery README's QA finding described — three
/// items and two diagnostics — measured again here as one and one.
#[test]
fn a_broken_header_no_longer_distorts_the_tree() {
let src = "module m #(parameter W = , parameter X = 4) (input a);\n wire ok;\nendmodule\n";
let (file, diags) = parse_source_tolerant(src);
assert_eq!(diags.len(), 1, "{diags:?}");
assert_eq!(file.items.len(), 1, "the body no longer re-parses at file scope");
let m = module_named(&file, "m");
assert!(m.end_label.is_none() && !m.items.is_empty());
// And no orphaned `endmodule` behind it.
assert!(!file.items.iter().any(|i| matches!(i.kind, ItemKind::Error(_))));
}
#[test]
fn garbage_between_two_modules_leaves_both_intact() {
for garbage in ["@#!", "foo bar baz", "???", "wire", "end", "* ) ]"] {