Iterative Refinement of Project-Level Code Context for Precise Code Generation with Compiler Feedback

Zhangqian Bi, Yao Wan, Zheng Wang, Hongyu Zhang, Batu Guan +5 more
3/25/2024
cs.CLcs.SE

No official code found. Best implementation: CGCL-codes/naturalcc (320 stars, MIT, last commit 2026-04-28).

Abstract

Large Language Models (LLMs) have shown remarkable progress in automated code generation. Yet, LLM-generated code may contain errors in API usage, class, data structure, or missing project-specific information. As much of this project-specific context cannot fit into the prompts of LLMs, we must find ways to allow the model to explore the project-level code context. We present CoCoGen, a new code generation approach that uses compiler feedback to improve the LLM-generated code. CoCoGen first leverages static analysis to identify mismatches between the generated code and the project's context. It then iteratively aligns and fixes the identified errors using information extracted from the code repository. We integrate CoCoGen with two representative LLMs, i.e., GPT-3.5-Turbo and Code Llama (13B), and apply it to Python code generation. Experimental results show that CoCoGen significantly improves the vanilla LLMs by over 80% in generating code dependent on the project context and consistently outperforms the existing retrieval-based code generation baselines.

View on arXivView PDF

Code Implementations(1)

MIT

NaturalCC: An Open-Source Toolkit for Code Intelligence

32061Shell, PythonDec 4, 20205 months agoMIT
deep-learningnatural-language-processingprogramming-languagetoolkit

Cite this paper

@article{bi2024iterative,
  title  = {Iterative Refinement of Project-Level Code Context for Precise Code Generation with Compiler Feedback},
  author = {Zhangqian Bi and Yao Wan and Zheng Wang and Hongyu Zhang and Batu Guan and Fangxin Lu and Zili Zhang and Yulei Sui and Hai Jin and Xuanhua Shi},
  year   = {2024},
  eprint = {2403.16792},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2403.16792v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2403.16792.svg)](https://codeofpaper.com/paper/2403.16792)

Discussion