Re:Myths about Integer Overflow in Rust
by Manishearth on Friday April 29, 2016 @06:03PM
(#11599062)
I know that UB can be useful for optimizations. Where did I assert otherwise?
I'm saying that overflow is not undefined in Rust (the very first section of the blog post says this). I made this same mistake a few days ago and thought it was undefined (and implementation-defined to panic on debug), but I was wrong. Overflow is well defined in Rust.
Say in data flow analysis, when the compiler can assume "(value + 1) > value" to be always true, a whole expensive branch can be removed.
If the overflow is never going to happen anyways, the savings are considerable (expensive branch eliminated) and the result is always correct.