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

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Huang, Zhechong, Zhang, Zhao, Ji, Ruyi, Xia, Tingxuan, Zhu, Qihao, Cao, Qinxiang, Sun, Zeyu, Zhou, Wiggin, Xiong, Yingfei
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866910013765713920
author Huang, Zhechong
Zhang, Zhao
Ji, Ruyi
Xia, Tingxuan
Zhu, Qihao
Cao, Qinxiang
Sun, Zeyu
Zhou, Wiggin
Xiong, Yingfei
author_facet Huang, Zhechong
Zhang, Zhao
Ji, Ruyi
Xia, Tingxuan
Zhu, Qihao
Cao, Qinxiang
Sun, Zeyu
Zhou, Wiggin
Xiong, Yingfei
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2510_10216
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesis
Huang, Zhechong
Zhang, Zhao
Ji, Ruyi
Xia, Tingxuan
Zhu, Qihao
Cao, Qinxiang
Sun, Zeyu
Zhou, Wiggin
Xiong, Yingfei
Programming Languages
Artificial Intelligence
Software Engineering
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.
title Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesis
topic Programming Languages
Artificial Intelligence
Software Engineering
url https://arxiv.org/abs/2510.10216