Just-in-time static type checking for dynamic languages

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.

[1]  Peter J. Stuckey,et al.  Incremental analysis of constraint logic programs , 2000, TOPL.

[2]  Matthias Felleisen,et al.  Contracts for higher-order functions , 2002, ICFP '02.

[3]  Simon L. Peyton Jones,et al.  Template meta-programming for Haskell , 2002, Haskell '02.

[4]  Sophia Drossopoulou,et al.  Towards Type Inference for JavaScript , 2005, ECOOP.

[5]  Peter Thiemann Towards a Type System for Analyzing JavaScript Programs , 2005, ESOP.

[6]  Jeremy G. Siek Gradual Typing for Functional Languages , 2006 .

[7]  Walid Taha,et al.  Gradual Typing for Objects , 2007, ECOOP.

[8]  Davide Ancona,et al.  RPython: a step towards reconciling dynamically and statically typed OO languages , 2007, DLS '07.

[9]  Sam Tobin-Hochstadt,et al.  The design and implementation of typed scheme , 2008, POPL '08.

[10]  Jeffrey S. Foster,et al.  Static type inference for Ruby , 2009, SAC '09.

[11]  Michael Hicks,et al.  The ruby intermediate language , 2009, DLS '09.

[12]  Sorin Lerner,et al.  Staged information flow for javascript , 2009, PLDI '09.

[13]  Avik Chaudhuri,et al.  Static Typing for Ruby on Rails , 2009, 2009 IEEE/ACM International Conference on Automated Software Engineering.

[14]  J. Foster,et al.  Profile-guided static typing for dynamic scripting languages , 2009, OOPSLA '09.

[15]  Jan Vitek,et al.  Thorn: robust, concurrent, extensible scripting on the JVM , 2009, OOPSLA '09.

[16]  Jan Vitek,et al.  An analysis of the dynamic behavior of JavaScript programs , 2010, PLDI '10.

[17]  Jan Vitek,et al.  Integrating typed and untyped code in a scripting language , 2010, POPL '10.

[18]  Sam Tobin-Hochstadt,et al.  Logical types for untyped languages , 2010, ICFP '10.

[19]  Jan Vitek,et al.  The Eval That Men Do - A Large-Scale Study of the Use of Eval in JavaScript Applications , 2011, ECOOP.

[20]  Avik Chaudhuri,et al.  Dynamic inference of static types for ruby , 2011, POPL '11.

[21]  Sam Tobin-Hochstadt,et al.  Typing the Numeric Tower , 2012, PADL.

[22]  Henning Christiansen,et al.  Efficient tabling of structured data using indexing and program transformation , 2012 .

[23]  T. Stephen Strickland,et al.  The ruby type checker , 2013, SAC '13.

[24]  Giuseppe Castagna ECOOP 2013 – Object-Oriented Programming , 2013, Lecture Notes in Computer Science.

[25]  Joe Gibbs Politz,et al.  TeJaS: retrofitting type systems for JavaScript , 2013, DLS '13.

[26]  Jincheng Li,et al.  Combining Form and Function: Static Types for JQuery Programs , 2013, ECOOP.

[27]  Anders Møller,et al.  Checking correctness of TypeScript interfaces for JavaScript libraries , 2014, OOPSLA.

[28]  Martín Abadi,et al.  Understanding TypeScript , 2014, ECOOP.

[29]  Jim Baker,et al.  Design and evaluation of gradual typing for python , 2015, DLS.

[30]  T. Stephen Strickland,et al.  Contracts for domain-specific languages in Ruby , 2014, DLS.

[31]  Jim Baker,et al.  Design and evaluation of gradual typing for python , 2014, DLS.

[32]  Viktor Kuncak,et al.  Checking Data Structure Properties Orders of Magnitude Faster , 2014, RV.

[33]  André Murbach Maidl,et al.  Typed Lua: An Optional Type System for Lua , 2014, Dyla'14.

[34]  Gavin M. Bierman,et al.  Safe & Efficient Gradual Typing for TypeScript , 2015, POPL.

[35]  Manuel V. Hermenegildo,et al.  Practical run-time checking via unobtrusive property caching , 2015, Theory and Practice of Logic Programming.

[36]  Brianna M. Ren,et al.  Just-in-time static type checking for dynamic languages , 2016, PLDI.

[37]  Ibrahim Taha,et al.  Anthroposemiotics of literature: The cultural nature , 2016 .