Abstract
The promise of gradual typing is that programmers should get the best of both worlds: the static guarantees of static types, and the dynamic flexibility of untyped programming. This is an enticing benefit, but one that, in practice, may carry significant costs. Significant enough, in fact, to threaten the very practicality of gradual typing; slowdowns as high as 120x are reported as arising from gradual typing.
If one examines these results closely, though, it becomes clear that the costs of gradual typing are not evenly distributed. Indeed, while mixing typed and untyped code almost invariably carries non-trivial costs, many truly deal-breaking slowdowns exhibit pathological performance. Unfortunately, the very presence of these pathological cases---and therefore the possibility of hitting them during development---makes gradual typing a risky proposition in any setting that even remotely cares about performance.
This work attacks one source of large overheads in these pathological cases: an accumulation of contract wrappers that perform redundant checks. The work introduces a novel strategy for contract checking---collapsible contracts---which eliminates this redundancy for function and vector contracts and drastically reduces the overhead of contract wrappers.
We implemented this checking strategy as part of the Racket contract system, which is used in the Typed Racket gradual typing system. Our experiments show that our strategy successfully brings a class of pathological cases in line with normal cases, while not introducing an undue overhead to any of the other cases. Our results also show that the performance of gradual typing in Racket remains prohibitive for many programs, but that collapsible contracts are one essential ingredient in reducing the cost of gradual typing.
- Esteban Allende, Oscar Callaú, Johan Fabry, Éric Tanter, and Marcus Denker. Gradual typing for Smalltalk. Science of Computer Programming 96(1), pp. 52–69, 2013. Google Scholar
Digital Library
- Matthew Arnold, Stephen Fink, David Grove, Michael Hind, and Peter F. Sweeney. Adaptive optimization in the Jalapeño JVM. In Proc. ACM Conf. Object-Oriented Programming, Systems, Languages and Applications, pp. 47–65, 2000. Google Scholar
Digital Library
- Spenser Bauman, Carl Friedrich Bolz-Tereick, Jeremy Siek, and Sam Tobin-Hochstadt. Sound Gradual Typing: Only Mostly Dead. Proceedings of the ACM on Programming Languages 1(OOPSLA), pp. 54:1–54:24, 2017. Google Scholar
Digital Library
- Gavin Bierman, Martin Abadi, and Mads Torgersen. Understanding TypeScript. In Proc. European Conf. Object-Oriented Programming, pp. 257–281, 2014. Google Scholar
Digital Library
- Carl Friedrich Bolz, Antonio Cuni, Maciej Fijalkowski, and Armin Rigo. Tracing the meta-level: PyPy’s tracing JIT compiler. In Proc. Wksp. on the Implementation, Compilation, Optimization of Object-Oriented Languages and Programming Systems, pp. 18–25, 2009. Google Scholar
Digital Library
- Gilad Bracha and David Griswold. Strongtalk: Typechecking Smalltalk in a Production Environment. In Proc. ACM Conf. Object-Oriented Programming, Systems, Languages and Applications, pp. 215–230, 1993. Google Scholar
Digital Library
- Avik Chaudhuri, Panagiotis Vekris, Sam Goldman, Marshall Roch, and Gabriel Levy. Fast and Precise Type Checking for JavaScript. Proceedings of the ACM on Programming Languages 1(OOPSLA), pp. 48:1–48:30, 2017. Google Scholar
Digital Library
- Benjamin W. Chung, Paley Li, Francesco Zappa Nardelli, and Jan Vitek. KafKa: Gradual Typing for Objects. In Proc. European Conf. Object-Oriented Programming, pp. 12:1–12:23, 2018.Google Scholar
- Christos Dimoulas, Sam Tobin-Hochstadt, and Matthias Felleisen. Complete Monitors for Behavioral Contracts. In Proc. European Sym. on Programming, pp. 214–233, 2012. Google Scholar
Digital Library
- Robert Bruce Findler and Matthias Felleisen. Contracts for Higher-Order Functions. In Proc. ACM Intl. Conf. Functional Programming, pp. 48–59, 2002. Google Scholar
Digital Library
- Matthew Flatt and PLT. Reference: Racket. PLT Design Inc., PLT-TR-2010-1, 2010. https://racket-lang.org/tr1/Google Scholar
- Michael Greenberg. Space-Efficient Manifest Contracts. In Proc. ACM Sym. Principles of Programming Languages, pp. 181–194, 2015. Google Scholar
Digital Library
- Michael Greenberg. Space-Efficient Latent Contracts. In Proc. Sym. Trends in Functional Programming, 2016.Google Scholar
- Ben Greenman and Matthias Felleisen. A Spectrum of Type Soundness and Performance. Proceedings of the ACM on Programming Languages 2(ICFP), pp. 71:1–71:32, 2018. Google Scholar
Digital Library
- Ben Greenman and Zeina Migeed. On the Cost of Type-Tag Soundness. In Proc. Wksp. on Partial Evaluation and Program Manipulation, pp. 30–39, 2018. Google Scholar
Digital Library
- Jessica Gronski, Kenneth Knowles, Aaron Tomb, Stephen N. Freund, and Cormac Flanagan. Sage: Hybrid Checking for Flexible Specifications. In Proc. Wksp. Scheme and Functional Programming, pp. 93–104, 2006.Google Scholar
- Fritz Henglein. Dynamic typing: syntax and proof theory. Science of Computer Programming 22(3), pp. 197–230, 1994. Google Scholar
Digital Library
- David Herman, Aaron Tomb, and Cormac Flanagan. Space-efficient Gradual Typing. Higher-Order and Symbolic Computation 23(2), pp. 167–189, 2010. Google Scholar
Digital Library
- Andre Kuhlenschmidt, Deyaaeldeen Almahallawi, and Jeremy G. Siek. Efficient Gradual Typing. arXiv, 1802.06375v1, 2018.Google Scholar
- Jacob Matthews and Robert Bruce Findler. Operational Semantics for Multi-Language Programs. Trans. Programming Languages and Systems 31(3), pp. 12:1–12:44, 2009. Google Scholar
Digital Library
- David A. Moon. MACLISP Reference Manual. MIT, Revision 0, 1974.Google Scholar
- Fabian Muehlboeck and Ross Tate. Sound Gradual Typing is Nominally Alive and Well. Proceedings of the ACM on Programming Languages 1(OOPSLA), pp. 56:1–56:30, 2017. Google Scholar
Digital Library
- Aseem Rastogi, Nikhil Swamy, Cédric Fournet, Gavin Bierman, and Panagiotis Vekris. Safe & Efficient Gradual Typing for TypeScript. In Proc. ACM Sym. Principles of Programming Languages, pp. 167–180, 2015. Google Scholar
Digital Library
- Jakob Rehof. Polymorphic Dynamic Typing: Aspects of proof theory and inference. DIKU, 95/9, 1995.Google Scholar
- Gregor Richards, Francesco Zappa Nardelli, and Jan Vitek. Concrete Types for TypeScript. In Proc. European Conf. Object-Oriented Programming, 2015.Google Scholar
- Richard Roberts, Michael Homer, Stefan Marr, and James Noble. Shallow Types for Insightful Programs: Grace is Optional, Performance is Not. arXiv:1807.00661v1, 2018.Google Scholar
- Jeremy Siek, Peter Thiemann, and Philip Wadler. Blame and coercion: Together again for the first time. In Proc. ACM Conf. Programming Language Design and Implementation, pp. 425–435, 2015. Google Scholar
Digital Library
- Jeremy G. Siek and Walid Taha. Gradual Typing for Functional Languages. In Proc. Wksp. Scheme and Functional Programming, 2006.Google Scholar
- Guy L. Steele. Common Lisp the Language. 2nd edition. Digital Press, 1990. Google Scholar
Digital Library
- T. Stephen Strickland, Sam Tobin-Hochstadt, Robert Bruce Findler, and Matthew Flatt. Chaperones and Impersonators: Run-time Support for Reasonable Interposition. In Proc. ACM Conf. Object-Oriented Programming, Systems, Languages and Applications, pp. 943–962, 2012. Google Scholar
Digital Library
- Asumu Takikawa, Daniel Feltey, Earl Dean, Robert Bruce Findler, Matthew Flatt, Sam Tobin-Hochstadt, and Matthias Felleisen. Towards Practical Gradual Typing. In Proc. European Conf. Object-Oriented Programming, 2015.Google Scholar
- Asumu Takikawa, Daniel Feltey, Ben Greenman, Max New, Jan Vitek, and Matthias Felleisen. Is Sound Gradual Typing Dead? In Proc. ACM Sym. Principles of Programming Languages, pp. 456–468, 2016. Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. Interlanguage Migration: from Scripts to Programs. In Proc. Dynamic Languages Symposium, pp. 964–974, 2006. Google Scholar
Digital Library
- Sam Tobin-Hochstadt, Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, Ben Greenman, Andrew M. Kent, Vincent St-Amour, T. Stephen Strickland, and Asumu Takikawa. Migratory Typing: Ten Years Later. In Proc. Summit on Advances in Programming Languages, pp. 17:1–17:17, 2017.Google Scholar
- Michael M. Vitousek, Cameron Swords, and Jeremy G. Siek. Big Types in Little Runtime: Open-World Soundness and Collaborative Blame for Gradual Type Systems. In Proc. ACM Sym. Principles of Programming Languages, pp. 762–774, 2017. Google Scholar
Digital Library
- Jack Williams, J. Garrett Morris, Philip Wadler, and Jakub Zalewski. Mixed Messages: Measuring Conformance and Non-Interference in TypeScript. In Proc. European Conf. Object-Oriented Programming, pp. 28:1–28:29, 2017.Google Scholar
- Tobias Wrigstad, Francesco Zappa Nardelli, Sylvain Lebresne, Johan Östlund, and Jan Vitek. Integrating Typed and Untyped Code in a Scripting Language. In Proc. ACM Sym. Principles of Programming Languages, pp. 377–388, 2010. Google Scholar
Digital Library
Index Terms
Collapsible contracts: fixing a pathology of gradual typing
Recommendations
On polymorphic gradual typing
We study an extension of gradual typing—a method to integrate dynamic typing and static typing smoothly in a single language—to parametric polymorphism and its theoretical properties, including conservativity of typing and semantics over both statically ...
Gradual typing: a new perspective
We define a new, more semantic interpretation of gradual types and use it to ``gradualize'' two forms of polymorphism: subtyping polymorphism and implicit parametric polymorphism. In particular, we use the new interpretation to define three gradual type ...
Gradual typing with union and intersection types
We propose a type system for functional languages with gradual types and set-theoretic type connectives and prove its soundness. In particular, we show how to lift the definition of the domain and result type of an application from non-gradual types to ...






Comments