CrossCodeEval: A Diverse and Multilingual Benchmark for Cross-File Code Completion

Yangruibo Ding, Zijian Wang, Wasi Uddin Ahmad, Hantian Ding, Ming Tan, Nihal Jain, Murali Krishna Ramanathan, Ramesh Nallapati, Parminder Bhatia, Dan Roth, Bing Xiang

The Problem with Single-File Benchmarks

Most existing code completion benchmarks, such as HumanEval or MBPP, operate in a vacuum. They provide a single file—often just a function signature and a docstring—and ask the AI model to fill in the rest.

However, professional software development rarely happens in a single file. Modern repositories are complex webs of interconnected files where a class defined in utils.py is instantiated in main.py and tested in test_logic.py. If an AI model only looks at the "current file," it will inevitably hallucinate or fail when it encounters a custom API defined elsewhere in the project. Current benchmarks are over-simplified and fail to capture a model's ability to reason across an entire codebase.

To address this, researchers introduce CROSSCODEEVAL, a new, large-scale benchmark designed to evaluate how well AI models handle "cross-file" code completion—a critical real-world task where the necessary context lives in a different file than the one being edited.

Constructing a Strict Cross-File Benchmark

The authors developed an automated pipeline to create a benchmark that strictly requires cross-file context. They scraped over 1,000 permissively licensed GitHub repositories created between March and June 2023 to ensure the code was fresh and likely absent from the training data of existing models.

To identify code that relies on external files, they employed a clever static analysis technique known as the "Empty Class Trick."

Benchmark construction pipeline using the empty class substitution trick.
  1. Empty Class Substitution: The pipeline identifies an import from the same repository and replaces the imported class with an empty dummy class.
  2. Static Analysis: A compiler or linter (like pylint or javac) is run on the modified file. Any line that throws an "undefined name" or "no member" error is flagged as a strict cross-file dependency.
  3. Backward Mapping: These flagged lines become the "ground truth" for completion. The model is given the code up to that point and must predict the missing API call or reference.

The resulting dataset consists of 10,000 examples across 1,000 repositories in four languages: Python, Java, TypeScript, and C#.

Key Insights and Results

The study benchmarked several state-of-the-art models, including the CodeGen family, StarCoder, and GPT-3.5-Turbo, testing them with varying levels of context. Because models cannot fit an entire repository into their context window, the authors tested Retrieval-Augmented Generation (RAG) methods to find and plug in relevant snippets.

Performance comparison showing massive gains when cross-file context is retrieved.
  • The "In-File" Failure: When models are only given the current file, their performance is abysmal. For example, StarCoder achieves only an 8.8% exact match rate on Python tasks. This proves the benchmark successfully isolates cross-file dependencies.
  • Retrieval is the Bottleneck (and the Solution): Adding retrieved context from other files significantly boosts performance, often doubling or quadrupling the Exact Match (EM) scores across all models. Interestingly, simple keyword matching (BM25) often outperformed more complex neural retrievers for this specific task.
  • The "Oracle" Gap: The researchers tested a "Retrieval w/ Reference" setting—an upper bound where the retriever perfectly identifies the necessary cross-file context. Even with this perfect context, models still didn't reach 100% accuracy. This suggests that models struggle not just to find the right code, but to reason with it once it's in the prompt.
  • Language Variance: Results were fairly consistent across Python, Java, and C#, though TypeScript proved slightly more challenging for some models.

Future Directions

While CROSSCODEEVAL highlights a major gap in current code completion evaluation, it also points to future opportunities. The study primarily focused on zero-shot performance; few-shot prompting might yield different results but is currently constrained by context window sizes. Furthermore, as long-context models (with 100k+ token windows) become more prevalent, this benchmark will be crucial for testing whether "stuffing the whole repo" into the prompt is actually more effective than selective, syntax-aware retrieval.

Summary updated

BibTeX
@inproceedings{ding2023crosscodeeval,
  author = {Yangruibo Ding and Zijian Wang and Wasi Uddin Ahmad and Hantian Ding and Ming Tan and Nihal Jain and Murali Krishna Ramanathan and Ramesh Nallapati and Parminder Bhatia and Dan Roth and Bing Xiang},
  title = {{CrossCodeEval: A Diverse and Multilingual Benchmark for Cross-File Code Completion}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=wEM9CGJm7g},
}
Figure