CG-Diff:围绕调用图组织代码变更
CG-Diff: Organizing Code Changes Around Call Graphs
- UC San Diego(加州大学圣地亚哥分校)
机构由 AI 辅助整理,请以论文原文为准。
AI总结:
本研究提出CG-Diff方法,通过将代码变更按调用图分解为子图来组织PR展示,实证发现约40%的PR中多数变更函数相连,实验表明该方法有助于导航不熟悉代码库,惠及新贡献者和LLM生成PR的审查者。
AI中文摘要:
代码审查工具按文件逐文件展示代码变更。我们认为,通常情况下,变更可以更好地围绕变更代码的调用图来组织。通过对GitHub上真实世界中的拉取请求(PR)进行实证研究,我们发现:(1)在约40%的PR中,超过一半的变更函数(和方法)通过调用图相互连接;(2)必要的被调用函数(callees)通常与其调用者(callers)位于不同的文件中。基于这些发现,我们提出了CG-Diff的概念,即通过将变更代码的调用图分解为更小、更易于导航的有向图而得到的子图。随后,我们实现了一个基于网页的界面来查看PR,该界面围绕这些CG-Diff重构了PR的展示。通过一项受试者内研究,将我们的界面与GitHub的PR视图进行比较,我们发现CG-Diff有助于参与者定位,并为他们提供更有意义的结构来导航PR。我们还发现了若干局限性:跨多个CG-Diff重复出现的函数节点可能令人困惑,以及未包含在函数内的变更(如全局变量、导入)不够直观可见。我们的研究表明,利用调用图来帮助情境化和导航不熟悉的代码库具有前景,这可能有益于开源项目的新贡献者,以及审查不熟悉的LLM生成的PR的审查者。
英文摘要:
Tools for code review present code changes file-by-file. We argue that, oftentimes, changes can be better organized around a call graph of the changed code. From an empirical study of GitHub pull requests (PRs) in-the-wild, we find that (1) in around 40% of the PRs, more than half of the changed functions (and methods) are connected by call graphs, and (2) necessary callees are often located in different files from their callers. Based on these findings, we develop the notion of CG-Diffs, subgraphs derived by decomposing a call graph of the changed code into smaller and more navigable directed graphs. We then implement a web-based interface for viewing PRs that restructures the PR around these CG-Diffs. Through a within-subject study comparing our interface against GitHub's PR view, we find that CG-Diffs help orient participants and provide them with more meaningful structures to navigate the PR. We also found several limitations: function nodes repeated across multiple CG-Diffs can be disorienting, and changes not contained in a function (e.g. globals, imports) are not as immediately apparent. Our study shows promise in using call graphs to help contextualize and navigate unfamiliar codebases, which may benefit new contributors to open source, and reviewers of unfamiliar LLM-generated PRs.