arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2309.12938cs.AIcs.SE
收藏

对代码质量问题感到沮丧?LLM 可以提供帮助!

Frustrated with Code Quality Issues? LLMs can Help!

Microsoft Research(微软研究院)

Nalin Wadhwa, Jui Pradhan, Atharv Sonwane, Surya Prakash Sahu, Nagarajan Natarajan, Aditya Kanade, Suresh Parthasarathy, Sriram Rajamani

AI总结:

本文提出基于双 LLM(提议者与排序者)协同的代码修订工具 CORE,通过生成并排序候选修订来修复静态分析发现的代码质量问题,在 Python 和 Java 文件上均取得与专用工具相当的效果并显著降低误报。

摘要:

随着软件项目的推进,代码质量变得至关重要,因为它影响软件的可靠性、可维护性和安全性。因此,开发者工作流中使用静态分析工具来标记代码质量问题。然而,开发者需要付出额外努力,根据工具的发现来修改代码以提高代码质量。在这项工作中,我们研究了使用(遵循指令的)大语言模型(LLMs)来协助开发者修改代码以解决代码质量问题。我们提出了一个工具 CORE(COde REvisions 的缩写),其架构由一对 LLM 组成,分为提议者和排序者。静态分析工具的提供商会推荐缓解工具警告的方法,开发者遵循这些建议来修改代码。CORE 的提议者 LLM 接收同一组建议,并应用它们生成候选代码修订。通过静态质量检查的候选修订被保留。然而,LLM 可能引入微妙的、非预期的功能变化,这些变化可能不会被静态分析检测到。排序者 LLM 使用一个紧密遵循开发者会执行的验收标准的评分标准来评估提议者所做的更改。CORE 使用排序者 LLM 分配的分数对候选修订进行排序,然后将其呈现给开发者。CORE 能够修订 59.2% 的 Python 文件(跨 52 项质量检查),使它们能够通过工具和人工审查者的审查。在这些情况下,排序者 LLM 能够将误报减少 25.8%。CORE 生成的修订在 76.8% 的 Java 文件(跨 10 项质量检查)中通过了静态分析工具,与专门的程序修复工具的 78.3% 相当,但所需的工程工作量显著更少。

英文摘要:

As software projects progress, quality of code assumes paramount importance as it affects reliability, maintainability and security of software. For this reason, static analysis tools are used in developer workflows to flag code quality issues. However, developers need to spend extra efforts to revise their code to improve code quality based on the tool findings. In this work, we investigate the use of (instruction-following) large language models (LLMs) to assist developers in revising code to resolve code quality issues. We present a tool, CORE (short for COde REvisions), architected using a pair of LLMs organized as a duo comprised of a proposer and a ranker. Providers of static analysis tools recommend ways to mitigate the tool warnings and developers follow them to revise their code. The \emph{proposer LLM} of CORE takes the same set of recommendations and applies them to generate candidate code revisions. The candidates which pass the static quality checks are retained. However, the LLM may introduce subtle, unintended functionality changes which may go un-detected by the static analysis. The \emph{ranker LLM} evaluates the changes made by the proposer using a rubric that closely follows the acceptance criteria that a developer would enforce. CORE uses the scores assigned by the ranker LLM to rank the candidate revisions before presenting them to the developer. CORE could revise 59.2% Python files (across 52 quality checks) so that they pass scrutiny by both a tool and a human reviewer. The ranker LLM is able to reduce false positives by 25.8% in these cases. CORE produced revisions that passed the static analysis tool in 76.8% Java files (across 10 quality checks) comparable to 78.3% of a specialized program repair tool, with significantly much less engineering efforts.

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

↑