一句话:逐步为线性类型演算加入不可变借用、词法生命周期、再借用与可变借用,并用分离逻辑证明其语义类型安全。
线性类型系统能静态保证资源管理安全,但显式线性传递资源使用不便。Rust 式借用通过临时禁用释放或修改等权限,换取弱化、收缩等结构权限,从而减轻负担,同时保证资源最终归还。本文从无类型 lambda 演算上保障手动内存管理的线性类型系统出发,逐步加入不可变借用、词法生命周期、再借用和可变借用,形成 Borrow Calculus (BoCa)。作者提出 Borrow Logic (BoLo),一种面向借用领域的分离逻辑,并用其证明 BoCa 的语义类型可靠性。该逻辑的语义模型还保证程序终止且无内存泄漏,并可验证一些语法上类型不良、会临时破坏但能恢复不变式的程序安全。
Linear type systems are powerful because they can statically ensure the correct management of resources like memory, but they can also be cumbersome to work with, since even benign uses of a resource require that it be explicitly threaded through during computation. Borrowing , as popularized by Rust, reduces this burden by allowing one to temporarily disable certain resource permissions (e.g., deallocation or mutation) in exchange for enabling certain structural permissions (e.g., weakening or contraction). In particular, this mechanism spares the borrower of a resource from having to explicitly return it to the lender but nevertheless ensures that the lender eventually reclaims ownership of the resource. In this paper, we elucidate the semantics of borrowing by starting with a standard linear type system for ensuring safe manual memory management in an untyped lambda calculus and gradually augmenting it with immutable borrows, lexical lifetimes, reborrowing, and finally mutable borrows. We prove semantic type soundness for our Borrow Calculus ( BoCa ) using Borrow Logic ( BoLo ), a novel domain-specific separation logic for borrowing. We establish the soundness of this logic using a semantic model that additionally guarantees that our calculus is terminating and free of memory leaks. We also show that our Borrow Logic is robust enough to establish the semantic safety of some syntactically ill-typed programs that temporarily break but reestablish invariants.
@article{paperbot2967,
title = {From Linearity to Borrowing},
author = {Andrew Wagner and Olek Gierczak and Brianna Marshall and John M. Li and Amal Ahmed},
journal = {Proceedings of the ACM on Programming Languages},
volume = {9},
number = {OOPSLA2},
year = {2025},
doi = {10.1145/3764117}
}