{"id": "http://arxiv.org/abs/2605.16829v1", "title": "Constrained Code Generation with Discrete Diffusion", "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. 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.", "published_at": "2026-05-16T06:15:47+00:00", "source_updated_at": null, "source_url": "https://arxiv.org/abs/2605.16829v1", "source_hash": "b0b378437b506ba700a06776095fd5dece98d267409805c1af76671994c98047", "source_version": "v1", "full_text_available": true, "evidence_kind": "full_text_excerpt", "analysis_scope": "full_text_excerpt", "scope": "core", "topics": ["discrete-diffusion", "code-generation"], "code_url": null, "has_code": false, "indexable": true, "authors": [], "related_ids": ["http://arxiv.org/abs/2609.00495v1", "http://arxiv.org/abs/2608.30922v1", "http://arxiv.org/abs/2608.20123v1"], "related_work": {"version": "related-work-v1", "status": "not_assessed", "reason": "missing_context", "items": []}, "review": null, "full_text_brief": null, "explanations": {}, "resources": {"version": "paper-resources-v1", "source_hash": "b0b378437b506ba700a06776095fd5dece98d267409805c1af76671994c98047", "evidence_kind": "full_text_excerpt", "availability": "not_checked", "limited": false, "items": [{"origin": "source_excerpt", "evidence": "e, Daniel Arp, and Konrad Rieck. Modeling and discovering vulnerabilities with\ncode property graphs. In 2014 IEEE Symposium on Security and Privacy, pages 590–604. IEEE, 2014. doi:\n10.1109/SP.2014.44. URL https://doi.org/10.1109/SP.2014.44.\n[34] Max Brunsfeld.\nTree-sitter: An incremental parsing system.\nhttps://tree-sitter.github.io/\ntree-sitter/, 2018. URL https://tree-sitter.github.io/tree-sitter/.\n\n### Broader Impact\n\nThis work aims to improve the reliability and security of code generation by steering diffusion models toward programs\nthat better satisfy functional and security constraints. Potential benefits include fewer syntax", "url": "https://tree-sitter.github.io/", "kind": "project", "span": [47487, 48127], "evidence_hash": "9a702cc99f5693dd744b43af3b84cf649f1ba7c14f7f94e30d59d0caca8056d1"}, {"origin": "source_excerpt", "evidence": "nerabilities with\ncode property graphs. In 2014 IEEE Symposium on Security and Privacy, pages 590–604. IEEE, 2014. doi:\n10.1109/SP.2014.44. URL https://doi.org/10.1109/SP.2014.44.\n[34] Max Brunsfeld.\nTree-sitter: An incremental parsing system.\nhttps://tree-sitter.github.io/\ntree-sitter/, 2018. URL https://tree-sitter.github.io/tree-sitter/.\n\n### Broader Impact\n\nThis work aims to improve the reliability and security of code generation by steering diffusion models toward programs\nthat better satisfy functional and security constraints. Potential benefits include fewer syntax errors, higher task\n\n11\n\n## Page 12\n\nConstrained Code Genera", "url": "https://tree-sitter.github.io/tree-sitter/", "kind": "project", "span": [47548, 48188], "evidence_hash": "569bed2226e81113530c1b70e73a48d938b333a7a222e1cd15967e5e0dec75b0"}]}, "slug": "2605.16829-constrained-code-generation-with-discrete-diffusion"}