A positive supercompiler

We introduce a positive supercompiler, a version of Turchin's supercompiler maintaining only positive information during transformation, and using folding without generalization. The positive supercompiler can also be regarded as a variant of Wadler's deforestation maintaining an increased amount of information. We compare our algorithm to deforestation and, in less detail, to partial evaluation, Turchin's supercompiler, Generalized Partial Computation (GPC), and partial deduction by classifying these transformers by the amount of information they maintain during transformation. This factor is significant, as a differentiating example reveals: positive supercompilation, Turchin's supercompiler, GPC and partial deduction can specialize a general pattern matcher with respect to a fixed pattern to obtain an efficient matcher very similar to the Knuth-Morris-Pratt algorithm. Deforestation and traditional partial evaluation achieve this effect only after a non-trivial hand rewriting of the general matcher. Capsule Review Supercompilation is a technique of function transformation developed originally by Turchin (1986) for a functional language Refal. The technique uses DRIVING (the forced unfolding guided by functional configurations) to construct a potentially infinite tree of states (configurations) and transitions. This tree is then converted into a self-sufficient graph by reducing some of the configurations to their predecessors, which is similar to folding, or creating new configurations by generalization and redoing the driving. Supercompilation has been shown to do partial evaluation and deforestation, as well as more difficult transformations. Sorensen, Gliick and Jones present and discuss the essential features of supercompilation, using a simplified version of the supercompiler which they call POSITIVE. The reason for this name is that the information which is propagated through the graph during driving includes only POSITIVE elements, i.e. statements that a variable matches a certain pattern, while the NEGATIVE statements that a variable does not match a pattern (which are propagated in Turchin's supercompiler as RESTRICTIONS) are not taken along. Generalization is also not done in the positive supercompiler. These simplifications allow the authors to present supercompilation in more traditional formalism and in more detail, as well as compare it with similar techniques: partial evaluation, deforestation and generalized partial computation. The authors consider in detail one wellknown example of program transformation: the transformation of a naive string matcher by specializing it for a given specific pattern into an efficient algorithm known as KMP (it became a kind of standard test in partial evaluation and similar techniques). They show that while supercompilation (both full and positive) and generalized partial computation solve the problem, 'regular' partial evaluation and deforestation cannot do this without a non-trivial modification in the original unspecialized matcher. 812 M. H. Sorensen, R. Gltick and N. D. Jones

[1]  Martin S. Feather,et al.  A System for Assisting Program Transformation , 1982, TOPL.

[2]  Philip Wadler,et al.  When Will Deforestation Stop , 1988 .

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

[4]  Akihiko Takano,et al.  Generalized partial computation for a lazy functional language , 1991, PEPM '91.

[5]  Robert Glück,et al.  Generating Transformers for Deforestation and Supercompilation , 1994, SAS.

[6]  Valentin F. Turchin,et al.  Semantic definitions in REFAL and the automatic production of compilers , 1980, Semantics-Directed Compiler Generation.

[7]  Neil D. Jones The Essence of Program Transformation by Partial Evaluation and Driving , 1994, Logic, Language and Computation.

[8]  Luc Maranget,et al.  Compiling lazy pattern matching , 1992, LFP '92.

[9]  David Sands,et al.  Proving the Correctness of Recursion-Based Automatic Program Transformations , 1995, Theor. Comput. Sci..

[10]  Valentin F. Turchin,et al.  The concept of a supercompiler , 1986, TOPL.

[11]  Olivier Danvy,et al.  For a Better Support of Static Data Flow , 1991, FPCA.

[12]  Morten Heine B. Sorensen,et al.  Turchin's Supercompiler Revisited - An operational theory of positive information propagation , 1996 .

[13]  Helmut Seidl Integer Constraints to Stop Deforestation , 1996, ESOP.

[14]  J. W. Lloyd Logic Programming, Proceedings of the 1995 International Symposium, Portland, Oregon, USA, December 4-7, 1995 , 1995, ILPS.

[15]  Pierre Deransart,et al.  Programming Languages Implementation and Logic Programming , 1989, Lecture Notes in Computer Science.

[16]  Valentin F. Turchin,et al.  Experiments with a supercompiler , 1982, LFP '82.

[17]  Robert Glück,et al.  Partial Deduction and Driving are Equivalent , 1994, PLILP.

[18]  Simon L. Peyton Jones,et al.  The Implementation of Functional Programming Languages , 1987 .

[19]  John Launchbury,et al.  A natural semantics for lazy evaluation , 1993, POPL '93.

[20]  Matthias Felleisen,et al.  A call-by-need lambda calculus , 1995, POPL '95.

[21]  Robert Glück,et al.  Occam's Razor in Metacompuation: the Notion of a Perfect Process Tree , 1993, WSA.

[22]  Donald A. Smith,et al.  Partial evaluation of pattern matching in constraint logic programming languages , 1991, PEPM '91.

[23]  Morten Heine Sørensen,et al.  Call-By-Name CPS-Translation as a Binding-Time Improvement , 1995, SAS.

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

[25]  V. F. Turchin,et al.  A supercompiler system based on the language REFAL , 1979, SIGP.

[26]  Peter Sestoft,et al.  Automatic call unfolding in a partial evaluator , 1987 .

[27]  Jan Komorowski,et al.  An Introduction to Partial Deduction , 1992, META.

[28]  Robert Glück,et al.  Application of metasystem transition to function inversion and transformation , 1990, ISSAC '90.

[29]  Wei-Ngan Chin Safe fusion of functional expressions , 1992, LFP '92.

[30]  Yoshihiko Futamura Program Evaluation and Generalized Partial Computation , 1988, FGCS.

[31]  Morten Heine Sørensen,et al.  Grammar-Based Data-Flow Analysis to Stop Deforestation , 1994, CAAP.

[32]  Richard S. Bird,et al.  Introduction to functional programming , 1988, Prentice Hall International series in computer science.

[33]  Donald E. Knuth,et al.  Fast Pattern Matching in Strings , 1977, SIAM J. Comput..

[34]  Robert Glück,et al.  An Algorithm of Generalization in Positive Supercompilation , 1995, ILPS.

[35]  John W. Lloyd,et al.  Partial Evaluation in Logic Programming , 1991, J. Log. Program..

[36]  Olivier Danvy,et al.  Partial Evaluation of Pattern Matching in Strings , 1989, Inf. Process. Lett..

[37]  Philip Wadler,et al.  Deforestation: Transforming Programs to Eliminate Trees , 1990, Theor. Comput. Sci..

[38]  David Sands,et al.  Total correctness by local improvement in program transformation , 1995, POPL '95.

[39]  John Darlington,et al.  A Transformation System for Developing Recursive Programs , 1977, J. ACM.

[40]  Alberto Pettorossi,et al.  Unfolding - Definition - Folding, in this Order, for Avaoiding Unnecessary Variables in Logic Programs , 1991, PLILP.

[41]  Akihiko Takano Generalized partial computation for a lazy functional language , 1991 .

[42]  Geoff W. Hamilton,et al.  Compile-time optimisation of store usage in lazy functional programs , 1993 .