Inlining as staged computation

Inlining and specialization appear in various forms throughout the implementation of modern programming languages. From mere compiler optimizations to sophisticated techniques in partial evaluation, they are omnipresent, yet each application is treated differently. This paper is an attempt at uncovering the relations between inlining (as done in production compilers) and staged computation (as done in partial evaluators) in the hope of bringing together the research advances in both fields. Using a two-level lambda calculus as the intermediate language, we show how to model inlining as a staged computation while avoiding unnecessary code duplication. The new framework allows us to define inlining annotations formally and to reason about their interactions with module code. In fact, we present a cross-module inlining algorithm that inlines all functions marked inlinable, even in the presence of ML-style parameterized modules.

[1]  ScienceYale UniversityNew Haven An Overview of the Flint/ml Compiler , 1997 .

[2]  Lars Birkedal,et al.  Binding-time analysis for Standard ML , 1994, LISP Symb. Comput..

[3]  Walid Taha,et al.  An Idealized MetaML: Simpler, and More Expressive , 1999, ESOP.

[4]  X. Leroy Le système Caml Special Light: modules et compilation efficace en Caml , 1995 .

[5]  Amr Sabry,et al.  Macros as multi-stage computations: type-safe, generative, binding macros in MacroML , 2001, ICFP '01.

[6]  Alexander Aiken,et al.  A theory of type qualifiers , 1999, PLDI '99.

[7]  Simon L. Peyton Jones,et al.  Secrets of the Glasgow Haskell Compiler inliner , 2002, Journal of Functional Programming.

[8]  Mark P. Jones A Theory of Qualified Types , 1992, ESOP.

[9]  Kenichi Asai Binding-Time Analysis for Both Static and Dynamic Expressions , 1999, SAS.

[10]  Andrew W. Appel,et al.  Compiling with Continuations , 1991 .

[11]  John C. Reynolds,et al.  Towards a theory of type structure , 1974, Symposium on Programming.

[12]  Olin Shivers,et al.  Control-flow analysis of higher-order languages of taming lambda , 1991 .

[13]  Charles Consel,et al.  A general approach for run-time specialization and its application to C , 1996, POPL '96.

[14]  Fritz Henglein,et al.  Polymorphic Binding-Time Analysis , 1994, ESOP.

[15]  Xavier Leroy,et al.  Unboxed objects and polymorphic typing , 1992, POPL '92.

[16]  Amr Sabry,et al.  The essence of compiling with continuations , 1993, PLDI '93.

[17]  Rowan Davies,et al.  A temporal-logic approach to binding-time analysis , 1995, Proceedings 11th Annual IEEE Symposium on Logic in Computer Science.

[18]  Zhong Shao,et al.  Optimal Type Lifting , 1998, Types in Compilation.

[19]  Zhong Shao Transparent modules with fully syntatic signatures , 1999, ICFP '99.

[20]  Charles Consel,et al.  Polyvariant binding-time analysis for applicative languages , 1993, PEPM '93.

[21]  Philip Wadler,et al.  How to make ad-hoc polymorphism less ad hoc , 1989, POPL '89.

[22]  FlanaganCormac,et al.  The essence of compiling with continuations , 1993 .

[23]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[24]  Andrew W. Appel,et al.  Standard ML of New Jersey , 1991, PLILP.

[25]  Simon L. Peyton Jones,et al.  Imperative functional programming , 1993, POPL '93.

[26]  Peter Thiemann,et al.  Two for the price of one: composing partial evaluation and compilation , 1997, PLDI '97.

[27]  David Tarditi,et al.  Design and Implementation of Code Optimizations for a Type-Directed Compiler for Standard ML. , 1996 .

[28]  Zhong Shao Flexible representation analysis , 1997, ICFP '97.

[29]  Walid Taha,et al.  Multi-stage programming with explicit annotations , 1997 .

[30]  Jacques Garrigue,et al.  On the runtime complexity of type-directed unboxing , 1998, ICFP '98.

[31]  Frank Pfenning,et al.  A modal analysis of staged computation , 1996, POPL '96.

[32]  J. Ferrante,et al.  Proceedings of the 15th ACM SIGPLAN-SIGACT symposium on Principles of programming languages , 1988 .

[33]  Jens Palsberg,et al.  Eta-expansion does The Trick , 1995, TOPL.

[34]  J. Y. Girard,et al.  Interpretation fonctionelle et elimination des coupures dans l'aritmetique d'ordre superieur , 1972 .

[35]  Eugenio Moggi,et al.  A categorical account of two-level languages , 1997, MFPS.

[36]  Walid Taha,et al.  Multi-stage programming with explicit annotations , 1997, PEPM.

[37]  Mark P. Jones A Theory of Qualified Types , 1994, Sci. Comput. Program..

[38]  Olivier Danvy,et al.  Type-directed partial evaluation , 1995, POPL '96.

[39]  J. Michael Ashley The effectiveness of flow analysis for inlining , 1997, ICFP '97.

[40]  Peter J. Stuckey,et al.  Boolean Constraints for Binding-Time Analysis , 2001, PADO.

[41]  Charles Consel,et al.  Efficient incremental run-time specialization for free , 1999, PLDI '99.

[42]  Robert Harper,et al.  Compiling polymorphism using intensional type analysis , 1995, POPL '95.

[43]  Flemming Nielson,et al.  Two-level functional languages , 1992, Cambridge tracts in theoretical computer science.

[44]  Zhong Shao,et al.  Implementing typed intermediate languages , 1998, ICFP '98.

[45]  John C. Mitchell,et al.  Higher-order modules and the phase distinction , 1989, POPL '90.

[46]  Walid Taha,et al.  Multi-Stage Programming: Its Theory and Applications , 1999 .

[47]  Peter Thiemann,et al.  Realistic compilation by partial evaluation , 1996, PLDI '96.

[48]  Zhong Shao Typed cross-module compilation , 1998, ICFP '98.

[49]  Robin Milner,et al.  Definition of standard ML , 1990 .

[50]  Andrew W. Appel,et al.  Lambda-splitting: a higher-order approach to cross-module optimizations , 1997, ICFP '97.

[51]  Eugenio Moggi,et al.  Computational lambda-calculus and monads , 1989, [1989] Proceedings. Fourth Annual Symposium on Logic in Computer Science.