Skip to main content
QUICK REVIEW

[Paper Review] CATCODER: Repository-Level Code Generation with Relevant Code and Type Context

Zhiyuan Pan, Xing Hu|arXiv (Cornell University)|Jun 5, 2024
Software Testing and Debugging TechniquesComputer Science3 citations
TL;DR

CatCoder is a retrieval-augmented code generation framework for statically typed languages that enhances repository-level code generation by integrating both retrieved relevant code and type context derived from static analysis. It improves pass@k scores by up to 17.35% over RepoCoder, demonstrating consistent gains across diverse LLMs without requiring model fine-tuning or external databases.

ABSTRACT

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.

Motivation & Objective

  • To address the limitations of existing retrieval-based approaches in repository-level code generation, which often fail to capture cross-file dependencies and suffer from hallucinations due to insufficient context.
  • To explore whether type context—derived from static analysis of class fields and method signatures—can serve as a complementary source of information to improve code generation in statically typed languages.
  • To design a practical, generalizable framework that enhances LLM-based code generation without requiring model fine-tuning or external databases.
  • To construct and evaluate a new benchmark for repository-level code generation in Rust, a less-studied language in this context.

Proposed method

  • CatCoder retrieves relevant code snippets from a repository using a retrieval mechanism, similar to prior work like RepoCoder.
  • It leverages existing static analyzers to extract type context, including fields and method signatures of the target class, by analyzing dependencies from the method signature.
  • The framework generates textual representations of the extracted type context to be integrated into the LLM prompt.
  • It merges the retrieved code and type context into a single, comprehensive prompt for the LLM, enhancing contextual awareness.
  • The approach operates on top of a frozen LLM, avoiding the need for fine-tuning or training.
  • The framework is evaluated using a new benchmark of 199 Java and 90 Rust tasks drawn from real open-source repositories.

Experimental results

Research questions

  • RQ1Can integrating type context with retrieved code improve the accuracy of repository-level code generation in statically typed languages?
  • RQ2How does CatCoder perform compared to state-of-the-art retrieval-based baselines like RepoCoder in terms of pass@k score?
  • RQ3To what extent is CatCoder generalizable across different LLMs, including both code-specialized and general-purpose models?
  • RQ4Can CatCoder effectively support code generation in less common statically typed languages like Rust?

Key findings

  • CatCoder outperforms the RepoCoder baseline by up to 17.35% in pass@k score on the evaluated benchmarks, demonstrating significant performance gains.
  • The framework improves pass@k scores across all tested LLMs, including both code-specialized and general-purpose models, confirming its generalizability.
  • The integration of type context provides meaningful auxiliary information that complements code retrieval, reducing hallucinations and improving code correctness.
  • The study presents the first repository-level code generation benchmark for Rust, enabling evaluation of code generation frameworks in this language.
  • CatCoder achieves these results without requiring model fine-tuning or external databases, making it practical for real-world deployment.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.