一句话:提出无名共上下文的全局标签表示,借助线性类型在 Agda 中实现按构造类型正确的编译器。
本文研究编译器的类型正确性:用 Agda 将编译器写成内在类型化函数,直接操作良类型源/目标程序,从而按构造保证若源程序良类型则目标代码良类型。难点是字节码标签的全局绑定使类型性成为非组合的全程序性质,单个编译操作难以保持。论文提出无名、共上下文的类型化全局标签表示,借助线性确保标签恰好定义一次,并在 Agda 中基于分离逻辑实现线性依赖类型的浅嵌入语言,以简洁描述内在类型化字节码操作。最终为带结构化控制流的语言实现了内在类型化编译器。
To avoid compilation errors it is desirable to verify that a compiler is type correct —i.e., given well-typed source code, it always outputs well-typed target code. This can be done intrinsically by implementing it as a function in a dependently typed programming language, such as Agda. This function manipulates data types of well-typed source and target programs, and is therefore type correct by construction. A key challenge in implementing an intrinsically typed compiler is the representation of labels in bytecode. Because label names are global, bytecode typing appears to be inherently a non-compositional, whole-program property. The individual operations of the compiler do not preserve this property, which requires the programmer to reason about labels, which spoils the compiler definition with proof terms. In this paper, we address this problem using a new nameless and co-contextual representation of typed global label binding, which is compositional. Our key idea is to use linearity to ensure that all labels are defined exactly once. To write concise compilers that manipulate programs in our representation, we develop a linear, dependently typed, shallowly embedded language in Agda, based on separation logic. We show that this language enables the concise specification and implementation of intrinsically typed operations on bytecode, culminating in an intrinsically typed compiler for a language with structured control-flow.
@article{paperbot1196,
title = {Intrinsically typed compilation with nameless labels},
author = {Arjen Rouvoet and Robbert Krebbers and Eelco Visser},
journal = {Proceedings of the ACM on Programming Languages},
volume = {5},
number = {POPL},
year = {2021},
doi = {10.1145/3434303}
}