Higher-order functions and the ability to create new functions at runtime, either by partial application or λ-abstraction of existing functions, are important features of functional languages. Since these runtime-created functions may outlive their creating functions, it is necessary to represent all functional parameters by closures in a memory area which is not affected by the termination of function calls, i.e. in a heap component. Such a closure contains the original function, which may be a closure again, and the bindings of the parameters used (by the partial application). It many cases, however, it is possible to avoid this expensive heap allocation and use the run-time stack or even statically allocated closures. Often a closure created for a partial application is used only locally and will never be part of the result of the creating function. In these cases, the closure may be allocated on the stack. This approach is feasible in eager and lazy languages. If we can additionally ensure that there will never be more than one incarnation of a partial application, a closure can be allocated statically. In order to use this optimisation in lazy languages, we have to perform a strictness analysis first. We develop an abstract interpretation for the detection of inheritance information which allows us to decide whether the heap cells of an argument may be propagated to the result of a function call (i.e. are part of the result). Furthermore we give a criterion for checking whether there will be always only one incarnation of a certain partial application during runtime. In order to increase efficiency, we show how the number of recomputations can be decreased by using only parts of the abstract domains. The worst case time complexity is essentially quadratic in the size of the program. We illustrate the method developed in this paper with several examples. Correctness of the analysis is considered, using a modified denotational semantics as reference point. The main goal of our work is to keep both the run-time and the compile-time overhead as small as possible.
[1]
Philip Wadler,et al.
Deforestation: Transforming Programs to Eliminate Trees
,
1988,
Theoretical Computer Science.
[2]
Thomas Johnsson,et al.
Lambda Lifting: Treansforming Programs to Recursive Equations
,
1985,
FPCA.
[3]
Markus Mohnen.
Efficient Compile-Time Garbage Collection for Arbitrary Data Structures
,
1995,
PLILP.
[4]
Samson Abramsky,et al.
Strictness analysis and polymorphic invariance
,
1985,
Programs as Data Objects.
[5]
John Hughes,et al.
Abstract Interpretation of Polymorphic Functions
,
1989,
Functional Programming.
[6]
Simon L. Peyton Jones,et al.
A short cut to deforestation
,
1993,
FPCA '93.
[7]
Alan Mycroft,et al.
The Theory and Practice of Transforming Call-by-need into Call-by-value
,
1980,
Symposium on Programming.
[8]
Benjamin Goldberg,et al.
Higher Order Escape Analysis: Optimizing Stack Allocation in Functional Program Implementations
,
1990,
ESOP.
[9]
Simon Hughes,et al.
Compile-Time Garbage Collection for Higher-Order Functional Languages
,
1992,
J. Log. Comput..
[10]
R. J. M. Hughes,et al.
Design and Implementation of Programming Languages
,
1977,
Lecture Notes in Computer Science.
[11]
Daniel Le Métayer,et al.
Computer-Time Garbage Collection by Sharing Analysis
,
1989,
FPCA.