一句话:提出并实现 Rust 的 GC 方案 Alloy,首次让既有析构函数自动充当 GC 终结器,并解决由此带来的健全性与性能问题。
Rust 不是带垃圾回收的语言,但缺少 GC 使得需要共享所有权的数据结构难以表达,写起来别扭或效率低下。本文提出并实现了面向 Rust 的新 GC 设计 Alloy。与此前在 Rust 中引入 GC 的方案不同,Alloy 允许把 Rust 已有的析构函数自动复用为 GC 终结器,从而与现有 Rust 代码更好地集成,但也因此引入了出人意料的健全性与性能问题。针对这些核心难题,Alloy 给出三项新机制:终结器安全性分析会拒绝那些不健全的析构函数被自动当作终结器复用;终结器省略优化掉不必要的终结器;过早终结预防则保证终结器只在可证明安全时才运行。作者通过 Alloy 的实现展示了这些机制如何共同支撑一个既可用又安全的 Rust GC。
Rust is a non-Garbage Collected (GCed) language, but the lack of GC makes expressing data-structures that require shared ownership awkward, inefficient, or both. In this paper we explore a new design for, and implementation of, GC in Rust, called Alloy. Unlike previous approaches to GC in Rust, Alloy allows existing Rust destructors to be automatically used as GC finalizers: this makes Alloy integrate better with existing Rust code than previous solutions but introduces surprising soundness and performance problems. Alloy provides novel solutions for the core problems: finalizer safety analysis rejects unsound destructors from automatically being reused as finalizers; finalizer elision optimises away unnecessary finalizers; and premature finalizer prevention ensures that finalizers are only run when it is provably safe to do so.