Deep learning type inference

Deep learning type inference
复制标题

DOI:
10.1145/3236024.3236051
复制
发表时间:
2018-10
期刊:
Proceedings of the 2018 26th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering
影响因子:
--
通讯作者:
Vincent J. Hellendoorn;C. Bird;Earl T. Barr;Miltiadis Allamanis
Vincent J. Hellendoorn;C. Bird;Earl T. Barr;Miltiadis Allamanis
中科院分区:
其他
文献类型:
--
作者:
Vincent J. Hellendoorn;C. Bird;Earl T. Barr;Miltiadis Allamanis

文献摘要

相似文献

JavaScript 和 Python 等动态类型语言越来越流行,但静态类型尚未完全被淘汰:Python 现在支持类型注解,而 TypeScript 等语言则为 JavaScript 提供了一个中间地带:JavaScript 的严格超集(可转译为 JavaScript),再加上允许部分类型程序的类型系统。然而,静态类型化需要付出代价:添加注释、阅读添加的语法,以及与类型系统搏斗以修复类型错误。类型推断可以简化向更多静态类型代码的过渡,并释放更丰富的编译时信息所带来的好处,但在 JavaScript 等语言中却受到限制,因为它无法通过 eval 稳妥地处理 duck-typing 或运行时评估。我们提出的 DeepTyper 是一种深度学习模型,它能理解在特定上下文和关系中自然出现的类型,并能提供类型建议,即使类型检查程序最初无法推断出类型,也往往可以通过类型检查程序进行验证。DeepTyper 利用自动对齐的标记和类型语料库,可以准确预测数千种变量和函数类型注释。此外,我们还证明了上下文是准确分配这些类型的关键,并介绍了一种减少局部线索过度拟合的技术,同时强调了进一步改进的必要性。最后,我们展示了我们的模型可以与编译器交互,以 95% 以上的精确度提供 4000 多种额外的类型注释,而这些注释在没有 DeepTyper 的帮助下是无法推断出来的。
Dynamically typed languages such as JavaScript and Python are increasingly popular, yet static typing has not been totally eclipsed: Python now supports type annotations and languages like TypeScript offer a middle-ground for JavaScript: a strict superset of JavaScript, to which it transpiles, coupled with a type system that permits partially typed programs. However, static typing has a cost: adding annotations, reading the added syntax, and wrestling with the type system to fix type errors. Type inference can ease the transition to more statically typed code and unlock the benefits of richer compile-time information, but is limited in languages like JavaScript as it cannot soundly handle duck-typing or runtime evaluation via eval. We propose DeepTyper, a deep learning model that understands which types naturally occur in certain contexts and relations and can provide type suggestions, which can often be verified by the type checker, even if it could not infer the type initially. DeepTyper, leverages an automatically aligned corpus of tokens and types to accurately predict thousands of variable and function type annotations. Furthermore, we demonstrate that context is key in accurately assigning these types and introduce a technique to reduce overfitting on local cues while highlighting the need for further improvements. Finally, we show that our model can interact with a compiler to provide more than 4,000 additional type annotations with over 95% precision that could not be inferred without the aid of DeepTyper.