To effectively guide the exploration of the code transform space for automated code evolution techniques, we present in this paper the first approach for structurally predicting code transforms at the level of AST nodes using conditional random fields (CRFs). Our approach first learns offline a probabilistic model that captures how certain code transforms are applied to certain AST nodes, and then uses the learned model to predict transforms for arbitrary new, unseen code snippets. {Our approach involves a novel representation of both programs and code transforms. Specifically, we introduce the formal framework for defining the so-called AST-level code transforms and we demonstrate how the CRF model can be accordingly designed, learned, and used for prediction}. We instantiate our approach in the context of repair transform prediction for Java programs. Our instantiation contains a set of carefully designed code features, deals with the training data imbalance issue, and comprises transform constraints that are specific to code. We conduct a large-scale experimental evaluation based on a dataset of bug fixing commits from real-world Java projects. The results show that when the popular evaluation metric \emph{top-3} is used, our approach predicts the code transforms with an accuracy varying from 41\% to 53\% depending on the transforms. Our model outperforms two baselines based on history probability and neural machine translation (NMT), suggesting the importance of considering code structure in achieving good prediction accuracy. In addition, a proof-of-concept synthesizer is implemented to concretize some repair transforms to get the final patches. The evaluation of the synthesizer on the Defects4j benchmark confirms the usefulness of the predicted AST-level repair transforms in producing high-quality patches.
翻译:本文提出了一种基于条件随机场(CRF)在抽象语法树(AST)节点级别上对代码变换进行结构化预测的首个方法,旨在有效引导自动化代码演化技术在代码变换空间中的探索。该方法首先离线学习一个概率模型,捕获特定代码变换如何应用于特定AST节点,随后利用该模型对任意未知的新代码片段进行变换预测。我们的方法涉及一种全新的程序与代码变换表示方式:具体而言,我们引入了一种形式化框架用于定义所谓的AST级代码变换,并展示了如何相应地设计、学习CRF模型并用于预测。在Java程序修复变换预测的背景下,我们对方法进行了实例化。该实例化包含一套精心设计的代码特征,处理训练数据不平衡问题,并整合了代码特定的变换约束。基于真实Java项目中的缺陷修复提交数据集,我们进行了大规模实验评估。结果表明,当采用常用评估指标top-3时,该方法对代码变换的预测准确率根据变换类型不同在41%至53%之间波动。我们的模型优于基于历史概率和神经机器翻译(NMT)的两种基线方法,表明了考虑代码结构对实现良好预测准确率的重要性。此外,我们实现了一个概念验证型合成器,将部分修复变换具体化为最终补丁。在Defects4j基准测试上的评估结果证实,预测出的AST级修复变换在生成高质量补丁方面具有实用性。