From interpreting to compiling binding times
- 269 Downloads
The key to realistic self-applicable partial evaluation is to analyze binding times in the source program, i.e., whether the result of partially evaluating a source expression is static or dynamic, given a static/dynamic division of the input. Source programs are specialized with respect to the static part of their input. When a source expression depends on the concrete result of specializing another expression, the binding time of this other expression is first interpreted. A safe approximation of these abstract values is computed by binding time analysis.
This paper points out that this value-based information can be compiled into control-based directives driving the specializer as to what to do for each expression — instead of how to use the result of partially evaluating an expression. This compilation is achieved by a non-standard interpretation of the specialization semantics, based on the observation that a source expression is either reduced or rebuilt. The result is an action trees isomorphic to the abstract syntax tree of the source program. This approach suggests to reorganize the specializer so that it is driven first by the action tree and then by the abstract syntax tree — instead of performing first a syntax analysis and then interpreting binding times.
Some subtrees imply the corresponding expressions to be completely reduced or completely rebuilt. These expressions are completely evaluated or reproduced verbatim. This suggests to refine the specializer so that it evaluates, reduces, rebuilds, or reproduces source expressions. This also suggests a more radical implementation.
By pruning the source program based on its action trees, we extract combinators for each subtree that should be evaluated completely or reproduced verbatim. By implementing these combinators as runtime operators, we prune the text of the partial evaluator that was dedicated to evaluating or reproducing source expressions using symbolic interpretation. Because source programs are smaller, they can be specialized faster. Because half of the specializer disappears, it is smaller and faster too. For these compound reasons self-application performs better.
As a result, more processing is shifted away from the actual specializer. A pleasing symmetry appears in the actual specialization process. Its significance, e.g., in the structure of compilers generated by self-application, remains to be explored.
Keywordspartial evaluation self-application actions combinators
- [Bondorf et al. 88]Anders Bondorf, Neil D. Jones, Torben Æ. Mogensen, Peter Sestoft: Binding Time Analysis and the Taming of Self-Application, to appear in TOPLAS, DIKU, University of Copenhagen, Denmark (1988)Google Scholar
- [Consel & Danvy 89]
- [Consel 89]Charles Consel: Analyse de Programme, Evaluation Partielle, et Génération de Compilateurs, PhD thesis, University of Paris VI, Paris, France (June 1989)Google Scholar
- [Consel 90]Charles Consel: Higher Order Partial Evaluation with Data Structures, Working paper, Computer Science Department, Yale University, New Haven, Connecticut (January 1990)Google Scholar
- [Consel & Danvy 90]Charles Consel, Olivier Danvy: Static and Dynamic Semantics Processing, Technical Report 761, Computer Science Department, Yale University, New Haven, Connecticut (November 1989)Google Scholar
- [Danvy 89]Olivier Danvy: Avoiding Name Clashes during Self-Applicable Partial Evaluation, Working paper, Computer Science Department, Indiana University, Bloomington, Indiana (fall 1989)Google Scholar
- [Jones & Muchnick 78]Neil D. Jones, Steven S. Muchnick: TEMPO: A Unified Treatment of Binding Time Parameter Passing Concepts in Programming Languages, G. Goos & J. Hartmanis (eds.), Lecture Notes in Computer Science No 66, Springer-Verlag (1978)Google Scholar
- [Jones et al. 89]Neil D. Jones, Peter Sestoft, Harald Søndergaard: MIX: a Self-Applicable Partial Evaluator for Experiments in Compiler Generation, Vol. 2, No 1 pp 9–50 of the International Journal LISP and Symbolic Computation (1989)Google Scholar
- [Jones & Nielsen 89]Neil D. Jones, Flemming Nielsen: Abstract Interpretation: a Semantics-Based Tool for Program Analysis, to appear in the Handbook of Logic and Computer Science, University of Copenhagen and Aarhus University, Denmark (1989)Google Scholar
- [Nielsen & Nielsen 88]Flemming Nielsen, Hanne R. Nielsen: Automatic Binding Time Analysis for a Typed Lambda-Calculus, proceedings of the ACM Symposium on Principles of Programming Languages pp 98–106 (1988)Google Scholar
- [Rees & Clinger 86]Jonathan Rees, William Clinger (eds.): Revised 3 Report on the Algorithmic Language Scheme, Sigplan Notices, Vol. 21, No 12 pp 37–79 (December 1986)Google Scholar
- [Sestoft 86]Peter Sestoft: The Structure of a Self-Applicable Partial Evaluator, pp 236–256 of Programs as Data Objects, Harald Ganzinger and Neil D. Jones (eds.), Lecture Notes in Computer Science No 217, Springer-Verlag (1986)Google Scholar
- [Wand 82]Mitchell Wand: Semantics-Directed Machine Architecture, proceedings of the ACM Symposium on Principles of Programming Languages pp 234–241 (1982)Google Scholar