Static Inference Meets Deep learning: A Hybrid Type Inference Approach for Python

Static Inference Meets Deep learning: A Hybrid Type Inference Approach for Python
复制标题

DOI:
10.1145/3510003.3510038
复制
发表时间:
2021-05
期刊:
2022 IEEE/ACM 44th International Conference on Software Engineering (ICSE)
影响因子:
--
通讯作者:
Yun Peng;Cuiyun Gao;Zongjie Li;Bowei Gao;David Lo;Qi-reng Zhang;Michael R. Lyu
Yun Peng;Cuiyun Gao;Zongjie Li;Bowei Gao;David Lo;Qi-reng Zhang;Michael R. Lyu
中科院分区:
其他
文献类型:
--
作者:
Yun Peng;Cuiyun Gao;Zongjie Li;Bowei Gao;David Lo;Qi-reng Zhang;Michael R. Lyu

文献摘要

相似文献

动态编程语言(如Python)的类型推断是一项重要但具有挑战性的任务。静态类型推断技术可以精确地推断具有足够静态约束的变量,但无法处理具有动态特征的变量。基于深度学习(DL)的方法是特征不可知的,但它们不能保证预测类型的正确性。它们的性能很大程度上取决于训练数据的质量(即,DL模型在训练数据集中很少出现的一些常见类型上表现不佳)。有趣的是,静态和基于DL的方法提供了互补的好处。不幸的是,据我们所知,基于静态推理和神经预测的精确类型推理尚未被利用,仍然是一个开放的挑战。特别是,很难将深度学习模型集成到基于规则的静态方法的框架中。本文填补了这一差距,提出了一种基于静态推理和深度学习的混合型推理方法Hityper。具体来说,我们的关键见解是记录每个函数中变量之间的类型依赖关系,并将依赖关系信息编码到类型依赖图(TDG)中。基于TDGs,我们可以很容易地在节点中集成类型推理规则来进行静态推理,并集成类型拒绝规则来检查神经预测的正确性。Hityper迭代地进行静态推断和基于DL的预测,直到TDG被完全推断出来。在两个基准数据集上的实验表明,Hityper的性能优于最先进的DL模型,可以准确匹配10%以上的人类注释。Hityper在推断稀有类型方面也实现了超过30%的增长。仅考虑Hityper的静态部分,它比现有的静态类型推理工具多推理2× ~3×的类型。此外,Hityper还成功地纠正了六个GitHub项目中的七个错误的人工标注,其中两个已经得到了仓库所有者的批准。
Type inference for dynamic programming languages such as Python is an important yet challenging task. Static type inference techniques can precisely infer variables with enough static constraints but are unable to handle variables with dynamic features. Deep learning (DL) based approaches are feature-agnostic, but they can-not guarantee the correctness of the predicted types. Their per-formance significantly depends on the quality of the training data (i.e., DL models perform poorly on some common types that rarely appear in the training dataset). It is interesting to note that the static and DL-based approaches offer complementary benefits. Un-fortunately, to our knowledge, precise type inference based on both static inference and neural predictions has not been exploited and remains an open challenge. In particular, it is hard to integrate DL models into the framework of rule-based static approaches. This paper fills the gap and proposes a hybrid type inference approach named Hityper based on both static inference and deep learning. Specifically, our key insight is to record type dependen-cies among variables in each function and encode the dependency information in type dependency graphs (TDGs). Based on TDGs, we can easily integrate type inference rules in the nodes to conduct static inference and type rejection rules to inspect the correctness of neural predictions. Hityper iteratively conducts static inference and DL-based prediction until the TDG is fully inferred. Experi-ments on two benchmark datasets show that Hityper outperforms state-of-the-art DL models by exactly matching 10% more human annotations. Hityper also achieves an increase of more than 30% on inferring rare types. Considering only the static part of Hityper, it infers 2× ~3× more types than existing static type inference tools. Moreover, Hityper successfully corrected seven wrong human an-notations in six GitHub projects, and two of them have already been approved by the repository owners.