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.
翻译:Ruby、 Python 和 JavaScript 等动态语言有许多令人信服的好处,但缺乏静态类型意味着在代码中隐蔽的微妙错误可能长期存在。虽然许多研究人员已经开发了各种系统,将静态类型的一些好处带给动态语言,但先前的方法在处理元程序设置代码方面有困难。在本文中,我们提议蜂鸟,这是一个使用新颖技术的新系统,即即时静态类型检查,以输入鲁比代码,即使存在元程序化。在蜂鸟中,方法型号的签名可以在运行时动态代码中继续隐藏。在创建这些方法时,方法会动态地收集。当一种方法被使用时,蜂鸟静型对方法体进行测试,以动态格式进行彻底的静态检查,同时允许任意复杂的元程序设置。对于性功能,蜂鸟对静态类型检查进行记录,即使是在出现元程序设置时也无效。在运行时,我们用核心、 Ruby 语言在运行时会自动收集, 证明它是否正常运行, 我们用 Hprimal 格式来评估 Hdrimal 。