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.
- 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 Scholar
Digital Library
- Andrew W. Appel. 1992. Compiling with Continuations. Cambridge University Press, Cambridge, England, UK.
Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- William D. Clinger and Lars T. Hansen. 2017. The Larceny Project. http://www.larcenists.org
Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- Peter Shirley. 2020. Ray Tracing in One Weekend. https://raytracing.github.io
Google Scholar
- 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 Scholar
- Jeffrey M. Siskind. 1999. Flow-Directed Lightweight Closure Conversion. NEC Research Institute, Princeton, New Jersey.
Google Scholar
- 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 Scholar
Digital Library
- Dimitrios Vardoulakis. 2012. CFA2: Pushdown Flow Analysis for Higher-Order Languages. Ph. D. Dissertation. Northeastern University. Boston, MA, USA.
Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
Digital Library
Index Terms
Analyzing binding extent in 3CPS
Recommendations
3CPS: The Design of an Environment-Focussed Intermediate Representation
IFL '21: Proceedings of the 33rd Symposium on Implementation and Application of Functional LanguagesWe describe the design of 3CPS, a compiler intermediate representation (IR) we have developed for use in compiling call-by-value functional languages such as SML, OCaml, Scheme, and Lisp. The language is a low-level form designed in tandem with a ...
A model of CPS translation and interpretation
ACM-SE 42: Proceedings of the 42nd annual Southeast regional conferenceThis paper presents a model of translation of functional languages. The source language of the translation is a simple extension of lambda expressions and the target language is a language in continuation passing style (CPS).We have implemented, in SML [...
A New Backend for Standard ML of New Jersey
IFL '20: Proceedings of the 32nd Symposium on Implementation and Application of Functional LanguagesThis paper describes the design and implementation of a new backend for the Standard ML of New Jersey (SML/NJ) system that is based on the LLVM compiler infrastructure. We first describe the history and design of the current backend, which is based on ...






Comments