Abstract: Flow-Based Function Representation Transformation

When implementing function-oriented languages (e.g., Haskell, LISP, ML, and Scheme), first-class functions have generally been represented by closures, data structures which pair a pointer to machine code with an environment containing the values of the free variables of the function. A compiler implements this with a closure conversion phase, which usually has been constrained to choose a single kind of closure and to represent all functions this way. This is limiting because there are many kinds of closures. Also, there are important alternatives to closures: the code of a function can sometimes be inlined at call sites and the environment can sometimes be reconstructed at the call sites (lightweight closure conversion).

This talk describes a more general representation transformation compiler phase which simultaneously implements many different customized function representations. This phase is being implemented in an experimental compiler for Standard ML. Flow and type information is used to guide the transformation so that conflicting function representations do not interfere with each other. Intersection and union types support polyvariant flow information for greater flexibility. Function creation forms and call sites are automatically duplicated if required to support incompatible representations. The transformation does standard closure conversion and lightweight closure conversion, as well as flow-directed inlining.