Synthesizing Formal Semantics from Executable Interpreters

Jiangyi Liu, Charlie Murphy, Anvay Grover, Keith J. C. Johnson, Thomas W. Reps, Loris D'Antoni · DOI · OpenReview

TL;DR

This paper introduces SYNANTIC, a novel algorithm and tool that automatically synthesizes formal semantics for programming languages directly from executable interpreters. This significantly lowers the barrier to entry for using advanced program verification and synthesis tools, which traditionally require manual, error-prone semantic definitions.

What Problem Does This Paper Address?

Many powerful program verification and synthesis frameworks rely on formally defined language semantics. However, writing these semantics is a notoriously difficult, time-consuming, and error-prone task, often involving natural language descriptions that can be ambiguous or inconsistent. This requirement acts as a major bottleneck, preventing broader adoption of these advanced tools by users who may not be experts in formal semantics. The authors aim to bridge this gap by automating the creation of formal semantics from readily available executable interpreters.

Methods

The core of the paper is the SYNANTIC algorithm, which employs a Counterexample-Guided Synthesis (CEGIS) approach. Instead of trying to synthesize the entire semantics at once, SYNANTIC breaks down the problem by synthesizing the semantic rule for each grammar production (language construct) independently.

Key techniques include:

  • Constrained Horn Clauses (CHCs): Formal semantics are represented using CHCs, a well-established logical framework suitable for inductive definitions and compositional reasoning.
  • CEGIS Loop: For each production, SYNANTIC iteratively synthesizes a candidate semantic constraint. This candidate is then verified against the executable interpreter. If an inconsistency is found, a counterexample is generated, added to the example set, and the synthesis process repeats with the updated information.
  • SyGuS Solver Integration: The problem of synthesizing the semantic constraint for each production is framed as a Syntax-Guided Synthesis (SyGuS) problem, which is then dispatched to existing SyGuS solvers.
  • Per-Production Synthesis: The algorithm synthesizes semantics production by production, starting from simpler, "leaf" productions and building up to more complex ones. This compositional approach makes the problem tractable.
  • Multi-Output Optimization: For productions with multiple outputs (e.g., assignments to multiple variables), SYNANTIC employs an optimization to synthesize constraints for each output independently, reducing the complexity for the SyGuS solver.

Datasets

The authors evaluated SYNANTIC on 15 benchmarks, categorized as follows:

  • SemGuS Benchmarks: 11 languages from the SemGuS benchmark repository, chosen for their relevance to program synthesis applications.
  • Attribute-Grammar Synthesis Benchmarks: 4 languages from the Panini tool for synthesizing attribute grammars.

They specifically excluded languages with abstract data types or those requiring a large range of inputs due to SyGuS solver limitations. For parametric languages, they tested up to the largest parameter value for which the solver did not time out.

Key Insights and Ideas

  • Executable interpreters are a rich source for formal semantics: The paper demonstrates that a "closed-box" executable interpreter, without needing internal access, is sufficient to derive a formal semantics. This is a significant finding as interpreters are often more readily available than formal semantics.
  • Decomposition is key: The CEGIS approach applied per-production is crucial. Synthesizing the entire semantics monolithically is infeasible; breaking it down into smaller, manageable synthesis problems for each language construct makes the task achievable.
  • CHCs are a natural fit: The choice of CHCs for representing semantics aligns well with the inductive nature of grammars and facilitates compositional reasoning, which is essential for the per-production synthesis strategy.
  • Automated synthesis can uncover bugs: In one benchmark, SYNANTIC's synthesized semantics revealed an inconsistency in the original manually-written semantics, leading to a more efficient implementation. This highlights the potential of automated tools not just for generation but also for debugging and improving existing code.
  • Theory choice matters for performance: For the IMPARR language, using the theory of arrays to model an arbitrary number of variables resulted in faster synthesis compared to IMP(2), which explicitly passed a fixed number of variables. This suggests that choosing appropriate SMT theories can significantly simplify the synthesis problem.

Key Results

  • High success rate: SYNANTIC successfully synthesized complete semantics for 12 out of 15 benchmark languages (approximately 80%).
  • Efficiency gains: For one benchmark (regular expressions), fixing an inconsistency found by SYNANTIC led to a speedup of up to 1.2x for a synthesizer.
  • Performance breakdown: The majority of the synthesis time is spent solving SyGuS problems (median 16.24% of total solving time), with a significant portion also spent on SMT queries (median 19.90%). For slower rules, SyGuS solving time can dominate (up to 64.91%).
  • Multi-output optimization effectiveness: The optimization for multi-output productions was effective for languages with 3 or more output variables, preventing timeouts in many cases.
  • Identical or equivalent semantics: For most benchmarks, the synthesized semantics were either identical to or logically equivalent to the manually written ones.

Limitations and Future Work

  • SyGuS solver limitations: The performance and scalability of the SyGuS solver are a bottleneck, especially for complex semantic constraints or languages with many outputs. The authors note that the time-out often occurred during SyGuS solver calls.
  • Theory support: The current approach is limited by the theories supported by SyGuS solvers. Future work could involve extending SYNANTIC to use "higher-level" theories that support more complex abstractions like stores or algebraic data types.
  • Recursive semantics complexity: While SYNANTIC handles semantically recursive productions, the synthesis of these can be time-consuming, as seen with the do_while loop example.
  • Manual intervention for complex cases: For some benchmarks, SYNANTIC timed out, indicating that the complexity of the required semantic functions exceeded the system's capabilities within the given time limits.

The authors suggest extending SYNANTIC to leverage SemGuS solvers themselves for synthesizing semantic constraints, potentially enabling the use of more advanced theories.

Summary updated

BibTeX
@article{liu2024synthesizing,
  author = {Jiangyi Liu and Charlie Murphy and Anvay Grover and Keith J. C. Johnson and Thomas W. Reps and Loris D'Antoni},
  title = {{Synthesizing Formal Semantics from Executable Interpreters}},
  journal = {Proc. ACM Program. Lang.},
  year = {2024},
  doi = {10.1145/3689724},
}
Figure