skip to main content
research-article
Open Access
Artifacts Evaluated & Reusable / v1.1

Analyzing binding extent in 3CPS

Published:31 August 2022Publication History
Skip Abstract Section

Abstract

To date, the most effective approach to compiling strict, higher-order functional languages (such as OCaml, Scheme, and SML) has been to use whole-program techniques to convert the program to a first-order monomorphic representation that can be optimized using traditional compilation techniques. This approach, popularized by MLton, has limitations, however. We are interested in exploring a different approach to compiling such languages, one that preserves the higher-order and polymorphic character of the program throughout optimization. To enable such an approach, we must have effective analyses that both provide precise information about higher-order programs and that scale to larger units of compilation. This paper describes one such analysis for determining the extent of variable bindings. We classify the extent of variables as either register (only one binding instance can be live at any time), stack (the lifetimes of binding instances obey a LIFO order), or heap (binding lifetimes are arbitrary). These extents naturally connect variables to the machine resources required to represent them. We believe that precise information about binding extents will enable efficient management of environments, which is a key problem in the efficient compilation of higher-order programs.

At the core of the paper is the 3CPS intermediate representation, which is a factored CPS-based intermediate representation (IR) that statically marks variables to indicate their binding extent. We formally specify the management of this binding structure by means of a small-step operational semantics and define a static analysis that determines the extents of the variables in a program. We evaluate our analysis using a standard suite of SML benchmark programs. Our implementation gets surprisingly high yield and exhibits scalable performance. While this paper uses a CPS-based IR, the algorithm and results are easily transferable to other λ-calculus IRs, such as ANF.

References

  1. Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman. 2007. Compilers: Principles, Techniques and Tools (2nd ed.). Pearson, New York City, New York, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Andrew W. Appel. 1992. Compiling with Continuations. Cambridge University Press, Cambridge, England, UK. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Andrew W. Appel and Trevor T.Y. Jim. 1988. Optimizing Closure Environment Representations. Department of Computer Science, Princeton University. https://www.cs.princeton.edu/research/techreps/TR-168-88 Google ScholarGoogle Scholar
  4. Bruno Blanchet. 1998. Escape Analysis: Correctness Proof, Implementation and Experimental Results. In Proceedings of the 25th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’98). Association for Computing Machinery, New York, NY, USA. 25–37. isbn:0897919793 https://doi.org/10.1145/268946.268949 Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Luca Cardelli. 1984. Compiling a Functional Language. In Proceedings of the 1984 ACM Symposium on LISP and Functional Programming (LFP ’84). Association for Computing Machinery, New York, NY, USA. 208–217. https://doi.org/10.1145/800055.802037 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Henry Cejtin, Suresh Jagannathan, and Stephen Weeks. 2000. Flow-Directed Closure Conversion for Typed Languages. In Proceedings of the 9th European Symposium on Programming Languages and Systems (ESOP ’00) (Lecture Notes in Computer Science, Vol. 1782). Springer-Verlag, New York, NY, USA. 56–71. Google ScholarGoogle ScholarCross RefCross Ref
  7. William D. Clinger and Lars T. Hansen. 2017. The Larceny Project. http://www.larcenists.org Google ScholarGoogle Scholar
  8. Youyou Cong, Leo Osvald, Grégory M. Essertel, and Tiark Rompf. 2019. Compiling with Continuations, or without? Whatever.. Proceedings of the ACM on Programming Languages, 3, ICFP (2019), Article 79, jul, 28 pages. https://doi.org/10.1145/3341643 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Patrick Cousot and Radhia Cousot. 1977. Abstract Interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In Proceedings of the Fourth Annual ACM Symposium on Principles of Programming Languages (POPL ’77), Ravi Sethi (Ed.). Association for Computing Machinery, New York, NY, USA. 238–252. https://doi.org/10.1145/512950.512973 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Olivier Danvy and Andrzej Filinski. 1992. Representing Control: A study of the CPS transformation. Mathematical Structures in Computer Science, 2, 4 (1992), Dec., 361–391. https://doi.org/10.1017/S0960129500001535 Google ScholarGoogle ScholarCross RefCross Ref
  11. Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. 1993. The Essence of Compiling with Continuations. In Proceedings of the ACM SIGPLAN 1993 Conference on Programming Language Design and Implementation (PLDI ’93). Association for Computing Machinery, New York, NY, USA. 237–247. https://doi.org/10.1145/155090.155113 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Thomas Gilray, Steven Lyde, Michael D. Adams, Matthew Might, and David Van Horn. 2016. Pushdown control-flow analysis for free. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016. Association for Computing Machinery, New York, NY, USA. 691–704. https://doi.org/10.1145/2837614.2837631 Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Pieter H. Hartel, Marc Feeley, Martin Alt, Lennart Augustsson, Peter Baumann, Marcel Beemster, Emmanuel Chailloux, Christine H. Flood, Wolfgang Grieskamp, John H. G. Van Groningen, and et al.. 1996. Benchmarking implementations of functional languages with ‘Pseudoknot’, a float-intensive benchmark. Journal of Functional Programming, 6, 4 (1996), 621–655. https://doi.org/10.1017/S0956796800001891 Google ScholarGoogle ScholarCross RefCross Ref
  14. J. Ian Johnson, Ilya Sergey, Christopher Earl, Matthew Might, and David Van Horn. 2014. Pushdown flow analysis with abstract garbage collection. Journal of Functional Programming, 24, 2-3 (2014), 218–283. https://doi.org/10.1017/S0956796814000100 Google ScholarGoogle ScholarCross RefCross Ref
  15. Andrew Kennedy. 2007. Compiling with Continuations, Continued. In Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming (ICFP ’07). Association for Computing Machinery, New York, NY, USA. 177–190. https://doi.org/10.1145/1291151.1291179 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. David Kranz, Richard Kesley, Jonathan Rees, Paul Hudak, Jonathan Philbin, and Norman Adams. 1986. ORBIT: An Optimizing Compiler for Scheme. In Proceedings of the 1986 Symposium on Compiler Construction, Stuart I. Feldman (Ed.) (SIGPLAN Notices, Vol. 21, No 7). ACM Press, Palo Alto, California. 219–233. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. David A. Kranz. 1988. ORBIT: An Optimizing Compiler for Scheme. Ph. D. Dissertation. Computer Science Department, Yale University. New Haven, Connecticut. Research Report 632 Google ScholarGoogle Scholar
  18. Fabrice Le Fessant and Luc Maranget. 2001. Optimizing Pattern Matching. In Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming ICFP ’01. Association for Computing Machinery, New York, NY, USA. 26–37. https://doi.org/10.1145/507635.507641 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Luke Maurer, Paul Downen, Zena M. Ariola, and Simon Peyton Jones. 2017. Compiling without Continuations. In Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’17). Association for Computing Machinery, New York, NY, USA. 482–494. https://doi.org/10.1145/3062341.3062380 Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Matthew Might and Olin Shivers. 2006. Improving flow analyses via Γ CFA: Abstract garbage collection and counting. In Proceedings of the Eleventh ACM SIGPLAN International Conference on Functional Programming (ICFP’06). Association for Computing Machinery, New York, NY, USA. 13–25. https://doi.org/10.1016/j.tcs.2006.12.031 Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Markus Mohnen. 1995. Efficient Closure Utilisation by Higher-Order Inheritance Analysis. In Proceedings of the Second International Symposium on Static Analysis (SAS ’95). Springer-Verlag, Berlin, Heidelberg. 261–278. https://doi.org/10.1007/3-540-60360-3_44 Google ScholarGoogle ScholarCross RefCross Ref
  22. Young Gil Park and Benjamin Goldberg. 1992. Escape Analysis on Lists. In Proceedings of the ACM SIGPLAN 1992 Conference on Programming Language Design and Implementation (PLDI ’92). Association for Computing Machinery, New York, NY, USA. 116–127. isbn:0897914759 https://doi.org/10.1145/143095.143125 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Benjamin Quiring, John Reppy, and Olin Shivers. 2021. 3CPS: The Design of an Environment-Focussed Intermediate Representation. In 33rd Symposium on Implementation and Application of Functional Languages (IFL ’21). Association for Computing Machinery, New York, NY, USA. 9 pages. https://doi.org/10.1145/3544885.3544889 Google ScholarGoogle Scholar
  24. John C. Reynolds. 1972. Definitional Interpreters for Higher-Order Programming Languages. In Proceedings of the ACM Annual Conference - Volume 2 (ACM ’72). Association for Computing Machinery, New York, NY, USA. 717–740. isbn:9781450374927 https://doi.org/10.1145/800194.805852 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Manuel Serrano. 1995. Control Flow Analysis: A Functional Languages Compilation Paradigm. In Proceedings of the 1995 ACM Symposium on Applied Computing (SAC ’95) (SAC ’95). ACM, New York, NY, USA. 118–122. https://doi.org/10.1145/315891.315934 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Manuel Serrano and Marc Feeley. 1996. Storage Use Analysis and Its Applications. In Proceedings of the First ACM SIGPLAN International Conference on Functional Programming (ICFP ’96). Association for Computing Machinery, New York, NY, USA. 50–61. https://doi.org/10.1145/232627.232635 Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Zhong Shao and Andrew W. Appel. 2000. Efficient and Safe-for-Space Closure Conversion. ACM Transactions on Programming Languages and Systems, 22, 1 (2000), Jan., 129–161. issn:0164-0925 https://doi.org/10.1145/345099.345125 Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Peter Shirley. 2020. Ray Tracing in One Weekend. https://raytracing.github.io Google ScholarGoogle Scholar
  29. Olin Shivers. 1991. Control-Flow Analysis of Higher-Order Languages, or Taming Lambda. Ph. D. Dissertation. School of Computer Science, Carnegie Mellon University. Pittsburgh, Pennsylvania. Technical Report CMU-CS-91-145 Google ScholarGoogle Scholar
  30. Jeffrey M. Siskind. 1999. Flow-Directed Lightweight Closure Conversion. NEC Research Institute, Princeton, New Jersey. Google ScholarGoogle Scholar
  31. Andrew Tolmach and Dino P. Oliva. 1998. From ML to Ada: Strongly-Typed Language Interoperability via Source Translation. Journal of Functional Programming, 8, 4 (1998), July, 367–412. https://doi.org/10.1017/S0956796898003086 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Dimitrios Vardoulakis. 2012. CFA2: Pushdown Flow Analysis for Higher-Order Languages. Ph. D. Dissertation. Northeastern University. Boston, MA, USA. Google ScholarGoogle Scholar
  33. Dimitrios Vardoulakis and Olin Shivers. 2011. CFA2: A context-free approach to control-flow analysis. Logical Methods in Computer Science, 7, 2 (2011), Article 3, May, 39 pages. https://doi.org/10.2168/LMCS-7(2:3)2011 Special issue for ESOP 2010. Google ScholarGoogle ScholarCross RefCross Ref
  34. Stephen Weeks. 2006. Whole-program compilation in MLton. In Proceedings of the ACM Workshop on ML, Andrew Kennedy and François Pottier (Eds.). Association for Computing Machinery, New York, NY, USA. 1. https://doi.org/10.1145/1159876.1159877 Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Analyzing binding extent in 3CPS

        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)239
          • Downloads (Last 6 weeks)18

          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!