Twobit Pass 4: closure conversion.

Twobit represents procedures and environments as specially tagged arrays whose elements contain code, cells for global variables mentioned by the code, the values of constants and non-global free variables mentioned by the code, and a static link to another environment. Each such array is called a rib.

Lambda lifting results in flat or nearly flat closures. Static measurements from Twobit compiling itself show that over 90% of the sites that create a closure create a flat closure with only 1 rib. Over 98% of these sites create a closure that contain only 1 or 2 ribs. It does not appear worthwhile to use display closures as in Chez Scheme, since they are advantageous only for closures with 3 or more ribs.

Twobit generates code to close every lambda expression, but multiple lambda expressions often share a closure. Twobit generates code to create a closure whenever: