一句话:提出多模态 NMT 代码编辑引擎 Modit,融合编辑位置、代码上下文与提交消息,显著提升 top-1 正确补丁生成率。
基于神经机器翻译(NMT)的代码编辑系统通常只以待修改代码为输入,输出排序后的补丁候选列表,但正确补丁未必排在首位,其选择往往取决于开发者需求与补丁应用的具体上下文。本文提出 Modit,一个多模态 NMT 代码编辑引擎,同时利用三种模态信息:编辑位置、编辑代码上下文,以及作为开发者自然语言提示代理的提交消息(commit message),以约束补丁生成空间。通过深入的实验与分析,作者表明将开发者提示作为输入模态能够有效缩小补丁搜索空间,并在 top-1 位置生成正确补丁这一指标上优于当前最优模型,验证了多模态信息对自动代码编辑的价值。
In recent years, Neural Machine Translator (NMT) has shown promise in automatically editing source code. Typical NMT based code editor only considers the code that needs to be changed as input and suggests developers with a ranked list of patched code to choose from - where the correct one may not always be at the top of the list. While NMT based code editing systems generate a broad spectrum of plausible patches, the correct one depends on the developers’ requirement and often on the context where the patch is applied. Thus, if developers provide some hints, using natural language, or providing patch context, NMT models can benefit from them.As a proof of concept, in this research, we leverage three modalities of information: edit location, edit code context, commit messages (as a proxy of developers’ hint in natural language) to automatically generate edits with NMT models. To that end, we build Modit, a multi-modal NMT based code editing engine. With in-depth investigation and analysis, we show that developers’ hint as an input modality can narrow the search space for patches and outperform state-of-the-art models to generate correctly patched code in top-1 position.