3 ms·
That is interesting... Can you point me to any information about Rust and how it avoids array aliasing? Is it because Rust disallows pointer manipulation with a
by joosters 13y ago
That is interesting... Can you point me to any information about Rust and how it avoids array aliasing? Is it because Rust disallows pointer manipulation with arrays?
It's a shame that C prevents these optimisations by default. I suppose that a quick runtime check could see if the arrays overlapped and could then switch to the faster loop style, but the compiler would have to decide whether the loop was important enought to be worth generating the two code paths for.
- pcwalton 13y agoNo, Rust has pointer arithmetic, though it's bounds checked with slices. The restriction is that two mutable references cannot point to the same location. This is enforced by the borrow check: http://pcwalton.github.io/blog/2013/01/21/the-new-borrow-check-in-a-nutshell/ http://pcwalton.github.io/blog/2013/01/21/the-new-borrow-che...
- joosters 13y agoThanks!
- mcguire 13y agoAt compile time or run time?
- pcwalton 13y agoBounds checked at runtime (unless you use the unsafe sublanguage). Without dependent types (which I feel would exceed our complexity budget) we can't do much better. However, for simple iteration, if you use iterators idiomatically instead of C-style for loops then you won't incur any bounds checks.
- mcguire 13y agoI was just about to accuse you of dependent typing.