Hostname: page-component-cd9895bd7-jkksz Total loading time: 0 Render date: 2024-12-21T16:57:18.387Z Has data issue: false hasContentIssue false

Safe fusion of functional expressions II: Further improvements

Published online by Cambridge University Press:  07 November 2008

Wei-Ngan Chin
Affiliation:
Department of Information Systems and Computer Science, National University of Singapore, Singapore 0511 (Email: chinwn@iscs.nus.sg)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

Large functional programs are often constructed by decomposing each big task into smaller tasks which can be performed by simpler functions. This hierarchical style of developing programs has been found to improve programmers' productivity because smaller functions are easier to construct and reuse. However, programs written in this way tend to be less efficient. Unnecessary intermediate data structures may be created. More function invocations may be required.

To reduce such performance penalties, Phil Wadler proposed a transformation algorithm, called deforestation, which could automatically fuse certain composed expressions together to eliminate intermediate tree-like data structures. However, his technique is currently safe (terminates with no loss of efficiency) for only a subset of first-order expressions.

This paper will generalise the deforestation technique to make it safe for all first-order and higher-order functional programs. Our generalisation is explained using a model for safe fusion which views each function as a producer and its parameters as consumers. Through this model, syntactic program properties are proposed to classify producers and consumers as either safe or unsafe. This classification is used to identify sub-terms that can be safely fused/eliminated. We present the generalised transformation algorithm, illustrate it with examples and provide a termination proof for the transformation algorithm of first-order programs. This paper also contains a suite of additional techniques to further improve the basic safe fusion method. These improvements could be viewed as enhancements to compensate for some inadequacies of the syntactic analyses used.

Type
Articles
Copyright
Copyright © Cambridge University Press 1994

References

Augustsson, L (1985) Compiling pattern-matching. In: Conference on Functional Programming and Computer Architecture (LNCS 201, ed Jouannaud), pp. 368381, Nancy, France.CrossRefGoogle Scholar
Burstall, R. R & Darlington, J. (1977) A transformation system for developing recursive programs. J. ACM, 24(1): 4467, 01.CrossRefGoogle Scholar
Bjorner, D, Ershov, A. P. & Jones, N. D. (1988) Workshop on Partial Evaluation and Mixed Computations. Gl Avarnes, Denmark. North-Holland.Google Scholar
Chin, W.-N. & Darlington, J. (1992) Higher-order removal transformation technique for functional programs. In: 15th Australian Computer Science Conf.,Hobart, Tasmania. Australian CS Comm., 141:181194.)Google Scholar
Chin, W.-N. (1990) Automatic Methods for Program Transformation. PhD thesis, Imperial College, University of London, 03.Google Scholar
Chin, W.-N. (1991) Generalising deforestation for all first-order functional programs. In: Workshop on Static Analysis of Equational, Functional and Logic Programming Languages, BIGRE 74, pp. 173181, Bordeaux, France, 10.Google Scholar
Chin, W.-N. (1992 a) Safe fusion of functional expressions. In: 7th ACM Lisp and Functional Programming Conf. pp. 1120, San Francisco, CA, 06.CrossRefGoogle Scholar
Chin, W.-N. (1992) Synthesizing parallel lemma. In: Proc. JSPS Seminar on Parallel Programming Systems, World Scientific Publishing, pp. 201217, Tokyo, Japan, 05.Google Scholar
Chin, W.-N. (1993) Towards an automated tupling strategy. In: 3rd ACM Symposium on Partial Evaluation and Semantics-Based Program Manipulation,ACM Press, pp. 119132, Copenhagen, Denmark, 06.CrossRefGoogle Scholar
Chin, W.-N. & Khoo, S.-C. (1993) Tupling functions with multiple recursion parameters. In: 3rd Int. Workshop on Static Analysis: LNCS 724, Springer-Verlag, pp. 124140, Padova, Italy, 09.CrossRefGoogle Scholar
Consel, C (1990) Binding time analysis for higher-order untyped functional languages. In: 6th ACM Conf. on Lisp and Functional Programming, pp. 264272, 06.Google Scholar
Feather, M. S. (1982) A system for assisting program transformation. ACM Trans. Programming Languages & Systems, 4(1): 120, 01.CrossRefGoogle Scholar
Ferguson, A. B. & Wadler, P. (1988) When will deforestation stop? In: Proc. Glasgow Workshop on Functional Programming (available as Research Report 89/R4, Glasgow University), pp. 3956, Rothesay, Isle of Bute, 08.Google Scholar
Holst, C. K. (1991) Finiteness analysis. In: 5th ACM Conf. on Functional Programming Languages and Computer Architecture, pp. 473495, Cambridge, MA, 08.CrossRefGoogle Scholar
Jones, N. D. (1988) Automatic program specialisation: A re-examination from basic principles. In: Workshop on Partial Evaluation and Mixed Computations, pp. 225282, Gl Avarnes, Denmark. North-Holland.Google Scholar
Jones, N. D., Sestoft, P. & Sondergaard, H. (1989) An experiment in partial evaluation: the generation of a compiler generator. J. LISP and Symbolic Computation, 2(1): 950.CrossRefGoogle Scholar
Milner, R. (1978) A theory of type polymorphism. J. Comp. & Syst. Sci., 348375.CrossRefGoogle Scholar
Proietti, M. & Pettorossi, A. (1991) Unfolding - definition - folding, in this order for avoiding unnecessary variables in logic programs. In: Proc. PLILP'91; LNCS 528, pp. 347358, Passau, Germany, 08.Google Scholar
Runciman, C, Firth, M. & Jagger, N. (1989) Transformation in a non-strict language: An approach to instantiation. In: Glasgow Functional Programming Workshop, 08.Google Scholar
Sands, D. (1990) Complexity analysis for a lazy higher-order language. In: 3rd Euro. Symposium on Programming: LNCS 432, pp. 361376, Copenhagen, Denmark, 05.Google Scholar
Sestoft, P. (1988) Automatic call unfolding in a partial evaluator. In: Workshop on Partial Evaluation and Mixed Computations, pp. 485506, Gl Avarnes, Denmark. North-Holland.Google Scholar
Turchin, V. F. (1986) The concept of a supercompiler. ACM Trans. Programming Languages & Systems, 8(3): 90121, 07.CrossRefGoogle Scholar
Turchin, V. F. (1988) The algorithm of generalisation in the supercompiler. In: Workshop on Partial Evaluation and Mixed Computations, pp. 531549, Gl Avarnes, Denmark. North-Holland.Google Scholar
Wadler, P. (1984) Listlessness is better than laziness: Lazy evaluation and garbage collection at compile-time. In: ACM Symposium on Lisp and Functional Programming, pp. 4552, Austin, TX, 08.Google Scholar
Wadler, P. (1985) Listlessness is better than laziness II: Composing listless functions. In: Workshop on Programs as Data Objects, pp. 282305, Springer-Verlag, New York.Google Scholar
Wadler, P. (1987) Efficient compilation of pattern-matching. In: S., Peyton-Jones (ed.), The Implementation of Functional Programming Languages. Prentice-Hall.Google Scholar
Wadler, P. (1988) Deforestation: Transforming programs to eliminate trees. In: Euro. Symposium on Programming, pp 344358, Nancy, France, 03.Google Scholar
Waters, R. C. (1991) Automatic transformation of series expressions into loops. ACM Trans. Programming Languages & Systems, 13(1): 5298, 01.CrossRefGoogle Scholar
Submit a response

Discussions

No Discussions have been published for this article.