一句话:首次形式化证明平坦环境闭包转换保持语义并对时间与空间安全,且计入垃圾回收。
本文形式化证明 CPS λ 演算中平坦环境闭包转换的正确性:保持语义,并保持程序执行所需的时间和空间。作者给出转换前后代码的代价模型,用带 profiling 的语义跟踪时间与空间资源,并计入垃圾回收。为证明资源保持,他们建立与垃圾回收兼容的二元逻辑关系,刻画程序的功能正确性与资源消耗不变量。基于此,论文证明终止源程序的语义、时间与空间安全,以及发散源程序的发散保持与空间安全。这是首个闭包转换空间安全性的形式化证明,结果在 Coq 中机器化,并用于 CertiCoq 编译器从 Gallina 经 CompCert Clight 到汇编的流水线。
We formally prove that closure conversion with flat environments for CPS lambda calculus is correct (preserves semantics) and safe for time and space, meaning that produced code preserves the time and space required for the execution of the source program. We give a cost model to pre- and post-closure-conversion code by formalizing profiling semantics that keep track of the time and space resources needed for the execution of a program, taking garbage collection into account. To show preservation of time and space we set up a general, "garbage-collection compatible", binary logical relation that establishes invariants on resource consumption of the related programs, along with functional correctness. Using this framework, we show semantics preservation and space and time safety for terminating source programs, and divergence preservation and space safety for diverging source programs. We formally prove that closure conversion with flat environments for CPS lambda calculus is correct (preserves semantics) and safe for time and space, meaning that produced code preserves the time and space required for the execution of the source program. We give a cost model to pre- and post-closure-conversion code by formalizing profiling semantics that keep track of the time and space resources needed for the execution of a program, taking garbage collection into account. To show preservation of time and space we set up a general, "garbage-collection compatible", binary logical relation that establishes invariants on resource consumption of the related programs, along with functional correctness. Using this framework, we show semantics preservation and space and time safety for terminating source programs, and divergence preservation and space safety for diverging source programs. This is the first formal proof of space-safety of a closure-conversion transformation. The transformation and the proof are parts of the CertiCoq compiler pipeline from Coq (Gallina) through CompCert Clight to assembly language. Our results are mechanized in the Coq proof assistant.