Skip to content

Checkpoint/restore for compiler IR state between passes #79

@avrabe

Description

@avrabe

Context

NASA Trick simulation framework can snapshot and restore full simulation state at any point. Rapier Physics guarantees deterministic, bit-identical state serialization. Both use this for debugging, regression testing, and incremental computation.

Problem

When a compilation issue occurs in Synth, debugging requires re-running the full pipeline. There's no way to inspect IR state between passes, compare IR across compiler versions, or skip unchanged passes during incremental recompilation.

Proposal

Add serializable IR checkpoints between compilation phases:

  1. Serialize IR state after each major phase (parse → IR → optimize → select → encode)
  2. Deterministic serialization — bit-identical output for identical input (avoid HashMap iteration order, etc.)
  3. Use cases:
    • Debugging: Dump IR before/after a suspicious pass
    • Regression testing: Diff serialized IR between compiler versions
    • Bisection: Binary search for which pass introduced a problem
    • Incremental recompilation: Skip passes whose inputs haven't changed
    • Snapshot-diff verification: Prove pre/post snapshots are equivalent via Z3 (complementing Rocq proofs)

Implementation

  • Derive serde::Serialize/Deserialize on IR types
  • Add --checkpoint-dir <path> CLI flag to synth-cli
  • Add --resume-from <phase> flag to skip completed phases
  • Determinism: use BTreeMap instead of HashMap in IR, or sort before serialization

Priority

Medium-High — enables incremental compilation and snapshot-diff verification.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions