Representing code changes as numeric feature vectors, i.e., code change representations, is usually an essential step to automate many software engineering tasks related to code changes, e.g., commit message generation and just-in-time defect prediction. Intuitively, the quality of code change representations is crucial for the effectiveness of automated approaches. Prior work on code changes usually designs and evaluates code change representation approaches for a specific task, and little work has investigated code change encoders that can be used and jointly trained on various tasks. To fill this gap, this work proposes a novel Code Change Representation learning approach named CCRep, which can learn to encode code changes as feature vectors for diverse downstream tasks. Specifically, CCRep regards a code change as the combination of its before-change and after-change code, leverages a pre-trained code model to obtain high-quality contextual embeddings of code, and uses a novel mechanism named query back to extract and encode the changed code fragments and make them explicitly interact with the whole code change. To evaluate CCRep and demonstrate its applicability to diverse code-change-related tasks, we apply it to three tasks: commit message generation, patch correctness assessment, and just-in-time defect prediction. Experimental results show that CCRep outperforms the state-of-the-art techniques on each task.
翻译:将代码变更表示为数值特征向量(即代码变更表示),通常是自动化许多与代码变更相关的软件工程任务的关键步骤,例如提交信息生成和即时缺陷预测。直觉上,代码变更表示的质量对自动化方法的有效性至关重要。以往关于代码变更的研究通常针对特定任务设计和评估代码变更表示方法,而很少有工作研究可应用于多种任务并可联合训练的代码变更编码器。为填补这一空白,本文提出一种名为CCRep的新型代码变更表示学习方法,该方法能够学习将代码变更编码为特征向量以适用于多种下游任务。具体而言,CCRep将代码变更视为变更前代码与变更后代码的组合,利用预训练代码模型获取高质量的代码上下文嵌入,并采用一种名为查询回退的新机制提取和编码变更后的代码片段,使其与整个代码变更显式交互。为评估CCRep并展示其对多种代码变更相关任务的适用性,我们将其应用于三个任务:提交信息生成、补丁正确性评估和即时缺陷预测。实验结果表明,CCRep在每个任务上均优于现有最先进技术。