Code completion models have made significant progress in recent years, yet current popular evaluation datasets, such as HumanEval and MBPP, predominantly focus on code completion tasks within a single file. This over-simplified setting falls short of representing the real-world software development scenario where repositories span multiple files with numerous cross-file dependencies, and accessing and understanding cross-file context is often required to complete the code correctly. To fill in this gap, we propose CrossCodeEval, a diverse and multilingual code completion benchmark that necessitates an in-depth cross-file contextual understanding to complete the code accurately. CrossCodeEval is built on a diverse set of real-world, open-sourced, permissively-licensed repositories in four popular programming languages: Python, Java, TypeScript, and C#. To create examples that strictly require cross-file context for accurate completion, we propose a straightforward yet efficient static-analysis-based approach to pinpoint the use of cross-file context within the current file. Extensive experiments on state-of-the-art code language models like CodeGen and StarCoder demonstrate that CrossCodeEval is extremely challenging when the relevant cross-file context is absent, and we see clear improvements when adding these context into the prompt. However, despite such improvements, the pinnacle of performance remains notably unattained even with the highest-performing model, indicating that CrossCodeEval is also capable of assessing model's capability in leveraging extensive context to make better code completion. Finally, we benchmarked various methods in retrieving cross-file context, and show that CrossCodeEval can also be used to measure the capability of code retrievers.
翻译:代码补全模型近年来取得了显著进展,但当前流行的评估数据集(如HumanEval和MBPP)主要聚焦于单文件内的代码补全任务。这种过度简化的设定无法真实反映实际软件开发场景——仓库往往包含多个文件,存在大量跨文件依赖关系,且正确完成代码通常需要访问并理解跨文件上下文。为填补这一空白,我们提出CrossCodeEval,一个需要深度跨文件上下文理解才能准确完成代码补全的多样化多语言基准。CrossCodeEval基于四种主流编程语言(Python、Java、TypeScript和C#)中真实世界、开源且采用宽松许可的多样化仓库构建。为生成严格依赖跨文件上下文才能准确补全的示例,我们提出了一种直接高效的基于静态分析的方法,用于精确定位当前文件中跨文件上下文的引用。针对CodeGen和StarCoder等最先进代码语言模型的大量实验表明,当缺乏相关跨文件上下文时,CrossCodeEval极具挑战性;而将此类上下文加入提示后,模型性能明显提升。然而,即便性能最强的模型也难以触及性能顶峰,表明CrossCodeEval还能评估模型利用扩展上下文优化代码补全的能力。最后,我们测试了多种跨文件上下文检索方法,证明CrossCodeEval亦可衡量代码检索器的能力。