Automatic program repair (APR) is crucial to reduce manual debugging efforts for developers and improve software reliability. While conventional search-based techniques typically rely on heuristic rules or a redundancy assumption to mine fix patterns, recent years have witnessed the surge of deep learning (DL) based approaches to automate the program repair process in a data-driven manner. However, their performance is often limited by a fixed set of parameters to model the highly complex search space of APR. To ease such burden on the parametric models, in this work, we propose a novel Retrieval-Augmented Patch Generation framework (RAP-Gen) by explicitly leveraging relevant fix patterns retrieved from a codebase of previous bug-fix pairs. Specifically, we build a hybrid patch retriever to account for both lexical and semantic matching based on the raw source code in a language-agnostic manner, which does not rely on any code-specific features. In addition, we adapt a code-aware language model CodeT5 as our foundation model to facilitate both patch retrieval and generation tasks in a unified manner. We adopt a stage-wise approach where the patch retriever first retrieves a relevant external bug-fix pair to augment the buggy input for the CodeT5 patch generator, which synthesizes a ranked list of repair patch candidates. Notably, RAP-Gen is a generic APR framework that can flexibly integrate different patch retrievers and generators to repair various types of bugs. We thoroughly evaluate RAP-Gen on three benchmarks in two programming languages, including the TFix benchmark in JavaScript, and Code Refinement and Defects4J benchmarks in Java, where the bug localization information may or may not be provided. Experimental results show that RAP-Gen significantly outperforms previous state-of-the-art approaches on all benchmarks, e.g., repairing 15 more bugs on 818 Defects4J bugs.
翻译:自动程序修复(APR)对于减少开发人员的手动调试工作并提升软件可靠性至关重要。传统基于搜索的技术通常依赖启发式规则或冗余性假设来挖掘修复模式,而近年来,基于深度学习(DL)的方法以数据驱动方式自动化程序修复过程逐渐兴起。然而,由于模型采用固定参数集来描述APR高度复杂的搜索空间,其性能常受局限。为减轻参数化模型的这一负担,本文提出一种新颖的检索增强补丁生成框架(RAP-Gen),通过显式利用从历史缺陷-修复对代码库中检索到的相关修复模式。具体而言,我们构建了一个混合补丁检索器,基于原始源代码以语言无关方式实现词汇和语义匹配,且不依赖任何代码特定特征。此外,我们采用代码感知语言模型CodeT5作为基础模型,以统一方式同时支持补丁检索和生成任务。我们采用分阶段方法,首先由补丁检索器检索相关外部缺陷-修复对来增强CodeT5补丁生成器的缺陷输入,随后由生成器合成排序后的修复候选补丁列表。值得注意的是,RAP-Gen是一种通用APR框架,可灵活集成不同补丁检索器和生成器以修复多种类型缺陷。我们在两个编程语言的三个基准(包括JavaScript语言的TFix基准、以及Java语言的Code Refinement和Defects4J基准)上对RAP-Gen进行全面评估,其中缺陷定位信息可能提供或不提供。实验结果表明,RAP-Gen在所有基准上均显著优于先前最先进方法,例如在包含818个缺陷的Defects4J基准上多修复了15个缺陷。