3 ms·
UB can be confusing, but please remember it also means a lot of very reasonable optimization opportunities. Say in data flow analysis, when the compiler can as
by vardump 11y ago
UB can be confusing, but please remember it also means a lot of very reasonable optimization opportunities.
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.
- Manishearth 11y agoI 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.