自动化硬分叉的零样本补丁移植
Automating Zero-Shot Patch Porting for Hard Forks
AI总结:
本文提出基于LLM的PPatHF方法,在零样本设置下通过缩减模块和移植模块实现硬分叉的函数级补丁自动移植,在Vim到Neovim的310个补丁上正确移植42.3%并减少57%手动编辑。
摘要:
分叉是代码复用的典型方式,它通过复制和修改现有代码库,为开发者提供了一种创建变体软件(称为硬分叉)的简单方法。尽管有诸多好处,分叉也导致了软件维护中的重复工作。开发者需要在硬分叉之间移植补丁,以解决相似的漏洞或实现相似的功能。由于源项目和硬分叉之间的差异,补丁移植变得复杂,需要对相同功能的不同实现进行调整。在本研究中,我们迈出了在零样本设置下自动化硬分叉补丁移植的第一步。我们首先对过去十年中从 Vim 移植到 Neovim 的补丁进行了实证研究,以调查补丁移植的必要性以及当前实践中的潜在缺陷。然后,我们提出了一种基于大语言模型(LLM)的方法(即 PPatHF),在函数级别上自动为硬分叉移植补丁。具体而言,PPatHF 由一个缩减模块和一个移植模块组成。给定参考项目中函数的补丁前和补丁后版本,以及目标项目中对应的函数,缩减模块首先通过移除与补丁关联较小的代码片段来精简输入函数。然后,移植模块利用 LLM 将补丁应用到目标项目的函数中。我们在 310 个从 Vim 移植到 Neovim 的补丁上评估了 PPatHF。实验结果表明,PPatHF 显著优于基线方法。具体而言,PPatHF 能够正确移植 131 个(42.3%)补丁,并自动化了开发者移植补丁所需的 57% 的手动编辑工作。
英文摘要:
Forking is a typical way of code reuse, which provides a simple way for developers to create a variant software (denoted as hard fork) by copying and modifying an existing codebase. Despite of the benefits, forking also leads to duplicate efforts in software maintenance. Developers need to port patches across the hard forks to address similar bugs or implement similar features. Due to the divergence between the source project and the hard fork, patch porting is complicated, which requires an adaption regarding different implementations of the same functionality. In this work, we take the first step to automate patch porting for hard forks under a zero-shot setting. We first conduct an empirical study of the patches ported from Vim to Neovim over the last ten years to investigate the necessities of patch porting and the potential flaws in the current practice. We then propose a large language model (LLM) based approach (namely PPatHF) to automatically port patches for hard forks on a function-wise basis. Specifically, PPatHF is composed of a reduction module and a porting module. Given the pre- and post-patch versions of a function from the reference project and the corresponding function from the target project, the reduction module first slims the input functions by removing code snippets less relevant to the patch. Then, the porting module leverages a LLM to apply the patch to the function from the target project. We evaluate PPatHF on 310 Neovim patches ported from Vim. The experimental results show that PPatHF outperforms the baselines significantly. Specifically, PPatHF can correctly port 131 (42.3%) patches and automate 57% of the manual edits required for the developer to port the patch.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。