paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Dependency-Aware Code Naturalness

依赖感知的代码自然度
OOPSLA 8(OOPSLA2)2024匹配度 3/10 · 论文将程序依赖图用于代码自然度度量,并服务于代码模型的数据清洗与缺陷行识别,属于PL与ML交叉的程序分析工作;但它不涉及用户核心关注的“在ML系统/Agentic程序中做静态分析”或“用LLM/Agent改进静态分析/形式化验证”,也与浮点程序分析和贝叶斯程序分析无直接关系。仅在依赖分析、程序分析工具与代码模型数据质量层面有较弱关联。引用 6 inbox
Chen Yang, Junjie Chen, Jiajun Jiang, Yuliang Huang
dblp: 2026-09-10crossref: 2026-09-10arxiv: 2026-09-10

AI 速览

一句话:提出DAN,利用程序依赖图抽取代码行序列以整体度量代码自然度,并验证依赖信息能提升区分与下游任务效果。

代码自然度刻画程序语言中的重复性与可预测性,但现有方法多逐行度量,忽略程序依赖等跨行深层语义关系,影响精度。本文首次实证研究将代码依赖引入自然度度量能否提升精度,并提出DAN:遍历程序依赖图,抽取由依赖连接的多个代码行序列,再以序列为单位度量自然度,从而捕获依赖信息。作者在三种新兴应用场景下与最先进方法比较,包括区分自然/非自然代码、识别有缺陷代码行以及为训练更好的代码模型进行数据清洗。结果表明,DAN不仅能更好区分自然与非自然代码,还能显著提升上述下游任务,说明代码依赖对代码自然度度量具有重要意义。

问题
现有代码自然度度量多基于单行代码,忽略程序依赖等跨行语义关系,导致度量精度受限;本文研究引入代码依赖能否提升自然度度量精度。
方法
提出DAN,通过遍历程序依赖图抽取由依赖连接的代码行序列,并以序列整体为单位度量代码自然度,从而捕获依赖信息。
评估
在三种应用场景下与最先进方法比较,评估DAN区分自然/非自然代码、识别缺陷代码行及数据清洗以训练代码模型的效果。
原文摘要(Abstract)

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. Despite the intuitive appeal of extending the code naturalness measure to the code dependency domain (as there are some work that have initiated the utilization of code dependency for diverse code-related tasks), this assumption remains unexplored and warrants direct investigation. 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.

链接与引用

DOI 原文 · arXiv · PDF(开放获取) · DBLP

BibTeX
@article{Yang0JH24,
  title = {Dependency-Aware Code Naturalness},
  author = {Chen Yang and Junjie Chen and Jiajun Jiang and Yuliang Huang},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {8},
  number = {OOPSLA2},
  year = {2024},
  doi = {10.1145/3689794}
}