Closure Conversion, Flat Environments, and the Complexity of Abstract Machines

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Accattoli, Beniamino, Ghica, Dan, Guerrieri, Giulio, Lourenço, Cláudio Belo, Coen, Claudio Sacerdoti
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866913951389843456
author Accattoli, Beniamino
Ghica, Dan
Guerrieri, Giulio
Lourenço, Cláudio Belo
Coen, Claudio Sacerdoti
author_facet Accattoli, Beniamino
Ghica, Dan
Guerrieri, Giulio
Lourenço, Cláudio Belo
Coen, Claudio Sacerdoti
contents Closure conversion is a program transformation at work in compilers for functional languages to turn inner functions into global ones, by building closures pairing the transformed functions with the environment of their free variables. Abstract machines rely on similar and yet different concepts of closures and environments. In this paper, we study the relationship between the two approaches. We adopt a very simple λ-calculus with tuples as source language and study abstract machines for both the source language and the target of closure conversion. Moreover, we focus on the simple case of flat closures/environments, that is, with no sharing of environments. We provide three contributions. Firstly, a new simple proof technique for the correctness of closure conversion, inspired by abstract machines. Secondly, we show how the closure invariants of the target language allow us to design a new way of handling environments in abstract machines, not suffering the shortcomings of other styles. Thirdly, we study the machines from the point of view of time complexity, adapting analyses by Accattoli and co-authors. We show that closure conversion decreases various dynamic costs while increasing the size of the initial code. Despite these changes, the overall complexity of the machines before and after closure conversion turns out to be the same.
format Preprint
id arxiv_https___arxiv_org_abs_2507_15843
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Closure Conversion, Flat Environments, and the Complexity of Abstract Machines
Accattoli, Beniamino
Ghica, Dan
Guerrieri, Giulio
Lourenço, Cláudio Belo
Coen, Claudio Sacerdoti
Programming Languages
D.3.1; F.3.1; F.3.2; D.2.4
Closure conversion is a program transformation at work in compilers for functional languages to turn inner functions into global ones, by building closures pairing the transformed functions with the environment of their free variables. Abstract machines rely on similar and yet different concepts of closures and environments. In this paper, we study the relationship between the two approaches. We adopt a very simple λ-calculus with tuples as source language and study abstract machines for both the source language and the target of closure conversion. Moreover, we focus on the simple case of flat closures/environments, that is, with no sharing of environments. We provide three contributions. Firstly, a new simple proof technique for the correctness of closure conversion, inspired by abstract machines. Secondly, we show how the closure invariants of the target language allow us to design a new way of handling environments in abstract machines, not suffering the shortcomings of other styles. Thirdly, we study the machines from the point of view of time complexity, adapting analyses by Accattoli and co-authors. We show that closure conversion decreases various dynamic costs while increasing the size of the initial code. Despite these changes, the overall complexity of the machines before and after closure conversion turns out to be the same.
title Closure Conversion, Flat Environments, and the Complexity of Abstract Machines
topic Programming Languages
D.3.1; F.3.1; F.3.2; D.2.4
url https://arxiv.org/abs/2507.15843