skip to main content
research-article
Open Access
Artifacts Available

Sound gradual typing: only mostly dead

Published:12 October 2017Publication History
Skip Abstract Section

Abstract

While gradual typing has proven itself attractive to programmers, many systems have avoided sound gradual typing due to the run time overhead of enforcement. In the context of sound gradual typing, both anecdotal and systematic evidence has suggested that run time costs are quite high, and often unacceptable, casting doubt on the viability of soundness as an approach.

We show that these overheads are not fundamental, and that with appropriate improvements, just-in-time compilers can greatly reduce the overhead of sound gradual typing. Our study takes benchmarks published in a recent paper on gradual typing performance in Typed Racket (Takikawa et al., POPL 2016) and evaluates them using a experimental tracing JIT compiler for Racket, called Pycket. On typical benchmarks, Pycket is able to eliminate more than 90% of the gradual typing overhead. While our current results are not the final word in optimizing gradual typing, we show that the situation is not dire, and where more work is needed.

Pycket's performance comes from several sources, which we detail and measure individually. First, we apply a sophisticated tracing JIT compiler and optimizer, automatically generated in Pycket using the RPython framework originally created for PyPy. Second, we focus our optimization efforts on the challenges posed by run time checks, implemented in Racket by chaperones and impersonators. We introduce representation improvements, including a novel use of hidden classes to optimize these data structures.

Skip Supplemental Material Section

Supplemental Material

References

  1. Norman Adams, David Kranz, Richard Kelsey, Jonathan Rees, Paul Hudak, and James Philbin. 1986. ORBIT: An Optimizing Compiler for Scheme. In Proceedings of the 1986 SIGPLAN Symposium on Compiler Construction (SIGPLAN ’86). ACM, 219–233.Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Esteban Allende, Oscar Callau, Johan Fabry, Éric Tanter, and Marcus Denker. 2014. Gradual typing for Smalltalk. Science of Computer Programming 96 (2014), 52–69. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Esteban Allende and Johan Fabry. 2011. Application optimization when using gradual typing. In Proceedings of the 6th Workshop on Implementation, Compilation, Optimization of Object-Oriented Languages, Programs and Systems. ACM, 3. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Esteban Allende, Johan Fabry, and Éric Tanter. 2013. Cast Insertion Strategies for Gradually-typed Objects. In Proceedings of the 9th Symposium on Dynamic Languages (DLS ’13). ACM, 27–36. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Håkan Ardö, Carl Friedrich Bolz, and Maciej Fijałkowski. 2012. Loop-aware Optimizations in PyPy’s Tracing JIT. In Proceedings of the 8th Symposium on Dynamic Languages (DLS ’12). ACM, New York, NY, USA, 63–72. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Edd Barrett, Carl Friedrich Bolz, Rebecca Killick, Vincent Knight, Sarah Mount, and Laurence Tratt. 2016. Virtual machine warmup blows hot and cold. arXiv preprint arXiv:1602.00602 (2016).Google ScholarGoogle Scholar
  7. Spenser Bauman, Carl Friedrich Bolz, Robert Hirschfeld, Vasily Kirilichev, Tobias Pape, Jeremy G Siek, and Sam TobinHochstadt. 2015. Pycket: A tracing JIT for a functional language. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming. ACM, 22–34.Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Gavin Bierman, Martín Abadi, and Mads Torgersen. 2014. Understanding TypeScript. In ECOOP 2014–Object-Oriented Programming. Springer, 257–281. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Gavin Bierman, Erik Meijer, and Mads Torgersen. 2010. Adding Dynamic Types to C#. In European Conference on ObjectOriented Programming. Springer, 76–100.Google ScholarGoogle Scholar
  10. Carl Friedrich Bolz, Antonio Cuni, Maciej Fijakowski, Michael Leuschel, Samuele Pedroni, and Armin Rigo. 2011. Runtime Feedback in a Meta-Tracing JIT for Efficient Dynamic Languages. In Proc. ICOOOLPS. 9:19:8. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Carl Friedrich Bolz, Antonio Cuni, Maciej Fijakowski, and Armin Rigo. 2009. Tracing the Meta-Level: PyPy’s Tracing JIT Compiler. In Proc. ICOOOLPS. 18–25. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Carl Friedrich Bolz, Tobias Pape, Jeremy G. Siek, and Sam Tobin-Hochstadt. 2014. Meta-tracing makes a fast Racket. In Workshop on Dynamic Languages and Applications.Google ScholarGoogle Scholar
  13. Ambrose Bonnaire-Sergeant, Rowan Davies, and Sam Tobin-Hochstadt. 2016. Practical Optional Types for Clojure. European Symposium on Programming 25 (2016).Google ScholarGoogle Scholar
  14. C. Chambers, D. Ungar, and E. Lee. 1989. An Efficient Implementation of SELF a Dynamically-typed Object-oriented Language Based on Prototypes. In Conference Proceedings on Object-oriented Programming Systems, Languages and Applications (OOPSLA ’89). ACM, 49–70. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Olivier Danvy. 1991. Three Steps for the CPS Transformation. Technical Report CIS-92-02. Kansas State University.Google ScholarGoogle Scholar
  16. Facebook. 2017a. Flow Documentation. (2017). http://flowtype.org/docs/about-flow.htmlGoogle ScholarGoogle Scholar
  17. Facebook. 2017b. Hack Documentation. (2017). https://docs.hhvm.com/hack/Google ScholarGoogle Scholar
  18. Matthias Felleisen and Daniel P. Friedman. 1987. Control operators, the SECD-machine and the lambda-calculus. In Working Conf. on Formal Description of Programming Concepts - III. Elsevier, 193–217.Google ScholarGoogle Scholar
  19. R. B. Findler and M. Felleisen. 2002. Contracts for higher-order functions. In International Conference on Functional Programming (ICFP). 48–59. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The essence of compiling with continuations. In Proc. PLDI. 502–514. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Google. 2015. Dart Programming Language Specification. Technical Report. EMCA International. https://www.dartlang. org/docs/spec/Google ScholarGoogle Scholar
  22. Brian Hackett and Shu-yu Guo. 2012. Fast and Precise Hybrid Type Inference for JavaScript. In Proceedings of the 33rd ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’12). ACM, New York, NY, USA, 239–250. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Jukka Lehtosalo and David J Greaves. 2011. Language with a Pluggable Type System and Optional Runtime Monitoring of Type Errors. In Proceedings of International Workshop on Scripts to Programs (STOP).Google ScholarGoogle Scholar
  24. André Murbach Maidl, Fabio Mascarenhas, and Roberto Ierusalimschy. 2014. Typed lua: An optional type system for lua. In Proceedings of the Workshop on Dynamic Languages and Applications. ACM, 1–10. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Kevin Millikin and Florian Schneider. 2010. A New Crankshaft for V8. The Chromium Blog 7 (2010).Google ScholarGoogle Scholar
  26. Aseem Rastogi, Nikhil Swamy, Cédric Fournet, Gavin Bierman, and Panagiotis Vekris. 2015. Safe & Efficient Gradual Typing for TypeScript. In Proceedings of the 42Nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’15). ACM, 167–180.Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Rob Reiner. 1987. The Princess Bride. (1987).Google ScholarGoogle Scholar
  28. Gregor Richards, Francesco Zappa Nardelli, and Jan Vitek. 2015. Concrete types for TypeScript. In LIPIcs-Leibniz International Proceedings in Informatics, Vol. 37. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik.Google ScholarGoogle Scholar
  29. Armin Rigo and Samuele Pedroni. 2006. PyPy’s Approach to Virtual Machine Construction. In Proc. DLS. 944–953. Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Thomas Schilling. 2013. Trace-based Just-in-time Compilation for Lazy Functional Programming Languages. Ph.D. Dissertation. University of Kent.Google ScholarGoogle Scholar
  31. Jeremy G Siek and Walid Taha. 2006. Gradual typing for functional languages. In Scheme and Functional Programming Workshop, Vol. 6. 81–92.Google ScholarGoogle Scholar
  32. Jeremy G Siek, Michael M Vitousek, Matteo Cimini, Sam Tobin-Hochstadt, and Ronald Garcia. 2015. Monotonic references for efficient gradual typing. In Programming Languages and Systems. Springer, 432–456.Google ScholarGoogle Scholar
  33. T. Stephen Strickland, Sam Tobin-Hochstadt, Robert Bruce Findler, and Matthew Flatt. 2012. Chaperones and impersonators: run-time support for reasonable interposition. In Object Oriented Programming Systems Languages and Applications (OOPSLA ’12). Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Asumu Takikawa, Daniel Feltey, Earl Dean, Matthew Flatt, Robert Bruce Findler, Sam Tobin-Hochstadt, and Matthias Felleisen. 2015. Towards practical gradual typing. In LIPIcs-Leibniz International Proceedings in Informatics, Vol. 37. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik.Google ScholarGoogle Scholar
  35. Asumu Takikawa, Daniel Feltey, Ben Greenman, Max S New, Jan Vitek, and Matthias Felleisen. 2016. Is sound gradual typing dead?. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, 456–468. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Sam Tobin-Hochstadt and Matthias Felleisen. 2006. Interlanguage migration: from scripts to programs. In Companion to the 21st ACM SIGPLAN symposium on Object-oriented programming systems, languages, and applications. ACM, 964–974. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Sam Tobin-Hochstadt and Matthias Felleisen. 2008. The Design and Implementation of Typed Scheme. In Proceedings of the 35th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’08). ACM, New York, NY, USA, 395–406. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Sam Tobin-Hochstadt, Vincent St-Amour, Ryan Culpepper, Matthew Flatt, and Matthias Felleisen. 2011. Languages as libraries. In Proceedings of the 32nd ACM SIGPLAN conference on Programming language design and implementation (PLDI ’11). ACM, 132–141. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Michael M. Vitousek, Andrew M. Kent, Jeremy G. Siek, and Jim Baker. 2014. Design and Evaluation of Gradual Typing for Python. In Proceedings of the 10th ACM Symposium on Dynamic Languages (DLS ’14). ACM, 45–56. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Michael M. Vitousek, Cameron Swords, and Jeremy G. Siek. 2017. Big Types in Little Runtime: Open-world Soundness and Collaborative Blame for Gradual Type Systems. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). ACM, New York, NY, USA, 762–774. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Tobias Wrigstad, Francesco Zappa Nardelli, Sylvain Lebresne, Johan Östlund, and Jan Vitek. 2010. 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). ACM, 377–388. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Sound gradual typing: only mostly dead

        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

        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!