一句话:提出 Hoare 自动机类型,将符号有限自动机融入精化类型,以自动验证依赖有状态库的数据结构表示不变式。
函数式程序常通过有状态库的抽象接口维护隐藏状态,数据结构的表示不变式往往依赖库状态的历史,而库规格过于通用,难以直接表达和验证这些不变量。本文提出用符号有限自动机(SFA)精确刻画客户端与有状态库交互中的时序与数据相关历史;并将 SFA 集成进精化类型系统,形成 Hoare 自动机类型(HAT),用于限定有状态计算并模块化地描述表示不变式。作者还设计双向类型检查算法,实现 HAT 上高效的子类型包含检查,并将其翻译为可由 SMT 自动求解的形式。实验在 OCaml 数据结构实现上验证了该方法的可行性,能自动检查分层于有状态库 API 之上的复杂表示不变式。
Functional programs typically interact with stateful libraries that hide state behind typed abstractions. One particularly important class of applications are data structure implementations that rely on such libraries to provide a level of efficiency and scalability that may be otherwise difficult to achieve. However, because the specifications of the methods provided by these libraries are necessarily general and rarely specialized to the needs of any specific client, any required application-level invariants must often be expressed in terms of additional constraints on the (often) opaque state maintained by the library. In this paper, we consider the specification and verification of such representation invariants using symbolic finite automata (SFA). We show that SFAs can be used to succinctly and precisely capture fine-grained temporal and data-dependent histories of interactions between functional clients and stateful libraries. To facilitate modular and compositional reasoning, we integrate SFAs into a refinement type system to qualify stateful computations resulting from such interactions. The particular instantiation we consider, Hoare Automata Types (HATs), allows us to both specify and automatically type-check the representation invariants of a datatype, even when its implementation depends on stateful library methods that operate over hidden state. We also develop a new bidirectional type checking algorithm that implements an efficient subtyping inclusion check over HATs, enabling their translation into a form amenable for SMT-based automated verification. We present extensive experimental results on an implementation of this algorithm that demonstrates the feasibility of type-checking complex and sophisticated HAT-specified OCaml data structure implementations layered on top of stateful library APIs.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@article{abs-2404-01484,
title = {A HAT Trick: Automatically Verifying Representation Invariants using Symbolic Finite Automata},
author = {Zhe Zhou and Qianchuan Ye and Benjamin Delaware and Suresh Jagannathan},
journal = {Proceedings of the ACM on Programming Languages},
volume = {8},
number = {PLDI},
year = {2024},
doi = {10.1145/3656433}
}