skip to main content

Corpse reviver: sound and efficient gradual typing via contract verification

Published:04 January 2021Publication History
Skip Abstract Section

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarCross RefCross Ref
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. Robert Cartwright and Mike Fagan. 1991. Soft Typing. IPnrogramming Language Design and Implementation (PLDI). DOI: http://dx.doi.org/10.1145/113445.113469 Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. Mathias Felleisen, Robert Bruce Findler, and Mathew Flat. 2009. Semantics Engineering with PLT Redex.Google ScholarGoogle Scholar
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. Google Inc. 2018. Dart. ( 2018 ) h. ttps://dart.dev/Google ScholarGoogle Scholar
  15. 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 ScholarGoogle ScholarCross RefCross Ref
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarCross RefCross Ref
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  22. Jukka Lehtosalo. 2017. MyPy: Optional Static Typing for Python. ( 2h0t1t7p ).://mypy-lang.org/Google ScholarGoogle Scholar
  23. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  24. Microsoft Corp. 2014. TypeScript Language Specification. ( 2014 ).http://www.typescriptlang.orgGoogle ScholarGoogle Scholar
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle ScholarCross RefCross Ref
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. 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 ScholarGoogle ScholarCross RefCross Ref
  33. Jeremy G. Siek and Walid Taha. 2006. Gradual Typing for Functional LanguagSecsh. eImne and Functional Programming Workshop.Google ScholarGoogle Scholar
  34. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  35. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  36. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  37. Stripe Inc. 2019. Sorbet. ( 2019 ) h.ttps://sorbet.org/Google ScholarGoogle Scholar
  38. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  39. 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 ScholarGoogle ScholarCross RefCross Ref
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  43. 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 ScholarGoogle ScholarCross RefCross Ref
  44. 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 ScholarGoogle ScholarCross RefCross Ref
  45. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  46. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  47. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  48. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  49. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  50. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  51. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  52. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  53. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Corpse reviver: sound and efficient gradual typing via contract verification

      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!