论文精选

生成式编译:在AI生成代码时通过编译器即时反馈

Generative Compilation: On-the-Fly Compiler Feedback as AI Generates Code

精选理由

这篇论文让编译器在AI写Rust代码时实时纠错,而不是写完再报错,对写复杂项目特别有用。

AI 摘要

本研究提出生成式编译(Generative Compilation),其核心设备sealor能将部分程序转换为完整程序,使标准编译器可诊断。在核心Rust-like演算上形式化证明了sealor满足不拒绝可能完成的部分程序等性质,并扩展到真实Rust。在仓库级Rust编程任务上,相比传统后生成反馈,该方法减少了非编译输出数量并提升了功能正确性。

原文 · arXiv cs.AI

Generative Compilation: On-the-Fly Compiler Feedback as AI Generates Code

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.