Table of Contents
Fetching ...

Automatic Linear Resource Bound Analysis for Rust via Prophecy Potentials

Qihao Lian, Di Wang

TL;DR

RaRust addresses statically inferring resource bounds for Rust programs by integrating automatic amortized resource analysis with Rust's borrow semantics. It introduces Resource-Aware Borrow Calculus (RABC) and prophecy potentials to model shared and mutable borrows, together with a lattice of resource-annotated types to manage aliasing. The framework proves soundness via a potential-based argument and demonstrates a prototype that infers symbolic linear bounds for safe Rust constructs like shared/mutable borrows, reborrows, and recursive data structures. This work enables automatic, compositional resource reasoning for Rust, with practical impact for predicting performance and guiding optimizations in resource-constrained systems. Future work envisions extending RaRust to unsafe code, generics, higher-order functions, and non-linear resource bounds, broadening real-world applicability.

Abstract

Rust has become a popular system programming language that strikes a balance between memory safety and performance. Rust's type system ensures the safety of low-level memory controls; however, a well-typed Rust program is not guaranteed to enjoy high performance. This article studies static analysis for resource consumption of Rust programs, aiming at understanding the performance of Rust programs. Although there have been tons of studies on static resource analysis, exploiting Rust's memory safety -- especially the borrow mechanisms and their properties -- to aid resource-bound analysis, remains unexplored. This article presents RaRust, a type-based linear resource-bound analysis for well-typed Rust programs. RaRust follows the methodology of automatic amortized resource analysis (AARA) to build a resource-aware type system. To support Rust's borrow mechanisms, including shared and mutable borrows, RaRust introduces shared and novel prophecy potentials to reason about borrows compositionally. To prove the soundness of RaRust, this article proposes Resource-Aware Borrow Calculus (RABC) as a variant of recently proposed Low-Level Borrow Calculus (LLBC). The experimental evaluation of a prototype implementation of RaRust demonstrates that RaRust is capable of inferring symbolic linear resource bounds for Rust programs featuring shared and mutable borrows, reborrows, heap-allocated data structures, loops, and recursion.

Automatic Linear Resource Bound Analysis for Rust via Prophecy Potentials

TL;DR

RaRust addresses statically inferring resource bounds for Rust programs by integrating automatic amortized resource analysis with Rust's borrow semantics. It introduces Resource-Aware Borrow Calculus (RABC) and prophecy potentials to model shared and mutable borrows, together with a lattice of resource-annotated types to manage aliasing. The framework proves soundness via a potential-based argument and demonstrates a prototype that infers symbolic linear bounds for safe Rust constructs like shared/mutable borrows, reborrows, and recursive data structures. This work enables automatic, compositional resource reasoning for Rust, with practical impact for predicting performance and guiding optimizations in resource-constrained systems. Future work envisions extending RaRust to unsafe code, generics, higher-order functions, and non-linear resource bounds, broadening real-world applicability.

Abstract

Rust has become a popular system programming language that strikes a balance between memory safety and performance. Rust's type system ensures the safety of low-level memory controls; however, a well-typed Rust program is not guaranteed to enjoy high performance. This article studies static analysis for resource consumption of Rust programs, aiming at understanding the performance of Rust programs. Although there have been tons of studies on static resource analysis, exploiting Rust's memory safety -- especially the borrow mechanisms and their properties -- to aid resource-bound analysis, remains unexplored. This article presents RaRust, a type-based linear resource-bound analysis for well-typed Rust programs. RaRust follows the methodology of automatic amortized resource analysis (AARA) to build a resource-aware type system. To support Rust's borrow mechanisms, including shared and mutable borrows, RaRust introduces shared and novel prophecy potentials to reason about borrows compositionally. To prove the soundness of RaRust, this article proposes Resource-Aware Borrow Calculus (RABC) as a variant of recently proposed Low-Level Borrow Calculus (LLBC). The experimental evaluation of a prototype implementation of RaRust demonstrates that RaRust is capable of inferring symbolic linear resource bounds for Rust programs featuring shared and mutable borrows, reborrows, heap-allocated data structures, loops, and recursion.

Paper Structure

This paper contains 37 sections, 11 theorems, 9 equations, 18 figures, 2 tables.

Key Result

lemma 1

Potential is non-negative and keeps subtyping:

Figures (18)

  • Figure 1: Examples to Demonstrate Rust's Borrow Mechanisms and Automatic Amortized Resource Analysis
  • Figure 2: Examples to Demonstrate How RaRust Works
  • Figure 3: Syntax
  • Figure 4: Value
  • Figure 5: Store Reading and Writing
  • ...and 13 more figures

Theorems & Definitions (13)

  • lemma 1
  • corollary 1
  • definition 1
  • lemma 2
  • theorem 1: Soundness
  • lemma 3: Update
  • lemma 4: Evaluation
  • definition 2
  • lemma 5: Weakening
  • lemma 6
  • ...and 3 more