Re:Businesses are in for a mighty debt hangover
by steveklabnik on Wednesday May 17, 2023 @01:26PM
(#35978520)
> I think really importantly, whatever failings the technique has, it’s reflective of humanity itself, and humans are often slightly wrong or misleading.
Absolutely, and I don't think every explanation has to be perfect to be useful, hence me saying "you gotta watch out" and not "fuck this tool, nobody should use it."
I agree - it’s not a panacea devoid of human involvement. I think really importantly, whatever failings the technique has, it’s reflective of humanity itself, and humans are often slightly wrong or misleading. I think confusing it’s output with that of a deterministic program is wrong - it’s much more akin to the output of a human than not.
My argument though is it’s not a freshman in college level of human failings. It’s clarity is far beyond that on many subjects, and it’s facility to “understand” is remarkable for a human let alone a computer. The fact I can interrogate it and ask it the clarifying question you bring out is beyond useful - I can dig into the specific areas of confusion I have, and often if it’s wrong I’ll cop to it unlike a human oracle.
> Clarify then: If a type is "pinned" (wrapped in a Pin), it is a guarantee that the memory location of the value inside will not change.
When we say "the memory location of the value inside will not change," what we mean is that the value that the pointer points to is guaranteed to not move in memory. This is a critical guarantee when working with certain types of data, like self-referential structs or certain async code in Rust.
Let's take an example of Pin<Box<T>>. Here's what it means:
Box<T>: This is a heap-allocated instance of T. The Box is a smart pointer that points to this heap-allocated T. Pin<Box<T>>: This is a Pin wrapping the Box. This means that the T that the Box points to is pinned. This does not mean that the Box itself cannot be moved. The Box is a pointer, and pointers can be copied and moved freely. But because we have used Pin, the actual heap-allocated T that it points to cannot be moved. This is what we mean when we say "the memory location of the value inside will not change." We're talking about the T, not the Box.
This is important when the type T has self-references, because moving T in memory would invalidate those self-references. By using Pin, we ensure that T stays put, and those self-references remain valid. This is a key part of the design of Rust's async programming model.
However, this guarantee is only upheld as long as the type T does not implement Unpin, which is a marker trait that indicates that it is safe to move a type out of a Pin. Types that are not Unpin uphold the guarantee that they cannot be moved out of the Pin once they are placed in it.