arXiv:2510.10216cs.PLcs.AI2025-10被引 1

让代码模型内化类型推理,自动生成无类型错误的程序。

Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesis

  • 用类型引导的合成树重构代码表示,使模型内部学习类型系统。
  • 在多个基准上实现0类型错误,功能正确率显著提升。
  • 适合需要高可靠性代码生成的研究者与工程团队。

语言模型在代码生成方面表现出色,但保证类型正确性仍是难题。传统方法如约束解码通过外部过滤不可类型化的代码来缓解问题,但模型本身未能有效内化类型推理,最终限制整体性能。本文提出TyFlow,一种将类型推理内化于代码生成的新系统。其核心是新型类型引导的程序合成机制,保持类型推导树与合成推导树之间的同构关系,从而采用基于合成决策序列的新代码表示方式,而非传统的文本标记序列。通过将类型系统学习的复杂度转移到表示本身,模型可将计算资源聚焦于更高层次的程序语义。评估表明,TyFlow不仅完全消除类型错误,还显著提升功能正确性,凸显了将语言模型与类型系统内部对齐的重要性。

原文摘要 · Abstract (English)

Language models have shown remarkable proficiency in code generation; nevertheless, ensuring type correctness remains a challenge. Although traditional methods, such as constrained decoding, alleviate this problem by externally rejecting untypable code, the model itself does not effectively learn type reasoning internally, which ultimately limits its overall performance. This paper introduces TyFlow, a novel system that internalizes type reasoning within code generation to guide the model to learn the type system. The core of our approach is a novel type-guided program synthesis system that maintains an isomorphism between type derivation trees and synthesis derivation trees, enabling a new code representation based on synthesis decision sequences rather than traditional text-based token sequences. By offloading the complexity of type system learning to the representation itself, models can redirect their computational resources toward higher-level program semantics. Our evaluation shows that TyFlow not only eliminates type errors but also significantly improves functional correctness, highlighting the importance of aligning LMs with type systems internally.

代码生成类型系统程序合成

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。