News for hackers. Stuff that matters.
Re:Rust Ownership Rules by quietbritishjim on Monday March 02, 2020 @09:11AM (#22464565)
Thanks for the clarification! I suppose there are two interpretations of "move" in general: (1) the object is now owned by a different variable, potentially with a different lifetime; (2) the footprint of the object is now in a different location in memory. It seems that std::pin refers to the second one:

> A Pin<P> ensures that the pointee of any pointer type P has a stable location in memory, meaning it cannot be moved elsewhere and its memory cannot be deallocated until it gets dropped. We say that the pointee is "pinned".

That is actually the definition of "move" that I had meant, after all that is what is bad for an object that points into its own footprint. But I realise that "move" in Rust normally means the first one (but note that even Rust's own documentation uses "move" the other way in that snippet above!).

Re:Rust Ownership Rules by withoutboats on Monday March 02, 2020 @09:27AM (#22464668)
Your post suggests a bit of confusion about the meaning of "lifetime" in Rust - a confusion which is common and why we are somewhat unhappy with how that terminology has played out.

Variables don't have a "lifetime," references do. When we talk about lifetimes we talk about the lifetime of references to variables, during which time the variable cannot be moved, dropped, etc. The "lifetime of the variable must be greater than the lifetime of the reference" is a common mental model but this lifetime of the variable doesn't really come into play in reality.

Your 1) and 2) always coincide in the abstract model, though the compiler may optimize out memcpys that have no impact. When you move a pointer around, you don't move the object it points to.

Re:Rust Ownership Rules by quietbritishjim on Monday March 02, 2020 @09:33AM (#22464717)
Ah OK. What word would you use to describe the period starting where the variable is assigned to and ending when it is dropped or moved-from?
Re:Rust Ownership Rules by withoutboats on Monday March 02, 2020 @09:43AM (#22464790)
This is sort of the problem: its very natural to refer to that as a lifetime! In fact, more natural than the lifetime of a reference, because we intuitively think of variables as being "alive" and references as being short-term "views" of the variables.

As in the sibling comment, "scope" could be used, but indeed maybe we should have just called lifetimes "scopes" or something (though they are not lexical, whereas scopes are usually thought of as lexical pyramids).

I probably would just say lifetime usually, but I would be being imprecise and potentially unclear!

Re:Rust Ownership Rules by oconnor663 on Monday March 02, 2020 @10:09AM (#22465000)
I propose that we refer to the (potentially non-lexical) scope of a variable as its "zone". Active variables would thus be said to be "in the zone".
Re:Rust Ownership Rules by withoutboats on Monday March 02, 2020 @10:18AM (#22465065)
This touches on some interesting history: lifetimes were originally (in other PL literature) called "regions" (MS Research's Verona also uses this terminology). Lifetime was chosen because an analogy to time seemed more intuitive for this concept than an analogy to space - space analogies being usually used for sections of program memory, rather than periods of program execution.
Re:Rust Ownership Rules by oconnor663 on Monday March 02, 2020 @09:33AM (#22464712)
What's the more precise term for a variable's "lifetime"? Its "scope"?