Abstract
Modern program synthesis and compiler optimization require representing and searching through astronomically large sets of candidate programs. While existing structures like Version-Space Algebras (VSAs) and e-graphs exploit subterm independence, they struggle with "entangled" program spaces where choices are interdependent. This paper introduces Equality-Constrained Tree Automata (ECTAs), a novel data structure designed to represent these dependencies compactly. By implementing ECTA-based search with static and dynamic reduction algorithms, we developed Hectare, a Haskell synthesizer that is significantly more efficient and concise than current state-of-the-art tools.
Introduction
In the field of program synthesis, the primary challenge is the scale of the search space. To manage this, researchers typically use data structures that represent many programs simultaneously by sharing common sub-expressions. However, a significant limitation of current approaches is the assumption of independence: the belief that choosing a subterm for one part of a program does not restrict the choices for another.
In reality, program spaces are often highly "entangled." For example, in type-driven synthesis involving polymorphic functions (e.g., $f : \alpha \to \alpha$), the specific type chosen for the input must strictly match the type of the output. Traditional structures like VSAs or e-graphs cannot natively represent these constraints, often leading to a combinatorial explosion of nodes or requiring inefficient "guess-and-check" backtracking during the search process.
Equality-Constrained Tree Automata (ECTA)
To address the limitations of existing structures, we propose Equality-Constrained Tree Automata (ECTAs). An ECTA extends standard tree automata by annotating transitions with equality constraints between different paths in the tree. For instance, a constraint might specify that the subterm at path 0.0 must be identical to the subterm at path 1.0. This allows the data structure to represent dependencies as first-class citizens.
Static and Dynamic Reduction
Representing constraints is only half the battle; searching them efficiently is the other. We introduce two core algorithms to optimize ECTA search:
- Static Reduction: This process occurs before enumeration. By performing automata intersection, the algorithm prunes branches that can never satisfy the defined equality constraints. This significantly reduces the size of the search space before the synthesizer even begins generating code.
- Dynamic Reduction: During enumeration, the algorithm avoids "eager" guessing. Instead of picking a concrete term and checking if it fits, it uses unification variables to represent constrained nodes. This defers specific choices until sufficient information is available, transforming the search into a constraint-solving process that minimizes unnecessary backtracking.
Furthermore, we extend these concepts to Cyclic ECTAs, which use a "lasso form" representation to handle infinite program spaces, such as those found in recursive Haskell types.
Evaluation: The Hectare Synthesizer
We evaluated the ECTA framework by building Hectare, a type-driven synthesizer for Haskell. Hectare was benchmarked against Hoogle+, the previous state-of-the-art, using two primary datasets:
- Hoogle+ Benchmarks: 45 standard synthesis queries involving 291 library components.
- StackOverflow Benchmarks: 19 complex queries involving higher-order functions and partial applications—scenarios that typically challenge existing synthesizers.
Key Results
Hectare demonstrated substantial improvements in both performance and simplicity:
- Efficiency: Hectare achieved an average 8x speedup over Hoogle+. In an interactive IDE context, Hectare solved 84% of benchmarks in under 7 seconds.
- Reliability: Hectare solved 88% of the total benchmark suite, compared to only 64% for Hoogle+.
- Code Complexity: Due to the native handling of polymorphism and higher-order functions via ECTAs, Hectare consists of only 400 lines of Haskell code—a 10x reduction compared to the 4,000 lines required for Hoogle+.
Discussion and Future Work
The success of ECTAs suggests that the primary bottleneck in modern synthesis is not the raw size of the search space, but the complexity of the dependencies within it. By treating equality constraints as fundamental components of the data structure, we can reason about these dependencies directly rather than treating them as secondary filters.
However, several avenues for future research remain. Currently, ECTAs are optimized to find any valid program, but they lack a native mechanism for "optimal extraction" (finding the most idiomatic or shortest code). Additionally, while the current system focuses on equality, future iterations could incorporate disequality constraints. Finally, while we have established a "finitely-constrained" restriction to ensure decidability in cyclic ECTAs, further exploration of the boundaries of tractability in infinite spaces is warranted.
Conclusion
Equality-Constrained Tree Automata provide a powerful new lens for program synthesis. By shifting the focus toward entanglement and utilizing lazy, constraint-driven reduction, we can build synthesizers that are both faster and significantly simpler than previous generations of tools.
Summary updated