LGOct 11, 2024

Don't Transform the Code, Code the Transforms: Towards Precise Code Rewriting using LLMs

Meta AI
arXiv:2410.08806v19 citationsh-index: 16
Originality Incremental advance
AI Analysis

This addresses the need for fast and correct code transformation tools for developers, though it is incremental as it builds on existing LLM capabilities.

The paper tackles the problem of using large language models (LLMs) for code rewriting by proposing a method where LLMs generate code transformations from examples, rather than directly rewriting code, resulting in perfectly precise transforms for 7 out of 16 cases and reduced imprecision compared to direct rewriting.

Tools for rewriting, refactoring and optimizing code should be fast and correct. Large language models (LLMs), by their nature, possess neither of these qualities. Yet, there remains tremendous opportunity in using LLMs to improve code. We explore the use of LLMs not to transform code, but to code transforms. We propose a chain-of-thought approach to synthesizing code transformations from a small number of input/output code examples that incorporates execution and feedback. Unlike the direct rewrite approach, LLM-generated transformations are easy to inspect, debug, and validate. The logic of the rewrite is explicitly coded and easy to adapt. The compute required to run code transformations is minute compared to that of LLM rewriting. We test our approach on 16 Python code transformations and find that LLM- generated transforms are perfectly precise for 7 of them and less imprecise than direct LLM rewriting on the others. We hope to encourage further research to improving the precision of LLM code rewriting.

Foundations

The foundational work for this paper's niche, ranked by how specifically the neighbourhood builds on it — not by global fame.

Your Notes