# closure conversion

## closure conversion

(theory)
The transformation of continuation passing style code so that the only free variables of functions are names of other functions.

Mentioned in ?
References in periodicals archive ?
The goal of closure conversion is to choose closure representations that minimize stores (for closure creation), fetches (to access free variables), and memory use (for reachable data).
The main contribution of this paper is an efficient and safe-for-space closure conversion algorithm that integrates and improves most previous closure-analysis technique [Kranz 1987; Appel and Shao 1992; Steele 1978; Rozas 1984; Hanson 1990; Johnsson 1985] using a simple and general framework expressed in continuation-passing and closure-passing style [Appel and Jim 1989; Appel and Shao 1992].
fun iter(x,p,f) = let fun h(a,r) = if p(a,r) then a else h(f(a),a) in h(x,1) end We use CPS as the intermediate language for closure conversion because we want to treat all activation records as continuation closures.
Function iter after closure conversion. 01 fun iter(I,C0,C1,C2,C3,x,p,f) = 02 let fun h(a,r,CR,p) = 03 let fun J0(J1,J2,J3,z) = 04 if z then 05 let val C0 = select(0,J1) 06 val C1 = select(1,J1) 07 val C2 = select(2,J1) 08 val C3 = select(3,J1) 09 in C0(C1,C2,C3,J2) 10 end 11 else 12 let fun Q0(Q1,Q2,Q3,b) 13 = h(b,Q2,Q1,Q3) 14 val f = select(4,CR) 15 val f0 = select(0,f) 16 in f0(f,Q0,J1,J2,J3,J2) 17 end 18 val p0 = select(0,p) 19 in p0(p,J0,CR,a,p,a,r) 20 end 21 val CR = (C0,C1,C2,C3,f) 22 in h(x,1,CR,p) 23 end The original function J (in Figure 6) had free variables C, f, a, h.
EDA funds may be made available to assist a community with base closure conversion or realignment.
An optimizing compiler for a high-level language such as ML may make as many as 20 passes over a single program, performing sophisticated analyses and transformations such as CPS conversion, closure conversion, unboxing, subsumption elimination, or region inference.
The second compilation stage is closure conversion, which makes closures explicit, thereby separating program code from data.
We begin with closure conversion proper; the hoisting step is considered in Section 5.2.
Although the operational explanation of closure conversion is quite simple, there are a number of subtle issues involved in type-checking the resulting code.
We consider the problem of lightweight closure conversion, in which multiple procedure call protocols may coexist in the same code.
Additional Key Words and Phrases: Closure conversion, compiler construction, global optimization/flow analysis, program transformations
Here we study one such transformation, called closure conversion. In a lexically scoped higher-order language, a procedure is typically represented by a record consisting of a piece of pure code (a closed [lambda]-abstraction) and the values of the free variables of the original procedure (an environment).

Site: Follow: Share:
Open / Close