arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2311.07369cs.PL
收藏

拆箱数据构造器——或,cpp 如何判定一个停机问题

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

Nicolas Chataing, Stephen Dolan, Gabriel Scherer, Jeremy Yallop

AI总结:

本文提出 ML 系语言中数据构造器的选择性拆箱特性,通过静态分析拒绝可能导致表示混淆的拆箱,并给出与 cpp 宏展开规范化相关的终止检测算法。

摘要:

我们为 ML 系语言提出一项新的语言特性:能够选择性地对某些数据构造器进行拆箱,使其运行时表示被编译消除,仅保留对其参数的恒等映射。当拆箱可能引入混淆,即不同值具有相同表示时,必须在静态阶段予以拒绝。我们讨论了“大数”这一用例,其中拆箱允许编写既高效又安全的代码,以替代安全但缓慢的版本或快速但不安全的版本。我们解释了拒绝错误拆箱请求所必需的静态分析。我们展示了该特性在 OCaml 编程语言中的原型实现,讨论了若干设计选择,以及与守卫代数数据类型等高级特性的交互。我们的静态分析要求在类型表达式中展开类型定义,而在存在递归类型定义时,这种展开未必会规范化。换言之,我们必须判定带递归的一阶 lambda 演算中项的规范化问题。我们提供了一种在归约过程中实时检测不终止的算法,并给出了正确性与完备性证明。我们的终止监控算法与 `cpp` 预处理器中宏展开的规范化策略密切相关。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑