Skip to main content
QUICK REVIEW

[论文解读] CodePlan: Repository-level Coding using LLMs and Planning

Ramakrishna Bairi, Atharv Sonwane|arXiv (Cornell University)|Sep 21, 2023
Software Engineering ResearchComputer Science被引用 3
一句话总结

CodePlan 是一种基于规划的框架,通过基于依赖关系和影响分析的多步骤编辑编排,利用大语言模型(LLMs)自动化复杂、跨仓库的代码修改。它在 6 个仓库中实现了 5 个通过有效性检查——优于所有失败的基线模型——通过动态识别并传播跨相互依赖文件的必要更改。

ABSTRACT

Software engineering activities such as package migration, fixing errors reports from static analysis or testing, and adding type annotations or other specifications to a codebase, involve pervasively editing the entire repository of code. We formulate these activities as repository-level coding tasks. Recent tools like GitHub Copilot, which are powered by Large Language Models (LLMs), have succeeded in offering high-quality solutions to localized coding problems. Repository-level coding tasks are more involved and cannot be solved directly using LLMs, since code within a repository is inter-dependent and the entire repository may be too large to fit into the prompt. We frame repository-level coding as a planning problem and present a task-agnostic framework, called CodePlan to solve it. CodePlan synthesizes a multi-step chain of edits (plan), where each step results in a call to an LLM on a code location with context derived from the entire repository, previous code changes and task-specific instructions. CodePlan is based on a novel combination of an incremental dependency analysis, a change may-impact analysis and an adaptive planning algorithm. We evaluate the effectiveness of CodePlan on two repository-level tasks: package migration (C#) and temporal code edits (Python). Each task is evaluated on multiple code repositories, each of which requires inter-dependent changes to many files (between 2-97 files). Coding tasks of this level of complexity have not been automated using LLMs before. Our results show that CodePlan has better match with the ground truth compared to baselines. CodePlan is able to get 5/6 repositories to pass the validity checks (e.g., to build without errors and make correct code edits) whereas the baselines (without planning but with the same type of contextual information as CodePlan) cannot get any of the repositories to pass them.

研究动机与目标

  • 为解决当前基于大语言模型的工具无法处理的、跨整个仓库的大规模、相互依赖的代码修改挑战。
  • 克服大语言模型在受限上下文窗口和代码相互依赖性影响下处理仓库级编辑的局限性。
  • 设计一种与任务无关的框架,通过动态分析代码依赖关系和更改影响,生成一系列编辑指令。
  • 通过将规划与大语言模型生成相结合,提升自动化代码迁移和重构的准确性和可靠性。

提出的方法

  • CodePlan 将仓库级编码视为一个规划问题,将编辑操作分解为一系列原子的、上下文感知的大语言模型调用。
  • 它执行增量依赖分析,以追踪代码库中文件之间的语法和语义关系。
  • 它应用更改可能影响分析,以预测每次编辑会影响哪些代码区域,并为后续步骤生成‘更改义务’。
  • 它使用自适应规划算法,基于依赖顺序和影响传播来优先排序和编排编辑操作。
  • 每次大语言模型调用都会接收一个经过筛选的上下文,包括完整仓库、先前的编辑结果和特定任务的指令,以确保正确性。
  • 该框架对每次编辑进行增量验证,确保在进入下一步之前保持语法和语义的一致性。

实验结果

研究问题

  • RQ1基于规划的框架能否有效自动化需要在多个文件间进行广泛、相互依赖更改的仓库级编码任务?
  • RQ2当上下文过大无法通过单个提示处理时,如何引导大语言模型在大型代码库中做出正确且一致的编辑?
  • RQ3动态影响分析在减少错误和提升多步代码转换正确性方面发挥什么作用?
  • RQ4与直接对单体代码上下文进行大语言模型提示相比,自适应规划如何提升成功率?
  • RQ5与任务无关的框架在多大程度上能够处理包括 API 迁移和时间相关编辑在内的多样化仓库级任务?

主要发现

  • CodePlan 在 6 个仓库中实现了 5 个通过有效性检查(如编译通过和语义更改正确),而使用相同上下文信息的基线模型在所有任务中均失败。
  • 与基线方法相比,该框架在处理跨文件边界的传递依赖关系方面表现出更优的与真实编辑的一致性。
  • 影响分析显著减少了错误或冗余编辑的数量,通过在大语言模型介入前识别受影响的代码区域。
  • 增量依赖追踪的使用使得复杂调用图和数据依赖关系中的更改能够被准确传播。
  • 自适应规划策略相比非规划基线,提高了收敛性并减少了失败的编辑序列数量。
  • 该框架成功处理了包含 2 至 97 个文件、需协调编辑的 C# 和 Python 仓库,证明了其可扩展性和鲁棒性。

更好的研究,从现在开始

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

无需绑定信用卡

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