arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2604.02702cs.SEcs.PL
收藏

TypePro: 通过跨过程切片提升基于大语言模型的类型推断

TypePro: Boosting LLM-Based Type Inference via Inter-Procedural Slicing

Xiamen University(厦门大学)

Teyu Lin, Minghao Fan, Huaxun Huang, Zhirong Shen, Rongxin Wu

AI总结:

本文提出TypePro方法,通过跨过程代码切片补充上下文信息,提升动态语言类型推断的准确性和鲁棒性,实验结果显示在ManyTypes4Py和ManyTypes4TypeScript数据集上分别达到88.9%和86.6%的Top-1精确匹配率。

摘要:

动态语言(如Python和JavaScript)提供了灵活的类型处理机制,但这也导致类型相关错误增加以及编译时类型推断的额外开销。因此,动态语言的类型推断已成为热门研究领域。现有方法通常通过静态分析、机器学习或大语言模型(LLMs)实现类型推断。然而,现有工作仅关注与类型推断相关的变量直接依赖作为上下文,导致上下文信息不完整,从而影响类型推断的准确性。为了解决这一问题,本文提出了一种名为TypePro的方法,利用LLMs进行动态语言的类型推断。TypePro通过执行跨过程代码切片来补充上下文信息。然后,TypePro基于切片中隐含的数据类型结构信息提出一组候选复杂类型,从而弥补LLMs的领域知识不足。我们在ManyTypes4Py和ManyTypes4TypeScript数据集上进行了实验,分别达到了88.9%和86.6%的Top-1精确匹配率。值得注意的是,TypePro在第二好的方法基础上分别提高了7.1和10.3个百分点的Top-1精确匹配率,显示出TypePro的有效性和鲁棒性。

英文摘要:

Dynamic languages (such as Python and JavaScript) offer flexibility and simplified type handling for programming, but this can also lead to an increase in type-related errors and additional overhead for compile-time type inference. As a result, type inference for dynamic languages has become a popular research area. Existing approaches typically achieve type inference through static analysis, machine learning, or large language models (LLMs). However, current work only focuses on the direct dependencies of variables related to type inference as the context, resulting in incomplete contextual information and thus affecting the accuracy of type inference. To address this issue, this paper proposes a method called TypePro, which leverages LLMs for type inference in dynamic languages. TypePro supplements contextual information by conducting inter-procedural code slicing. Then, TypePro proposes a set of candidate complex types based on the structural information of data types implied in the slices, thereby addressing the lack of domain knowledge of LLMs. We conducted experiments on the ManyTypes4Py and ManyTypes4TypeScript datasets, achieving Top-1 exact match (EM) rates of 88.9% and 86.6%, respectively. Notably, TypePro improves the Top-1 Exact Match by 7.1 and 10.3 percentage points over the second-best approach, showing the effectiveness and robustness of TypePro.

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

↑