Share your thoughts, 1 month free Claude Pro on usSee more
WorkDL logo mark

Constrained Code Generation with Discrete Diffusion

About

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.

Lize Shao, Michael Cardei, Zichen Xie, Ferdinando Fioretto, Wenxi Wang• 2026

Related benchmarks

TaskDatasetResultRank
Secure Code GenerationCWEval
pass@139.8
29
Code GenerationHumanEval-X C++
Compilation Success Rate79.2
13
Code GenerationMBPP C++
Compilation Success Rate72
13
Security-aware code generationLLMSecEval+
Functional Success @130.7
5
Showing 4 of 4 rows

Other info

Follow for update