Abstract
Lambda-lifting is a program transformation used in compilers and in partial evaluators and that operates in cubic time. In this article, we show how to reduce this complexity to quadratic time.
Lambda-lifting transforms a block-structured program into a set of recursive equations, one for each local function in the source program. Each equation carries extra parameters to account for the free variables of the corresponding local function and of all its callees. It is the search for these extra parameters that yields the cubic factor in the traditional formulation of lambda-lifting, which is due to Johnsson. This search is carried out by a transitive closure.
Instead, we partition the call graph of the source program into strongly connected components, based on the simple observation that all functions in each component need the same extra parameters and thus a transitive closure is not needed. We therefore simplify the search for extra parameters by treating each strongly connected component instead of each function as a unit, thereby reducing the time complexity of lambda-lifting from \( \mathcal{O}(n^3 log n) \) to \( \mathcal{O}(n^2 log n) \), where n is the size of the program.
Since a lambda-lifter can output programs of size \( \mathcal{O}(n^2 ) \), we believe that our algorithm is close to optimal.
An extended version of this article is available in the BRICS Research Series [14].
Basic Research in Computer Science (www.brics.dk), funded by the Danish National Research Foundation.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
References
Alfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman. Compilers: Principles, Techniques and Tools. Addison-Wesley, 1986. 148
Andrew W. Appel. Modern Compiler Implementation in {C, Java, ML}. Cambridge University Press, New York, 1998. 146
Andrew W. Appel. SSA is functional programming. ACM SIGPLAN Notices, 33(4):17–20, April 1998. 146
Andrew W. Appel and Trevor Jim. Continuation-passing, closure-passing style. In Michael J. O’Donnell and Stuart Feldman, editors, Proceedings of the Sixteent Annual ACM Symposium on Principles of Programming Languages, pages 293–302, Austin, Texas, January 1989. ACM Press. 145
Andrew W. Appel and David B. MacQueen. Standard ML of New Jersey. In Jan Małuszyński and Martin Wirsing, editors, Third International Symposium on Programming Language Implementation and Logic Programming, number 528 in Lecture Notes in Computer Science, pages 1–13, Passau, Germany, August 1991. Springer-Verlag. 145
Lennart Augustsson. A compiler for Lazy ML. In Guy L. Steele Jr., editor, Conference Record of the 1984 ACM Symposium on Lisp and Functional Programming, pages 218–227, Austin, Texas, August 1984. ACM Press. 134
Adam Bakewell and Colin Runciman. Automatic generalisation of function definitions. In Taisuke Sato, editors. Fourth Fuji International Symposium on Functional and Logic Programming, number 1722 in Lecture Notes in Computer Science, Tsukuba, Japan, November 1999. Springer-Verlag Middeldorp and Sato [23], pages 225–240. 135
Anders Bondorf and Olivier Danvy. Automatic autoprojection of recursive equations with global variables and abstract data types. Science of Computer Programming, 16:151–195, 1991. 135, 145
William Clinger and Lars Thomas Hansen. Lambda, the ultimate label, or a simple optimizing compiler for Scheme. In Talcott [33], pages 128–139. 135, 145, 147
Charles Consel. A tour of Schism: A partial evaluation system for higher-order applicative languages. In David A. Schmidt, editor, Proceedings of the Second ACM SIGPLAN Symposium on Partial Evaluation and Semantics-Based Program Manipulation, pages 145–154, Copenhagen, Denmark, June 1993. ACM Press. 135, 145
Ole-Johan Dahl, Bjørn Myhrhaug, and Kristen Nygaard. Simula: Common Base Language. Norwegian Computing Center, October 1970. 148
Olivier Danvy. An extensional characterization of lambda-lifting and lambda-dropping. In Taisuke Sato, editors. Fourth Fuji International Symposium on Functional and Logic Programming, number 1722 in Lecture Notes in Computer Science, Tsukuba, Japan, November 1999. Springer-Verlag Middeldorp and Sato [23], pages 241–250. Extended version available as the technical report BRICS RS-99-21. 147
Olivier Danvy and Ulrik P. Schultz. Lambda-dropping: Transforming recursive equations into programs with block structure. Theoretical Computer Science, 248(1–2):243–287, 2000. 145, 146
Olivier Danvy and Ulrik P. Schultz. Lambda-lifting in quadratic time. Technical Report BRICS RS-02-30, Department of Computer Science, University of Aarhus, Aarhus, Denmark, June 2002. 134
Adam Fischbach and John Hannan. Specification and correctness of lambda lifting. In Walid Taha, editor, Proceedings of the First Workshop on Semantics, Applications, and Implementation of Program Generation (SAIG 2000), number 1924 in Lecture Notes in Computer Science, pages 108–128, Montréal, Canada, September 2000. Springer-Verlag. 147
James Gosling, Bill Joy, and Guy Steele. The Java Language Specification. Addison-Wesley, 1996. 148
John Hughes. Super combinators: A new implementation method for applicative languages. In Daniel P. Friedman and David S. Wise, editors, Conference Record of the 1982 ACM Symposium on Lisp and Functional Programming, pages 1–10, Pittsburgh, Pennsylvania, August 1982. ACM Press. 134, 144
Thomas Johnsson. Lambda lifting: Transforming programs to recursive equations. In Jean-Pierre Jouannaud, editor, Functional Programming Languages and Computer Architecture, number 201 in Lecture Notes in Computer Science, pages 190–203, Nancy, France, September 1985. Springer-Verlag. 134, 137
Thomas Johnsson. Compiling Lazy Functional Languages. PhD thesis, Department of Computer Sciences, Chalmers University of Technology, Göteborg, Sweden, 1987. 137
Peter J. Landin. The mechanical evaluation of expressions. Computer Journal, 6:308–320, 1964. 145
Ole L. Madsen, Birger Møller-Pedersen, and Kristen Nygaard. Object-oriented programming in the Beta programming language. Addison-Wesley, Reading, MA, USA, 1993. 148
Karoline Malmkjær, Nevin Heintze, and Olivier Danvy. ML partial evaluation using set-based analysis. In John Reppy, editor, Record of the 1994 ACM SIGPLAN Workshop on ML and its Applications, Rapport de recherche N o 2265, INRIA, pages 112–119, Orlando, Florida, June 1994. Also appears as Technical report CMU-CS-94-129. 135, 145
Aart Middeldorp and Taisuke Sato, editors. Fourth Fuji International Symposium on Functional and Logic Programming, number 1722 in Lecture Notes in Computer Science, Tsukuba, Japan, November 1999. Springer-Verlag. 149
Simon L. Peyton Jones. An introduction to fully-lazy supercombinators. In Guy Cousineau, Pierre-Louis Curien, and Bernard Robinet, editors, Combinators and Functional Programming Languages, number 242 in Lecture Notes in Computer Science, pages 176–208, Val d’Ajol, France, 1985. Springer-Verlag. 144
Simon L. Peyton Jones. The Implementation of Functional Programming Languages. Prentice Hall International Series in Computer Science. Prentice-Hall International, 1987. 134, 138, 144, 145
John Reppy. Local CPS conversion in a direct-style compiler. In Amr Sabry, editor, Proceedings of the Third ACM SIGPLAN Workshop on Continuations, Technical report 545, Computer Science Department, Indiana University, pages 1–6, London, England, January 2001. 135, 147
André Santos. Compilation by transformation in non-strict functional languages. PhD thesis, Department of Computing, University of Glasgow, Glasgow, Scotland, 1996. 135
Ulrik P. Schultz. Object-Oriented Software Engineering Using Partial Evaluation. PhD thesis, University of Rennes I, Rennes, France, 2000. 148
Ulrik P. Schultz. Partial evaluation for class-based object-oriented languages. In Olivier Danvy and Andrzej Filinski, editors, Programs as Data Objects, Second Symposium, PADO 2001, number 2053 in Lecture Notes in Computer Science, pages 173–197, Aarhus, Denmark, May 2001. Springer-Verlag. 148
Ulrik P. Schultz, Julia Lawall, Charles Consel, and Gilles Muller. Towards automatic specialization of Java programs. In Rachid Guerraoui, editor, Proceedings of the European Conference on Object-oriented Programming (ECOOP’99), volume 1628 of Lecture Notes in Computer Science, pages 367–390, Lisbon, Portugal, June 1999. Springer-Verlag. 148
Zhong Shao and Andrew W. Appel. Space-efficient closure representations. In Talcott [33], pages 150–161. 145
Paul A. Steckler and Mitchell Wand. Lightweight closure conversion. ACM Transactions on Programming Languages and Systems, 19(1):48–86, 1997. 147
Carolyn L. Talcott, editor. Proceedings of the 1994 ACM Conference on Lisp and Functional Programming, LISP Pointers, Vol. VII, No. 3, Orlando, Florida, June 1994. ACM Press. 149, 151
Mitchell Wand. From interpreter to compiler: a representational derivation. In Harald Ganzinger and Neil D. Jones, editors, Programs as Data Objects, number 217 in Lecture Notes in Computer Science, pages 306–324, Copenhagen, Denmark, October 1985. Springer-Verlag. 147
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2002 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Danvy, O., Schultz, U.P. (2002). Lambda-Lifting in Quadratic Time. In: Hu, Z., RodrÃguez-Artalejo, M. (eds) Functional and Logic Programming. FLOPS 2002. Lecture Notes in Computer Science, vol 2441. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-45788-7_8
Download citation
DOI: https://doi.org/10.1007/3-540-45788-7_8
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-44233-2
Online ISBN: 978-3-540-45788-6
eBook Packages: Springer Book Archive