Introduction
Fixing compiler errors is a daily ritual for programmers, but automating this task is notoriously difficult. Existing machine learning models for program repair face two major hurdles:
- Reasoning across distances: A compiler might report an error on line 20, but the actual mistake (like a wrong variable type) might be on line 5. Standard sequence-to-sequence models struggle to connect these distant dots.
- Data Scarcity: High-quality datasets of "broken program vs. fixed program" pairs are small and expensive to curate manually.
To address these issues, researchers introduce DrRepair, a novel framework for automatic program repair that treats compiler error messages as structural hints rather than plain text. By representing code and diagnostic feedback as a unified graph and pre-training on millions of self-supervised examples, DrRepair achieves a massive 22.9% absolute improvement in repair rates over previous state-of-the-art models.
Core Innovations
1. The Program-Feedback Graph
Instead of treating code as a simple string of text, DrRepair builds a graph that links symbols (identifiers, types, operators) across the source code and the compiler's error message.
- Nodes: Every variable name or type mentioned in the code or the error message becomes a node.
- Edges: Identical symbols are connected by edges, creating "cliques."
This structure allows a Graph Neural Network (GNN) to propagate information directly between the error message and the relevant parts of the code, regardless of how many lines apart they are.
2. Self-Supervised Learning (DrPerturb)
To solve the data scarcity problem, the authors developed DrPerturb. They took hundreds of thousands of working programs from the web and "broke" them using randomized modules that mimic common human errors:
- Syntax: Messing up semicolons or braces.
- ID-type: Changing a
stringto achar. - ID-typo: Misspelling variable names.
- Keyword: Swapping
ifforwhile.
By running these corrupted programs through a real compiler, they automatically generated 1.5 million training examples (broken code + compiler feedback + original fix) without any manual labeling.
Key Insights
- Feedback as a Map: The compiler message isn't just a string; it acts as a pointer. By explicitly linking the symbols in the message to the code, the model "learns" to jump directly to the source of the problem.
- The "Aha" Moment in Attention: Visualization of the model's attention shows that when it sees an error about a variable on line 9, the graph allows it to immediately focus on the line where that variable was declared (e.g., line 5), effectively tracking the symbol's history.
- Synthetic Errors Must Be Realistic: Simple random token deletion proved to be a poor pre-training task. The targeted DrPerturb modules were significantly more effective because they forced the model to learn the specific rules of C++ semantics and syntax.
Datasets and Results
The model was pre-trained on 310,000 successful C++ programs from Codeforces.com (yielding 1.5 million synthetic repair examples) and evaluated on two primary benchmarks:
- DeepFix: A dataset of broken C programs submitted by students in introductory programming courses. DrRepair achieved a 68.2% full repair rate, a staggering +22.9% absolute improvement over the previous best model (SampleFix).
- SPoC: A dataset where the goal is to synthesize C++ code from natural language pseudocode. DrRepair was used to fix the "near-miss" programs that failed to compile, improving the synthesis success rate to 48.4% (+3.7% over the prior best).
Ablation studies confirmed that the graph representation and the pre-training are complementary. Using the graph alone improved performance, but combining it with self-supervised pre-training yielded the best results, especially for rare or complex error types.
Limitations and Future Work
- Single-Line Fixes: The current architecture is optimized to repair one line at a time. While it can be run iteratively to fix multiple errors, it might struggle with bugs that require simultaneous changes across many lines.
- Compiler Dependency: The model relies heavily on the quality of the compiler's diagnostic feedback. If a compiler provides a misleading error message, the model's performance may degrade.
- Broader Applications: The authors suggest this "edit-based-on-feedback" paradigm could be extended beyond code—for example, to automated essay grading or interactive dialogue systems where a user provides corrective feedback.
Summary updated