Skip to content

Fix P0 correctness bugs: abort hang, label→BDD conversion, HOA writer, input-driven panics - #11

Merged
leonbohn merged 4 commits into
mainfrom
refactor
Nov 5, 2026
Merged

leonbohn merged 4 commits into
mainfrom
refactor

Conversation

@leonbohn

@leonbohn leonbohn commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Fixes the first four P0 items of the refactor list: a hang, wrong/failing label-to-BDD conversion, an invalid HOA writer, and panics on valid or untrusted input.

1. first_automaton_split_position no longer loops forever

When --ABORT-- appeared before the first --END--, the loop restarted the same find calls on the same slice. It now advances past the abort, skips aborted automata and returns the end of the first non-aborted automaton as an index into the original input (None if no --END-- follows the last abort). Documented on the function, with tests for abort-before-end, abort-after-end, multiple aborts and no end.

2. Labels convert to BDDs by recursive fold

AbstractLabelExpression::try_into_bdd handled only flat conjunctions/disjunctions of atoms, so Spot's usual output was rejected. It is now a plain recursive fold (Boolean → true/false, bounds-checked Integer → mk_var, Negated → not, Conjunction → and from true, Disjunction → or from false). Atomic/try_atom are gone.

This fixes:

  • [0&!1 | !0&1], [(0|1) & !1], [0 & t] — were Err, now convert;
  • [0 & !0] — was the wrong BDD (!0), now false;
  • [0 & !7] with 2 APs — panicked, now returns Err.

The conversion takes a pre-built &BddVariableSet (and &self), so a whole automaton can be converted with one variable set; AP i is BddVariable::from_index(i), which removes the need for the vars slice and for building a fresh set per label.

3. The writer emits valid, re-parsable HOA

  • Labels are printed as [<expr>] with precedence-aware parentheses (a disjunction inside a conjunction, a non-atom inside a negation) instead of the Rust Debug representation.
  • LabelExpression::Expression(Bdd) is printed as a DNF from sat_clauses().
  • properties: unambiguous is spelled correctly (was unabmiguous).
  • tool:/name: values are quoted, and tool: without a version no longer prints a trailing space.
  • One quoting helper escapes \ and " for every string (AP names, tool/name, state comments).
  • State no longer ends in a newline (no blank line after every state), and edges omit the trailing space when they have no acceptance signature.

4. Panics on untrusted or valid input

  • Integers that do not fit (States: 99999999999) are reported as span-carrying parse errors instead of panicking, and an AP identifier ≥ 65536 is a parse error instead of being silently truncated.
  • Accessors no longer debug_assert multiplicities the spec does not require (States:, Start:, acc-name:, AP: are all optional), so debug builds no longer panic on valid files.

Breaking changes

  • HoaRepresentation::aps → &[String] (empty without AP:), num_aps → u16, acceptance → Option<HoaAcceptance>, Header::acceptance_name → Option<AcceptanceName>.
  • AbstractLabelExpression::try_into_bdd(&self, &BddVariableSet); try_into_prop/try_into_hoa_expression take the AP count as u16.
  • build_vars (unused) removed.

Both the changelog and the README.md version notes are updated.

Testing

  • ./scripts/check passes (fmt, clippy -D warnings, doc, 24 tests).
  • New tests: abort/split cases; cardinality() for 0&!1 | !0&1 (2), (0|1)&!1 (1), 0&t (2), 0&!0 (0), t (4), f (0); out-of-bounds AP is Err; label parenthesisation; BDD labels printed as DNF and re-parsed to the same BDD; writer round-trip (parse → print → parse → compare) over every file in hoa/ and a sample with aliases, nested labels and quoting; integer/AP overflow errors; every accessor on a minimal file (HOA: v1 + Acceptance: 0 t) and on Default::default().

Search continues past an abort instead of re-running the same find calls on
the same input. The returned index is the end of the first non-aborted
automaton, as a byte index into the original input.

Adds regression tests for an abort before the first --END--, multiple
aborts, and inputs without any --END--.
AbstractLabelExpression::try_into_bdd now folds the expression
recursively instead of only handling flat conjunctions/disjunctions of
atoms. This fixes:

- nested labels such as `0&!1 | !0&1` or `(0|1)&!1` being rejected,
- `0 & !0` yielding `!0` instead of `false`,
- `0 & !7` with 2 APs panicking instead of returning an error.

The new signature takes a pre-built `&BddVariableSet` (and `&self`), so a
whole automaton can be converted with a single variable set; AP `i` is
`BddVariable::from_index(i)`, making the `vars` slice unnecessary. The
unused `build_vars` helper is removed.
- Print labels as `[<expr>]` via a precedence-aware Display for
  AbstractLabelExpression (parenthesise a disjunction inside a
  conjunction and anything non-atomic inside a negation) instead of the
  Rust Debug representation.
- Print `LabelExpression::Expression(Bdd)` as DNF from sat_clauses().
- Fix the `unambiguous` property spelling.
- Quote `tool:`/`name:` values and drop the trailing space when `tool:`
  has no version.
- Add a quoting helper that escapes `\` and `"` and use it for all
  strings (AP names, tool/name, state comments).
- Stop emitting a trailing newline in State Display (blank line after
  every state) and a trailing space for edges without an acceptance
  signature.

Adds round-trip tests (parse, print, parse, compare) over hoa/ and a
sample using nested labels, aliases and every quoting path, plus tests
for parenthesisation and BDD label printing.
- integer() and acceptance-info integers use try_map, so overflowing
  values (e.g. `States: 99999999999`) are parse errors with a span
  instead of ParseIntError panics.
- Label AP identifiers are converted with u16::try_from, so an index
  >= 65536 is a parse error instead of being silently truncated.
- Remove the debug_asserts on header multiplicity from num_states,
  start, aps, acceptance and acceptance_name: `States:`, `Start:`,
  `acc-name:` and `AP:` are all optional, so debug builds panicked on
  valid files.
- Accessor signatures: aps() -> &[String] (empty without `AP:`),
  num_aps() -> u16, acceptance() -> Option<HoaAcceptance>,
  Header::acceptance_name() -> Option<AcceptanceName>.
- try_into_prop/try_into_hoa_expression take the AP count as u16 to
  match BddVariableSet and num_aps.

Tests cover integer and AP-identifier overflow, and that a minimal file
(`HOA: v1` + `Acceptance: 0 t` only) and Default::default() work with
every accessor without panicking.
@leonbohn
leonbohn merged commit b325c37 into main Nov 5, 2026
3 checks passed
@leonbohn
leonbohn deleted the refactor branch November 5, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant