一句话:提出Gamma,用预训练语言模型以掩码填空方式生成修复代码,替代模板修复中难以抉择的donor code检索,显著提升修复效果。
基于模板的自动程序修复虽已取得可观成效,但其关键瓶颈在于难以从局部缺陷文件中挑选合适的donor code——即便修复模式正确,错误的donor code仍会生成看似合理却实际错误的补丁。本文重新审视该路线,提出Gamma:不再检索donor code,而是将TBar等先进模板修复技术中的多种修复模板改写为掩码模式(mask pattern),把修复转化为完形填空任务,由预训练语言模型基于上下文代码片段与修复模式直接预测被掩码的代码token。作者基于UniXcoder实现了实用工具Gamma,并在Defects4J-v1.2上正确修复82个缺陷,较TBar与Recoder分别多修复14与17个缺陷;在Defects4J-v2.0与QuixBugs上分别修复45与22个缺陷,表明其可缓解数据集过拟合;基于CodeBERT与ChatGPT的变体也能分别修复80与67个缺陷,说明了方法对预训练模型的可扩展性。
Automated program repair (APR) aims to fix software bugs without manual debugging efforts and plays a crucial role in software development and maintenance. Template-based APR has been widely investigated and shown promising results. However, it is challenging for template-based APR to select the appropriate donor code, which is an important repair ingredient for generating candidate patches. Inappropriate donor code may cause plausible but incorrect patch generation even with correct fix patterns, limiting the repair performance. In this paper, we aim to revisit template-based APR, and propose Gamma, to directly leverage large pre-trained language models for donor code generation. Our main insight is that instead of retrieving donor code in the local buggy file, we can directly predict the correct code tokens based on the context code snippets and repair patterns by a cloze task. Specifically, (1) Gamma revises a variety of fix templates from state-of-the-art template-based APR techniques (i.e., TBar) and transforms them into mask patterns. (2) Gamma adopts a pre-trained language model to predict the correct code for masked code as a fill-in-the-blank task. Although our idea is general and can be built on various existing pre-trained language models, we have implemented Gamma as a practical APR tool based on the recent UniXcoder model. The experimental results demonstrate that Gamma correctly repairs 82 bugs on Defects4J-v1.2, which achieves 20.59% (14 bugs) and 26.15% (17 bugs) improvement over the previous state-of-the-art template-based approach TBar and learning-based one Recoder. Furthermore, Gamma repairs 45 bugs and 22 bugs from the additional Defects4J-v2.0 and QuixBugs, indicating the generalizability of Gamma in addressing the dataset overfitting issue. We also prove that adopting other pre-trained language models can provide substantial advancement, e.g., CodeBERT-based and ChatGPT-based Gamma is able to fix 80 and 67 bugs on Defects4J-v1.2, indicating the scalability of Gamma. Overall, our study highlights the promising future of adopting pre-trained models to generate correct patches on top of fix patterns in practice.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@inproceedings{ZhangFZYSC23,
title = {Gamma: Revisiting Template-Based Automated Program Repair Via Mask Prediction},
author = {Quanjun Zhang and Chunrong Fang and Tongke Zhang and Bowen Yu and Weisong Sun and Zhenyu Chen},
booktitle = {ASE},
year = {2023},
doi = {10.1109/ase56229.2023.00063}
}