3 ms·
Most programming languages are not expressive enough to reliably eliminate redundant overflow checks (or overflows); afaik doing so in general way requires some
by zokier 4y ago
Most programming languages are not expressive enough to reliably eliminate redundant overflow checks (or overflows); afaik doing so in general way requires something in the ballpark of refinement/dependent types
- jiggawatts 4y agoIn which case the compiler will emit the overflow or bounds checks, which is fine. If the developer is certain that a specific add operation should use unchecked add for performance, then they can override the behaviour as a spot micro-optimisation. That then becomes a "self documenting" thing, easily found by a simple keyword search. To give you an idea of just how rarely this is actually needed or done, there are less than a thousand uses of "unchecked_add()" in all of the Rust code on GitHub! https://github.com/search?q=.unchecked_add%28+language%3ARust&type=code&l=Rust https://github.com/search?q=.unchecked_add%28+language%3ARus...