Typed closure conversion

Yasuhiko Minamide, Greg Morrisett, Robert Harper

1996 · 209 citations · 30 references

DOIFull text

Open access

Concepts

TL;DR

Closure conversion is a program transformation used by compilers to separate code from data; previous accounts use only untyped target languages, but recent studies show that translating to typed target languages enables efficient data representations, calling conventions, and tag‑free garbage collection. We present closure conversion as a type‑directed, type‑preserving translation for both the simply‑typed and polymorphic λ‑calculus, facilitating security, debugging, and correctness arguments through automatic type checking and logical relations. Our translations are based on a simple “closures as objects” principle, viewing higher‑order functions as objects with a single method and environment; in the simply‑typed case we use the Pierce‑Turner model of object typing with existential packages, while in the polymorphic case we employ a variant of the Harper‑Lillibridge translucent type formalism to track type sharing.

Abstract

Closure conversion is a program transformation used by compilers to separate code from data. Previous accounts of closure conversion use only untyped target languages. Recent studies show that translating to typed target languages is a useful methodology for building compilers, because a compiler can use the types to implement efficient data representations, calling conventions, and tag-free garbage collection. Furthermore, type-based translations facilitate security and debugging through automatic type checking, as well as correctness arguments through the method of logical relations.We present closure conversion as a type-directed, and type-preserving translation for both the simply-typed and the polymorphic λ-calculus. Our translations are based on a simple "closures as objects" principle: higher-order functions are viewed as objects consisting of a single method (the code) and a single instance variable (the environment). In the simply-typed case, the Pierce-Turner model of object typing where objects are packages of existential type suffices. In the polymorphic case, more careful tracking of type sharing is required. We exploit a variant of the Harper-Lillibridge "translucent type" formalism to characterize the types of polymorphic closures.

References

30