Iteration is a programming operation that traditionally refers to visiting the elements of a data structure in sequence. However, modern programming systems such as Rust, Java, and C# generalise iteration far beyond the traditional use case. They allow iterators to be parameterised with (potentially side-effectful) closures and support the composition of iterators to form iterator chains, where each iterator in the chain consumes values from its predecessor and produces values for its successor. Such generalisations pose three major challenges for modular specification and verification of iterators and the client code using them: (1) How can parameterised iterators be specified modularly and their (accumulated) side effects reasoned about? (2) How can the behaviour of an iterator chain be derived from the specifications of its component iterators? (3) How can proofs about such iterators be automated? We present the first methodology for the modular specification and verification of advanced iteration idioms with side-effectful computations. It addresses the three challenges above using a combination of inductive two-state invariants, higher-order closure contracts, and separation logic-like ownership. We implement and our methodology in a state-of-the-art SMT-based Rust verifier. Our evaluation shows that our methodology is sufficiently expressive to handle advanced and idiomatic iteration idioms and requires modest annotation overhead.
翻译:循环是一种编程操作,传统上是指访问数据结构的序列要素。然而,现代编程系统,如Rust、 Java 和 C# 等,在传统使用情况之外还远不止于传统的循环。它们允许循环器的参数化(潜在的副作用)关闭,支持循环器的构成形成循环链,链中每个迭代器消耗其前身的值,并为其后续者生产值。这种通则对模块规格和校验迭代器和使用它们的客户代码提出了三大挑战:(1) 如何用模块化代号及其(累积的)副作用来指定参数化迭代器? (2) 循环器链的行为如何从其组件迭代器的规格(潜在的副作用)中衍生出来?(3) 如何能自动生成循环器的校验? 我们提出模块规格和核实高级迭代器规格的首个方法,以侧作用的计算为基础。它用来应对上述三项挑战,使用了两个调制状态组合,更高阶型的迭代代代号关闭合同及其(累积的)副作用副作用? (2) 迭代式关闭链条链的(累积式) 从其部件转换式关闭合同和逻辑处理方法充分展示了我们的高级逻辑所有权。