Abstract
Gradually typed programming languages permit the incremental addition of static types to untyped programs. To remain sound, languages insert run-time checks at the boundaries between typed and untyped code. Unfortunately, performance studies have shown that the overhead of these checks can be disastrously high, calling into question the viability of sound gradual typing. In this paper, we show that by building on existing work on soft contract verification, we can reduce or eliminate this overhead.
Our key insight is that while untyped code cannot be trusted by a gradual type system, there is no need to consider only the worst case when optimizing a gradually typed program. Instead, we statically analyze the untyped portions of a gradually typed program to prove that almost all of the dynamic checks implied by gradual type boundaries cannot fail, and can be eliminated at compile time. Our analysis is modular, and can be applied to any portion of a program.
We evaluate this approach on a dozen existing gradually typed programs previously shown to have prohibitive performance overhead—with a median overhead of 2.5× and up to 80.6× in the worst case—and eliminate all overhead in most cases, suffering only 1.5× overhead in the worst case.
- Alexander Aiken, Edward L. Wimmers, and T. K. Lakshman. 1994. Soft Typing with Conditional TypesP.rIinnciples of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/174675.177847 Google Scholar
Digital Library
- Leif Andersen, Vincent St-Amour, Jan Vitek, and Mathias Felleisen. 2018. Feature-Specific ProfilinTgra. nsactions on Programming Languages and Systems (TOPLAS) ( 2018 ). DOI:http://dx.doi.org/10.1145/3275519 Google Scholar
Digital Library
- Spenser Bauman, Carl Friedrich Bolz-Tereick, Jeremy Siek, and Sam Tobin-Hochstadt. 2017. Sound Gradual Typing: Only Mostly Dead. InObject-Oriented Programming, Systems, Languages and Applications (OOPSLA). DOI:http://dx.doi.org/ 10.1145/3133878 Google Scholar
Digital Library
- Gavin Bierman, Erik Meijer, and Mads Torgersen. 2010. Adding Dynamic Types to C#E. uInropean Conference on ObjectOriented Programming (ECOOP). DOI:http://dx.doi.org/10.1007/978-3-642-14107-2_5 Google Scholar
Cross Ref
- Andrew P. Black, Kim B. Bruce, Michael Homer, and James Noble. 2012. Grace: The Absence of (Inessential) Dificulty. In New Ideas, New Paradigms, and Reflections on Programming and Software (Onward!). DOI:http://dx.doi.org/10.1145/ 2384592.2384601 Google Scholar
Digital Library
- Robert Cartwright and Mike Fagan. 1991. Soft Typing. IPnrogramming Language Design and Implementation (PLDI). DOI: http://dx.doi.org/10.1145/113445.113469 Google Scholar
Digital Library
- Avik Chaudhuri, Panagiotis Vekris, Sam Goldman, Marshall Roch, and Gabriel Levi. 2017. Fast and Precise Type Checking for JavaScript. InObject-Oriented Programming, Systems, Languages and Applications (OOPSLA). DOI:http://dx.doi.org/ 10.1145/3133872 Google Scholar
Digital Library
- William D. Clinger. 1998. Proper Tail Recursion and Space Eficiency. PInrogramming Language Design and Implementation (PLDI). DOI:http://dx.doi.org/10.1145/277650.277719 Google Scholar
Digital Library
- David Darais, Nicholas Labich, Phúc C. Nguyễn, and David Van Horn. 2017. Abstracting Definitional Interpreters (Functional Pearl). IInnternational Conference on Functional Programming (ICFP). DOI:http://dx.doi.org/10.1145/3110256 Google Scholar
Digital Library
- Mathias Felleisen, Robert Bruce Findler, and Mathew Flat. 2009. Semantics Engineering with PLT Redex.Google Scholar
- Daniel Feltey, Ben Greenman, Christophe Scholliers, Robert Bruce Findler, and Vincent St-Amour. 2018. Collapsible Contracts: Fixing a Pathology of Gradual TypinOg.bjIenct-Oriented Programming, Systems, Languages and Applications (OOPSLA). DOI:http://dx.doi.org/10.1145/3276503 Google Scholar
Digital Library
- Robert Bruce Findler and Mathias Felleisen. 2002. Contracts for Higher-Order FunctioInntse.rInnational Conference on Functional Programming (ICFP). DOI:http://dx.doi.org/10.1145/581478.581484 Google Scholar
Digital Library
- Cormac Flanagan and Mathias Felleisen. 1999. Componential Set-Based AnaTlryasnis. actions on Programming Languages and Systems (TOPLAS) ( 1999 ). DOI:http://dx.doi.org/10.1145/316686.316703 Google Scholar
Digital Library
- Google Inc. 2018. Dart. ( 2018 ) h. ttps://dart.dev/Google Scholar
- Michael Greenberg. 2016. Space-Eficient Latent ContractsT.rIennds in Functional Programming (TFP). DOI:http://dx.doi. org/10.1007/978-3-030-14805-8_1 Google Scholar
Cross Ref
- Ben Greenman and Mathias Felleisen. 2018. A Spectrum of Type Soundness and PerformanceIn. tIenrnational Conference on Functional Programming (ICFP). DOI:http://dx.doi.org/10.1145/3236766 Google Scholar
Digital Library
- Ben Greenman and Zeina Migeed. 2017. On the Cost of Type-Tag SoundnesPsa.rItnial Evaluation and Program Manipulation (PEPM). DOI:http://dx.doi.org/10.1145/3162066 Google Scholar
Digital Library
- Ben Greenman, Asumu Takikawa, Max S. New, Daniel Feltey, Robert Bruce Findler, Jan Vitek, and Mathias Felleisen. 2019. How to Evaluate the Performance of Gradual Typing SystJeomursn. al of Functional Programming (JFP) ( 2019 ). DOI: http://dx.doi.org/10.1017/S0956796818000217 Google Scholar
Cross Ref
- Fritz Henglein. 1994. Dynamic Typing: Syntax and Proof Theory. Science of Computer Programming ( 1994 ). DOI:http://dx.doi.org/10.1016/ 0167-6423 ( 94 ) 00004-2 Google Scholar
Digital Library
- David Herman, Aaron Tomb, and Cormac Flanagan. 2010. Space-Eficient Gradual TypinHgi.gher-Order and Symbolic Computation ( 2010 ). DOI:http://dx.doi.org/10.1007/s10990-011-9066-z Google Scholar
Digital Library
- Andre Kuhlenschmidt, Deyaaeldeen Almahallawi, and Jeremy G. Siek. 2019. Toward Eficient Gradual Typing for Structural Types via Coercions. IPnrogramming Language Design and Implementation (PLDI). DOI:http://dx.doi.org/10.1145/ 3314221.3314627 Google Scholar
Digital Library
- Jukka Lehtosalo. 2017. MyPy: Optional Static Typing for Python. ( 2h0t1t7p ).://mypy-lang.org/Google Scholar
- Philippe Meunier, Robert Bruce Findler, and Mathias Felleisen. 2006. Modular Set-Based Analysis from Contracts. In Principles of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/1111037.1111057 Google Scholar
Digital Library
- Microsoft Corp. 2014. TypeScript Language Specification. ( 2014 ).http://www.typescriptlang.orgGoogle Scholar
- Fabian Muehlboeck and Ross Tate. 2017. Sound Gradual Typing is Nominally Alive and WOebljelc.tI-nOriented Programming, Systems, Languages and Applications (OOPSLA). DOI:http://dx.doi.org/10.1145/3133880 Google Scholar
Digital Library
- Phúc C. Nguyễn, Thomas Gilray, Sam Tobin-Hochstadt, and David Van Horn. 2018. Soft Contract Verification for HigherOrder Stateful Programs. PInrinciples of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/3158139 Google Scholar
Digital Library
- Phúc C. Nguyễn, Sam Tobin-Hochstadt, and David Van Horn. 2014. Soft Contract VerificatioInn.tIenrnational Conference on Functional Programming (ICFP). DOI:http://dx.doi.org/10.1145/2628136.2628156 Google Scholar
Digital Library
- Phúc C. Nguyễn, Sam Tobin-Hochstadt, and David Van Horn. 2017. Higher-Order Symbolic Execution for Contract Verification and RefutatioJnou.rnal of Functional Programming (JFP) ( 2017 ). DOI:http://dx.doi.org/10.1017/S0956796816000216 Google Scholar
Cross Ref
- Phúc C. Nguyễn and David Van Horn. 2015. Relatively Complete Counterexamples for Higher-Order PrograPmros-. In gramming Language Design and Implementation (PLDI). DOI:http://dx.doi.org/10.1145/2737924.2737971 Google Scholar
Digital Library
- Aseem Rastogi, Nikhil Swamy, Cédric Fournet, Gavin Bierman, and Panagiotis Vekris. 2015. Safe & Eficient Gradual Typing for TypeScript. InPrinciples of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/2676726.2676971 Google Scholar
Digital Library
- Gregor Richards, Ellen Arteca, and Alexi Turcote. 2017. The VM Already Knew That: Leveraging Compile-Time Knowledge to Optimize Gradual Typing. IOnbject-Oriented Programming, Systems, Languages and Applications (OOPSLA). DOI: http://dx.doi.org/10.1145/3133879 Google Scholar
Digital Library
- Gregor Richards, Francesco Zappa Nardelli, and Jan Vitek. 2015. Concrete Types for TypeScrEiputr.oIpnean Conference on Object-Oriented Programming (ECOOP). DOI:http://dx.doi.org/10.4230/LIPIcs.ECOOP. 2015.76 Google Scholar
Cross Ref
- Jeremy G. Siek and Walid Taha. 2006. Gradual Typing for Functional LanguagSecsh. eImne and Functional Programming Workshop.Google Scholar
- Jeremy G. Siek, Michael M. Vitousek, Mateo Cimini, Sam Tobin-Hochstadt, and Ronald Garcia. 2015. Monotonic References for Eficient Gradual Typing. InEuropean Symposium on Programming (ESOP). DOI:http://dx.doi.org/10.1007/978-3-662-46669-8_18 Google Scholar
Digital Library
- Jeremy G. Siek and Philip Wadler. 2010. Threesomes, with and without Blame. PInrinciples of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/1706299.1706342 Google Scholar
Digital Library
- T. Strickland, Sam Tobin-Hochstadt, Robert Bruce Findler, and Mathew Flat. 2012. Chaperones and Impersonators: RunTime Support for Reasonable InterpositionO. Ibnject-Oriented Programming, Systems, Languages and Applications (OOPSLA). DOI:http://dx.doi.org/10.1145/2384616.2384685 Google Scholar
Digital Library
- Stripe Inc. 2019. Sorbet. ( 2019 ) h.ttps://sorbet.org/Google Scholar
- Nikhil Swamy, Cedric Fournet, Aseem Rastogi, Karthikeyan Bhargavan, Juan Chen, Pierre-Yves Strub, and Gavin Bierman. 2014. Gradual Typing Embedded Securely in JavaScript.PIrninciples of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/2535838.2535889 Google Scholar
Digital Library
- Asumu Takikawa, Daniel Feltey, Earl Dean, Mathew Flat, Robert Bruce Findler, Sam Tobin-Hochstadt, and Mathias Felleisen. 2015. Towards Practical Gradual TypingE.uIrnopean Conference on Object-Oriented Programming (ECOOP). DOI:http://dx.doi.org/10.4230/LIPIcs.ECOOP. 2015.4 Google Scholar
Cross Ref
- Asumu Takikawa, Daniel Feltey, Ben Greenman, Max S. New, Jan Vitek, and Mathias Felleisen. 2016. Is Sound Gradual Typing Dead?. InPrinciples of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/2837614.2837630 Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Mathias Felleisen. 2006. Interlanguage Migration: From Scripts to ProgrOabmjesc.tI-nOriented Programming, Systems, Languages and Applications (OOPSLA). DOI:http://dx.doi.org/10.1145/1176617.1176755 Google Scholar
Digital Library
- Sam Tobin-Hochstadt and Mathias Felleisen. 2008. The Design and Implementation of Typed SchemeP.rIinnciples of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/1328438.1328486 Google Scholar
Digital Library
- Sam Tobin-Hochstadt, Mathias Felleisen, Robert Bruce Findler, Mathew Flat, Ben Greenman, Andrew M. Kent, Vincent St-Amour, T. Strickland, and Asumu Takikawa. 2017. Migratory Typing: Ten Years LatSeur.mInmit on Advances in Programming Languages (SNAPL). DOI:http://dx.doi.org/10.4230/LIPIcs.SNAPL. 2017.17 Google Scholar
Cross Ref
- Yuya Tsuda, Atsushi Igarashi, and Tomoya Tabuchi. 2020. Space-Eficient Gradual Typing in Coercion-Passing Style. In European Conference on Object-Oriented Programming (ECOOP). DOI:http://dx.doi.org/10.4230/LIPIcs.ECOOP. 2020.8 Google Scholar
Cross Ref
- David Van Horn and Mathew Might. 2010. Abstracting Abstract MachineIsn.teIrnnational Conference on Functional Programming (ICFP). DOI:http://dx.doi.org/10.1145/1863543.1863553 Google Scholar
Digital Library
- Michael M. Vitousek, Andrew M. Kent, Jeremy G. Siek, and Jim Baker. 2014. Design and Evaluation of Gradual Typing for Python. InDynamic Languages Symposium (DLS). DOI:http://dx.doi.org/10.1145/2661088.2661101 Google Scholar
Digital Library
- Michael M. Vitousek, Jeremy G. Siek, and Avik Chaudhuri. 2019. Optimizing and Evaluating Transient Gradual Typing. In Dynamic Languages Symposium (DLS). DOI:http://dx.doi.org/10.1145/3359619.3359742 Google Scholar
Digital Library
- Michael M. Vitousek, Cameron Swords, and Jeremy G. Siek. 2017. Big Types in Litle Runtime: Open-World Soundness and Collaborative Blame for Gradual Type SystemsP.rIinciples of Programming Languages (POPL). DOI:http://dx.doi.org/ 10.1145/3009837.3009849 Google Scholar
Digital Library
- Dimitrios Vytiniotis, Simon Peyton Jones, Koen Claessen, and Dan Rosén. 2013. HALO: Haskell to Logic through Denotational Semantics. IPnrinciples of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/2429069.2429121 Google Scholar
Digital Library
- Andrew K. Wright and Robert Cartwright. 1997. A Practical Soft Type System for ScheTmraen. sactions on Programming Languages and Systems (TOPLAS) ( 1997 ). DOI:http://dx.doi.org/10.1145/239912.239917 Google Scholar
Digital Library
- Tobias Wrigstad, Francesco Zappa Nardelli, Sylvain Lebresne, Johan Östlund, and Jan Vitek. 2010. Integrating Typed and Untyped Code in a Scripting Language.PIrninciples of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/ 1706299.1706343 Google Scholar
Digital Library
- Dana N. Xu. 2012. Hybrid Contract Checking via Symbolic SimplificationP.aIrntial Evaluation and Program Manipulation (PEPM). DOI:http://dx.doi.org/10.1145/2103746.2103767 Google Scholar
Digital Library
- Dana N. Xu, Simon Peyton Jones, and Koen Claessen. 2009. Static Contract Checking for HaPsrkienlclip.lIens of Programming Languages (POPL). DOI:http://dx.doi.org/10.1145/1480881.1480889 Google Scholar
Digital Library
Index Terms
Corpse reviver: sound and efficient gradual typing via contract verification
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 ...
Toward efficient gradual typing for structural types via coercions
PLDI 2019: Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and ImplementationGradual typing combines static and dynamic typing in the same program. Siek et al. (2015) describe five criteria for gradually typed languages, including type soundness and the gradual guarantee. A significant number of languages have been developed in ...






Comments