TransRepair: Context-aware Program Repair for Compilation Errors

Xueyang Li, Shangqing Liu, Ruitao Feng, Guozhu Meng, Xiaofei Xie, Kai Chen, Yang Liu

Abstract

Automated Program Repair (APR) for compilation errors remains a significant challenge due to the discrepancy between compiler error reports and the actual root causes of bugs. This paper presents TransRepair, a Transformer-based framework that integrates compiler diagnostic feedback with a specialized context analyzer. By training on a novel synthetic dataset of over 1.8 million programs derived from a comprehensive 74-pattern error taxonomy, TransRepair demonstrates superior performance in both error localization and repair. Experimental results on the DeepFix and TRACER benchmarks show that TransRepair achieves a 68.53% full repair rate, outperforming existing state-of-the-art tools.

1. Introduction

Fixing compilation errors is a fundamental task in software development, yet it poses a substantial hurdle for novice programmers and automated code generation systems. Traditional Automated Program Repair (APR) tools often fail to resolve these errors effectively due to three primary limitations: misleading compiler feedback, where the reported error line is a symptom rather than the cause; a lack of global context, where the model fails to see relevant variable declarations or type definitions; and a scarcity of diverse training data.

TransRepair addresses these challenges by shifting the focus from isolated line repair to context-aware program analysis. By leveraging the Transformer architecture's ability to handle long-range dependencies and incorporating a pointer mechanism for out-of-vocabulary tokens, TransRepair provides a robust solution for fixing complex C compilation errors.

2. Methodology

The TransRepair framework is built upon an end-to-end Transformer architecture, optimized through several key components:

2.1 Context Analyzer

To overcome the limitations of local error analysis, the Context Analyzer performs lexical analysis to identify lines related to the error. It specifically tracks variable declarations and previous usages, providing the model with the necessary scope to resolve "variable not defined" or "type mismatch" errors that occur far from the initial declaration.

2.2 Transformer-based Encoder-Decoder

Unlike previous Recurrent Neural Network (RNN) models, the Transformer architecture allows TransRepair to relate compiler error messages to distant code segments effectively. This global attention mechanism is crucial for understanding the relationship between the error diagnostic and the program structure.

2.3 Pointer Mechanism

Codebases frequently contain unique identifiers and custom variable names that are not present in a standard vocabulary. TransRepair utilizes a pointer mechanism that allows the decoder to copy specific tokens directly from the input sequence, mitigating the "Out-of-Vocabulary" (OOV) problem.

2.4 Multi-Task Learning

The model is trained using a multi-task learning objective. It simultaneously learns to locate the erroneous line via a Multi-Layer Perceptron (MLP) head and generate the corrected code via the Transformer decoder. This dual focus ensures that the model's generative capabilities are grounded in accurate error localization.

3. Data Generation and Taxonomy

A significant contribution of this work is the creation of a high-quality, large-scale dataset. The authors developed a 74-pattern taxonomy of C compilation errors by analyzing data from DeepFix, TRACER, and StackOverflow. These patterns span five categories: Structure, Statement, Variable Declaration, Type Mismatch, and Identifier Misuse.

Using this taxonomy, the researchers employed a "program corruption" technique to generate a synthetic dataset of 1,821,275 erroneous C programs. This diversity allows the model to generalize across a wide array of real-world coding mistakes that previous models, trained on narrower datasets, could not handle.

4. Experimental Results

TransRepair was evaluated against the DeepFix and TRACER benchmarks, comparing its performance with state-of-the-art tools like DrRepair.

  • Repair Accuracy: On the TRACER dataset, TransRepair achieved a 49.65% Acc@1 for single repairs, surpassing DrRepair’s 48.56%.
  • Full Program Repair: On the DeepFix test set, which requires iterative fixing of multiple errors, TransRepair achieved a 68.53% full repair rate—a nearly 5% improvement over previous benchmarks.
  • Ablation Studies: Tests confirmed that both the "context" and "diagnostic feedback" are vital. Removing either component resulted in a significant decline in repair accuracy, validating the multi-modal approach.

5. Discussion: The Localization-Repair Paradox

An interesting finding in the evaluation was that while TransRepair's exact localization accuracy (83.21%) was slightly lower than some LSTM-based models (86.72%), its overall repair success was higher. This suggests that the Transformer’s generative power is robust enough to compensate for minor offsets in localization, effectively "finding" the fix even if the initial search was slightly off-target.

6. Conclusion and Future Work

TransRepair demonstrates that context-aware modeling and diverse synthetic data are essential for automated compilation error repair. While currently specialized for the C language and self-contained programs, future work will focus on improving localization precision and extending the framework to support other languages like Java and Python, as well as complex multi-file software systems.

Summary updated

BibTeX
@inproceedings{li2022transrepair,
  author = {Xueyang Li and Shangqing Liu and Ruitao Feng and Guozhu Meng and Xiaofei Xie and Kai Chen and Yang Liu},
  title = {{TransRepair: Context-aware Program Repair for Compilation Errors}},
  booktitle = {ASE},
  year = {2022},
  url = {https://openreview.net/forum?id=FCYISvgHmWE},
}
Figure