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

CATCODER: 基于相关代码和类型上下文的仓库级代码生成

CATCODER: Repository-Level Code Generation with Relevant Code and Type Context

The State Key Laboratory of Blockchain and Data Security, Zhejiang University(区块链与数据安全国家重点实验室,浙江大学)

Zhiyuan Pan, Xing Hu, Xin Xia, Xiaohu Yang

AI总结:

CatCoder通过整合相关代码和类型上下文,提升仓库级代码生成的性能和可扩展性。

摘要:

大型语言模型(LLMs)在代码生成任务中展现了显著的能力。然而,仓库级代码生成面临着独特的挑战,特别是由于需要利用存储在仓库中的多个文件的信息。具体而言,成功的生成依赖于对一般性的、上下文无关的知识和特定的、上下文相关的知识的深刻理解。尽管LLMs被广泛用于上下文无关方面,但现有的基于检索的方法有时效果有限,因为它们在获取更广泛和深入的仓库上下文方面存在局限。在本文中,我们提出了CatCoder,一种针对静态类型编程语言的新型代码生成框架。CatCoder通过整合相关代码和类型上下文来增强仓库级代码生成。具体而言,它利用静态分析工具提取类型依赖关系,并将此信息与检索到的代码合并,以创建全面的提示供LLMs使用。为了评估CatCoder的有效性,我们调整并构建了包含199个Java任务和90个Rust任务的基准测试。结果表明,CatCoder在compile@k和pass@k得分上比RepoCoder基线高出高达14.44%和17.35%。此外,通过使用各种LLMs,包括专门用于代码的模型和通用模型,评估了CatCoder的通用性。我们的发现表明,在所有模型上都实现了持续的性能提升,这证明了CatCoder的实用性。此外,我们评估了CatCoder在大型开源仓库中的时间消耗,结果展示了CatCoder的可扩展性。

英文摘要:

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.

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

↑