Skip to main content
QUICK REVIEW

[论文解读] Frustrated with Code Quality Issues? LLMs can Help!

N. K. Wadhwa, Jui Pradhan|arXiv (Cornell University)|Sep 22, 2023
Software Engineering ResearchComputer Science被引用 3
一句话总结

本文提出CORE,一种基于大语言模型的两阶段系统,利用指令遵循型语言模型(生成器)根据静态分析警告生成代码修复,再通过第二个大语言模型(评分器)评估并排序这些修复方案在功能正确性和代码质量方面的表现。CORE在多个工具和检查项下,对Python的修复成功率达到59.2%,对Java达到76.8%,同时将误报率降低25.8%,且仅需极少工程投入,即可达到专业化自动程序修复(APR)工具的性能水平。

ABSTRACT

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.

研究动机与目标

  • 降低开发者在修复静态分析工具标记的代码质量问题时的负担。
  • 克服现有自动化程序修复(APR)工具的局限性,这些工具通常需要大量工程投入、训练数据,或仅适用于特定模式。
  • 利用静态分析工具提供的自然语言修复建议作为大语言模型的指令,实现零样本、少样本或零样本提示(zero-shot-with-prompting)的代码修订。
  • 通过检测并过滤掉通过静态检查但语义错误的修复方案,提升修复质量。
  • 在最小工程投入下,实现跨工具、跨语言和跨检查项的兼容性。

提出的方法

  • CORE采用一对指令微调的大语言模型:生成器模型根据静态分析建议生成候选代码修复方案。
  • 将有缺陷的代码、质量缺陷描述以及自然语言修复建议作为提示输入生成器模型,以生成修订后的代码。
  • 对生成的修复方案使用原始静态分析工具进行验证,以过滤掉未能解决原始问题的方案。
  • 第二个模型(评分器)依据与人类接受标准一致的评估标准,对每个候选修复方案进行评分,评估其正确性与功能保全性。
  • 评分器通过对比原始代码与修订后代码的差异(code diffs)进行推理,提升对细微回归问题的检测能力。
  • 最终,根据评分器的得分对候选修复方案进行排序,并呈现给开发者,从而减少人工审查的工作量。

实验结果

研究问题

  • RQ1大语言模型是否能在无需微调或训练数据的情况下,生成既满足静态分析检查又符合人类评审标准的代码修复?
  • RQ2第二个大语言模型在识别并过滤掉通过静态检查但引入非预期语义变更的修复方案方面,效果如何?
  • RQ3像CORE这样的双大语言模型系统,能否在多种编程语言(如Python和Java)、多种静态分析工具(如CodeQL和SonarQube)以及多样化的代码质量检查中实现泛化?
  • RQ4在有效性与工程成本方面,CORE的修复成功率与误报率与基于规则的自动化程序修复工具相比如何?
  • RQ5静态分析工具提供的自然语言修复建议,在零样本设置下,能在多大程度上被直接用作大语言模型的指令?

主要发现

  • 在52项代码质量检查中,CORE在Python代码上的修复成功率达到59.2%,且修复方案同时通过了静态分析工具和人工评审。
  • 评分器大语言模型通过识别并过滤掉通过静态检查但引入非预期功能变更的修复方案,将误报率降低了25.8%。
  • 在Java基准测试中,CORE在10项质量检查中实现了76.8%的修复成功率,与专用的基于规则的APR工具(78.3%)相当,但所需工程投入显著更少。
  • 该系统在无需模型微调或任务特定数据的情况下,成功处理了两种编程语言和两种静态分析工具中的多样化代码质量问题。
  • GPT-4在分析代码差异方面优于GPT-3.5-Turbo,证明了模型能力在语义评估中的关键作用。
  • 将自然语言修复建议直接作为提示,实现了高效的零样本代码修订,避免了对大规模训练数据或模式挖掘的依赖。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。