skip to main content
10.1145/3610612.3610622acmotherconferencesArticle/Chapter ViewAbstractPublication PagesppdpConference Proceedingsconference-collections
research-article

Closure Conversion in Little Pieces

Published:22 October 2023Publication History

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.

Skip Supplemental Material Section

Supplemental Material

References

  1. 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 ScholarGoogle Scholar
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. Andrew W. Appel. 1992. Compiling with Continuations. Cambridge University Press.Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  5. 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 ScholarGoogle Scholar
  6. 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 ScholarGoogle Scholar
  7. 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 ScholarGoogle Scholar
  8. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  9. Sebastian Graf and Simon Peyton Jones. 2019. Selective Lambda Lifting. CoRR abs/1910.11717 (2019).Google ScholarGoogle Scholar
  10. John Hannan. 1995. Type systems for closure conversions. Types for Program Analysis (1995), 64.Google ScholarGoogle Scholar
  11. Jean-Louis Krivine. 2007. A call-by-name lambda-calculus machine. Higher-Order and Symbolic Computation 20, 3 (2007), 199–207.Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Paul Blain Levy. 2001. Call-by-push-value. Ph. D. Dissertation. Queen Mary University of London, UK.Google ScholarGoogle Scholar
  13. John Maraist, Martin Odersky, and Philip Wadler. 1998. The Call-by-Need Lambda Calculus. J. Funct. Program. 8, 3 (1998), 275–317.Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  15. 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 ScholarGoogle Scholar
  16. 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 ScholarGoogle Scholar
  17. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. Zoe Paraskevopoulou, John M. Li, and Andrew W. Appel. 2021. Compositional optimizations for CertiCoq. Proc. ACM Program. Lang. 5, ICFP (2021), 1–30.Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle Scholar
  21. 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 ScholarGoogle Scholar
  22. Andrew M. Pitts. 2000. Parametric polymorphism and operational equivalence. Math. Struct. Comput. Sci. 10, 3 (2000), 321–359.Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Jill Seaman and S. Purushothaman Iyer. 1996. An Operational Semantics of Sharing in Lazy Evaluation. Sci. Comput. Program. 27, 3 (1996), 289–322.Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Peter Sestoft. 1997. Deriving a Lazy Abstract Machine. J. Funct. Program. 7, 3 (1997), 231–264.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  26. Guy L. Steele. 1978. Rabbit: A Compiler for Scheme. Master’s thesis. Massachusetts Institute of Technology.Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  28. 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 ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Closure Conversion in Little Pieces

      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
      • Published in

        cover image ACM Other conferences
        PPDP '23: Proceedings of the 25th International Symposium on Principles and Practice of Declarative Programming
        October 2023
        173 pages
        ISBN:9798400708121
        DOI:10.1145/3610612

        Copyright © 2023 ACM

        Publication rights licensed to ACM. ACM acknowledges that this contribution was authored or co-authored by an employee, contractor or affiliate of the United States government. As such, the Government retains a nonexclusive, royalty-free right to publish or reproduce this article, or to allow others to do so, for Government purposes only.

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 22 October 2023

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article
        • Research
        • Refereed limited

        Acceptance Rates

        Overall Acceptance Rate143of297submissions,48%
      • Article Metrics

        • Downloads (Last 12 months)46
        • Downloads (Last 6 weeks)12

        Other Metrics

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      HTML Format

      View this article in HTML Format .

      View HTML Format