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

Automatic Program Synthesis of Long Programs with a Learned Garbage Collector

Amit Zohar, Lior Wolf

Introduction

Automatic program synthesis—the ability to generate code that satisfies a given set of input-output examples—is often considered a "holy grail" of artificial intelligence. However, it faces a massive scaling problem: the search space of possible programs grows exponentially with the program's length.

Previous state-of-the-art models, such as DeepCoder, attempted to solve this by predicting which functions were likely to appear in a program and then using an optimized search. While effective for short snippets (around 5–6 lines), this "global" approach falls apart as programs get longer. Furthermore, in Domain Specific Languages (DSLs) where every line creates a new variable, the system quickly runs out of "memory slots" to track intermediate states, making it nearly impossible to reason about complex, multi-step logic.

To address this, researchers introduce PCCoder (Predict and Collect Coder), a neural program synthesis tool that generates code step-by-step. Its core innovation is a learned garbage collector that identifies and discards unnecessary variables, allowing the model to synthesize programs twice as long as previous state-of-the-art methods while running up to 100 times faster.

The PCCoder Architecture and Learned Garbage Collector

PCCoder shifts away from global prediction in favor of a step-wise approach. Instead of guessing the whole program at once, a neural network evaluates the current state (the values of all variables currently in memory) and predicts the next most likely statement, including the operator and its operands.

PCCoder Architecture

To manage the exploding state space, PCCoder introduces a Learned Garbage Collector (GC). A dedicated neural network head is trained to predict which variables in memory are no longer needed for future steps. When the memory limit is reached, the GC "drops" the least useful variables. Interestingly, training this GC acts as an auxiliary task that forces the model to learn the "lifetime" of a variable, helping the main network better understand the underlying program logic.

The model processes the program state using a "Dense Block" architecture (inspired by DenseNet). This uses skip-connections to maintain high model capacity while keeping the network relatively shallow and fast—essential for a model evaluated thousands of times during search. The search itself is conducted using Complete Anytime Beam search (CAB), a "spiral" search that starts narrow and gradually weakens pruning rules to find solutions quickly while remaining exhaustive.

Datasets and Key Insights

The model was trained and evaluated on a synthetic dataset generated from a specific DSL (first introduced in the DeepCoder paper), which includes 19 lambda functions and higher-order operators like MAP, FILTER, and SORT. The training set comprised 143,000 programs, with 2,500 semantically disjoint programs reserved for testing (ranging from length 5 to 14).

A key insight from the development of PCCoder is prioritizing search efficiency over raw evaluation speed. While PCCoder is slower per individual neural network evaluation than simpler models, its predictions are vastly more accurate. This accuracy allows it to explore far fewer "dead-end" paths, leading to a massive overall reduction in runtime. Furthermore, the model treats the input-output examples as a permutation-invariant set, using average pooling to combine information from multiple examples into a single robust "environment" representation.

Key Results

PCCoder significantly outperforms the DeepCoder baseline across all metrics, particularly as program length increases.

Performance Comparison Table
  • Speed: For programs of length 5, PCCoder reached a 60% success rate in just 259 seconds, compared to 2,654 seconds for the original DeepCoder—a 10x improvement. In some configurations, it was two orders of magnitude (100x) faster.
  • Complexity and Length: PCCoder successfully synthesized programs up to 14 statements long, maintaining a 52%–60% success rate. In contrast, DeepCoder failed to solve even 5% of programs longer than 10 statements.
  • Accuracy: On the original benchmarks used in previous literature, PCCoder achieved near-perfect accuracy within the allotted time budget.

Limitations and Future Work

While PCCoder represents a significant leap in program synthesis, it is currently tied to a specific, relatively simple DSL. Extending this approach to general-purpose languages like Python remains a challenge due to the increased complexity of state representation. Additionally, the current architecture assumes a small, fixed number of input-output examples. Future work may explore incorporating Reinforcement Learning (RL) or more advanced "look-ahead" strategies to handle even more complex logic and broader language applications.

Summary updated

BibTeX
@inproceedings{zohar2018automatic,
  author = {Amit Zohar and Lior Wolf},
  title = {{Automatic Program Synthesis of Long Programs with a Learned Garbage Collector}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2018},
  url = {https://openreview.net/forum?id=SyND7P-d-H},
}
Figure