Generative Compilation: On-the-Fly Compiler Feedback as AI Generates Code
Abstract
Languages with rich static semantics, such as Rust, provide stronger guarantees for AI-generated code, but their strictness makes generation more difficult. Off-the-shelf compilers can provide useful feedback post-generation, but does not guide intermediate generation steps, such as those during autoregressive LLM decoding. Constrained decoding intervenes earlier by rejecting invalid tokens during sampling, but requires white-box model access and costly reimplementation for semantic constraints.We introduce generative compilation, the first approach to obtaining compiler feedback on partial programs during generation. The core technical device is a sealor: a lightweight, mostly syntax-guided transformation that converts partial programs into complete ones that standard compilers can diagnose. It is designed such that possible-to-complete partial programs are never rejected, while preserving enough code context to catch genuine dead ends early. We construct such a sealor on a core Rust-like calculus and prove that it satisfies these properties, all mechanized in Lean. We extend it to the first partial-program checker for real Rust. We evaluate our method on challenging repository-level Rust coding tasks, across both frontier black-box and open-weight models. We show that generative compilation reduces non-compiling outputs and improves functional correctness, relative to standard post-generation feedback. It does so by detecting a broad range of errors close to their source and early during generation, thereby reducing errors cascades and enabling focused diagnostics. More broadly, generative compilation is a step toward making compilers a first-class citizen of AI-assisted programming active during generation, rather than a separate post-generation check.
Community
We introduce generative compilation, which provides LLMs with compiler feedback during code generation.
Its core device is a sealor: a lightweight, mostly syntax-guided transformation that closes a partial program so that an off-the-shelf compiler can diagnose it.
We formalize the properties for such a sealor to be correct and useful, mechanize a sealor for a core Rust calculus in Lean, and build the first partial-program checker for real Rust.
Across seven frontier and open-weight models on repository-level Rust translation and API-update tasks, generative compilation reduces non-compiling outputs from 20.7% with post-generation feedback to 13.1%, while improving average functional correctness from 59.5% to 63.0%.
It detects errors after a mean 33.3% of the file has been generated and returns substantially more focused diagnostics.
This is an automated message from the Librarian Bot. I found the following papers similar to this paper.
The following papers were recommended by the Semantic Scholar API
- AdaTrans: Automated C to Rust Transformation via Error-Adaptive Repair (2026)
- Symbolon: Symbolic Execution by Learning Code Transformation (2026)
- LACUNA: Safe Agents as Recursive Program Holes (2026)
- Teaching Code LLMs to Reason with Intermediate Formal Specifications (2026)
- Foundational Constraint Solving for Expressive Refinement Typing (2026)
- Harnessing Code Agents for Automatic Software Verification (2026)
- Agentic Model Checking (2026)
Please give a thumbs up to this comment if you found it helpful!
If you want recommendations for any Paper on Hugging Face checkout this Space
You can directly ask Librarian Bot for paper recommendations by tagging it in a comment: @librarian-bot recommend
Models citing this paper 0
No model linking this paper
Datasets citing this paper 2
eth-sri/API-Upgrade
Spaces citing this paper 0
No Space linking this paper