Abstract
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.
- D. Ancona, M. Ancona, A. Cuni, and N. D. Matsakis. RPython: A Step Towards Reconciling Dynamically and Statically Typed OO Languages. In Proceedings of the 2007 Symposium on Dynamic Languages, DLS ’07, pages 53–64, New York, NY, USA, 2007. ACM. ISBN 978-1-59593-868-8. doi: 10.1145/1297081.1297091. Google Scholar
Digital Library
- C. Anderson, P. Giannini, and S. Drossopoulou. Towards Type Inference for Javascript. In Proceedings of the 19th European Conference on Object-Oriented Programming, ECOOP’05, pages 428–452, Berlin, Heidelberg, 2005. Springer-Verlag. ISBN 3-540-27992-X, 978-3-540-27992-1. doi: 10.1007/ 11531142 19. Google Scholar
Digital Library
- J. Aycock. Aggressive Type Inference. In International Python Conference, 2000.Google Scholar
- G. Bierman, M. Abadi, and M. Torgersen. Understanding typescript. In ECOOP 2014–Object-Oriented Programming, pages 257–281. Springer, 2014. Google Scholar
Digital Library
- B. Bloom, J. Field, N. Nystrom, J. Östlund, G. Richards, R. Strniˇsa, J. Vitek, and T. Wrigstad. Thorn: Robust, Concurrent, Extensible Scripting on the JVM. In Proceedings of the 24th ACM SIGPLAN Conference on Object Oriented Programming Systems Languages and Applications, OOPSLA ’09, pages 117–136, New York, NY, USA, 2009. ACM. ISBN 978-1-60558-766-0. doi: 10.1145/1640089.1640098. Google Scholar
Digital Library
- R. Chugh, J. A. Meister, R. Jhala, and S. Lerner. Staged Information Flow for Javascript. In Proceedings of the 30th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’09, pages 50–62, New York, NY, USA, 2009. ACM. ISBN 978-1-60558-392-1. doi: 10.1145/1542476.1542483. Google Scholar
Digital Library
- Dart. Dart, 2015. https://www.dartlang.org.Google Scholar
- DRuby. Diamondback Ruby, 2009. http://www.cs.umd. edu/projects/PL/druby/.Google Scholar
- F #. Type Provider, 2016. https://msdn.microsoft.com/ en-us/library/hh156509.aspx.Google Scholar
- A. Feldthaus and A. Møller. Checking Correctness of Type-Script Interfaces for JavaScript Libraries. In Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications, OOPSLA ’14, pages 1–16, New York, NY, USA, 2014. ACM. ISBN 978-1-4503-2585-1. doi: 10.1145/2660193.2660215. Google Scholar
Digital Library
- R. B. Findler and M. Felleisen. Contracts for Higher-order Functions. In Proceedings of the Seventh ACM SIGPLAN International Conference on Functional Programming, ICFP ’02, pages 48–59, New York, NY, USA, 2002. ACM. ISBN 1-58113-487-8. doi: 10.1145/581478.581484. Google Scholar
Digital Library
- M. Furr, J. hoon (David) An, and J. S. Foster. Profile-Guided Static Typing for Dynamic Scripting Languages. In ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages and Applications (OOPSLA), pages 283–300, Orlando, Floria, October 2009. doi: 10.1145/1639949.1640110. Best student paper award. Google Scholar
Digital Library
- M. Furr, J. hoon (David) An, J. S. Foster, and M. Hicks. The Ruby Intermediate Langauge. In Dynamic Languages Symposium (DLS), pages 89–98, Orlando, Florida, October 2009. doi: 10.1145/1837513.1640148. Google Scholar
Digital Library
- M. Furr, J. hoon (David) An, J. S. Foster, and M. Hicks. Static Type Inference for Ruby. In Object-Oriented Program Languages and Systems (OOPS) Track at ACM Symposium on Applied Computing (SAC), pages 1859–1866, Honolulu, Hawaii, March 2009. doi: 10.1145/1529282.1529700. Google Scholar
Digital Library
- GHCLanguageFeatures. Deferring Type Errors to Runtime, 2016. https://downloads.haskell.org/~ghc/latest/ docs/html/users_guide/defer-type-errors.html.Google Scholar
- M. Hermenegildo, G. Puebla, K. Marriott, and P. J. Stuckey. Incremental Analysis of Constraint Logic Programs. ACM Trans. Program. Lang. Syst., 22(2):187–223, Mar. 2000. ISSN 0164-0925. doi: 10.1145/349214.349216. Google Scholar
Digital Library
- J. hoon (David) An, A. Chaudhuri, and J. S. Foster. Static Typing for Ruby on Rails. In IEEE/ACM International Conference on Automated Software Engineering (ASE), pages 590– 594, Auckland, New Zealand, November 2009. Short paper. Google Scholar
Digital Library
- J. hoon (David) An, A. Chaudhuri, J. S. Foster, and M. Hicks. Dynamic Inference of Static Types for Ruby. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pages 459–472, Austin, TX, USA, January 2011. doi: 10.1145/1926385.1926437. Google Scholar
Digital Library
- E. Koukoutos and V. Kuncak. Checking Data Structure Properties Orders of Magnitude Faster. In Runtime Verification - 5th International Conference, RV 2014, Toronto, ON, Canada, September 22-25, 2014. Proceedings, pages 263–268, 2014.Google Scholar
- doi: 10.1007/978-3-319-11164-3 22.Google Scholar
- B. S. Lerner, L. Elberty, J. Li, and S. Krishnamurthi. Combining Form and Function: Static Types for JQuery Programs. In Proceedings of the 27th European Conference on Object-Oriented Programming, ECOOP’13, pages 79–103, Berlin, Heidelberg, 2013. Springer-Verlag. ISBN 978-3-642-39037- 1. doi: 10.1007/978-3-642-39038-8 4. Google Scholar
Digital Library
- B. S. Lerner, J. G. Politz, A. Guha, and S. Krishnamurthi. Te-JaS: Retrofitting Type Systems for JavaScript. In Proceedings of the 9th Symposium on Dynamic Languages, DLS ’13, pages 1–16, New York, NY, USA, 2013. ACM. ISBN 978-1-4503- 2433-5. doi: 10.1145/2508168.2508170. Google Scholar
Digital Library
- A. M. Maidl, F. Mascarenhas, and R. Ierusalimschy. Typed Lua: An Optional Type System for Lua. In Proceedings of the Workshop on Dynamic Languages and Applications, Dyla’14, pages 3:1–3:10, New York, NY, USA, 2014. ACM. ISBN 978-1-4503-2916-3. doi: 10.1145/2617548.2617553. Google Scholar
Digital Library
- RailsGuides. Active Record Associations, 2015. http:// guides.rubyonrails.org/association_basics.html.Google Scholar
- RailsGuides. Autoloading and Reloading Constants, 2016. http://guides.rubyonrails.org/autoloading_ and_reloading_constants.html.Google Scholar
- A. Rastogi, N. Swamy, C. Fournet, G. Bierman, and P. Vekris. Safe & Efficient Gradual Typing for TypeScript. In Proceedings of the 42Nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’15, pages 167–180, New York, NY, USA, 2015. ACM. ISBN 978-1- 4503-3300-9. doi: 10.1145/2676726.2676971. Google Scholar
Digital Library
- RDL. RDL, 2015. https://github.com/plum-umd/rdl.Google Scholar
- B. Ren and J. S. Foster. Just-in-Time Static Type Checking for Dynamic Languages, 2016. preprint, http://arxiv.org/ abs/1604.03641. Google Scholar
Digital Library
- B. M. Ren, J. Toman, T. S. Strickland, and J. S. Foster. The Ruby Type Checker. In Object-Oriented Program Languages and Systems (OOPS) Track at ACM Symposium on Applied Computing, pages 1565–1572, Coimbra, Portugal, March 2013. doi: 10.1145/2480362.2480655. Google Scholar
Digital Library
- G. Richards, S. Lebresne, B. Burg, and J. Vitek. An Analysis of the Dynamic Behavior of JavaScript Programs. In Proceedings of the 31st ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’10, pages 1–12, New York, NY, USA, 2010. ACM. ISBN 978-1-4503-0019-3. doi: 10.1145/1806596.1806598. Google Scholar
Digital Library
- G. Richards, C. Hammer, B. Burg, and J. Vitek. The Eval That Men Do: A Large-scale Study of the Use of Eval in Javascript Applications. In Proceedings of the 25th European Conference on Object-oriented Programming, ECOOP’11, pages 52–78, Berlin, Heidelberg, 2011. Springer-Verlag. ISBN 978- 3-642-22654-0. Google Scholar
Digital Library
- T. Sheard and S. P. Jones. Template Meta-programming for Haskell. SIGPLAN Not., 37(12):60–75, Dec. 2002. ISSN 0362-1340. doi: 10.1145/636517.636528. Google Scholar
Digital Library
- J. G. Siek and W. Taha. Gradual Typing for Functional Languages. In Scheme and Functional Programming Workshop, 2006.Google Scholar
- V. St-Amour, S. Tobin-Hochstadt, M. Flatt, and M. Felleisen. Typing the Numeric Tower. In Proceedings of the 14th International Conference on Practical Aspects of Declarative Languages, PADL’12, pages 289–303, Berlin, Heidelberg, 2012. Springer-Verlag. ISBN 978-3-642-27693-4. doi: 10.1007/978-3-642-27694-1 21. Google Scholar
Digital Library
- T. S. Strickland, B. Ren, and J. S. Foster. Contracts for Domain-Specific Languages in Ruby. In Dynamic Languages Symposium (DLS), Portland, OR, October 2014. doi: 10.1145/ 2661088.2661092. Google Scholar
Digital Library
- N. Stulova, J. F. Morales, and M. V. Hermenegildo. Practical Run-time Checking via Unobtrusive Property Caching. CoRR, abs/1507.05986, 2015.Google Scholar
- W. Taha. MetaOcaml, 2016. http://www.cs.rice.edu/ ~taha/MetaOCaml.Google Scholar
- P. Thiemann. Towards a Type System for Analyzing Javascript Programs. In Proceedings of the 14th European Conference on Programming Languages and Systems, ESOP’05, pages 408–422, Berlin, Heidelberg, 2005. Springer-Verlag. ISBN 3-540-25435-8, 978-3-540-25435-5. doi: 10.1007/ 978-3-540-31987-0 28. Google Scholar
Digital Library
- S. Tobin-Hochstadt and M. Felleisen. The Design and Implementation of Typed Scheme. In Proceedings of the 35th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’08, pages 395–406, New York, NY, USA, 2008. ACM. ISBN 978-1-59593-689-9. doi: 10.1145/1328438.1328486. Google Scholar
Digital Library
- S. Tobin-Hochstadt and M. Felleisen. Logical Types for Untyped Languages. In Proceedings of the 15th ACM SIGPLAN International Conference on Functional Programming, ICFP ’10, pages 117–128, New York, NY, USA, 2010. ACM. ISBN 978-1-60558-794-3. doi: 10.1145/1863543.1863561. Google Scholar
Digital Library
- M. M. Vitousek, A. M. Kent, J. G. Siek, and J. Baker. Design and Evaluation of Gradual Typing for Python. In Proceedings of the 10th ACM Symposium on Dynamic Languages, DLS ’14, pages 45–56, New York, NY, USA, 2014. ACM. ISBN 978-1-4503-3211-8. doi: 10.1145/2661088.2661101. Google Scholar
Digital Library
- D. A. Wheeler. SLOCCount, 2015. http://www.dwheeler. com/sloccount.Google Scholar
- T. Wrigstad, F. Z. Nardelli, S. Lebresne, J. Östlund, and J. Vitek. Integrating Typed and Untyped Code in a Scripting Language. In Proceedings of the 37th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’10, pages 377–388, New York, NY, USA, 2010. ACM. ISBN 978-1-60558-479-9. doi: 10.1145/ 1706299.1706343. Google Scholar
Digital Library
- Introduction Overview Formalism Implementation Experiments Related Work ConclusionGoogle Scholar
Index Terms
Just-in-time static type checking for dynamic languages
Recommendations
Just-in-time static type checking for dynamic languages
PLDI '16: Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and ImplementationDynamic 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 ...
Profile-guided static typing for dynamic scripting languages
OOPSLA '09Many popular scripting languages such as Ruby, Python, and Perl include highly dynamic language constructs, such as an eval method that evaluates a string as program text. While these constructs allow terse and expressive code, they have traditionally ...
Bringing dynamic languages to .NET with the DLR
DLS '07: Proceedings of the 2007 symposium on Dynamic languagesFrom the beginning, Microsoft's .NET framework was designed to support a broad range of different programming languages on a Common Language Runtime (CLR). The CLR provides shared services to these languages ranging from a world-class GC and JIT to a ...







Comments