Just-in-time static type checking for dynamic languages

Just-in-time static type checking for dynamic languages
复制标题

动态语言的即时静态类型检查

DOI:
10.1145/2908080.2908127
复制
发表时间:
2016
期刊:
Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation
影响因子:
--
通讯作者:
J. Foster
J. Foster
中科院分区:
--
文献类型:
--
作者:
Brianna M. Ren;J. Foster

文献摘要

被引文献

相似文献

Ruby,Python和JavaScript等动态语言具有许多引人注目的好处,但是缺乏静态类型意味着很长一段时间内的代码可能保持潜在的错误。尽管许多研究人员已经开发了各种系统来将静态类型的某些好处带入动态语言,但先前的方法很难处理元编程,该元编程会在程序执行时生成代码。在本文中,我们提出了一种使用新技术的新系统Hummingbird,即使在元编程的存在下,也可以使用一种新技术,即即时静态型型检查,以键入Ruby Code。在蜂鸟中,随着这些方法的创建,方法类型的签名会在运行时动态收集。当调用方法时,蜂鸟静态类型会检查该方法的主体针对当前类型的特征。因此,蜂鸟以每方法为基础提供了彻底的静态检查,同时也允许任意复杂的元编程。为了进行性能,Hummingbird会记住静态型检查通行证,仅在必要时才无效缓存检查。我们使用核心,类似红宝石的语言将蜂鸟正式化,并证明它是听起来的。为了评估蜂鸟,我们将其应用于六个应用程序,其中包括三个在Rails上使用Ruby,这是一个强大的框架,极大地依赖于元编程。我们发现所有应用程序都成功地使用了Hummingbird,并且Hummingbird的性能开销是合理的。我们将蜂鸟应用于一个Rails应用程序的早期版本,发现了引入然后固定的几种类型错误。最后,我们证明在Rails开发模式中使用Hummingbird来打字应用程序,因为应用了实时更新。
Dynamic languages such as Ruby, Python, and JavaScript have many compelling benefits, but the lack of static types means subtle errors can remain latent in code for a long time. While many researchers have developed various systems to bring some of the benefits of static types to dynamic languages, prior approaches have trouble dealing with metaprogramming, which generates code as the program executes. In this paper, we propose Hummingbird, a new system that uses a novel technique, just-in-time static type checking, to type check Ruby code even in the presence of metaprogramming. In Hummingbird, method type signatures are gathered dynamically at run-time, as those methods are created. When a method is called, Hummingbird statically type checks the method body against current type signatures. Thus, Hummingbird provides thorough static checks on a per-method basis, while also allowing arbitrarily complex metaprogramming. For performance, Hummingbird memoizes the static type checking pass, invalidating cached checks only if necessary. We formalize Hummingbird using a core, Ruby-like language and prove it sound. To evaluate Hummingbird, we applied it to six apps, including three that use Ruby on Rails, a powerful framework that relies heavily on metaprogramming. We found that all apps typecheck successfully using Hummingbird, and that Hummingbird's performance overhead is reasonable. We applied Hummingbird to earlier versions of one Rails app and found several type errors that had been introduced and then fixed. Lastly, we demonstrate using Hummingbird in Rails development mode to typecheck an app as live updates are applied to it.