Source-linked AI summary

In Line with Context: Repository-Level Code Generation via Context Inlining

Chao Hu, Wenhao Zeng, Yuling Shi, Beijun Shen, Xiaodong Gu

arXiv:2601.00376v3cs.SEcs.AI

TL;DR

Repository-level code generation requires repository-wide dependency reasoning, while similarity-based retrieval and linear context assembly can miss a function’s actual usage and dependencies. InlineCoder generates an anchor, inlines it into upstream callers, retrieves downstream callees, and uses confidence-guided context for final generation. It reports the best overall performance across DevEval and RepoExec, including 29.73% EM, 20.82% ES, and 49.34% BLEU average relative gains on RepoExec versus the strongest baseline.

  • Problem

    Repository-level generation must capture complex inter-function dependencies, but retrieval and linearized call-chain methods do not systematically represent callers’ usage or callees’ dependencies.

  • Method

    InlineCoder generates an anchor draft, inlines it into upstream callers, retrieves downstream callees, and uses perplexity-based confidence to guide final context-aware generation.

  • Results

    InlineCoder achieves the best overall performance across DevEval and RepoExec; on RepoExec, it gains 29.73% in EM, 20.82% in ES, and 49.34% in BLEU versus the strongest baseline.

  • Takeaways & Limitations

    Inlining upstream usage and downstream dependency context provides a repository-specific view that supports consistent improvements across benchmarks, domains, and contextual environments.

  • Takeaways & Limitations

    The empirical evaluation uses Python repositories, which may limit generalizability to other programming languages and software projects.

Abstract

from arXiv · show

Repository-level code generation has attracted growing attention in recent years. Unlike function-level code generation, it requires the model to understand the entire repository, reasoning over complex dependencies across functions, classes, and modules. However, existing approaches such as retrieval-augmented generation (RAG) or context-based function selection often fall short: they primarily rely on surface-level similarity and struggle to capture the rich dependencies that govern repository-level semantics. In this paper, we introduce InlineCoder, a novel framework for repository-level code generation. InlineCoder enhances the understanding of repository context by inlining the unfinished function into its call graph, thereby reframing the challenging repository understanding as an easier function-level coding task. Given a function signature, InlineCoder first generates a draft completion, termed an anchor, which approximates downstream dependencies and enables perplexity-based confidence estimation. This anchor drives a bidirectional inlining process: (i) Upstream Inlining, which embeds the anchor into its callers to capture diverse usage scenarios; and (ii) Downstream Retrieval, which integrates the anchor's callees into the prompt to provide precise dependency context. The enriched context, combining draft completion with upstream and downstream perspectives, equips the LLM with a comprehensive repository view.

1 Introduction

Repository-level code generation must reason over repository-wide conventions and dependencies, but existing retrieval methods struggle to identify the context that governs a function’s role. InlineCoder addresses this by inlining a draft completion into upstream callers and retrieving downstream callees before final generation.

  • Repository-level generation requires reasoning over coding conventions, API usage, and intricate dependencies across an entire repository.
  • Directly supplying all repository files is infeasible because context windows cannot accommodate the volume of irrelevant or redundant code.
  • InlineCoder reframes repository-level generation as function-level coding by placing the unfinished function within its call graph.
  • The framework generates an anchor draft, inlines it into callers for usage scenarios, and retrieves its callees for dependency context.
  • 29.73% average relative gains in EM, 20.82% in ES, and 49.34% in BLEU are reported on RepoExec against the strongest baseline.
  • The paper presents upstream and downstream context integration as its central contribution and reports consistent improvements across benchmarks, domains, and contextual environments.

2 Motivation

Similarity-based retrieval and linear call-chain concatenation can miss how a target function is used and what its implementation depends on. InlineCoder instead inlines the target within calling contexts while coupling this with targeted downstream retrieval.

  • Retrieval based on text similarity or structural proximity rarely represents both callers’ usage and callees’ dependencies systematically.
  • Simply prepending retrieved functions to a target signature can hide input/output constraints, variable bindings, return types, and appropriate API variants.
  • Conventional isolation led the model to select extract_functions and return dict instead of the expected list[str].
  • Inlining the target into its calling context exposes variable bindings, return formats, and valid API usage in a form the model can interpret.
  • The motivating example’s corrected function returns list[str] and invokes the appropriate callees after targeted retrieval is combined with inlining.

3 Methodology

InlineCoder transforms repository-level generation into a function-level task by placing a draft implementation within its call-graph context. Its pipeline combines draft generation, bidirectional context construction, and confidence-guided final generation.

  • Draft Generation: InlineCoder first generates an anchor draft that approximates downstream dependencies and supports perplexity-based confidence estimation.The draft is produced from a prompt containing imports, referenced dependencies, the unfinished signature, and its natural-language description.
  • Upstream Inlining: The anchor is inlined into callers to expose upstream usage scenarios and convert distributed call relations into a linearized function-local context.The procedure identifies callers through repository AST traversal and embeds the draft while preserving surrounding syntactic structure.
  • Context-Aware Code Generation: The final context-enhanced prompt combines the base prompt, retrieved upstream and downstream context, draft guidance, and confidence instructions.Perplexity calibrates whether the model should reuse the draft, partially rely on it, or regenerate it.
  • Upstream Inlining: Inline expansion applies parameter substitution, return normalization, assignment redirection, and sequential body expansion to preserve semantic equivalence in caller context.These transformations make the target function’s input, output, and behavior explicit within the surrounding caller body.
  • Downstream Retrieval: Downstream retrieval unions function calls extracted from the draft AST with LLM-predicted callees to retrieve candidate dependent functions.The resulting candidate set forms downstream context aligned with the draft’s generation trajectory.

4 Experiment Setup

The experiments evaluate repository-level code generation across two benchmarks, multiple backbone models, several code-quality metrics, and a broad baseline suite. The setup also excludes execution-based metrics because environmental variability can make their results misleading or incomparable.

  • Datasets: Experiments use DevEval and REPOEXEC to evaluate completion of entire unfinished function bodies.DevEval contains 1,825 Python samples from 115 repositories across 10 domains, while REPOEXEC provides 355 Python functions with ground-truth annotations.
  • Evaluation Metrics: Evaluation measures exact code match, edit similarity, BLEU overlap, and identifier-level F1.The metrics compare generated code with reference code using exact matching, Levenshtein distance, n-gram overlap, and identifier-set precision and recall.
  • Evaluation Metrics: Execution-based metrics such as Pass@k are omitted because repository-level tests and dependencies can produce substantial environmental fluctuations unrelated to the model.The authors state that these fluctuations could yield misleading or non-comparable scores.
  • Baselines: The study compares InlineCoder with in-file, prompt-based, similarity-retrieval, and static-analysis-based repository-context methods.The baseline suite includes In-File, Vanilla, RepoCoder, DRACO, and GraphCoder.
  • Implementation Details: Python call graphs for context retrieval are constructed with Tree-Sitter and Pydepcall, while draft generation uses the Vanilla prompts for each dataset.The framework is evaluated with DeepSeek-V3, Qwen3-Coder, and GPT-5-mini backbones, using Qwen2.5-Coder-1.5B for confidence estimation.

5 Experiments Results

InlineCoder improves repository-level code generation across backbones, datasets, metrics, domains, and targeted code structures. Ablations and case analyses attribute these gains to draft anchoring, confidence guidance, and bidirectional contextual information.

  • Overall Effectiveness: InlineCoder improves over the strongest baseline by 5.13% EM, 10.86% ES, and 10.67% BLEU on DevEval, and by 29.73% EM, 20.82% ES, and 49.34% BLEU on RepoExec.The reported gains are averaged across three backbone models.
  • Ablation Study: Removing any key component degrades performance, with draft removal causing the largest drop and confidence removal producing moderate, stable declines.Inlining and upstream/downstream context provide complementary gains, while perplexity-based confidence helps select more effective prompts.
  • Return Statements: InlineCoder achieves the best return-statement performance across metrics and improves EM by 2.07% over the compared methods.Structured upstream usage information provides more reliable guidance than naive multigeneration alone.
  • Function-Call Statements: InlineCoder achieves the best function-call performance and improves EM by 4.27%, demonstrating the value of downstream information for invocation statements.The result is reported for function-call statements in Table 5.
  • Domain Generalization: Across ten domains, InlineCoder leads in 9 for EM, 8 for ES, 9 for BLEU, and all 10 for ID.F1.Its only relatively weaker performance occurs in Scientific-Engineering, where cross-function invocation structure is sparse.
  • Case Analysis: A case analysis shows that downstream retrieval selects the correct parse_qs utility and parameters, while confidence guidance helps replace an erroneous draft with repository-consistent code.The analyses connect precise dependency context and draft re-evaluation to implementation correctness.

6 Discussion

InlineCoder performs best across repository-structure categories, with its largest gain in upstream contexts. The evaluation is limited by its focus on Python repositories, although the core principle is described as language-agnostic.

  • Repository Environments: InlineCoder outperforms baselines in nearly all structural scenarios, while No Context samples generally achieve higher overall scores because standalone functions are simpler.The DevEval structural groups are Upstream, Downstream, Up/Downstream, and No Context.
  • Repository Environments: InlineCoder achieves its most significant performance gain in the Upstream setting, supporting the value of caller information.The authors present this as empirical validation of their upstream-context design.
  • Threats to Validity: The evaluation uses Python repositories, which may limit generalizability to other programming languages and software projects.The implementation is Python-specific, although the authors describe the underlying AST-based principle as applicable across modern languages.

7 Related Work

Prior repository-level generation methods use retrieval, graphs, agents, static analysis, pruning, or fine-tuning, but often do not dynamically represent both function usage and dependencies. InlineCoder instead reframes generation through call-graph inlining and draft-anchored bidirectional retrieval.

  • Existing Approaches: Retrieval-augmented methods supply repository context through similar snippets, while graph-based methods model structural relationships such as control flow and data dependencies.These approaches improve context selection but represent repository structure through retrieval or graph constructions.
  • Existing Approaches: Agentic frameworks use multi-step reasoning and external tools, while static-analysis and pruning methods reduce noise or enrich prompts through dependency-focused context selection.These lines of work include iterative exploration, testing, dataflow guidance, and hierarchical dependency modeling.
  • Existing Approaches: Fine-tuning methods specialize models or datasets for particular domains and improve retrievers through reinforcement or reflexive training.Examples include Verilog completion, curriculum datasets, and retrieval-focused training.
  • InlineCoder: InlineCoder differs by inlining the unfinished function into its call stack, capturing upstream usage and downstream dependencies dynamically.A draft completion anchors bidirectional retrieval and supports iterative refinement without extensive fine-tuning.

8 Conclusion

InlineCoder combines upstream and downstream context inlining to improve repository-level code generation. Experiments report gains across datasets, metrics, domains, and backbone LLMs, with ablations identifying inlining as the primary driver.

  • Conclusion: InlineCoder integrates caller and callee context, consistently outperforming strong baselines across DevEval and REPOEXEC metrics.Ablations and targeted analyses link the improvements to return-statement accuracy and function-call precision.
  • Conclusion: The framework generalizes across programming domains and maintains stable performance with different backbone LLMs.The conclusion presents these findings alongside the reported repository-level improvements.
Loading 2601.00376v3…