TL;DR
When translating code, large language models usually write an entire program before checking if it actually compiles—meaning a tiny mistake on line 3 can quietly poison the rest of the file. Decoding Time Verification (DTV) puts compilers and type checkers inside the generation loop, pausing at natural code boundaries to verify, roll back, and repair mistakes on the fly. The result is significantly higher compilation pass rates using fewer tokens than standard self-debugging or repeated sampling.
What Problem Does This Paper Address?
Right now, one of the best ways to make a frozen LLM smarter is test-time scaling: spending extra compute during inference via repeated sampling or self-refinement. In open-ended domains, models rely on fuzzy probabilistic guesses to guide this search. Coding, however, has a superpower: deterministic verifiers like compilers, type checkers, and linters that give exact pass/fail verdicts and pinpoint diagnostics.
Standard approaches only run these verifiers post-hoc (after the entire program is generated). Because LLMs generate text autoregressively—conditioning every new token on what came before—an early mistake corrupts the context. Rather than recovering, the model tends to double down and build around its own bug, wasting hundreds of tokens on a doomed trajectory. Putting a compiler inside the token-generation loop solves this, but raises a tricky engineering puzzle: compilers choke on half-written lines of code, so when do you pause generation, how far do you rewind on an error, and how do you stop the model from making the exact same mistake again?
Methods
The authors introduce Decoding Time Verification (DTV), a deterministic state-machine controller that wraps around an open-weight LLM to manage generation as an "inner loop" (which can still be paired with an "outer loop" like multi-round self-refinement). DTV relies on three core mechanisms:
- Structural-Boundary Verification: You can't run
rustcon half a variable name. DTV uses a streaming parser to pause generation at meaningful structural boundaries—statements, blocks, functions, or full programs. At each pause, a deterministic renderer packages the current prefix into a valid artifact (e.g., closing open braces) and runs applicable verifiers. If all checks pass, the prefix is checkpointed and committed. - Structure-Aware Rollback with Escalation: When a check fails, rewinding just one statement isn't always enough. (For instance, in Rust, a borrow-checker error on line 10 might be caused by forgetting
.clone()when ownership moved on line 5.) DTV starts by rolling back to the smallest scope (statement), and if the exact same error persists across retries, it escalates—widening the rollback to the enclosing block or function so the upstream root cause can be rewritten. - Feedback via Prompt Augmentation: Rewinding and sampling again blindly is inefficient. Instead, DTV summarizes the compiler's error diagnostics and injects them directly into the model's conditioning context (either as inline code comments or a patch request) so the retry actually knows what broke.
Datasets
DTV is evaluated on two code translation tasks (no model training is involved):
- C to Rust (unsafe-to-safe systems translation): 300 C programs sampled from CodeNet, using
rustcas the in-loop verifier. To ensure passing the compiler doesn't break program behavior, the authors also run post-hoc differential testing using inputs generated via AFL++ fuzzing with LLM-based seeding. - JavaScript to TypeScript (dynamic-to-static typing): 150 self-bundled programs from TypeWeaver (filtered so plain JS fails type-checking), verified in-loop using
tscand ESLint'stypedefrule.
Key Insights and Ideas
- Catching cascading errors at the root: In JavaScript-to-TypeScript, a single missing or wrong type annotation infects every downstream variable use. By intervening immediately, DTV cuts derivative error emissions roughly in half (0.50 median ratio vs. post-hoc generation) and avoids getting stuck in "under-typed" structural ruts that outer-loop refinement struggles to escape.
- Every piece of the state machine pulls its weight: Ablating DTV on C-to-Rust shows that simply aborting on an inner error without localized recovery drops pass rates by 15.0 percentage points. Stripping out diagnostic feedback costs 11.0 pp, and disabling scope escalation costs 6.0 pp.
- Local fixes shine; global redesigns are still tough: DTV's rescue rate is strongest when the required fix is right on the flagged error line, and drops monotonically when the fix requires non-local restructuring across distant parts of the program.
- Bigger models make verifier overhead cheaper: Calling external tools mid-decoding adds latency—especially slow, serial JS/TS linters. However, moving from a 4B model to a 30B model noticeably shrinks the relative wall-clock overhead because token generation becomes the bottleneck, making wasted tokens much more expensive than compiler checks.
Key Results
Under a matched generation budget of $16\times$ the source program's tokens using Qwen3-4B-Instruct:
- Higher pass rates, fewer tokens: Combined with outer-loop self-refinement, DTV boosts compilation pass rates from 72.3% to 82.0% on C-to-Rust (while cutting token usage from $7.18\times$ to $5.28\times$ source tokens) and from 33.3% to 46.0% on JS-to-TS.
- Strong one-shot gains: Even without outer-loop retries, DTV's inner loop alone jumps one-shot pass rates from 16.3% to 47.0% (C-to-Rust) and 4.7% to 21.3% (JS-to-TS).
- Dominates sampling baselines: On cost-matched subsets, DTV/self-refine comfortably beats Best-of-32 sampling and the compile-guided $S^*$ baseline on both pass rate and token cost.
- Cross-model generalization & safety: Gains transfer to Gemma-4-E4B and Qwen3-30B-A3B (reaching 97% on C-to-Rust and 66% on JS-to-TS). Post-hoc differential testing confirms C-to-Rust functional correctness holds steady (~8.3% vs. 9.3%, statistically indistinguishable), meaning compiler-guided decoding doesn't game the compiler by breaking logic.
Limitations and Future Work
- Requires open-weight control: Because DTV needs mid-generation stops, prefix rollbacks, and context surgery, it cannot currently be used with standard closed-weight commercial APIs.
- Static recovery rules & verifier latency: Slow verifiers (like serial
tsc/ESLint) increase wall-clock runtime on smaller models, and non-local errors can occasionally cause repetitive rollback loops before bailing out. The authors highlight adapting rollback decisions dynamically to the remaining token budget, lowering engineering effort for new languages, and expanding beyond code translation as key next steps.
Summary updated