Compiling Morphisms of Algebraic Data Types
Résumé
Now integrated in mainstream languages, Algebraic Data Types (ADTs) have
established themselves as a nice way to reason about data structures
and their manipulation using pattern matching.
However, their use in low-level programming remains limited
despite efforts, notably from the Rust community.
Recently, Baudon et al. [2023] propose to let programmers express
the precise memory layout of a given Algebraic Data Type,
while still enjoying high-level programming constructs.
Their compilation procedure covers efficient pattern matching,
but leaves out constructors and
struggles with arbitrarily mangled memory layouts.
So far, the literature on ADT compilation rarely mentions constructors,
which are indeed a non-issue on simple memory layouts.
However, when data pieces are broken and scattered in memory,
this task becomes particularly challenging.
Even simple accessors might require constructing new values.
This is the case for many low-level representations such as network packets,
instruction sets, database data-structures, or aggressively packed
representations.
In this article, we go one step further, by
enabling optimized compilation of any morphisms between
ADTs for arbitrary mangled memory representations.
We also provide full synthesis of bijections between memory representations
of the same type.
We subsume existing compilation algorithms, and extend them to
emit CFG-style programs with explicit memory allocation and full
support for recursive types.
Origine | Fichiers produits par l'(les) auteur(s) |
---|