Skip to main content
QUICK REVIEW

[论文解读] STALL+: Boosting LLM-based Repository-level Code Completion with Static Analysis

Junwei Liu, Yixuan Chen|arXiv (Cornell University)|Jun 14, 2024
Natural Language Processing TechniquesComputer Science被引用 3
一句话总结

该论文提出 STALL+,一种将静态分析整合到基于大语言模型的仓库级代码补全多个阶段的框架,以提升准确率并减少幻觉。研究发现,在提示生成阶段整合文件级依赖关系可实现最佳性能,尤其在 Java 等静态类型语言中表现更优;同时,将静态分析与 RAG 结合可带来互补且成本效益更高的性能提升。

ABSTRACT

Repository-level code completion is challenging as it involves complicated contexts from multiple files in the repository. To date, researchers have proposed two technical categories to enhance LLM-based repository-level code completion, i.e., retrieval-augmented generation (RAG) and static analysis integration. This work performs the first study on the static analysis integration in LLM-based repository-level code completion by investigating both the effectiveness and efficiency of static analysis integration strategies across different phases of code completion. We first implement a framework STALL+, which supports an extendable and customizable integration of multiple static analysis strategies into the complete pipeline of LLM-based repository-level code completion; and based on STALL+, we perform extensive experiments by including different code LLMs on the latest repository-level code completion benchmark CrossCodeEval. Our findings show that integrating file-level dependencies in prompting phase performs the best while the integration in post-processing phase performs the worse. Additionally, we observe different improvements from static analysis between dynamic languages and static languages, i.e., the best combination is prompting-phase with decoding-phase integration for Java while the best combination is prompting-phase with post-processing-phase integration for Python given the limitations of statically analyzing dynamic languages. Additionally, we find the complementarity between RAG and static analysis integration as well as their cost-effectiveness after combination.

研究动机与目标

  • 解决由于对本地仓库上下文知识有限,导致基于大语言模型的仓库级代码补全中出现幻觉的问题。
  • 探究将静态分析整合到代码补全流程不同阶段的有效性与效率。
  • 评估静态分析与检索增强生成(RAG)在提升代码补全准确率方面的互补性。
  • 提供一个可自定义、可扩展的框架,以支持多样化的静态分析策略及其与大语言模型的集成。

提出的方法

  • 设计 STALL+,一种模块化框架,支持在提示生成、解码和后处理三个阶段集成多种静态分析策略。
  • 支持将静态分析工具(如依赖关系提取器、类型检查器)以可扩展、可自定义的方式集成到大语言模型推理流程中。
  • 在提示生成阶段通过从其他文件中提取并注入相关代码依赖关系来集成静态分析。
  • 在解码阶段通过基于分析结果修改标记概率,以引导更准确的生成。
  • 在后处理阶段利用类型检查或控制流分析对生成的代码进行验证或优化。
  • 通过允许在输入中同时使用检索到的代码片段和静态分析结果,确保与 RAG 技术的兼容性。
Figure 1. Overview of the STALL + static analysis integration framework
Figure 1. Overview of the STALL + static analysis integration framework

实验结果

研究问题

  • RQ1将静态分析应用于基于大语言模型的代码补全过程的不同阶段(提示生成、解码、后处理)时,其有效性如何?
  • RQ2在动态语言(如 Python)与静态语言(如 Java)之间,静态分析集成的性能表现有何差异?
  • RQ3在仓库级代码补全中,将静态分析与检索增强生成(RAG)结合的相对有效性与效率如何?
  • RQ4在不同阶段组合使用哪些静态分析策略可使代码补全准确率获得最大提升?

主要发现

  • 通过静态分析在提示生成阶段集成文件级依赖关系,可实现最高的性能提升,优于在解码或后处理阶段的集成。
  • 后处理阶段的静态分析集成表现最差,表明其在最终代码优化中的作用有限。
  • 对于 Java(强类型语言),最佳性能来自在提示生成阶段与解码阶段同时集成静态分析。
  • 对于 Python(动态类型语言),最佳性能来自在提示生成阶段与后处理阶段结合使用静态分析,这是由于动态特性导致静态分析准确性受限。
  • 静态分析与 RAG 技术具有互补性:两者结合可实现高于单独使用任一技术的准确率,且具备更好的成本效益。
  • 框架 STALL+ 支持在代码补全过程的各阶段实现高效、可自定义的静态分析集成,为未来研究与工具开发提供支持。
Figure 2. Comparison case of three strategies
Figure 2. Comparison case of three strategies

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。