Re:Mozilla releases version 0.1 of the Rust programming lang...
by Chirono on Tuesday January 24, 2012 @03:15AM
(#3503936)
Thanks, uniqueness typing has been a bit of a hobby of mine for a few years, so I'm familiar with 1 & 2. Uniqueness in system-level languages, however, is not something I know so much about, so something like 3 is pretty interesting.
Re:Mozilla releases version 0.1 of the Rust programming lang...
by pcwalton on Tuesday January 24, 2012 @10:31AM
(#3505149)
You're correct regarding (3) -- that's the main reason unique pointers were added to Rust in the first place. We call the heap of unique pointers the "exchange heap" for this reason.
In particular:
1. The compiler can detect when a value is no longer "owned" (referenced) by anything and free it automatically -- without garbage collection. That's really handy for things like closures where the compiler automatically allocated the memory for you in the first place.
2. If an immutable value is modified then a copy usually needs to be made. But if the immutable value is uniquely-referenced then the compiler can reuse the old bit of memory, thereby saving a copy operation. It can do this because it can prove the old memory can no longer be accessed.
3. I think Rust might also use uniqueness when sending values between its tasks. Since it can prove the value will no longer be referenced by the old task the compiler can avoid copying the values while still preserving isolation.
http://en.wikipedia.org/wiki/Uniqueness_type