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

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

Just-in-Time Static Type Checking for Dynamic Languages

Brianna M. Ren, Jeffrey S. Foster

摘要:

Ruby、Python和JavaScript等动态语言有许多令人信服的优点,但缺乏静态类型意味着细微的错误可能会在代码中潜伏很长时间。虽然许多研究人员已经开发了各种系统,将静态类型的一些好处带到动态语言中,但以前的方法在处理元编程时遇到了麻烦,元编程在程序执行时生成代码。在本文中,我们提出了蜂鸟,一个新的系统,使用一种新的技术,即时静态类型检查,类型检查Ruby代码,即使在元编程的存在。在Hummingbird中,方法类型签名是在运行时动态收集的,因为这些方法是创建的。当一个方法被调用时,Hummingbird会根据当前的类型签名对方法体进行静态类型检查。因此,Hummingbird在每个方法的基础上提供了彻底的静态检查,同时也允许任意复杂的元编程。为了提高性能,Hummingbird会记住静态类型检查过程,仅在必要时才使缓存检查无效。我们使用一个核心的,类似Ruby的语言形式化Hummingbird,并证明它的声音。为了评估Hummingbird,我们将其应用于六个应用程序,其中三个使用Ruby on Rails,这是一个非常依赖元编程的强大框架。我们发现,所有的应用程序都成功地使用Hummingbird进行了类型检查,并且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.

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

↑