Skip to content

feat(scope): keep a FRET mode formula in the scope itself - #271

Merged
benmandrew merged 2 commits into
mainfrom
feat/formula-modes
Nov 24, 2026
Merged

benmandrew merged 2 commits into
mainfrom
feat/formula-modes

Conversation

@benmandrew

Copy link
Copy Markdown
Owner

A FRET scope may name a mode formula, such as in (PCVMode | PSVMode). The importer used to give each one a fresh output atom, mode_pcv_mode_or_psv_mode, and a non-weakenable definition G(mode_pcv_mode_or_psv_mode <-> (pcv_mode | psv_mode)). Scope::m_mode now holds the formula itself, as FRET does.

Engine changes:

  • A mode is either a bare signal name or a propositional formula over declared signals. A bare mode lowers, hashes and serialises byte-identically, so no determinism golden moved.
  • A formula mode is stored in one canonical spelling, (pcv_mode) | (psv_mode), is bracketed in the scope templates, and stays out of modes. Mutation never edits a mode, and similarity still compares it as text.
  • Model counting adds each atom of a formula mode (scope_mode_atoms), which keeps count_guard_models clear of the overflow assertion.
  • The importer writes the canonical formula and no longer makes the fresh atom or its definition.

examples/ventilator-controller is re-imported. It has 58 guarantees, 53 outputs and 10 modes, where it had 68, 63 and 20. Campaigns run on it before this change used the old spec, which their provenance tags still reproduce.

Checks:

  • ctest passes 70 of 70, and lint and format are clean.
  • All 11 formula-mode requirements are equivalent under ltlfilt --equivalent-to to FRET's ftExpanded, at ordinal ticks.
  • Against the old example, 47 guarantees have identical LTL and the other 11 are ltlfilt-equivalent to their old form with the mode_* atom replaced by its definition. The assumption is unchanged. Because each fresh atom was an output fixed by its definition, the two specifications are equisynthesizable.
  • Two small in (a | b) specifications, one realizable and one not, give the same realize verdict as formula modes and as fresh atoms. A full realize on the ventilator does not finish in reasonable time, so it was not run.

The trade-off is a mode field that now carries a small formula language, in exchange for 10 fewer atoms in the ventilator's mutation pool and model counts.

FRET scopes over a mode formula, such as `in (PCVMode | PSVMode)`,
were imported as a fresh output atom plus a non-weakenable guarantee
`G(m <-> f)`. That definition inflated the spec, and the repair
search had to carry it as an extra output and an extra guarantee.

`Scope::m_mode` may now hold the formula itself. A bare mode lowers,
hashes and serialises byte-for-byte as before, so no determinism
golden moved. Mutation never edits a mode and similarity compares it
as text, and both are unchanged. A formula mode stays out of `modes`,
and counting adds the formula's atoms. The importer writes the
canonical formula and drops the fresh atom.

examples/ventilator-controller is re-imported: guarantees go from 68
to 58, outputs from 63 to 53 and modes from 20 to 10.

Checks:
- ctest passes 70/70, and lint and format are clean.
- All 11 formula-mode requirements are equivalent under ltlfilt to
  FRET's ftExpanded at ordinal ticks.
- Of the 58 new guarantees, 47 have identical LTL. The other 11 are
  ltlfilt-equivalent to the old ones with the mode atom replaced by
  its definition. The assumption is unchanged.
- Two small `in (a | b)` specs give the same realize verdict both
  ways: one is realizable and one is not.
- The full ventilator was not put through realize, which is too slow.
The crash-report test sent SIGSEGV with kill() right after the run printed
"Seed: 7". Starting the search lazily builds the global thread pool. glibc
blocks every signal in the thread that calls pthread_create, so the new
worker starts with the signal unblocked, and a process-directed signal can
land on it before TSan has attached that thread. TSan then aborts with
"CHECK failed: tsan_interceptors_posix.cpp:2184 ((thr->slot)) != (0)".

Send the signal to the main thread with tgkill() instead. The main thread
holds it pending until it unblocks signals, so the handler still runs on a
thread TSan knows. tgkill is Linux-only, so other platforms keep kill().

Measured locally under TSan: 7 of 40 runs failed before this change and
0 of 30 failed after it.
@benmandrew
benmandrew merged commit 9e8ab61 into main Nov 24, 2026
10 checks passed
@benmandrew
benmandrew deleted the feat/formula-modes branch November 24, 2026 19:04
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