Skip to main content
QUICK REVIEW

[论文解读] RAP-Gen: Retrieval-Augmented Patch Generation with CodeT5 for Automatic Program Repair

Weishi Wang, Yue Wang|arXiv (Cornell University)|Sep 12, 2023
Software Engineering Research被引用 4
一句话总结

RAP-Gen 是一种用于自动程序修复的检索增强框架,通过从代码库中检索相关修复模式来增强基于 CodeT5 的补丁生成。通过集成混合词汇-语义检索器和统一的 CodeT5 主干网络,RAP-Gen 在 JavaScript 和 Java 基准测试中提升了修复准确率,实现了最先进水平的结果,包括在 TFix 上达到 54.15% 的修复率,以及在 Defects4J 上比之前的方法多修复 15 个缺陷。

ABSTRACT

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.

研究动机与目标

  • 通过引入显式的、外部的修复模式,减轻参数化深度学习模型在自动程序修复中的负担。
  • 通过使用语言无关的混合检索机制,从代码库中检索相关的错误-修复对,以提升修复准确率。
  • 利用 CodeT5 作为基础模型,在单一框架中统一补丁检索与生成。
  • 在 JavaScript 和 Java 的多样化 APR 基准测试中,展示检索增强生成的有效性。
  • 验证开发者式的调试行为(即参考先前修复)可以被有效建模并应用于 APR。

提出的方法

  • 设计了一种混合补丁检索器,可在无需代码特定特征的情况下,对原始源代码执行词汇和语义匹配,实现语言无关的检索。
  • 检索器从历史补丁的代码库中识别出最相关的错误-修复对,作为生成器的引导信号。
  • 对 CodeT5 进行微调,使其作为统一模型用于检索与生成,实现共享表示的端到端训练。
  • 采用分阶段框架:首先检索相关修复模式,然后将其与有错误的代码拼接,再生成候选补丁。
  • 该框架具有通用性,支持与多种检索器和生成器集成,可在不同缺陷类型和编程语言中灵活部署。
  • 检索采用 top-k 策略,检索到的修复模式与有错误的代码拼接,以引导生成过程。

实验结果

研究问题

  • RQ1检索相关历史修复模式是否能提升基于深度学习的程序修复模型的性能?
  • RQ2与纯参数化模型相比,检索增强方法在多样化基准测试中的修复准确率如何?
  • RQ3哪些类型的修复模式(例如,插入代码块、删除语句)在引导修复生成方面最有效?
  • RQ4检索机制在多大程度上反映了现实世界中开发者调试的行为?
  • RQ5该框架是否能在不依赖代码特定特征的情况下,跨编程语言和缺陷类型实现泛化?

主要发现

  • 在 JavaScript 的 TFix 基准测试中,RAP-Gen 达到 54.15% 的修复准确率,比 T5-large 基线(49.70%)高出 4.45 个百分点的绝对提升。
  • 在 Java 的 Defects4J 基准测试中,RAP-Gen 比之前的 SOTA 方法多修复 15 个缺陷,表明在真实修复场景中取得显著提升。
  • 混合检索器能有效检索相关修复模式,其中 P13('插入现有代码块')和 P14('删除语句')在 39 个难以修复的缺陷中最为有效。
  • 从基于规则的修复模式(例如,来自 SelfAPR)中检索,可提升 CodeT5 在 39 个此前无法修复的 Defects4J 缺陷上的表现,证实了检索引导生成的价值。
  • 即使在未提供错误定位信息的情况下,该框架仍保持强劲性能,表明其在实际场景中的鲁棒性。
  • 消融实验证实,检索器中词汇匹配与语义匹配的结合对检索质量及下游修复准确率均有显著贡献。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。