Unboxed data constructors -- or, how cpp decides a halting problem

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Chataing, Nicolas, Dolan, Stephen, Scherer, Gabriel, Yallop, Jeremy
Format: Preprint
Published: 2023
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866916239655305216
author Chataing, Nicolas
Dolan, Stephen
Scherer, Gabriel
Yallop, Jeremy
author_facet Chataing, Nicolas
Dolan, Stephen
Scherer, Gabriel
Yallop, Jeremy
contents We propose a new language feature for ML-family languages, the ability to selectively unbox certain data constructors, so that their runtime representation gets compiled away to just the identity on their argument. Unboxing must be statically rejected when it could introduce confusions, that is, distinct values with the same representation. We discuss the use-case of big numbers, where unboxing allows to write code that is both efficient and safe, replacing either a safe but slow version or a fast but unsafe version. We explain the static analysis necessary to reject incorrect unboxing requests. We present our prototype implementation of this feature for the OCaml programming language, discuss several design choices and the interaction with advanced features such as Guarded Algebraic Datatypes. Our static analysis requires expanding type definitions in type expressions, which is not necessarily normalizing in presence of recursive type definitions. In other words, we must decide normalization of terms in the first-order lambda-calculus with recursion. We provide an algorithm to detect non-termination on-the-fly during reduction, with proofs of correctness and completeness. Our termination-monitoring algorithm turns out to be closely related to the normalization strategy for macro expansion in the `cpp` preprocessor.
format Preprint
id arxiv_https___arxiv_org_abs_2311_07369
institution arXiv
publishDate 2023
record_format arxiv
spellingShingle Unboxed data constructors -- or, how cpp decides a halting problem
Chataing, Nicolas
Dolan, Stephen
Scherer, Gabriel
Yallop, Jeremy
Programming Languages
We propose a new language feature for ML-family languages, the ability to selectively unbox certain data constructors, so that their runtime representation gets compiled away to just the identity on their argument. Unboxing must be statically rejected when it could introduce confusions, that is, distinct values with the same representation. We discuss the use-case of big numbers, where unboxing allows to write code that is both efficient and safe, replacing either a safe but slow version or a fast but unsafe version. We explain the static analysis necessary to reject incorrect unboxing requests. We present our prototype implementation of this feature for the OCaml programming language, discuss several design choices and the interaction with advanced features such as Guarded Algebraic Datatypes. Our static analysis requires expanding type definitions in type expressions, which is not necessarily normalizing in presence of recursive type definitions. In other words, we must decide normalization of terms in the first-order lambda-calculus with recursion. We provide an algorithm to detect non-termination on-the-fly during reduction, with proofs of correctness and completeness. Our termination-monitoring algorithm turns out to be closely related to the normalization strategy for macro expansion in the `cpp` preprocessor.
title Unboxed data constructors -- or, how cpp decides a halting problem
topic Programming Languages
url https://arxiv.org/abs/2311.07369