arXiv:2605.15238cs.SEcs.AI2026-05

让代码生成出错时快速修复,不重跑整段代码

Hydra: Efficient, Correct Code Generation via Checkpoint-and-Rollback Support

论文配图:Hydra: Efficient, Correct Code Generation via Checkpoint-and-Rollback Support
图 1 · 摘自论文原文
  • 生成时异步检查,正确时不增加开销
  • 出错后只回滚修复问题部分,避免重生成
  • 适配Clang编译器,对大模型代码生成提速71%

大型语言模型在代码生成中越来越常用,但许多生成的程序无法通过编译,而这是后续正确性检查的前提。现有修复静态错误的方法在延迟和令牌消耗上成本高昂。事后修复会延迟错误发现,并常需重新生成大量原本正确的代码;约束语义解码虽每词检查,但有额外开销,且仅能修复当前词,无法处理早期根源问题。本文提出Hydra系统,支持生成过程中的异步检查,当代码语义正确时无检查开销。同时提供检查点与回滚机制,实现精准修复,避免重复生成和验证有效前缀。我们对Clang C/C++编译器进行了小幅改造以支持Hydra。结合高效的修复策略,相较于事后修复,Hydra在出现静态错误的C/C++代码生成任务中,延迟降低高达71%,令牌消耗减少高达70%。

原文摘要 · Abstract (English)

Large language models are increasingly used for code generation, but many generated programs fail to compile, a prerequisite for further correctness checks such as unit tests. Existing solutions for repairing static errors are costly in both latency and token consumption. Post-hoc repair delays error detection until generation completes and commonly regenerates large regions of previously valid code. Constrained semantic decoding checks after each token, incurring per-token overhead while limiting repair to the current token even when the root cause lies earlier. We present Hydra, a system for efficient recovery from static errors during code generation. Hydra allows checking to proceed asynchronously with generation, avoiding checker overhead when the generated code is semantically correct. In addition, it provides checkpoint-and-rollback support for targeted repair, avoiding regeneration and rechecking of valid prefixes. We retrofit the Clang C/C++ compiler to support Hydra with modest modifications. Paired with a token-efficient repair strategy, Hydra reduces latency by up to 71% and token consumption by up to 70% relative to post-hoc repair on C/C++ code generation tasks that encounter static errors.

代码生成编译优化大模型

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。