一句话:为任意正则递归类型定义的代数数据结构构造资源多项式,并在 AARA 资源类型系统中实现复杂数据结构上的自动资源界推断。
自动资源界分析旨在静态推断程序执行的符号化资源消耗上界,但其长期难点是推断依赖于复杂自定义数据结构的界。本文扩展基于类型的自动摊销资源分析(AARA),在正则递归类型定义的代数数据结构上统一构造资源多项式;这些资源函数推广了此前针对列表等结构提出的多项式资源函数,可视为给定递归类型值上的一般多项式概念。作者为带递归类型的核心语言 FPC 设计资源类型系统,说明如何将资源多项式与 AARA 集成并保留已有优势。为简洁表述规则并证明相对小步代价语义的可靠性,文章引入自由半模表达多元势标注,并用逻辑关系赋予资源类型语义,从而只需对类型推导作一次归纳即可证明可靠性。
The goal of automatic resource bound analysis is to statically infer symbolic bounds on the resource consumption of the evaluation of a program. A longstanding challenge for automatic resource analysis is the inference of bounds that are functions of complex custom data structures. This article builds on type-based automatic amortized resource analysis (AARA) to address this challenge. AARA is based on the potential method of amortized analysis and reduces bound inference to standard type inference with additional linear constraint solving, even when deriving non-linear bounds. Such bounds come from resource functions, which are linear combinations of basic functions of data structure sizes that fulfill certain closure properties.Previous work on AARA defined resource functions for many data structures such as lists of lists, but left open whether such functions exist for arbitrary data structures. This work answers this question positively by uniformly constructing resource polynomials for algebraic data structures defined by regular recursive types. These functions are a generalization of all previously proposed polynomial resource functions and can be seen as a general notion of polynomials for values of a given recursive type. A resource type system for FPC, a core language with recursive types, demonstrates how resource polynomials can be integrated with AARA while preserving all benefits of past techniques. The article also proposes the use of new techniques useful for stating the rules of this type system succinctly and proving it sound against a small-step cost semantics. First, multivariate potential annotations are stated in terms of free semimodules, substantially abstracting details of the presentation of annotations and the proofs of their properties. Second, a logical relation giving semantic meaning to resource types enables a proof of soundness by a single induction on typing derivations.