Bit-Stealing Made Legal: Compilation for Custom Memory Representations of Algebraic Data Types
Open Access
- 30 August 2023
- journal article
- research article
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Programming Languages
- Vol. 7 (ICFP) , 813-846
Abstract
Initially present only in functional languages such as OCaml and Haskell, Algebraic Data Types (ADTs) have now become pervasive in mainstream languages, providing nice data abstractions and an elegant way to express functions through pattern matching. Unfortunately, ADTs remain seldom used in low-level programming. One reason is that their increased convenience comes at the cost of abstracting away the exact memory layout of values. Even Rust, which tries to optimize data layout, severely limits control over memory representation. In this article, we present a new approach to specify the data layout of rich data types based on a dual view: a source type, providing a high-level description available in the rest of the code, along with a memory type, providing full control over the memory layout. This dual view allows for better reasoning about memory layout, both for correctness, with dedicated validity criteria linking the two views, and for optimizations that manipulate the memory view. We then provide algorithms to compile constructors and destructors, including pattern matching, to their low-level memory representation. We prove our compilation algorithms correct, implement them in a tool called ribbit that compiles to LLVM IR, and show some early experimental results.Keywords
This publication has 24 references indexed in Scilit:
- GADTs meet their match: pattern-matching warnings that account for GADTs, guards, and laziness2015
- Pattern Matches in HOL:2015
- Open pattern matching for C++2013
- Extensible pattern matching via a lightweight language extension2007
- Warnings for pattern matchingJournal of Functional Programming, 2007
- Optimizing pattern matching2001
- Unboxing using Specialisation1995
- Reasoning about programs in continuation-passing styleHigher-Order and Symbolic Computation, 1993
- Unboxed values as first class citizens in a non-strict functional language1991
- Efficient data representation in polymorphic languages1990