CIRCLE: continual repair across programming languages

Wei Yuan, Quanjun Zhang, Tieke He, Chunrong Fang, Nguyen Quoc Viet Hung, Xiaodong Hao, Hongzhi Yin · DOI · OpenReview

TL;DR

This paper introduces CIRCLE, a novel framework for automatic program repair (APR) that can learn to fix bugs across multiple programming languages continually. Unlike existing APR tools that are language-specific and require retraining for new languages, CIRCLE uses a single model to adapt to new languages and bug patterns without forgetting previous knowledge, achieving state-of-the-art performance.

What Problem Does This Paper Address?

The field of Automatic Program Repair (APR) aims to automatically generate patches for buggy code, significantly reducing manual debugging effort and improving software reliability. While deep learning (DL) has shown great promise in APR, current DL-based models face two major limitations:

  1. Language Specificity: Most models are trained for a single programming language. To support multiple languages, one must train and maintain separate models, which is inefficient and doesn't leverage shared learning across languages.
  2. Static Learning: Existing models are typically trained offline. This means they cannot adapt to new bug patterns or programming languages that emerge over time without complete retraining, which is time-consuming and impractical for evolving software development environments.

This paper addresses these limitations by proposing a system that can learn to repair bugs across multiple programming languages in a continual manner, meaning it can adapt to new tasks (languages) without forgetting previously learned ones.

Methods

CIRCLE is built upon a T5 transformer model and incorporates several novel techniques to achieve continual, multi-language APR:

  • Prompt-Based Data Representation: To bridge the gap between T5's pre-training on natural language tasks and the program repair task, CIRCLE uses a prompt template. This template reformulates bug-fixing inputs into a "fill-in-the-blank" format, making it more natural for T5 to fine-tune.
  • Difficulty-Based Example Replay: To combat catastrophic forgetting (where a model forgets previously learned tasks when learning new ones), CIRCLE employs a rehearsal strategy. Instead of storing all historical data, it selects a small subset of "difficult" examples from past tasks. These examples are then replayed during training on new tasks. The difficulty is measured by how poorly the model performs on a given example.
  • Sampling-Based EWC Regularization: To further prevent forgetting, CIRCLE uses Elastic Weight Consolidation (EWC). EWC constrains the updates to parameters that are important for previous tasks. To make this scalable, CIRCLE calculates the Fisher Matrix (a measure of parameter importance) only on the sampled difficult examples, rather than the entire historical dataset.
  • Cross-Language Re-Repairing: When repairing code across different languages, models can sometimes generate keywords with similar meanings but different syntax (e.g., "None" in Python vs. "null" in Java). CIRCLE includes a re-repairing mechanism that uses simple mapping tables and regular expressions to correct these cross-language errors, as well as format mismatches and rare symbol issues.

Datasets

The paper uses publicly available datasets for training and evaluation:

  • Training Data: The CoCoNut's training data is used, which includes bug-fix pairs for Java, Python, C, and JavaScript. For evaluation, a subset of 0.4 million examples was randomly selected due to computational constraints.
  • Evaluation Benchmarks: The evaluation is conducted on five commonly used benchmarks:
  • Defects4J (Java)
    • QuixBugs (Java and Python)
    • BugIDs (JavaScript)
    • ManyBugs (C)

Key Insights and Ideas

  • Shared Knowledge Across Languages: The paper's core hypothesis is that underlying code understanding and bug-fixing abilities are transferable across programming languages. This justifies the pursuit of a single, continually learning model.
  • Prompting for APR: Using prompt-based input significantly improves the convergence of T5 for the APR task, demonstrating the effectiveness of adapting pre-trained NLP models to code-related tasks.
  • Targeted Rehearsal is Key: Simply replaying random examples isn't enough. Focusing on "difficult" examples from previous tasks is crucial for effective continual learning, as these are the ones the model is most likely to forget.
  • Re-repairing for Robustness: Even powerful models like T5 can make subtle errors when dealing with cross-language nuances. A simple re-repairing step is surprisingly effective at cleaning up these generated patches.

Key Results

  • Continual Learning Effectiveness (RQ1): CIRCLE significantly outperforms a baseline "Finetuned-APR" model (which is retrained on new tasks without continual learning mechanisms) in a scenario where tasks arrive sequentially. CIRCLE shows much less performance degradation on previously learned tasks.
  • State-of-the-Art Performance (RQ2): A single CIRCLE model achieves state-of-the-art results across multiple benchmarks and languages, fixing 64 bugs in Defects4J and outperforming many specialized APR tools. It demonstrates strong performance on Java, Python, JavaScript, and C.
  • Component Contributions (RQ3):
    • Prompt-based input leads to lower validation loss and faster convergence.
  • The re-repairing mechanism improves the number of fixed bugs across all benchmarks.
  • The continual learning module (difficulty-based replay + EWC) is essential for maintaining performance on older tasks while learning new ones.

Limitations and Future Work

  • Computational Cost: While CIRCLE avoids retraining on full historical datasets, continual learning and EWC still require significant computational resources. The paper mentions using a subset of data for training due to these limitations.
  • Re-repairing Limitations: The re-repairing mechanism relies on predefined rules and mappings, which might not cover all possible cross-language errors or complex syntax issues.
  • Future Work: The authors suggest exploring more advanced continual learning strategies and expanding the re-repairing mechanism to handle a wider range of errors. They also highlight the potential for CIRCLE to be applied to other code-related tasks beyond bug fixing.

Summary updated

BibTeX
@inproceedings{yuan2022circle,
  author = {Wei Yuan and Quanjun Zhang and Tieke He and Chunrong Fang and Nguyen Quoc Viet Hung and Xiaodong Hao and Hongzhi Yin},
  title = {{CIRCLE: continual repair across programming languages}},
  booktitle = {ISSTA},
  year = {2022},
  doi = {10.1145/3533767.3534219},
}
Figure