skip to main content
article
Public Access

Just-in-time static type checking for dynamic languages

Published:02 June 2016Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. J. Aycock. Aggressive Type Inference. In International Python Conference, 2000.Google ScholarGoogle Scholar
  4. G. Bierman, M. Abadi, and M. Torgersen. Understanding typescript. In ECOOP 2014–Object-Oriented Programming, pages 257–281. Springer, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  7. Dart. Dart, 2015. https://www.dartlang.org.Google ScholarGoogle Scholar
  8. DRuby. Diamondback Ruby, 2009. http://www.cs.umd. edu/projects/PL/druby/.Google ScholarGoogle Scholar
  9. F #. Type Provider, 2016. https://msdn.microsoft.com/ en-us/library/hh156509.aspx.Google ScholarGoogle Scholar
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. GHCLanguageFeatures. Deferring Type Errors to Runtime, 2016. https://downloads.haskell.org/~ghc/latest/ docs/html/users_guide/defer-type-errors.html.Google ScholarGoogle Scholar
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle Scholar
  20. doi: 10.1007/978-3-319-11164-3 22.Google ScholarGoogle Scholar
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. RailsGuides. Active Record Associations, 2015. http:// guides.rubyonrails.org/association_basics.html.Google ScholarGoogle Scholar
  25. RailsGuides. Autoloading and Reloading Constants, 2016. http://guides.rubyonrails.org/autoloading_ and_reloading_constants.html.Google ScholarGoogle Scholar
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. RDL. RDL, 2015. https://github.com/plum-umd/rdl.Google ScholarGoogle Scholar
  28. B. Ren and J. S. Foster. Just-in-Time Static Type Checking for Dynamic Languages, 2016. preprint, http://arxiv.org/ abs/1604.03641. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  33. J. G. Siek and W. Taha. Gradual Typing for Functional Languages. In Scheme and Functional Programming Workshop, 2006.Google ScholarGoogle Scholar
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  36. N. Stulova, J. F. Morales, and M. V. Hermenegildo. Practical Run-time Checking via Unobtrusive Property Caching. CoRR, abs/1507.05986, 2015.Google ScholarGoogle Scholar
  37. W. Taha. MetaOcaml, 2016. http://www.cs.rice.edu/ ~taha/MetaOCaml.Google ScholarGoogle Scholar
  38. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. D. A. Wheeler. SLOCCount, 2015. http://www.dwheeler. com/sloccount.Google ScholarGoogle Scholar
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. Introduction Overview Formalism Implementation Experiments Related Work ConclusionGoogle ScholarGoogle Scholar

Index Terms

  1. Just-in-time static type checking for dynamic languages

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 51, Issue 6
      PLDI '16
      June 2016
      726 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2980983
      • Editor:
      • Andy Gill
      Issue’s Table of Contents
      • cover image ACM Conferences
        PLDI '16: Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation
        June 2016
        726 pages
        ISBN:9781450342612
        DOI:10.1145/2908080
        • General Chair:
        • Chandra Krintz,
        • Program Chair:
        • Emery Berger

      Copyright © 2016 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 2 June 2016

      Check for updates

      Qualifiers

      • article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!