NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Write, Execute, Assess: Program Synthesis with a REPL

Kevin Ellis, Maxwell I. Nye, Yewen Pu, Felix Sosa, Josh Tenenbaum, Armando Solar-LezamaarXiv 2019

Abstract

Neural program synthesis often struggles with the "brittleness" of code, where minor syntactic changes lead to drastic behavioral shifts. This paper presents a framework that integrates a Read-Eval-Print Loop (REPL) into the synthesis process, allowing models to "write, execute, and assess" code incrementally. By combining a policy network for code generation with a value function for state assessment, and utilizing Sequential Monte Carlo (SMC) search, the system effectively navigates complex semantic spaces. Evaluation on Inverse CAD and string-editing tasks demonstrates that this execution-guided approach significantly outperforms syntax-only models, scaling to more complex programs with higher efficiency.

Introduction: The Brittleness of Code

Program synthesis—the task of automatically generating code from a specification, such as input-output examples—is a fundamental challenge in AI. The primary difficulty lies in the "brittleness" of code: a single character change can completely alter a program's behavior, creating a "jagged" landscape where syntax and semantics are poorly correlated.

Most neural synthesizers attempt to write a program in one "shot" or use beam search based purely on the probability of the next token. However, this deviates from the human coding process. Humans typically write a few lines, run them in a REPL, observe the output, and decide whether to continue or backtrack. This paper addresses the gap between machine-led (syntax-heavy) and human-led (semantic-heavy) synthesis by integrating an interpreter directly into the search loop.

Overview of the program synthesis tasks for 3D CAD and string editing.

Methodology: The Write-Execute-Assess Loop

The authors frame program synthesis as a search problem within a Markov Decision Process (MDP). The system consists of three core components:

  1. The REPL (The Interpreter): Instead of analyzing raw code, the model observes the execution state. In graphics tasks, this is the rendered image; in text editing, it is the partially transformed string. This bridges the gap between syntax and semantics.
  2. The Policy ($\pi$) and Value Function ($v$):
    • The Policy proposes the next action (e.g., "add a circle" or "concatenate a substring").
  3. The Value Function predicts the probability that the current partial program will eventually satisfy the goal.
  4. Both are trained using a mix of supervised pretraining and reinforcement learning (REINFORCE).
  5. Sequential Monte Carlo (SMC) Search: At test time, the system maintains a "population" of candidate programs (particles). In each step, the policy proposes extensions, the REPL executes them, and the value function re-weights the candidates. Unpromising branches are pruned, and promising ones are "cloned," focusing the search on the most likely solutions.

Experimental Setup

The approach was evaluated on two distinct domains:

  • Inverse CAD (Computer-Aided Design): Generating Constructive Solid Geometry (CSG) programs to render target 2D or 3D shapes. Training involved scenes with up to 13 objects, while testing pushed the complexity to 30 objects.
  • String Editing: Based on "FlashFill" style programming-by-example. The researchers used the RobustFill language but introduced a new, more challenging dataset of 87 problems across 34 templates (e.g., transforming dates, addresses, and movie reviews) to test the limits of neural synthesizers.

Key Insights: Semantics over Syntax

A primary finding is that conditioning the search on execution states rather than just code tokens allows the model to perform search in the "semantic space." This makes the model much more robust to the inherent brittleness of code.

Furthermore, while prior execution-guided models used the REPL to inform the next step, this work demonstrates that using the REPL to evaluate the current state (via the value function) is what enables sophisticated search algorithms like SMC to succeed where traditional beam search fails. Additionally, SMC is highly parallelizable, allowing sampling and resampling steps to be batched on a GPU for high throughput.

Key Results

The system demonstrated significant improvements in both complexity scaling and efficiency:

  • Complexity Scaling: In 3D graphics, the system successfully inferred programs up to 19 lines long, navigating a branching factor of ~1.3 million per line. Baselines without the REPL or value function failed to scale beyond 3 lines.
  • Efficiency in Text Editing: On string editing tasks, the SMC-based search solved significantly more problems than RobustFill or beam search, often requiring 10x fewer node expansions.
  • Generalization: The models showed strong out-of-sample generalization, solving 2D graphics problems with 30 objects despite being trained on much simpler scenes.
Performance comparison showing the superiority of the SMC approach over various baselines.

Limitations and Future Work

Despite its success, the system has limitations. It currently requires domain-specific REPLs and defined grammars (DSLs) for every new task, which can be difficult to build. Additionally, the implementation focuses on "straight-line" code and does not yet handle complex control flow like loops or conditional branching.

Future work may explore stack-based languages (like Forth) as a natural fit for REPL-like representations of control flow. The authors also envision integrating other human-centric tools, such as debuggers and profilers, into the synthesis loop to further enhance the model's capabilities.

Summary updated

BibTeX
@misc{ellis2019write,
  author = {Kevin Ellis and Maxwell I. Nye and Yewen Pu and Felix Sosa and Josh Tenenbaum and Armando Solar-Lezama},
  title = {{Write, Execute, Assess: Program Synthesis with a REPL}},
  year = {2019},
  eprint = {1906.04604},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1906.04604},
}
Figure