The article explains that Rust's Pin type was designed in 2018 as a minimal, library-only solution to enable shipping async/await quickly, but this choice created a significant complexity cliff for users who must interact with pinned references, especially when implementing Future by hand. The author argues that these difficulties stem not from the inherent complexity of pinning as a concept, but from Pin being a pure library type lacking language support. The post proposes a set of fully backward-compatible language changes to make working with pinned references feel much closer to working with ordinary references.
In the previous post, I described the goal of Rust’s Pin type and the history of how it
came to exist. When we were initially developing this API in 2018, one of our explicit goals was the
limit the number of changes we would make to Rust, because we wanted to ship a “minimum viable
product” of async/await syntax as soon as possible. This meant that Pin is a type defined in the
standard library, without any syntactic or language support except for the ability to use it as a
method receiver. As I wrote in my previous post, in my opinion this is the source of a “complexity
cliff” when users have to interact with Pin.
We knew when we made this choice that pinned references would be harder to use and more confusing
than ordinary references, though I think we did underestimate just how much more challenging they
would be for most users. Our initial hope was that with async/await, pinning would disappear into
the background, because the await operator and the runtime’s spawn function would pin your
futures for you and you wouldn’t have to encounter it directly. As things played out, there are
still some cases where users must interact with pinned references, even when using async/await. And
sometimes users do need to “drop down” into a lower-level register to implement
Future themselves; this is when they truly encounter a huge complexity cliff: both the essential
complexity of implementing a state machine “by hand” and the additional complexity of understanding
the APIs to do with Pin.
My contention in my previous post was that the difficulties involved in this have very little to do
with the complexity inherent in the pinned typestate as a concept, or in pinned references as a way
of representing it, but instead arises from the fact that Pin is a pure library type without
support from the language. Users who deal with Pin are almost always doing something that is
totally memory safe, the problem is just that the idioms to do so with Pin are different from and
less clear than the idioms for doing so with ordinary references.
继续阅读全文
为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。
AI 摘要The author argues that the newly proposed UnpinCell wrapper type, which converts a pinned mutable reference into a plain mutable reference, could solve the biggest outstanding problem with Rust generators: the Iterator interface does not permit self-referential values. Because Pin was designed as a backward-compatible, opt-in contract, pre-existing traits like Iterator—which takes a plain mutable reference rather than a pinned one—cannot be implemented by self-referential types. As a result, generators cannot support self-referential values the way async functions do, unless the Iterator interface adopts pinned references.
AI 摘要The author proposes a new Rust design, UnpinCell, as a variation on their earlier pinned places proposal. Whereas the previous design relied on the unusual concept of 'pinned fields' to support pinned projection, this new approach aims to offer similar properties while remaining consistent with Rust's standard field projection behavior, without introducing a special field marker.
AI 摘要The article discusses Pin, a foundational but widely misunderstood part of Rust's async ecosystem that supports self-referential types by preventing them from moving in memory. The author, who originally proposed adding Pin to Rust, acknowledges critiques (such as one from the makers of Mojo) that interacting with Pin creates a 'complexity cliff' for users, and aims to explain what Pin achieves, how it came to be, and why it is hard to use. The author promises to present ideas for resolving this complexity in a follow-up post.
AI 摘要This article explains how substructural type theory applies to programming language design, arguing that designers should use accessible metaphors like 'ownership' to help ordinary programmers understand concepts such as constructors, destructors, and preventing aliasing of objects that represent external resources. Using Rust's ownership model as the primary example, the author aims to demystify these ideas so they become more common knowledge among programmers. While the post contains nothing groundbreaking for experts, it includes notes critiquing certain aspects of Rust's implementation that the author believes are incorrect.
AI 摘要The article revisits C.A.R. Hoare's 1974 critique of references and pointers in high-level languages, in which he argued they reintroduce machine-code problems—such as address/content confusion, unconstrained mutation through aliasing, lack of independent meaning, and performance overhead—calling them 'a step backward.' The author contends that while Hoare's famous 'billion dollar mistake' was the null pointer, the industry's broader disregard of his warnings about pointers in general was a 'trillion dollar mistake,' because mutable, aliased state destroys the ability to reason locally about a program's behavior. Preventing accidental mutation of aliased state, the author concludes, is essential to building correctly functioning software.