skip to main content
research-article
Open Access

CPS transformation with affine types for call-by-value implicit polymorphism

Published:19 August 2021Publication History
Skip Abstract Section

Abstract

Transformation of programs into continuation-passing style (CPS) reveals the notion of continuations, enabling many applications such as control operators and intermediate representations in compilers. Although type preservation makes CPS transformation more beneficial, achieving type-preserving CPS transformation for implicit polymorphism with call-by-value (CBV) semantics is known to be challenging. We identify the difficulty in the problem that we call scope intrusion. To address this problem, we propose a new CPS target language Λopen that supports two additional constructs for polymorphism: one only binds and the other only generalizes type variables. Unfortunately, their unrestricted use makes Λopen unsafe due to undesired generalization of type variables. We thus equip Λopen with affine types to allow only the type-safe generalization. We then define a CPS transformation from Curry-style CBV System F to type-safe Λopen and prove that the transformation is meaning and type preserving. We also study parametricity of Λopen as it is a fundamental property of polymorphic languages and plays a key role in applications of CPS transformation. To establish parametricity, we construct a parametric, step-indexed Kripke logical relation for Λopen and prove that it satisfies the Fundamental Property as well as soundness with respect to contextual equivalence.

Skip Supplemental Material Section

Supplemental Material

3473600.mp4

Presentation Videos

Auxiliary Presentation Video

The presentation video for “CPS Transformation with Affine Types for Call-By-Value Implicit Polymorphism” at ICFP 2021.

References

  1. Amal Ahmed and Matthias Blume. 2011. An equivalence-preserving CPS translation via multi-language semantics. In ACM SIGPLAN international conference on Functional Programming, ICFP 2011. 431–444. https://doi.org/10.1145/2034773.2034830 Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Amal Ahmed, Derek Dreyer, and Andreas Rossberg. 2009. State-dependent representation independence. In Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2009. 340–353. https://doi.org/10.1145/1480881.1480925 Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Amal Ahmed, Dustin Jamner, Jeremy G. Siek, and Philip Wadler. 2017. Theorems for free for free: parametricity, with and without types. Proc. ACM Program. Lang., 1, ICFP (2017), 39:1–39:28. https://doi.org/10.1145/3110283 Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Amal J. Ahmed. 2006. Step-Indexed Syntactic Logical Relations for Recursive and Quantified Types. In Programming Languages and Systems, 15th European Symposium on Programming, ESOP 2006, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2006, Vienna, Austria, March 27-28, 2006, Proceedings (Lecture Notes in Computer Science, Vol. 3924). Springer, 69–83. https://doi.org/10.1007/11693024_6 Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Andrew W. Appel. 1992. Compiling with Continuations. Cambridge University Press. isbn:0-521-41695-7Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Andrew W. Appel and David B. MacQueen. 1991. Standard ML of New Jersey. In Programming Language Implementation and Logic Programming, 3rd International Symposium, PLILP 1991, Proceedings. 1–13. https://doi.org/10.1007/3-540-54444-5_83 Google ScholarGoogle ScholarCross RefCross Ref
  7. Andrew W. Appel and David A. McAllester. 2001. An indexed model of recursive types for foundational proof-carrying code. ACM Trans. Program. Lang. Syst., 23, 5 (2001), 657–683. https://doi.org/10.1145/504709.504712 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Robert Atkey. 2018. Syntax and Semantics of Quantitative Type Theory. In Proceedings of the 33rd Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2018. 56–65. https://doi.org/10.1145/3209108.3209189 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Andrew Barber and Gordon D. Plotkin. 1996. Dual Intuitionistic Linear Logic. ECS-LFCS-96-347.Google ScholarGoogle Scholar
  10. Josh Berdine, Peter W. O’Hearn, Uday S. Reddy, and Hayo Thielecke. 2001. Linearly Used Continuations. In Proceedings of the Third ACM SIGPLAN Workshop on Continuations (CW’01). 47–54. https://www.microsoft.com/en-us/research/publication/linearly-used-continuations/Google ScholarGoogle Scholar
  11. Josh Berdine, Peter W. O’Hearn, Uday S. Reddy, and Hayo Thielecke. 2002. Linear Continuation-Passing. High. Order Symb. Comput., 15, 2-3 (2002), 181–208. https://doi.org/10.1023/A:1020891112409 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Joshua James Berdine. 2004. Linear and Affine Typing of Continuation-Passing Style. RR-04-04.Google ScholarGoogle Scholar
  13. Dariusz Biernacki, Olivier Danvy, and Kevin Millikin. 2015. A Dynamic Continuation-Passing Style for Dynamic Delimited Continuations. ACM Trans. Program. Lang. Syst., 38, 1 (2015), 2:1–2:25. https://doi.org/10.1145/2794078 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. William J. Bowman, Youyou Cong, Nick Rioux, and Amal Ahmed. 2018. Type-preserving CPS translation of Σ and Π types is not not possible. Proc. ACM Program. Lang., 2, POPL (2018), 22:1–22:33. https://doi.org/10.1145/3158110 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Iliano Cervesato and Frank Pfenning. 1996. A Linear Logical Framework. In Proceedings, 11th Annual IEEE Symposium on Logic in Computer Science, LICS 1996. 264–275. https://doi.org/10.1109/LICS.1996.561339 Google ScholarGoogle ScholarCross RefCross Ref
  16. Youyou Cong, Leo Osvald, Grégory M. Essertel, and Tiark Rompf. 2019. Compiling with continuations, or without? whatever. Proc. ACM Program. Lang., 3, ICFP (2019), 79:1–79:28. https://doi.org/10.1145/3341643 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Olivier Danvy. 1992. Three Steps for the CPS Transformation. CIS-92-2.Google ScholarGoogle Scholar
  18. Olivier Danvy and Andrzej Filinski. 1989. A functional abstraction of typed contexts.Google ScholarGoogle Scholar
  19. Olivier Danvy and Andrzej Filinski. 1990. Abstracting Control. In LISP and Functional Programming. 151–160. https://doi.org/10.1145/91556.91622 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Olivier Danvy and John Hatcliff. 1992. Thunks (Continued). In Actes WSA’92 Workshop on Static Analysis (Bordeaux, France), September 1992, Laboratoire Bordelais de Recherche en Informatique (LaBRI), Proceedings. 3–11.Google ScholarGoogle Scholar
  21. Matthias Felleisen, Daniel P. Friedman, Eugene E. Kohlbecker, and Bruce F. Duba. 1986. Reasoning with Continuations. In Proceedings of the Symposium on Logic in Computer Science (LICS ’86). 131–141.Google ScholarGoogle Scholar
  22. Matthias Felleisen and Robert Hieb. 1992. The Revised Report on the Syntactic Theories of Sequential Control and State. Theorical Computer Science, 103, 2 (1992), 235–271. https://doi.org/10.1016/0304-3975(92)90014-7 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Michael J. Fischer. 1972. Lambda Calculus Schemata. In Proceedings of ACM Conference on Proving Assertions about Programs. 104–109. https://doi.org/10.1145/800235.807077 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The Essence of Compiling with Continuations. In Proceedings of the ACM SIGPLAN’93 Conference on Programming Language Design and Implementation (PLDI). 237–247. https://doi.org/10.1145/155090.155113 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Matthew Fluet and Stephen Weeks. 2001. Contification Using Dominators. In Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming (ICFP ’01). 2–13. https://doi.org/10.1145/507635.507639 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Daniel P. Friedman and Christopher T. Haynes. 1985. Constraining Control. In Conference Record of the Twelfth Annual ACM Symposium on Principles of Programming Languages, New Orleans, Louisiana, USA, January 1985, Mary S. Van Deusen, Zvi Galil, and Brian K. Reid (Eds.). ACM Press, 245–254. https://doi.org/10.1145/318593.318654 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Jacques Garrigue. 2004. Relaxing the Value Restriction. In Functional and Logic Programming, 7th International Symposium, FLOPS 2004, Proceedings. 196–213. https://doi.org/10.1007/978-3-540-24754-8_15 Google ScholarGoogle ScholarCross RefCross Ref
  28. Jean-Yves Girard. 1987. Linear Logic. Theor. Comput. Sci., 50 (1987), 1–102. https://doi.org/10.1016/0304-3975(87)90045-4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. J. Y. Girard. 1972. Interprétation fonctionnelle et élimination des coupures de l’arithmétique d’ordre supérieur. Université Paris 7.Google ScholarGoogle Scholar
  30. Michael J. C. Gordon, Robin Milner, and Christopher P. Wadsworth. 1979. Edinburgh LCF (Lecture Notes in Computer Science, Vol. 78). Springer. isbn:3-540-09724-4 https://doi.org/10.1007/3-540-09724-4 Google ScholarGoogle Scholar
  31. Robert Harper and Mark Lillibridge. 1991. ML with callcc is unsound. Announcement on the types electronic forum. https://www.cis.upenn.edu/~bcpierce/types/archives/1991/msg00034.htmlGoogle ScholarGoogle Scholar
  32. Robert Harper and Mark Lillibridge. 1993. Explicit Polymorphism and CPS Conversion. In Conference Record of the Twentieth Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 206–219. https://doi.org/10.1145/158511.158630 Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Robert Harper and Mark Lillibridge. 1993. Polymorphic Type Assignment and CPS Conversion. Lisp and Symbolic Computation, 6, 3-4 (1993), 361–380.Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Masahito Hasegawa. 2002. Linearly Used Effects: Monadic and CPS Transformations into the Linear Lambda Calculus. In Functional and Logic Programming, 6th International Symposium, FLOPS 2002. 167–182. https://doi.org/10.1007/3-540-45788-7_10 Google ScholarGoogle ScholarCross RefCross Ref
  35. Daniel Hillerström, Sam Lindley, Robert Atkey, and K. C. Sivaramakrishnan. 2017. Continuation Passing Style for Effect Handlers. In 2nd International Conference on Formal Structures for Computation and Deduction, FSCD 2017. 18:1–18:19. https://doi.org/10.4230/LIPIcs.FSCD.2017.18 Google ScholarGoogle ScholarCross RefCross Ref
  36. My Hoang, John C. Mitchell, and Ramesh Viswanathan. 1993. Standard ML-NJ weak polymorphism and imperative constructs. In Proceedings of the Eighth Annual Symposium on Logic in Computer Science (LICS ’93). 15–25. https://doi.org/10.1109/LICS.1993.287604 Google ScholarGoogle ScholarCross RefCross Ref
  37. Atsushi Igarashi and Naoki Kobayashi. 1997. Type-Based Analysis of Communication for Concurrent Programming Languages. In Static Analysis, 4th International Symposium, SAS ’97. 187–201. https://doi.org/10.1007/BFb0032742 Google ScholarGoogle ScholarCross RefCross Ref
  38. Yukiyoshi Kameyama and Takuo Yonezawa. 2008. Typed Dynamic Control Operators for Delimited Continuations. In Functional and Logic Programming, 9th International Symposium, FLOPS 2008. 239–254. https://doi.org/10.1007/978-3-540-78969-7_18 Google ScholarGoogle Scholar
  39. Ohad Kammar and Matija Pretnar. 2017. No value restriction is needed for algebraic effects and handlers. Journal of Functional Programming, 27 (2017), e7. https://doi.org/10.1017/S0956796816000320 Google ScholarGoogle ScholarCross RefCross Ref
  40. Andrew Kennedy. 2007. Compiling with continuations, continued. In Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming, ICFP 2007. 177–190. https://doi.org/10.1145/1291151.1291179 Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Naoki Kobayashi. 2013. Model Checking Higher-Order Programs. J. ACM, 60, 3 (2013), 20:1–20:62. https://doi.org/10.1145/2487241.2487246 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Roland Leiß a, Marcel Köster, and Sebastian Hack. 2015. A graph-based higher-order intermediate representation. In Proceedings of the 13th Annual IEEE/ACM International Symposium on Code Generation and Optimization, CGO 2015. 202–212. https://doi.org/10.1109/CGO.2015.7054200 Google ScholarGoogle ScholarCross RefCross Ref
  43. Daniel Leivant. 1983. Polymorphic Type Inference. In Conference Record of the Tenth Annual ACM Symposium on Principles of Programming Languages, POPL 1983. 88–98. https://doi.org/10.1145/567067.567077 Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Xavier Leroy, Damien Doligez, Alain Frisch, Jacques Garrigue, Didier Rémy, and Jérôme Vouillon. 2020. The OCaml system release 4.10: Documentation and user’s manua. https://caml.inria.fr/pub/docs/manual-ocaml/Google ScholarGoogle Scholar
  45. Xavier Leroy and Pierre Weis. 1991. Polymorphic Type Inference and Assignment. In Proceedings of the 18th Annual ACM Symposium on Principles of Programming Languages. 291–302. https://doi.org/10.1145/99583.99622 Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. John Maraist, Martin Odersky, David N. Turner, and Philip Wadler. 1995. Call-by-name, call-by-value, call-by-need and the linear lambda calculus. In Eleventh Annual Conference on Mathematical Foundations of Programming Semantics, MFPS 1995. 370–392. https://doi.org/10.1016/S1571-0661(04)00022-2 Google ScholarGoogle ScholarCross RefCross Ref
  47. Albert R. Meyer and Mitchell Wand. 1985. Continuation Semantics in Typed Lambda-Calculi (Summary). In Logics of Programs. 219–224. https://doi.org/10.1007/3-540-15648-8_17 Google ScholarGoogle ScholarCross RefCross Ref
  48. Robin Milner, Joachim Parrow, and David Walker. 1992. A Calculus of Mobile Processes, I. Inf. Comput., 100, 1 (1992), 1–40. https://doi.org/10.1016/0890-5401(92)90008-4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Eugenio Moggi. 1989. Computational Lambda-Calculus and Monads. In Proceedings of the Fourth Annual Symposium on Logic in Computer Science (LICS ’89), Pacific Grove, California, USA, June 5-8, 1989. 14–23. https://doi.org/10.1109/LICS.1989.39155 Google ScholarGoogle Scholar
  50. Benoît Montagu and Didier Rémy. 2009. Modeling abstract types in modules with open existential types. In Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2009. 354–365. https://doi.org/10.1145/1480881.1480926 Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. James H. Morris. 1969. Lambda-calculus models of programming languages. Ph.D. Dissertation. Massachusetts Institute of Technology. https://dspace.mit.edu/handle/1721.1/64850Google ScholarGoogle Scholar
  52. J. Gregory Morrisett, David Walker, Karl Crary, and Neal Glew. 1999. From system F to typed assembly language. ACM Trans. Program. Lang. Syst., 21, 3 (1999), 527–568. https://doi.org/10.1145/319301.319345 Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Georg Neis, Derek Dreyer, and Andreas Rossberg. 2011. Non-parametric parametricity. J. Funct. Program., 21, 4-5 (2011), 497–562. https://doi.org/10.1017/S0956796811000165 Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. Max S. New, Dustin Jamner, and Amal Ahmed. 2020. Graduality and parametricity: together again for the first time. Proc. ACM Program. Lang., 4, POPL (2020), 46:1–46:32. https://doi.org/10.1145/3371114 Google ScholarGoogle ScholarDigital LibraryDigital Library
  55. Simon L. Peyton Jones and Philip Wadler. 1993. Imperative Functional Programming. In Conference Record of the Twentieth Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 71–84. https://doi.org/10.1145/158511.158524 Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. Andrew M. Pitts and Ian David Bede Stark. 1993. Observable Properties of Higher Order Functions that Dynamically Create Local Names, or What’s new? In Mathematical Foundations of Computer Science 1993, 18th International Symposium, MFCS 1993. 122–141. https://doi.org/10.1007/3-540-57182-5_8 Google ScholarGoogle ScholarCross RefCross Ref
  57. Gordon D. Plotkin. 1973. Lambda-definability and logical relations.Google ScholarGoogle Scholar
  58. Gordon D. Plotkin. 1975. Call-by-Name, Call-by-Value and the lambda-Calculus. Theor. Comput. Sci., 1, 2 (1975), 125–159. https://doi.org/10.1016/0304-3975(75)90017-1 Google ScholarGoogle ScholarCross RefCross Ref
  59. John C. Reynolds. 1972. Definitional Interpreters for Higher-Order Programming Languages. In Proceedings of the ACM Annual Conference - Volume 2 (ACM ’72). 717–740. https://doi.org/10.1145/800194.805852 Google ScholarGoogle ScholarDigital LibraryDigital Library
  60. John C. Reynolds. 1974. Towards a theory of type structure. In Programming Symposium, Proceedings Colloque sur la Programmation. 408–423. https://doi.org/10.1007/3-540-06859-7_148 Google ScholarGoogle ScholarCross RefCross Ref
  61. John C. Reynolds. 1983. Types, Abstraction and Parametric Polymorphism. In IFIP Congress. 513–523.Google ScholarGoogle Scholar
  62. John C. Reynolds. 1993. The Discoveries of Continuations. Lisp and Symbolic Computation, 6, 3-4 (1993), 233–248.Google ScholarGoogle ScholarDigital LibraryDigital Library
  63. Amr Sabry and Matthias Felleisen. 1992. Reasoning About Programs in Continuation-Passing Style. In Proceedings of the Conference on Lisp and Functional Programming, LFP 1992. 288–298. https://doi.org/10.1145/141471.141563 Google ScholarGoogle ScholarDigital LibraryDigital Library
  64. Taro Sekiyama and Atsushi Igarashi. 2019. Handling Polymorphic Algebraic Effects. In Programming Languages and Systems - 28th European Symposium on Programming, ESOP 2019, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2019, Proceedings. 353–380. https://doi.org/10.1007/978-3-030-17184-1_13 Google ScholarGoogle ScholarCross RefCross Ref
  65. Taro Sekiyama, Takeshi Tsukada, and Atsushi Igarashi. 2020. Signature restriction for polymorphic algebraic effects. Proc. ACM Program. Lang., 4, ICFP (2020), 117:1–117:30. https://doi.org/10.1145/3408999 Google ScholarGoogle ScholarDigital LibraryDigital Library
  66. William W. Tait. 1967. Intensional Interpretations of Functionals of Finite Type I. J. Symb. Log., 32, 2 (1967), 198–212. https://doi.org/10.2307/2271658 Google ScholarGoogle ScholarCross RefCross Ref
  67. Hayo Thielecke. 2003. From control effects to typed continuation passing. In Conference Record of POPL 2003: The 30th SIGPLAN-SIGACT Symposium on Principles of Programming Languages. 139–149. https://doi.org/10.1145/640128.604144 Google ScholarGoogle ScholarDigital LibraryDigital Library
  68. Hayo Thielecke. 2004. Answer Type Polymorphism in Call-by-Name Continuation Passing. In Programming Languages and Systems, 13th European Symposium on Programming, ESOP 2004, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2004. 279–293. https://doi.org/10.1007/978-3-540-24725-8_20 Google ScholarGoogle ScholarCross RefCross Ref
  69. Mads Tofte. 1990. Type Inference for Polymorphic References. Inf. Comput., 89, 1 (1990), 1–34. https://doi.org/10.1016/0890-5401(90)90018-D Google ScholarGoogle ScholarDigital LibraryDigital Library
  70. David N. Turner, Philip Wadler, and Christian Mossin. 1995. Once Upon a Type. In Proceedings of the seventh international conference on Functional programming languages and computer architecture, FPCA 1995. 1–11. https://doi.org/10.1145/224164.224168 Google ScholarGoogle ScholarDigital LibraryDigital Library
  71. Philip Wadler. 1989. Theorems for Free!. In Proceedings of the fourth international conference on Functional programming languages and computer architecture, FPCA 1989. 347–359. https://doi.org/10.1145/99370.99404 Google ScholarGoogle ScholarDigital LibraryDigital Library
  72. Andrew K. Wright and Matthias Felleisen. 1994. A Syntactic Approach to Type Soundness. Inf. Comput., 115, 1 (1994), 38–94. https://doi.org/10.1006/inco.1994.1093 Google ScholarGoogle ScholarDigital LibraryDigital Library
  73. Jianzhou Zhao, Qi Zhang, and Steve Zdancewic. 2010. Relational Parametricity for a Polymorphic Linear Lambda Calculus. In Programming Languages and Systems - 8th Asian Symposium, APLAS 2010, Shanghai, China, November 28 - December 1, 2010. Proceedings, Kazunori Ueda (Ed.) (Lecture Notes in Computer Science, Vol. 6461). Springer, 344–359. https://doi.org/10.1007/978-3-642-17164-2_24 Google ScholarGoogle ScholarCross RefCross Ref

Index Terms

  1. CPS transformation with affine types for call-by-value implicit polymorphism

          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

          • Article Metrics

            • Downloads (Last 12 months)109
            • Downloads (Last 6 weeks)14

            Other Metrics

          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!