Constrained Code Generation with Discrete Diffusion
Quick Answer
The paper presents Constrained Diffusion for Code (CDC), a neurosymbolic inference framework that enhances discrete diffusion models for code generation by integrating constraint satisfaction directly into the denoising process.
Quick Take
The paper presents Constrained Diffusion for Code (CDC), a neurosymbolic inference framework that enhances discrete diffusion models for code generation by integrating constraint satisfaction directly into the denoising process. CDC improves functional correctness, security, and syntax in generated code, outperforming traditional methods with fewer corrections and localized edits across benchmarks.
Key Points
- CDC integrates constraint satisfaction into the reverse denoising process of discrete diffusion models.
- It enhances code generation by improving functional correctness, security, and syntax.
- CDC outperforms discrete diffusion and autoregressive baselines with fewer corrective computations.
- The framework allows for parallel token refinement and local adjustments during generation.
- It identifies constraint-relevant regions in the program state to guide code generation.
Paper Resources
📖 Reader Mode
~2 min readAbstract:Discrete diffusion models are a powerful, emerging paradigm for code generation. They construct programs through iterative refinement of partially corrupted token sequences and enable parallel token refinement. Importantly, this paradigm exposes a global program state at each denoising step, which provides a natural intervention point for enforcing program-level functionality and security constraints, guiding the generation before the final code is committed. Building on this observation, the paper introduces Constrained Diffusion for Code (CDC), a training-free neurosymbolic inference framework that integrates constraint satisfaction directly into the reverse denoising process. CDC augments the base discrete diffusion sampler with constraint-aware denoising operators that combine mathematical optimization with program analysis to identify constraint-relevant regions of the intermediate program state and locally adjust the denoising trajectory, steering generation toward feasible programs while remaining close to the base model. Across code generation benchmarks, CDC consistently improves constraint satisfaction in functional correctness, security, and even syntax, outperforming discrete diffusion and autoregressive baselines with less corrective computation and more localized edits.
| Subjects: | Computation and Language (cs.CL); Programming Languages (cs.PL) |
| Cite as: | arXiv:2605.16829 [cs.CL] |
| (or arXiv:2605.16829v1 [cs.CL] for this version) | |
| https://doi.org/10.48550/arXiv.2605.16829 arXiv-issued DOI via DataCite (pending registration) |
Submission history
From: Lize Shao [view email]
[v1]
Sat, 16 May 2026 06:15:47 UTC (983 KB)
— Originally published at arxiv.org
Want this in your inbox every morning?
Daily brief at your local 8am — bilingual EN/中文, free.
More from arXiv cs.CL
See more →Quantifying Prior Dominance in Systems
The study introduces the Normalized Context Utilization (NCU) metric to evaluate Retrieval-Augmented Generation (RAG) systems, revealing that Small Language Models (SLMs) outperform larger models in factual extraction. The findings indicate that traditional scaling laws yield diminishing returns, with a commercial API frequently failing against adversarial evidence due to systemic confidence collapse.