arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2510.10216cs.PLcs.AIcs.SE
收藏

通过类型引导的程序合成学习保证类型正确性

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

Peking University(北京大学);University of Michigan(密歇根大学);Shanghai Jiao Tong University(上海交通大学);Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所);Tencent(腾讯)

Zhechong Huang, Zhao Zhang, Ruyi Ji, Tingxuan Xia, Qihao Zhu, Qinxiang Cao, Zeyu Sun, Wiggin Zhou, Yingfei Xiong

AI总结:

TyFlow 通过内部化类型推理,提升代码生成的类型正确性与功能正确性。

摘要:

语言模型在代码生成方面表现出显著的 proficiency,但确保类型正确性仍是一个挑战。尽管传统方法,如受约束解码,通过外部拒绝无法类型化的代码来缓解这一问题,但模型本身并未有效内部学习类型推理,这最终限制了其整体性能。本文介绍了一个名为 TyFlow 的新型系统,该系统在代码生成中内部化类型推理,以引导模型学习类型系统。我们的核心方法是一种新的类型引导程序合成系统,它在类型推导树和合成推导树之间保持同构性,从而基于合成决策序列而非传统文本令牌序列建立新的代码表示。通过将类型系统学习的复杂性转移给表示本身,模型可以将计算资源重新定向到更高层次的程序语义。我们的评估表明,TyFlow 不仅消除了类型错误,还显著提高了功能正确性,突显了将 LMs 与类型系统内部对齐的重要性。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑