paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Stacked borrows: an aliasing model for Rust

Stacked Borrows:一种面向 Rust 的别名模型
POPL 4(POPL)2019匹配度 3/10 · 论文是 Rust 别名纪律的形式语义与 Coq 验证,属于程序语言/形式验证方向,与静态分析和形式化验证有间接关联;但完全不涉及用户核心关注的 LLM/Agent 与静态分析交叉、浮点程序分析或贝叶斯程序分析。引用 67 inbox
Ralf Jung, Hoang-Hai Dang, Jeehoon Kang, Derek Dreyer
crossref: 2026-09-10

AI 速览

一句话:提出 Stacked Borrows 操作语义,为 Rust 定义别名纪律,并用 Coq 证明其足以支撑内存访问重排优化。

Rust 的类型系统对指针别名施加严格纪律,编译器希望利用这些别名信息重排内存访问以优化程序,但 unsafe 代码可绕过检查破坏该纪律。本文提出 Stacked Borrows:一种针对 Rust 内存访问的操作语义,它定义明确的别名纪律,并将违反者判定为未定义行为,使编译器在优化时无需考虑此类程序。作者用 Coq 机器化证明了该模型排除了足够多的程序,从而支持仅基于过程内推理、围绕未知代码与函数调用重排内存访问的优化;同时将操作模型实现于 Rust 解释器,并运行标准库测试套件的大部分用例,验证模型对真实 unsafe Rust 代码的容许度。

问题
在允许 unsafe 代码的前提下,如何为 Rust 提供一套别名规则,使 unsafe 作者遵循规则即可确保编译器优化不改变程序语义。
方法
提出 Stacked Borrows 操作语义,以别名纪律定义合法内存访问,违反者视为未定义行为,并用 Coq 机器化证明其足以支持内存访问重排优化。
评估
在 Rust 解释器中实现 Stacked Borrows,运行 Rust 标准库测试套件的大部分用例,检验该模型是否容许足量的真实 unsafe 代码。
原文摘要(Abstract)

Type systems are useful not just for the safety guarantees they provide, but also for helping compilers generate more efficient code by simplifying important program analyses. In Rust, the type system imposes a strict discipline on pointer aliasing, and it is an express goal of the Rust compiler developers to make use of that alias information for the purpose of program optimizations that reorder memory accesses. The problem is that Rust also supports unsafe code, and programmers can write unsafe code that bypasses the usual compiler checks to violate the aliasing discipline. To strike a balance between optimizations and unsafe code, the language needs to provide a set of rules such that unsafe code authors can be sure, if they are following these rules, that the compiler will preserve the semantics of their code despite all the optimizations it is doing. In this work, we propose Stacked Borrows , an operational semantics for memory accesses in Rust. Stacked Borrows defines an aliasing discipline and declares programs violating it to have undefined behavior , meaning the compiler does not have to consider such programs when performing optimizations. We give formal proofs (mechanized in Coq) showing that this rules out enough programs to enable optimizations that reorder memory accesses around unknown code and function calls, based solely on intraprocedural reasoning. We also implemented this operational model in an interpreter for Rust and ran large parts of the Rust standard library test suite in the interpreter to validate that the model permits enough real-world unsafe Rust code.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot519,
  title = {Stacked borrows: an aliasing model for Rust},
  author = {Ralf Jung and Hoang-Hai Dang and Jeehoon Kang and Derek Dreyer},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {4},
  number = {POPL},
  year = {2019},
  doi = {10.1145/3371109}
}