TL;DR
This paper introduces GRACE, a novel method that leverages large language models (LLMs) for code editing by conditioning their generation on "associated edits" – relevant past code changes. GRACE significantly improves LLM performance in predicting code edits, outperforming existing state-of-the-art methods and demonstrating the power of contextualizing LLMs with historical code evolution.
What Problem Does This Paper Address?
Developers spend a substantial amount of time maintaining and modifying existing code. While Integrated Development Environments (IDEs) offer tools to assist with this, predicting the exact code edits a developer intends to make remains a significant challenge. Existing approaches often struggle with the diversity of code changes and capturing the developer's intent. Symbolic methods are limited in generating new code, and prior neural models often fail to infer intent without contextual information from past edits. This paper aims to bridge this gap by using LLMs, enhanced with knowledge of relevant prior edits, to provide more accurate and context-aware code edit suggestions.
Methods
The core contribution of GRACE is its methodology for conditioning LLMs on associated edits. The authors propose two main ways to achieve this:
- Prompting LLMs: This involves crafting specific prompts that include the current code context and relevant past edits. The LLM (e.g., CODEX) is then used in a zero-shot or few-shot manner to predict the next edit. The prompt structure is designed to clearly delineate the current edit being considered and the associated edits.
- Fine-tuning LLMs: This approach involves taking a pre-trained LLM (e.g., CODET5) and fine-tuning it on a dataset of code edits, where the training data is prepared using the GRACE prompt format. This allows the model to learn the specific task of predicting edits conditioned on associated changes.
The key novelty lies in the concept of "associated edits" – not just spatially close edits, but also temporally relevant ones – and how they are integrated into LLM inference and training to capture developer intent.
Datasets
The authors evaluate GRACE using two established datasets:
- C3PO dataset: This dataset was created by scraping commits from popular C# GitHub repositories. It focuses on contextual edits, where associated edits are defined by spatial proximity to the target edit. The dataset was further filtered by its creators to remove simpler edits.
- OVERWATCH dataset: This dataset was collected from IDE sessions, capturing fine-grained edit sequences. It provides a richer history of code evolution.
Key Insights and Ideas
- Associated edits are crucial for intent inference: LLMs, while powerful, struggle to infer developer intent for code edits without context. Associated edits provide this crucial context, significantly improving prediction accuracy.
- Beyond spatial proximity: The paper demonstrates that temporal proximity and relevance of edits, not just spatial closeness, are important for effective code edit prediction.
- LLMs offer generative power: Unlike symbolic methods, LLMs can generate novel code snippets, making them more versatile for predicting complex edits, including "alien insertions" (new code not present in the immediate context).
- Relevance matters: The performance of GRACE degrades as the relevance of associated edits decreases, highlighting the importance of selecting truly related past changes.
- Pre-trained LLMs are a strong foundation: Leveraging existing large pre-trained models like CODEX and CODET5 with GRACE is more effective and efficient than training custom models from scratch.
Key Results
GRACE significantly boosts the performance of LLMs on code edit prediction tasks.
- CODEX-DAVINCI: Showed a 30% absolute increase in Exact Match on the C3PO dataset and a 17% increase on the OVERWATCH dataset when using associated edits.
- CODET5 (fine-tuned): Achieved approximately a 10% absolute increase in Exact Match on both datasets with associated edits.
- Outperforming baselines: GRACE-enhanced models substantially outperformed existing symbolic (OVERWATCH) and neural (C3PO) approaches, achieving up to 28.63% absolute improvement over C3PO and 53.82% relative improvement.
- Robustness to noise: Adding irrelevant edits to the associated edits set had a minimal negative impact, and in some cases, even slightly improved performance, suggesting a degree of robustness.
- Reduced entropy: The use of associated edits led to a smaller gap between Top-1 and Top-5 Exact Match scores, indicating more confident and precise predictions.
Limitations and Future Work
The authors acknowledge several limitations:
- Dependence on edit mining: The quality of GRACE's predictions is dependent on the quality of the associated edits identified by other techniques.
- LLM limitations: LLMs can still hallucinate or generate uncompilable code, and may struggle with edits requiring deep semantic understanding of method signatures or entirely new code generation.
- Data leakage concerns: While mitigated by using multiple datasets and models, the possibility of pre-training data overlap with test sets is a general concern for LLMs.
- Future work: The authors suggest exploring more sophisticated methods for discovering associated edits, applying GRACE to large-scale code migrations and refactorings, and enhancing the approach with "associated code context" (e.g., live variables, type signatures) for even more robust predictions.
Summary updated