Abstract
This paper presents a new closure conversion algorithm for simply-typed languages. We have have implemented the algorithm as part of MLton, a whole-program compiler for Standard ML (SML). MLton first applies all functors and eliminates polymorphism by code duplication to produce a simply-typed program. MLton then performs closure conversion to produce a first-order, simply-typed program. In contrast to typical functional language implementations, MLton performs most optimizations on the first-order language, after closure conversion. There are two notable contributions of our work:
-
1.
The translation uses a general flow-analysis framework which includes OCFA. The types in the target language fully capture the results of the analysis. MLton uses the analysis to insert coercions to translate between different representations of a closure to preserve type correctness of the target language program.
-
2.
The translation is practical. Experimental results over a range of benchmarks including large real-world programs such as the compiler itself and the ML-Kit [25] indicate that the compile-time cost of flow analysis and closure conversion is extremely small, and that the dispatches and coercions inserted by the algorithm are dynamically infrequent.
Chapter PDF
Similar content being viewed by others
Keywords
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.
References
Andrew W. Appel. Compiling with Continuations. Cambridge University Press, 1992.
J. Michael Ashley. A practical and flexible flow analysis for higher-order languages. In ACM Symposium on Principles of Programming Languages, pages 195–207, January 1996.
Jeffrey M. Bell, Françoise Bellegarde, and James Hook. Type-driven defunctionalization. In Proceedings of the 1997 ACM SIGPLAN International Conference on Functional Programming, pages 25–37, Amsterdam, The Netherlands, 9–11 June 1997.
Greg Defouw, David Grove, and Craig Chambers. Fast interprocedural class analysis. In ACM Symposium on Principles of Programming Languages, pages 222–236, January 1998.
Allyn Dimock, Robert Muller, Franklyn Turback, and J.B. Wells. Strongly-typed flow-directed representation transformations. In International Conference on Functional Programming, June 1997.
Matrin Elsman. Static interpretation of modules. In International Conference on Functional Programming, September 1999.
Marc Feeley, James Miller, Guillermo Rozas, and Jason Wilson. Compiling higher-order languages into fully tail-recursive portable c. Technical Report Technical Report 1078, Department of Computer Science, University of Montreal, 1997.
Robert Harper and John C. Mitchell. On the type structure of Standard ML. ACM Transactions on Programming Languages and Systems, 15(2):211–252, April 1993.
Nevin Heintze. Set-based analysis of ML programs. In ACM Conference on LISP and Functional Programming, pages 306–317, 1994.
Nevin Heintze and David A. McAllester. Linear-time subtransitive control flow analysis. In Proceedings of the ACM SIGPLAN’97 Conference on Programming Language Design and Implementation (PLDI), pages 261–272, Las Vegas, Nevada, 15–18 June 1997. SIGPLAN Notices 32(5), May 1997.
Fritz Henglein. Simple closure analysis. Technical Report D-193, Department of Computer Science, University of Copenhagen, March 1992.
Suresh Jagannathan, Stephen T. Weeks, and Andrew K. Wright. Type-directed flow analysis for typed intermediate languages. In International Static Analysis Symposium, September 1997.
Neil D. Jones and Stephen S. Muchnick. Flow Analysis and Optimization of LISP-like Structures, chapter 4, pages 102–131. Prentice-Hall, 1981.
Simon L. Peyton Jones, John Launchbury, Mark Shields, and Andrew Tolmach. Bridging the gulf: a common intermediate language for ML and Haskell. In ACM Symposium on Principles of Programming Languages, pages 49–51, January 1998.
Robin Milner, Mads Tofte, Robert Harper, and David B. Macqueen. The Definition of Standard ML (Revised). MIT Press, 1997.
Yasuhiko Minamide, J. Gregory Morrisett, and Robert Harper. Typed closure conversion. In ACM Symposium on Principles of Programming Languages, pages 271–283, St. Petersburg, FL, January 1996.
Jens Palsberg. Closure analysis in constraint form. ACM Transactions on Programming Languages and Systems, 17(1):47–62, January 1995.
Jens Palsberg and Patrick O’Keefe. A type system equivalent to flow analysis. ACM Transactions on Programming Languages and Systems, 17(4):576–599, July 1995. Preliminary version in Principles of Programming Languages, pages 367–378, January 1995.
John C. Reynolds. Definitional interpreters for higher-order programming languages. In ACM Annual Conference, pages 717–740, 1972.
Manuel Serrano and Pierre Weis. 1 + 1 = 1: an optimizing Caml compiler. In Workshop on ML and its applications, Orlando, Florida, June 1994. ACM SIG-PLAN. Also appears as INRIA RR-2301.
Zhong Shao and Andrew W. Appel. Space-efficient closure representations. In ACM Conference on LISP and Functional Programming, pages 150–161, Orlando, FL, Jun 1994.
David Tarditi, Anurag Acharya, and Peter Lee. No assembly required: Compiling Standard ML to C. ACM Letters on Programming Languages and Systems, June 1992. Appears as CMU-CS-90-187.
David Tarditi, J. Gregory Morrisett, Perry Cheng, Chris Stone, Robert Harper, and Peter Lee. TIL: A type-directed optimizing compiler for ML. In ACM Conference on Programming Language Design and Implementation, May 1996.
Mads Tofte and Lars Birkedal. A region inference algorithm. Transactions on Programming Languages and Systems, 20(4):724–767, 1998.
Mads Tofte, Lars Birkedal, Martin Elsman, Niels Hallenberg, Tommy Olesen, Peter Sestoft, and Peter Bertelsen. Programming with regions in the ML Kit. Technical Report Technical Report DIKU-TR-97/12, Department of Computer Science, University of Copenhagen, 1997.
Andrew Tolmach and Dino Oliva. From ML to Ada: Strongly-typed language interoperability via source translation. Journal of Functional Programming, 8(4):367–412, July 1998.
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2000 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Cejtin, H., Jagannathan, S., Weeks, S. (2000). Flow-Directed Closure Conversion for Typed Languages. In: Smolka, G. (eds) Programming Languages and Systems. ESOP 2000. Lecture Notes in Computer Science, vol 1782. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-46425-5_4
Download citation
DOI: https://doi.org/10.1007/3-540-46425-5_4
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-67262-3
Online ISBN: 978-3-540-46425-9
eBook Packages: Springer Book Archive