3 ms·
Has anyone thought through how mut and &mut interact with each other in terms of aliasing (since they could definitely alias f(&mut x as mut u8, &mut x)), and a
by dbaupp 13y ago
Has anyone thought through how mut and &mut interact with each other in terms of aliasing (since they could definitely alias f(&mut x as mut u8, &mut x)), and also how this interacts with things like TLS and global variables?
- pcwalton 13y agoI'm not sure about your first example—the formatting seems messed up—but the second example is solved with dynamic borrow checking.
- dbaupp 13y agoOh, yes, HN replaced * with italics. I was talking about raw pointers, i.e. the second example is: f(&mut x as *mut u8, &mut x) and there is no dynamic borrowing checking for that. Would it become some form of undefined behaviour to have an *mut aliasing with an &mut?
- pcwalton 13y agoNah, I think we can handle it without undefined behavior by telling LLVM that `﹡mut` can alias anything. In effect, we would only tell LLVM that `&mut T` cannot alias `&mut T` if there is no `﹡mut T` in scope. Of course, if you transmute stuff into `&mut T`, then you'd better make sure that those two `&mut T`s don't overlap. But `﹡mut T` should be fine.