将树转化为图:基于简化AST驱动的图卷积网络的自动代码评审
Turn Tree into Graph: Automatic Code Review via Simplified AST Driven Graph Convolutional Network
摘要:
自动代码审查(ACR)是软件工程中一项不可缺少的基本任务,它可以减轻人工审查的成本。为了处理ACR,现有的工作是序列化抽象语法树(AST)。然而,用序列编码的方法来理解整个AST是一项艰巨的任务,主要是由于AST中的一些冗余节点阻碍了节点信息的传输。更不用说序列化表示不足以掌握AST中树结构的信息。在本文中,我们首先提出了一个新的大规模Apache自动代码审查(AACR)数据集的ACR任务,因为在这个任务中仍然没有公开可用的数据集。该数据集的发布将推动该领域的研究。在此基础上,提出了一种基于简化AST的图卷积网络(SimAST-GCN)来处理ACR任务。具体来说,为了提高节点信息传播的效率,我们首先通过删除不包含连接属性的冗余节点来简化代码的AST,从而得到一个简化的AST。然后,我们基于简化的AST为每个代码构造关系图,以将树结构的代码片段之间的关系适当地体现到图中。随后,根据图结构的优点,我们探索了一种图卷积网络架构,该架构遵循注意力机制来利用代码片段的关键含义来导出代码表示。最后,我们利用一个简单但有效的减法运算在原始和修改后的代码之间的表示,使修改后的差异,以更好地学习,以决定ACR的结果。在AACR数据集上的实验结果表明,我们提出的模型优于最先进的方法。
英文摘要:
Automatic code review (ACR), which can relieve the costs of manual inspection, is an indispensable and essential task in software engineering. To deal with ACR, existing work is to serialize the abstract syntax tree (AST). However, making sense of the whole AST with sequence encoding approach is a daunting task, mostly due to some redundant nodes in AST hinder the transmission of node information. Not to mention that the serialized representation is inadequate to grasp the information of tree structure in AST. In this paper, we first present a new large-scale Apache Automatic Code Review (AACR) dataset for ACR task since there is still no publicly available dataset in this task. The release of this dataset would push forward the research in this field. Based on it, we propose a novel Simplified AST based Graph Convolutional Network (SimAST-GCN) to deal with ACR task. Concretely, to improve the efficiency of node information dissemination, we first simplify the AST of code by deleting the redundant nodes that do not contain connection attributes, and thus deriving a Simplified AST. Then, we construct a relation graph for each code based on the Simplified AST to properly embody the relations among code fragments of the tree structure into the graph. Subsequently, in the light of the merit of graph structure, we explore a graph convolution networks architecture that follows an attention mechanism to leverage the crucial implications of code fragments to derive code representations. Finally, we exploit a simple but effective subtraction operation in the representations between the original and revised code, enabling the revised difference to be preferably learned for deciding the results of ACR. Experimental results on the AACR dataset illustrate that our proposed model outperforms the state-of-the-art methods.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。