Re:I used Fable to rewrite 65kLoC of Go in Rust. It cost $400
by dgrunwald on Wednesday September 02, 2026 @07:42AM
(#49534834)
The compiler cannot optimize that into `while(true)` because the original code does not encounter undefined behavior when `limit` is small enough to fit into `int`.
What it can do: infer that `limit <= INT_MAX` and use that to optimize the code following after the loop (and in some cases, even the code before the loop).
My all-time favourite example is (again, my memory, I may be a bit wrong):
at some point limit could potentially become greater than INT_MAX, the compiler decided that i<limit could never be true because that would cause signed int overflow which is UB, so it "optimized" the loop into signed unsigned mismatch makes me shiver