Constrained Code Generation with Discrete Diffusion

Lize Shao, Michael Cardei, Zichen Xie, Ferdinando Fioretto, Wenxi Wang
5/16/2026
cs.CLcs.PL
diffusion-flow

No confident code implementation found for this paper.

Abstract

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.

Show full abstract

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.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{shao2026constrained,
  title  = {Constrained Code Generation with Discrete Diffusion},
  author = {Lize Shao and Michael Cardei and Zichen Xie and Ferdinando Fioretto and Wenxi Wang},
  year   = {2026},
  eprint = {2605.16829},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2605.16829v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2605.16829.svg)](https://codeofpaper.com/paper/2605.16829)

Discussion