[论文解读] CATCODER: Repository-Level Code Generation with Relevant Code and Type Context
CatCoder 是一种用于静态类型语言的检索增强代码生成框架,通过整合从静态分析中提取的类型上下文和检索到的相关代码,提升仓库级代码生成性能。相比 RepoCoder,其 pass@k 分数最高提升 17.35%,在多种大语言模型上均表现出一致的性能提升,且无需模型微调或外部数据库。
Large language models (LLMs) have demonstrated remarkable capabilities in code generation tasks. However, repository-level code generation presents unique challenges, particularly due to the need to utilize information spread across multiple files within a repository. Specifically, successful generation depends on a solid grasp of both general, context-agnostic knowledge and specific, context-dependent knowledge. While LLMs are widely used for the context-agnostic aspect, existing retrieval-based approaches sometimes fall short as they are limited in obtaining a broader and deeper repository context. In this paper, we present CatCoder, a novel code generation framework designed for statically typed programming languages. CatCoder enhances repository-level code generation by integrating relevant code and type context. Specifically, it leverages static analyzers to extract type dependencies and merges this information with retrieved code to create comprehensive prompts for LLMs. To evaluate the effectiveness of CatCoder, we adapt and construct benchmarks that include 199 Java tasks and 90 Rust tasks. The results show that CatCoder outperforms the RepoCoder baseline by up to 14.44% and 17.35%, in terms of compile@k and pass@k scores. In addition, the generalizability of CatCoder is assessed using various LLMs, including both code-specialized models and general-purpose models. Our findings indicate consistent performance improvements across all models, which underlines the practicality of CatCoder. Furthermore, we evaluate the time consumption of CatCoder in a large open source repository, and the results demonstrate the scalability of CatCoder.
研究动机与目标
- 为解决现有基于检索的仓库级代码生成方法的局限性,这些方法通常无法捕捉跨文件依赖关系,并因上下文不足而产生幻觉。
- 探究是否可将类型上下文——源自类字段和方法签名的静态分析结果——作为补充信息源,以提升静态类型语言中的代码生成性能。
- 设计一种实用且可泛化的框架,提升基于大语言模型的代码生成性能,且无需模型微调或外部数据库。
- 构建并评估一个针对 Rust 语言的仓库级代码生成新基准,该语言在此领域研究较少。
提出的方法
- CatCoder 使用类似 RepoCoder 等先前工作的检索机制,从仓库中检索相关代码片段。
- 它利用现有的静态分析器,通过分析方法签名的依赖关系,提取目标类的类型上下文,包括字段和方法签名。
- 该框架生成提取到的类型上下文的文本表示,以整合进大语言模型的提示中。
- 它将检索到的代码与类型上下文合并为一个统一且全面的提示输入大语言模型,增强上下文感知能力。
- 该方法基于冻结的大语言模型运行,无需微调或训练。
- 该框架使用从真实开源仓库中提取的 199 个 Java 任务和 90 个 Rust 任务构成的新基准进行评估。
实验结果
研究问题
- RQ1将类型上下文与检索代码结合,是否能提升静态类型语言中仓库级代码生成的准确性?
- RQ2在 pass@k 分数方面,CatCoder 相较于最先进的基于检索的基线方法(如 RepoCoder)表现如何?
- RQ3CatCoder 在不同大语言模型(包括代码专用和通用模型)上的泛化能力如何?
- RQ4CatCoder 是否能有效支持如 Rust 这类较少见的静态类型语言的代码生成?
主要发现
- 在评估基准上,CatCoder 相较于 RepoCoder 基线,pass@k 分数最高提升 17.35%,表现出显著的性能提升。
- 该框架在所有测试的大语言模型上均提升了 pass@k 分数,包括代码专用和通用模型,证实了其泛化能力。
- 类型上下文的整合提供了有意义的辅助信息,与代码检索形成互补,减少幻觉并提升代码正确性。
- 本研究首次构建了针对 Rust 的仓库级代码生成基准,使该语言的代码生成框架评估成为可能。
- CatCoder 在无需模型微调或外部数据库的情况下实现上述成果,具有实际部署的可行性。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。