Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

Analyzing binding extent in 3CPS

Published: 31 August 2022 Publication History

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.
[2]
Andrew W. Appel. 1992. Compiling with Continuations. Cambridge University Press, Cambridge, England, UK.
[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
[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
[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
[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.
[7]
William D. Clinger and Lars T. Hansen. 2017. The Larceny Project. http://www.larcenists.org
[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
[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
[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
[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
[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
[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
[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
[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
[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.
[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
[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
[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
[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
[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
[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
[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
[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
[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
[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
[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
[28]
Peter Shirley. 2020. Ray Tracing in One Weekend. https://raytracing.github.io
[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
[30]
Jeffrey M. Siskind. 1999. Flow-Directed Lightweight Closure Conversion. NEC Research Institute, Princeton, New Jersey.
[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
[32]
Dimitrios Vardoulakis. 2012. CFA2: Pushdown Flow Analysis for Higher-Order Languages. Ph. D. Dissertation. Northeastern University. Boston, MA, USA.
[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.
[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

Cited By

View all
  • (2024)Deriving with Derivatives: Optimizing Incremental Fixpoints for Higher-Order Flow AnalysisProceedings of the ACM on Programming Languages10.1145/36746508:ICFP(728-755)Online publication date: 15-Aug-2024
  • (2024)Generating Well-Typed Terms That Are Not “Useless”Proceedings of the ACM on Programming Languages10.1145/36329198:POPL(2318-2339)Online publication date: 5-Jan-2024

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 6, Issue ICFP
August 2022
959 pages
EISSN:2475-1421
DOI:10.1145/3554306
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution 4.0 International License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 31 August 2022
Published in PACMPL Volume 6, Issue ICFP

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. Compilers
  2. Continuation-Passing Style
  3. Higher-Order Flow Analysis
  4. Intermediate Representation

Qualifiers

  • Research-article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)240
  • Downloads (Last 6 weeks)48
Reflects downloads up to 25 Feb 2025

Other Metrics

Citations

Cited By

View all
  • (2024)Deriving with Derivatives: Optimizing Incremental Fixpoints for Higher-Order Flow AnalysisProceedings of the ACM on Programming Languages10.1145/36746508:ICFP(728-755)Online publication date: 15-Aug-2024
  • (2024)Generating Well-Typed Terms That Are Not “Useless”Proceedings of the ACM on Programming Languages10.1145/36329198:POPL(2318-2339)Online publication date: 5-Jan-2024

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media