On 12/03/2013 04:53 PM, Patrick Walton wrote:
On 12/3/13 12:54 AM, Josh Matthews wrote:
I don't entirely understand what this means, either in theory or in
practice.
So the issue is that the Rust compiler assumes a couple of things around
`&mut`:
1. No `&mut` aliases any `&` (because then `&` wouldn't be immutable).
2. No `&mut` aliases any other `&mut` (i.e. no two `&mut`s to the same
location).
Violating this will lead to undefined behavior, in particular iterator
invalidation. So these rules need to be enforced dynamically.
The easiest way, and the way we'd like to do it in the future, is to not
have mutable borrows of reference-counted or garbage-collected, and to
instead wrap individual fields that should be mutable in the new
`RefCell` (today called `Slot` in Servo), which exposes convenient
`.get()` and `.set()` methods. But the problem is that `RefCell`/`Slot`
currently bloats the field by adding an extra byte. I have a plan to fix
that for most fields, but this is not yet implemented. So it's probably
best to just `FIXME` it for now.
Patrick
Ah, so even though we get proper errors when trying to call value() and
mut_value() on a single JSManaged value, if there were two JSManaged
values containing a pointer to the same Rust object, the compiler would
allow us to do the same without any complaint. That makes sense.
_______________________________________________
dev-servo mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-servo