Advertisement

Flow-Directed Closure Conversion for Typed Languages

  • Henry Cejtin
  • Suresh Jagannathan
  • Stephen Weeks
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 1782)

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. 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. 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.

     

Keywords

Target Language Program Language Source Language Type Language Intermediate Language 
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

  1. 1.
    Andrew W. Appel. Compiling with Continuations. Cambridge University Press, 1992.Google Scholar
  2. 2.
    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.Google Scholar
  3. 3.
    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.Google Scholar
  4. 4.
    Greg Defouw, David Grove, and Craig Chambers. Fast interprocedural class analysis. In ACM Symposium on Principles of Programming Languages, pages 222–236, January 1998.Google Scholar
  5. 5.
    Allyn Dimock, Robert Muller, Franklyn Turback, and J.B. Wells. Strongly-typed flow-directed representation transformations. In International Conference on Functional Programming, June 1997.Google Scholar
  6. 6.
    Matrin Elsman. Static interpretation of modules. In International Conference on Functional Programming, September 1999.Google Scholar
  7. 7.
    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.Google Scholar
  8. 8.
    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.CrossRefGoogle Scholar
  9. 9.
    Nevin Heintze. Set-based analysis of ML programs. In ACM Conference on LISP and Functional Programming, pages 306–317, 1994.Google Scholar
  10. 10.
    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.Google Scholar
  11. 11.
    Fritz Henglein. Simple closure analysis. Technical Report D-193, Department of Computer Science, University of Copenhagen, March 1992.Google Scholar
  12. 12.
    Suresh Jagannathan, Stephen T. Weeks, and Andrew K. Wright. Type-directed flow analysis for typed intermediate languages. In International Static Analysis Symposium, September 1997.Google Scholar
  13. 13.
    Neil D. Jones and Stephen S. Muchnick. Flow Analysis and Optimization of LISP-like Structures, chapter 4, pages 102–131. Prentice-Hall, 1981.Google Scholar
  14. 14.
    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.Google Scholar
  15. 15.
    Robin Milner, Mads Tofte, Robert Harper, and David B. Macqueen. The Definition of Standard ML (Revised). MIT Press, 1997.Google Scholar
  16. 16.
    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.Google Scholar
  17. 17.
    Jens Palsberg. Closure analysis in constraint form. ACM Transactions on Programming Languages and Systems, 17(1):47–62, January 1995.CrossRefGoogle Scholar
  18. 18.
    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.CrossRefGoogle Scholar
  19. 19.
    John C. Reynolds. Definitional interpreters for higher-order programming languages. In ACM Annual Conference, pages 717–740, 1972.Google Scholar
  20. 20.
    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.Google Scholar
  21. 21.
    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.Google Scholar
  22. 22.
    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.Google Scholar
  23. 23.
    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.Google Scholar
  24. 24.
    Mads Tofte and Lars Birkedal. A region inference algorithm. Transactions on Programming Languages and Systems, 20(4):724–767, 1998.CrossRefGoogle Scholar
  25. 25.
    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.Google Scholar
  26. 26.
    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.zbMATHCrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2000

Authors and Affiliations

  • Henry Cejtin
    • 1
  • Suresh Jagannathan
    • 2
  • Stephen Weeks
    • 3
  1. 1.Entertainment Decisions, Inc.USA
  2. 2.NEC Research InstituteUSA
  3. 3.Intertrust STAR LaboratoriesUSA

Personalised recommendations