WIP §32 header recovery — DO NOT MERGE: half-finished; a fuzz test loops without advancing and exhausts memory (crashed the machine 2026-09-03)
Checkpoint of the interrupted dev work (rate limit) so master stays clean. Known state: a_half_typed_instantiation_is_one_error_node (expected to invert) and tolerant_parse_equals_strict_parse_on_valid_ sources FAIL; the error_recovery test binary exceeds 6 GB under tools/guard.sh (a non-advancing recovery loop under the delete-any- character / truncate fuzzers). Resume in a worktree of this branch, under tools/guard.sh, fixing the advance guarantee first. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
4d70de1976
commit
6a15594ae8
50 files changed
+1135
-430
No files matched your search
@@ -9,7 +9,7 @@ use super::*;
|
||||
#[derive(Default)]
|
||||
pub(super) struct ParamPortList {
|
||||
/// `None` when no `#( ... )` was written at all.
|
||||
pub(super) ports: Option<Vec<ParamPort>>,
|
||||
pub(super) ports: Option<Vec<ListElem<ParamPort>>>,
|
||||
pub(super) directives: Vec<ListDirective>,
|
||||
pub(super) dangling: Vec<Comment>,
|
||||
/// Comments written between the `#` and the `(`.
|
||||
@@ -41,7 +41,12 @@ impl<'a> Parser<'a> {
|
||||
let port_comments = self.take_before_open("(");
|
||||
let (ports, port_dangling, port_directives) = self.parse_port_list()?;
|
||||
let before_semi = self.gap_before(";");
|
||||
self.expect_sym(";")?;
|
||||
// A header that already recovered keeps its `;` optional: the missing
|
||||
// one is part of the typo already reported, and the body behind it is
|
||||
// what the module is for.
|
||||
let recovered =
|
||||
param_ports.iter().flatten().any(|p| p.is_error()) || ports.has_error();
|
||||
self.expect_after_recovery(";", recovered)?;
|
||||
let mut items = Vec::new();
|
||||
while !self.at_body_end(end_kw) {
|
||||
items.push(self.item_or_recover()?);
|
||||
@@ -325,12 +330,12 @@ impl<'a> Parser<'a> {
|
||||
self.take_list_directives(&mut out.directives, 0);
|
||||
if !self.cur().is_sym(")") {
|
||||
loop {
|
||||
list.push(self.parse_param_port()?);
|
||||
if let Some(last) = list.last_mut() {
|
||||
list.push(self.element_or_recover(|p| p.parse_param_port())?);
|
||||
if let Some(ListElem::Ok(last)) = list.last_mut() {
|
||||
self.take_before_sep(&mut last.meta, ",");
|
||||
}
|
||||
let comma = self.eat_sym(",");
|
||||
if let Some(last) = list.last_mut() {
|
||||
if let Some(ListElem::Ok(last)) = list.last_mut() {
|
||||
last.comma = comma;
|
||||
if comma && last.meta.trailing.is_none() {
|
||||
last.meta.trailing = self.take_trailing();
|
||||
@@ -341,13 +346,15 @@ impl<'a> Parser<'a> {
|
||||
// With one, only the closing bracket says so: an `` `ifdef``
|
||||
// arm may end without a comma and another arm may still follow
|
||||
// (`` `else``), or the arm may have been the tail of the list.
|
||||
if (!comma && !dirs.any) || (dirs.any && self.cur().is_sym(")")) {
|
||||
// In tolerant mode the closing bracket decides on its own; see
|
||||
// [`Parser::list_ends`].
|
||||
if self.list_ends(comma, dirs.any) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
out.dangling = self.take_dangling();
|
||||
self.expect_sym(")")?;
|
||||
self.close_list(list.iter().any(ListElem::is_error))?;
|
||||
out.ports = Some(list);
|
||||
Ok(out)
|
||||
}
|
||||
@@ -467,32 +474,32 @@ impl<'a> Parser<'a> {
|
||||
if ansi {
|
||||
let mut ports = Vec::new();
|
||||
loop {
|
||||
ports.push(self.parse_ansi_port()?);
|
||||
if let Some(last) = ports.last_mut() {
|
||||
ports.push(self.element_or_recover(|p| p.parse_ansi_port())?);
|
||||
if let Some(ListElem::Ok(last)) = ports.last_mut() {
|
||||
self.take_before_sep(&mut last.meta, ",");
|
||||
}
|
||||
let comma = self.eat_sym(",");
|
||||
if let Some(last) = ports.last_mut() {
|
||||
if let Some(ListElem::Ok(last)) = ports.last_mut() {
|
||||
last.comma = comma;
|
||||
if comma && last.meta.trailing.is_none() {
|
||||
last.meta.trailing = self.take_trailing();
|
||||
}
|
||||
}
|
||||
let dirs = self.take_list_directives(&mut directives, ports.len());
|
||||
if (!comma && !dirs.any) || (dirs.any && self.cur().is_sym(")")) {
|
||||
if self.list_ends(comma, dirs.any) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Comments on their own lines before the `)` belong inside it.
|
||||
let dangling = self.take_dangling();
|
||||
self.expect_sym(")")?;
|
||||
self.close_list(ports.iter().any(ListElem::is_error))?;
|
||||
// A trailing comment on the closing line belongs to the last
|
||||
// port — but only when the header did not write a `;` right
|
||||
// after the `)`. `module m (input a) /*c*/ ;` writes its comment
|
||||
// in the *header's* gap, and printing it back inside the parens
|
||||
// moves it across the `)`.
|
||||
if !self.cur().is_sym(";") {
|
||||
if let Some(last) = ports.last_mut() {
|
||||
if let Some(ListElem::Ok(last)) = ports.last_mut() {
|
||||
if last.meta.trailing.is_none() {
|
||||
last.meta.trailing = self.take_trailing();
|
||||
}
|
||||
@@ -502,25 +509,36 @@ impl<'a> Parser<'a> {
|
||||
} else {
|
||||
let mut ports = Vec::new();
|
||||
loop {
|
||||
let start = self.here();
|
||||
let mut meta = self.take_meta();
|
||||
let name = self.expect_ident()?;
|
||||
let span = self.span_from(start);
|
||||
self.take_before_sep(&mut meta, ",");
|
||||
let comma = self.eat_sym(",");
|
||||
meta.trailing = self.take_trailing();
|
||||
ports.push(NonAnsiPort { meta, name, comma, span });
|
||||
ports.push(self.element_or_recover(|p| p.parse_non_ansi_port())?);
|
||||
let comma = match ports.last() {
|
||||
Some(ListElem::Ok(last)) => last.comma,
|
||||
_ => false,
|
||||
};
|
||||
let dirs = self.take_list_directives(&mut directives, ports.len());
|
||||
if (!comma && !dirs.any) || (dirs.any && self.cur().is_sym(")")) {
|
||||
if self.list_ends(comma, dirs.any) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let dangling = self.take_dangling();
|
||||
self.expect_sym(")")?;
|
||||
self.close_list(ports.iter().any(ListElem::is_error))?;
|
||||
Ok((PortList::NonAnsi(ports), dangling, directives))
|
||||
}
|
||||
}
|
||||
|
||||
/// One name of a non-ANSI header's port list (`module m (a, b);`),
|
||||
/// its separator included: the port *is* its name, so there is nothing
|
||||
/// else to read and the `,` is what says whether another follows.
|
||||
fn parse_non_ansi_port(&mut self) -> PResult<NonAnsiPort> {
|
||||
let start = self.here();
|
||||
let mut meta = self.take_meta();
|
||||
let name = self.expect_ident()?;
|
||||
let span = self.span_from(start);
|
||||
self.take_before_sep(&mut meta, ",");
|
||||
let comma = self.eat_sym(",");
|
||||
meta.trailing = self.take_trailing();
|
||||
Ok(NonAnsiPort { meta, name, comma, span })
|
||||
}
|
||||
|
||||
fn parse_ansi_port(&mut self) -> PResult<AnsiPort> {
|
||||
let start = self.here();
|
||||
let mut meta = self.take_meta();
|
||||
|
||||
Reference in new issue
Block a user