arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2409.00747cs.SE
收藏

依赖感知的代码自然性

Dependency-Aware Code Naturalness

Chen Yang, Junjie Chen, Jiajun Jiang, Yuliang Huang

AI总结:

本文提出依赖感知的代码自然性度量方法DAN,通过程序依赖图提取代码行序列以融入依赖信息,实验表明其能更好区分自然与非自然代码,并显著提升缺陷代码行识别和代码模型数据清洗等下游任务效果。

摘要:

代码自然性刻画了编程语言中的重复性与可预测性,已被证明对软件工程中多种与代码相关的任务具有重要价值。然而,如何精确度量代码自然性仍然是一个根本性挑战。现有方法在逐行代码上度量代码自然性,却忽略了不同代码行之间的深层语义关系,例如程序依赖关系,这可能对度量的精度产生负面影响。在本研究中,我们旨在开展首次实证研究,以考察引入代码依赖信息而非单独分析各行代码是否能够提升代码自然性度量的精度。为此,我们首先提出了一种名为DAN的新方法,通过融入代码中丰富的依赖信息来度量代码自然性。具体而言,DAN通过遍历程序依赖图提取多条代码行序列,在每个序列中不同的代码行通过依赖关系相互连接,然后将每个序列作为一个整体来度量代码自然性。通过这种方式,依赖信息能够被很好地捕获。最后,我们开展了一项广泛的研究,以评估代码依赖对使用DAN度量代码自然性的影响,并在代码自然性的三个新兴应用场景下将其与最先进的方法进行了比较。实验结果表明,DAN不仅能够更好地区分自然代码与非自然代码,而且能够显著提升代码自然性的两个重要下游应用,即区分有缺陷和无缺陷的代码行以及为训练更好的代码模型进行数据清洗,这反映了代码依赖在度量代码自然性中的重要意义。

英文摘要:

Code naturalness, which captures repetitiveness and predictability in programming languages, has proven valuable for various code-related tasks in software engineering. However, precisely measuring code naturalness remains a fundamental challenge. Existing methods measure code naturalness over individual lines of code while ignoring the deep semantic relations among different lines, e.g., program dependency, which may negatively affect the precision of the measure. In this study, we aim to perform the first empirical study to investigate whether incorporating code dependency, instead of analyzing individual lines, can enhance the precision of measuring code naturalness. To achieve that, we first propose a new method named DAN for measuring code naturalness by incorporating the rich dependency information in the code. Specifically, DAN extracts multiple sequences of code lines by traversing the program dependency graph, where different code lines are connected by dependencies in each sequence, and then the code naturalness will be measured by taking each sequence as a whole. In this way, the dependency information can be well captured. Finally, we have conducted an extensive study to evaluate the influence of code dependency for measuring code naturalness with DAN, and compared it with the state-of-the-art methods under three emerging application scenarios of code naturalness. The results demonstrate that DAN can not only better distinguish natural and unnatural code, but also substantially boost two important downstream applications of code naturalness, i.e., distinguishing buggy and non-buggy code lines and data cleansing for training better code models, reflecting the significance of code dependency in measuring code naturalness.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑