There has been growing interest in automatically predicting missing type annotations in programs written in Python and JavaScript. While prior methods have achieved impressive accuracy when predicting the most common types, they often perform poorly on rare or complex types. In this paper, we present a new type inference method that treats type prediction as a code infilling task by leveraging CodeT5, a state-of-the-art seq2seq pre-trained language model for code. Our method uses static analysis to construct dynamic contexts for each code element whose type signature is to be predicted by the model. We also propose an iterative decoding scheme that incorporates previous type predictions in the model's input context, allowing information exchange between related code elements. Our evaluation shows that the proposed approach, TypeT5, not only achieves a higher overall accuracy (particularly on rare and complex types) but also produces more coherent results with fewer type errors -- while enabling easy user intervention.
Prompt-tuned Code Language Model as a Neural Knowledge Base for Type Inference in Statically-Typed Partial Code
部分代码通常涉及非完全限定的类型名(non-Full-Qualified Type Name)和未声明的接收对象。解析这些非类型和未声明的接收对象的类型(称为类型推断)是有效搜索和重用部分代码的先决条件。现有的基于字典查找的方法构建API名称和代码上下文的符号知识库,这涉及显著的编译开销并且对看不见的API名称和代码上下文变化敏感。在本文中,我们将类型推断描述为一个完形填空式的语言任务。建立在源代码的自然性,我们的方法微调的代码掩码语言模型(MLM)作为一个神经知识库的代码元素与一个新的“预训练,提示和预测”的范式从原始源代码。我们的方法是轻量级的,对代码编译的要求最低。与现有的符号名称和上下文匹配的类型推断,我们的优化代码MLM包在其参数中的CCN语法和用法,并支持模糊神经类型推断。我们在GitHub和Stack Overflow的大量源代码上系统地评估了我们的方法。我们的结果证实了我们的方法设计的有效性和实用性的部分代码类型推断。作为同类中的第一个,我们的神经类型推断方法为使用部分代码的许多创新方法打开了大门。
Co-Evolution of Types and Dependencies: Towards Repository-Level Type Inference for Python Code
Technology Center of Software Engineering, Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所软件工程中心);Key Laboratory of System Software (Chinese Academy of Sciences), Institute of Software, Chinese Academy of Sciences(中国科学院软件研究所系统软件重点实验室)
KubeCap: A Framework for Capability Minimization in Kubernetes via Static Analysis and LLM-Assisted Rule Inference
Key Laboratory of Data and Intelligent System Security, Ministry of Education, China (DISSec), Tianjin Key Laboratory of Network and Data Security Technology (NDST), College of Cryptology and Cyber Science, Nankai University(南开大学密码学与网络科学学院)