Re:DARPA: Translating All C to Rust (Tractor)
by grumpyprole on Wednesday July 31, 2024 @03:55AM
(#41117185)
Usually but not always. For example, the removal of an empty effect free infinite loop. This should be an error.
Re:DARPA: Translating All C to Rust (Tractor)
by the8472 on Wednesday July 31, 2024 @04:19AM
(#41117304)
The C++ forward progress guarantee enables more optimizations since it allows the compiler to reason more easily about loops:
> The standards added the forward progress guarantees to change an optimization problem from "solve the halting problem" to "there will be observable side effects in the forms of termination, I/O, volatile, and/or atomic synchronization, any other operation can be reordered". The former is generally impossible to solve, whereas the latter is eminently tractable.
But yeah, that's one of the more foot-gunny UB rules that Rust does not have. But it does mean it doesn't mark functions as `mustprogress` in LLVM IR which means it misses out on whatever optimizations that enables.
Undefined behavior is usually a result of runtime situation, it is usually not obvious from just the code whether it could or could not happen, so the compiler cannot reject the program.
The 'UB-based' optimization is just assumption that the code is correct and therefore UB-situation could not happen in runtime.