Space-Efficient Gradual Typing in Coercion-Passing Style

Authors Yuya Tsuda , Atsushi Igarashi , Tomoya Tabuchi



PDF
Thumbnail PDF

File

LIPIcs.ECOOP.2020.8.pdf
  • Filesize: 0.69 MB
  • 29 pages

Document Identifiers

Author Details

Yuya Tsuda
  • Graduate School of Informatics, Kyoto University, Japan
Atsushi Igarashi
  • Graduate School of Informatics, Kyoto University, Japan
Tomoya Tabuchi
  • Graduate School of Informatics, Kyoto University, Japan

Acknowledgements

We thank anonymous reviewers for valuable comments and John Toman for proofreading.

Cite AsGet BibTex

Yuya Tsuda, Atsushi Igarashi, and Tomoya Tabuchi. Space-Efficient Gradual Typing in Coercion-Passing Style. In 34th European Conference on Object-Oriented Programming (ECOOP 2020). Leibniz International Proceedings in Informatics (LIPIcs), Volume 166, pp. 8:1-8:29, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2020)
https://doi.org/10.4230/LIPIcs.ECOOP.2020.8

Abstract

Herman et al. pointed out that the insertion of run-time checks into a gradually typed program could hamper tail-call optimization and, as a result, worsen the space complexity of the program. To address the problem, they proposed a space-efficient coercion calculus, which was subsequently improved by Siek et al. The semantics of these calculi involves eager composition of run-time checks expressed by coercions to prevent the size of a term from growing. However, it relies also on a nonstandard reduction rule, which does not seem easy to implement. In fact, no compiler implementation of gradually typed languages fully supports the space-efficient semantics faithfully. In this paper, we study coercion-passing style, which Herman et al. have already mentioned, as a technique for straightforward space-efficient implementation of gradually typed languages. A program in coercion-passing style passes "the rest of the run-time checks" around - just like continuation-passing style (CPS), in which "the rest of the computation" is passed around - and (unlike CPS) composes coercions eagerly. We give a formal coercion-passing translation from λS by Siek et al. to λS₁, which is a new calculus of first-class coercions tailored for coercion-passing style, and prove correctness of the translation. We also implement our coercion-passing style transformation for the Grift compiler developed by Kuhlenschmidt et al. An experimental result shows stack overflow can be prevented properly at the cost of up to 3 times slower execution for most partially typed practical programs.

Subject Classification

ACM Subject Classification
  • Theory of computation → Semantics and reasoning
  • Software and its engineering → Compilers
  • Theory of computation → Operational semantics
Keywords
  • Gradual typing
  • coercion calculus
  • coercion-passing style
  • dynamic type checking
  • tail-call optimization

Metrics

  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    0
    PDF Downloads

References

  1. Amal Ahmed, Robert Bruce Findler, Jeremy G. Siek, and Philip Wadler. Blame for all. In Proceedings of the 38th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2011, Austin, TX, USA, January 26-28, 2011, pages 201-214, 2011. URL: https://doi.org/10.1145/1926385.1926409.
  2. Amal Ahmed, Dustin Jamner, Jeremy G. Siek, and Philip Wadler. Theorems for free for free: parametricity, with and without types. PACMPL, 1(ICFP):39:1-39:28, 2017. URL: https://doi.org/10.1145/3110283.
  3. Andrew W. Appel. Compiling with Continuations. Cambridge University Press, 1992. Google Scholar
  4. Spenser Bauman, Carl Friedrich Bolz-Tereick, Jeremy G. Siek, and Sam Tobin-Hochstadt. Sound gradual typing: only mostly dead. PACMPL, 1(OOPSLA):54:1-54:24, 2017. URL: https://doi.org/10.1145/3133878.
  5. Giuseppe Castagna, Guillaume Duboc, Victor Lanvin, and Jeremy G. Siek. A space-efficient call-by-value virtual machine for gradual set-theoretic types. In Proceedings of the 31st Symposium on Implementation and Application of Functional Languages, IFL 2019, Singapore, September 25-27, 2019, 2019. Google Scholar
  6. Julien Cretin and Didier Rémy. On the power of coercion abstraction. In Proceedings of the 39th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2012, Philadelphia, Pennsylvania, USA, January 22-28, 2012, pages 361-372, 2012. URL: https://doi.org/10.1145/2103656.2103699.
  7. Olivier Danvy and Andrzej Filinski. Abstracting control. In LISP and Functional Programming, pages 151-160, 1990. URL: https://doi.org/10.1145/91556.91622.
  8. Olivier Danvy and Andrzej Filinski. Representing control: A study of the CPS transformation. Mathematical Structures in Computer Science, 2(4):361-391, 1992. URL: https://doi.org/10.1017/S0960129500001535.
  9. Olivier Danvy and Lasse R. Nielsen. Syntactic theories in practice. Electr. Notes Theor. Comput. Sci., 59(4):358-374, 2001. URL: https://doi.org/10.1016/S1571-0661(04)00297-X.
  10. Olivier Danvy and Lasse R. Nielsen. A first-order one-pass CPS transformation. Theor. Comput. Sci., 308(1-3):239-257, 2003. URL: https://doi.org/10.1016/S0304-3975(02)00733-8.
  11. Matthias Felleisen, Mitchell Wand, Daniel P. Friedman, and Bruce F. Duba. Abstract continuations: A mathematical semantics for handling full jumps. In LISP and Functional Programming, pages 52-62, 1988. URL: https://doi.org/10.1145/62678.62684.
  12. Daniel Feltey, Ben Greenman, Christophe Scholliers, Robert Bruce Findler, and Vincent St-Amour. Collapsible contracts: fixing a pathology of gradual typing. PACMPL, 2(OOPSLA):133:1-133:27, 2018. URL: https://doi.org/10.1145/3276503.
  13. Robert Bruce Findler and Matthias Felleisen. Contracts for higher-order functions. In Proceedings of the Seventh ACM SIGPLAN International Conference on Functional Programming (ICFP '02), Pittsburgh, Pennsylvania, USA, October 4-6, 2002., pages 48-59, 2002. URL: https://doi.org/10.1145/581478.581484.
  14. Ronald Garcia. Calculating threesomes, with blame. In ACM SIGPLAN International Conference on Functional Programming, ICFP'13, Boston, MA, USA - September 25 - 27, 2013, pages 417-428, 2013. URL: https://doi.org/10.1145/2500365.2500603.
  15. Michael Greenberg. Space-efficient manifest contracts. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, Mumbai, India, January 15-17, 2015, pages 181-194, 2015. URL: https://doi.org/10.1145/2676726.2676967.
  16. Michael Greenberg, Benjamin C. Pierce, and Stephanie Weirich. Contracts made manifest. In Proceedings of the 37th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2010, Madrid, Spain, January 17-23, 2010, pages 353-364, 2010. URL: https://doi.org/10.1145/1706299.1706341.
  17. Michael Greenberg, Benjamin C. Pierce, and Stephanie Weirich. Contracts made manifest. J. Funct. Program., 22(3):225-274, 2012. URL: https://doi.org/10.1017/S0956796812000135.
  18. Fritz Henglein. Dynamic typing: Syntax and proof theory. Sci. Comput. Program., 22(3):197-230, 1994. URL: https://doi.org/10.1016/0167-6423(94)00004-2.
  19. David Herman, Aaron Tomb, and Cormac Flanagan. Space-efficient gradual typing. In Proceedings of the Eighth Symposium on Trends in Functional Programming, TFP 2007, New York City, New York, USA, April 2-4. 2007., pages 1-18, 2007. Google Scholar
  20. David Herman, Aaron Tomb, and Cormac Flanagan. Space-efficient gradual typing. Higher-Order and Symbolic Computation, 23(2):167-189, 2010. URL: https://doi.org/10.1007/s10990-011-9066-z.
  21. Yuu Igarashi, Taro Sekiyama, and Atsushi Igarashi. On polymorphic gradual typing. PACMPL, 1(ICFP):40:1-40:29, 2017. URL: https://doi.org/10.1145/3110284.
  22. Robert Kießling and Zhaohui Luo. Coercions in Hindley-Milner systems. In Types for Proofs and Programs, International Workshop, TYPES 2003, Torino, Italy, April 30 - May 4, 2003, Revised Selected Papers, pages 259-275, 2003. URL: https://doi.org/10.1007/978-3-540-24849-1_17.
  23. Kenneth Knowles and Cormac Flanagan. Hybrid type checking. ACM Trans. Program. Lang. Syst., 32(2):6:1-6:34, 2010. URL: https://doi.org/10.1145/1667048.1667051.
  24. Andre Kuhlenschmidt, Deyaaeldeen Almahallawi, and Jeremy G. Siek. Toward efficient gradual typing for structural types via coercions. In Proceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2019, Phoenix, AZ, USA, June 22-26, 2019, pages 517-532, 2019. URL: https://doi.org/10.1145/3314221.3314627.
  25. Tim Lindholm and Frank Yellin. The Java Virtual Machine Specification. Addison-Wesley, 2nd edition, 1999. Google Scholar
  26. Zhaohui Luo. Coercions in a polymorphic type system. Mathematical Structures in Computer Science, 18(4):729-751, 2008. URL: https://doi.org/10.1017/S0960129508006804.
  27. Fabian Muehlboeck and Ross Tate. Sound gradual typing is nominally alive and well. PACMPL, 1(OOPSLA):56:1-56:30, 2017. URL: https://doi.org/10.1145/3133880.
  28. Gordon D. Plotkin. Call-by-name, call-by-value and the λ-calculus. Theor. Comput. Sci., 1(2):125-159, 1975. URL: https://doi.org/10.1016/0304-3975(75)90017-1.
  29. Aseem Rastogi, Nikhil Swamy, Cédric Fournet, Gavin M. Bierman, and Panagiotis Vekris. Safe & efficient gradual typing for TypeScript. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, Mumbai, India, January 15-17, 2015, pages 167-180, 2015. URL: https://doi.org/10.1145/2676726.2676971.
  30. John C. Reynolds. Definitional interpreters for higher-order programming languages. Higher-Order and Symbolic Computation, 11(4):363-397, December 1998. This paper originally appeared in the Proceedings of the ACM National Conference, volume 2, August 1972, ACM, New York, pages 717-740. Google Scholar
  31. Gregor Richards, Ellen Arteca, and Alexi Turcotte. The VM already knew that: leveraging compile-time knowledge to optimize gradual typing. PACMPL, 1(OOPSLA):55:1-55:27, 2017. URL: https://doi.org/10.1145/3133879.
  32. Amr Sabry and Matthias Felleisen. Reasoning about programs in continuation-passing style. Lisp and Symbolic Computation, 6(3-4):289-360, 1993. Google Scholar
  33. Amr Sabry and Philip Wadler. A reflection on call-by-value. ACM Trans. Program. Lang. Syst., 19(6):916-941, 1997. URL: https://doi.org/10.1145/267959.269968.
  34. Jeremy G. Siek and Ronald Garcia. Interpretations of the gradually-typed lambda calculus. In Proceedings of the 2012 Annual Workshop on Scheme and Functional Programming, Scheme 2012, Copenhagen, Denmark, September 9-15, 2012, pages 68-80, 2012. URL: https://doi.org/10.1145/2661103.2661112.
  35. Jeremy G. Siek, Ronald Garcia, and Walid Taha. Exploring the design space of higher-order casts. In Programming Languages and Systems, 18th European Symposium on Programming, ESOP 2009, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2009, York, UK, March 22-29, 2009. Proceedings, pages 17-31, 2009. URL: https://doi.org/10.1007/978-3-642-00590-9_2.
  36. Jeremy G. Siek and Walid Taha. Gradual typing for functional languages. In Scheme and Functional Programming Workshop, pages 81-92, 2006. Google Scholar
  37. Jeremy G. Siek, Peter Thiemann, and Philip Wadler. Blame and coercion: together again for the first time. In Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation, Portland, OR, USA, June 15-17, 2015, pages 425-435, 2015. URL: https://doi.org/10.1145/2737924.2737968.
  38. Jeremy G. Siek and Philip Wadler. Threesomes, with and without blame. In Proceedings of the 37th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2010, Madrid, Spain, January 17-23, 2010, pages 365-376, 2010. URL: https://doi.org/10.1145/1706299.1706342.
  39. Asumu Takikawa, Daniel Feltey, Ben Greenman, Max S. New, Jan Vitek, and Matthias Felleisen. Is sound gradual typing dead? In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, St. Petersburg, FL, USA, January 20 - 22, 2016, pages 456-468, 2016. URL: https://doi.org/10.1145/2837614.2837630.
  40. Sam Tobin-Hochstadt and Matthias Felleisen. Interlanguage migration: from scripts to programs. In Proc. of Dynamic Languages Symposium, pages 964-974, 2006. URL: https://doi.org/10.1145/1176617.1176755.
  41. Sam Tobin-Hochstadt and Matthias Felleisen. The design and implementation of Typed Scheme. In Proceedings of the 35th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2008, San Francisco, California, USA, January 7-12, 2008, pages 395-406, 2008. URL: https://doi.org/10.1145/1328438.1328486.
  42. Matías Toro, Elizabeth Labrada, and Éric Tanter. Gradual parametricity, revisited. PACMPL, 3(POPL):17:1-17:30, 2019. URL: https://doi.org/10.1145/3290330.
  43. Philip Wadler and Robert Bruce Findler. Well-typed programs can't be blamed. In Programming Languages and Systems, 18th European Symposium on Programming, ESOP 2009, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2009, York, UK, March 22-29, 2009. Proceedings, pages 1-16, 2009. URL: https://doi.org/10.1007/978-3-642-00590-9_1.
  44. Dan S. Wallach and Edward W. Felten. Understanding java stack inspection. In Security and Privacy - 1998 IEEE Symposium on Security and Privacy, Oakland, CA, USA, May 3-6, 1998, Proceedings, pages 52-63, 1998. URL: https://doi.org/10.1109/SECPRI.1998.674823.
  45. Mitchell Wand. Correctness of procedure representations in higher-order assembly language. In Mathematical Foundations of Programming Semantics, 7th International Conference, Pittsburgh, PA, USA, March 25-28, 1991, Proceedings, pages 294-311, 1991. URL: https://doi.org/10.1007/3-540-55511-0_15.
  46. Andrew K. Wright and Matthias Felleisen. A syntactic approach to type soundness. Information and Computation, 115(1):38-94, November 1994. Google Scholar
  47. Ningning Xie, Xuan Bi, and Bruno C. d. S. Oliveira. Consistent subtyping for all. In Programming Languages and Systems - 27th European Symposium on Programming, ESOP 2018, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2018, Thessaloniki, Greece, April 14-20, 2018, Proceedings, pages 3-30, 2018. URL: https://doi.org/10.1007/978-3-319-89884-1_1.
Questions / Remarks / Feedback
X

Feedback for Dagstuhl Publishing


Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail