ABSTRACT
Closure conversion, an essential step in compiling functional programs, is traditionally presented as a global transformation from a language with higher-order functions to one without. Optimizing this transformation can be done at any of its three stages with various tradeoffs. After conversion, optimizations will be in the target language at the cost of a weaker equational theory. During conversion, optimizations may be embedded into the transformation itself at the cost of increasing its complexity and correctness. And before conversion, optimizations may be planned and anticipated in a specialized intermediate language (IL) where all the properties of the source program are still known, with the hope that they will survive the rest of the compilation process.
By building on the notion of abstract closures, we blur the distinctions between these three approaches to closure conversion and optimizations thereof, by combining all of their strengths and avoiding their weaknesses. Specifically, we develop an IL that includes closures alongside unclosed higher-order code, even inhabiting the same type. The IL comes equipped with an equational theory that is shown sound and complete with respect to an environment abstract machine. Thereby, a baseline closure conversion and common optimizations become provable equalities and thus are correct by construction. Moreover, the transformation and its correctness proof are broken down into little steps—as instances of the β and η axioms—instead of being expressed in terms of a recursive procedure.
Our proposed IL is based on call-by-push-value which we extend with sharing in order to capture closure conversion for both strict and lazy languages.
Supplemental Material
Available for Download
- M. Abadi, L. Cardelli, P.-L. Curien, and J.-J. Levy. 1989. Explicit Substitutions. In Proceedings of the 17th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages(POPL ’90). 31–46.Google Scholar
- Amal Ahmed and Matthias Blume. 2008. Typed closure conversion preserves observational equivalence. In Proceeding of the 13th ACM SIGPLAN international conference on Functional programming, ICFP 2008, Victoria, BC, Canada, September 20-28, 2008. 157–168.Google ScholarDigital Library
- Andrew W. Appel. 1992. Compiling with Continuations. Cambridge University Press.Google ScholarDigital Library
- Zena M. Ariola, John Maraist, Martin Odersky, Matthias Felleisen, and Philip Wadler. 1995. A Call-by-Need Lambda Calculus. In Proceedings of the 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages(POPL ’95). 233–246.Google ScholarDigital Library
- William J. Bowman and Amal Ahmed. 2018. Typed closure conversion for the calculus of constructions. In Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2018, Philadelphia, PA, USA, June 18-22, 2018. 797–811.Google Scholar
- Paul Downen and Zena M. Ariola. 2018. Beyond Polarity: Towards a Multi-Discipline Intermediate Language with Sharing. In 27th EACSL Annual Conference on Computer Science Logic, CSL 2018, September 4-7, 2018, Birmingham, UK. 21:1–21:23.Google Scholar
- Matthias Felleisen and Daniel P. Friedman. 1987. Control operators, the SECD-machine, and the λ -calculus. In Formal Description of Programming Concepts - III: Proceedings of the IFIP TC 2/WG 2.2 Working Conference on Formal Description of Programming Concepts - III, Ebberup, Denmark, 25-28 August 1986. 193–222.Google Scholar
- 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), Albuquerque, New Mexico, USA, June 23-25, 1993. 237–247.Google ScholarDigital Library
- Sebastian Graf and Simon Peyton Jones. 2019. Selective Lambda Lifting. CoRR abs/1910.11717 (2019).Google Scholar
- John Hannan. 1995. Type systems for closure conversions. Types for Program Analysis (1995), 64.Google Scholar
- Jean-Louis Krivine. 2007. A call-by-name lambda-calculus machine. Higher-Order and Symbolic Computation 20, 3 (2007), 199–207.Google ScholarDigital Library
- Paul Blain Levy. 2001. Call-by-push-value. Ph. D. Dissertation. Queen Mary University of London, UK.Google Scholar
- John Maraist, Martin Odersky, and Philip Wadler. 1998. The Call-by-Need Lambda Calculus. J. Funct. Program. 8, 3 (1998), 275–317.Google ScholarDigital Library
- Luke Maurer, Paul Downen, Zena M. Ariola, and Simon L. Peyton Jones. 2017. Compiling without continuations. In Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2017, Barcelona, Spain, June 18-23, 2017. 482–494.Google ScholarDigital Library
- Dylan McDermott and Alan Mycroft. 2019. Extended Call-by-Push-Value: Reasoning About Effectful Programs and Evaluation Order. 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, Prague, Czech Republic, April 6-11, 2019, Proceedings. 235–262.Google Scholar
- Yasuhiko Minamide, J. Gregory Morrisett, and Robert Harper. 1996. Typed Closure Conversion. In Conference Record of POPL’96: The 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, Papers Presented at the Symposium, St. Petersburg Beach, Florida, USA, January 21-24, 1996. 271–283.Google Scholar
- J. Gregory Morrisett, David Walker, Karl Crary, and Neal Glew. 1998. From System F to Typed Assembly Language. In POPL ’98, Proceedings of the 25th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Diego, CA, USA, January 19-21, 1998. 85–97.Google ScholarDigital Library
- Zoe Paraskevopoulou and Andrew W. Appel. 2019. Closure conversion is safe for space. Proc. ACM Program. Lang. 3, ICFP (2019), 83:1–83:29.Google ScholarDigital Library
- Zoe Paraskevopoulou, John M. Li, and Andrew W. Appel. 2021. Compositional optimizations for CertiCoq. Proc. ACM Program. Lang. 5, ICFP (2021), 1–30.Google ScholarDigital Library
- Simon L. Peyton Jones and John Launchbury. 1991. Unboxed Values as First Class Citizens in a Non-Strict Functional Language. In Functional Programming Languages and Computer Architecture, 5th ACM Conference, Cambridge, MA, USA, August 26-30, 1991, Proceedings. 636–666.Google Scholar
- Simon L. Peyton Jones and André L. M. Santos. 1998. A Transformation-Based Optimiser for Haskell. Sci. Comput. Program. 32, 1-3 (1998), 3–47.Google Scholar
- Andrew M. Pitts. 2000. Parametric polymorphism and operational equivalence. Math. Struct. Comput. Sci. 10, 3 (2000), 321–359.Google ScholarDigital Library
- Jill Seaman and S. Purushothaman Iyer. 1996. An Operational Semantics of Sharing in Lazy Evaluation. Sci. Comput. Program. 27, 3 (1996), 289–322.Google ScholarDigital Library
- Peter Sestoft. 1997. Deriving a Lazy Abstract Machine. J. Funct. Program. 7, 3 (1997), 231–264.Google ScholarDigital Library
- Zhong Shao and Andrew W. Appel. 2000. Efficient and safe-for-space closure conversion. ACM Trans. Program. Lang. Syst. 22, 1 (2000), 129–161.Google ScholarDigital Library
- Guy L. Steele. 1978. Rabbit: A Compiler for Scheme. Master’s thesis. Massachusetts Institute of Technology.Google ScholarDigital Library
- Zachary J. Sullivan, Paul Downen, and Zena M. Ariola. 2021. Strictly capturing non-strict closures. In Proceedings of the 2021 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM@POPL 2021, Virtual Event, Denmark, January 18-19, 2021. ACM, 74–89.Google ScholarDigital Library
- Mitchell Wand and Paul Steckler. 1994. Selective and Lightweight Closure Conversion. In Proceedings of the 21st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages(POPL ’94). 435–445.Google ScholarDigital Library
Index Terms
- Closure Conversion in Little Pieces
Recommendations
Typed closure conversion for the calculus of constructions
PLDI 2018: Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and ImplementationDependently typed languages such as Coq are used to specify and verify the full functional correctness of source programs. Type-preserving compilation can be used to preserve these specifications and proofs of correctness through compilation into the ...
Typed closure conversion for the calculus of constructions
PLDI '18Dependently typed languages such as Coq are used to specify and verify the full functional correctness of source programs. Type-preserving compilation can be used to preserve these specifications and proofs of correctness through compilation into the ...
Efficient and safe-for-space closure conversion
Modern compilers often implement function calls (or returns) in two steps: first, a “closure” environment is properly installed to provide access for free variables in the target program fragment; second, the control is transferred to the target by a “...
Comments