Conversation

So for example, you can have a simple loop over an array based on the length, and the compiler may not be able to tell that terminates since it can't tell that the length of the array isn't changed (even though a human trivially can). If you insert the intrinsic it destroys perf.
2
It depends on the simplicity of a condition and how it's written. You could write a binary search so that the compiler can see that it always terminates, but it wouldn't be the normal way to write it, etc. Many loops are not going to be verifiable as trivially terminating.
1
Mutually recursive function calls are another case that's very difficult. In order to avoid treating every single function call as needing to have that universal side effect inserted (destroying tons of optimization), the compiler would have to analyze the call graph.
1
Even if the recursion isn't via guaranteed tail calls stack overflow is well-defined and safe in these languages. It CANNOT be replaced with arbitrary memory corruption. They're saying that even remotely safe languages should have significantly worse compile-time and performance.
2
C compilers should be guaranteeing that stack overflow is safe and guaranteed to trap too. They shouldn't be optimizing out infinite recursion as they will happily do. It should either infinite loop or crash to be correct, not fall through to other code in an indeterminate state.
1
Guaranteed-to-trap isn't really safe unless you just count process termination is safe. In the presence of optimizations, there's no good way to assess what changes to state have or haven't taken place yet at the point of trap, so you can't really continue execution.
1
I'm saying that it should be guaranteed to trap and lead to the process being killed. That's perfectly safe. It's always a bug and could be exploited for denial of service but it remains memory and type safe. It can't be exploited for arbitrary code execution.
2
1
Their wrong implementation of the optimization can lead to arbitrary memory corruption. It breaks the safety semantics in safe languages very blatantly. It lets control flow fall through somewhere that's supposed to be impossible per the language's control flow and type system.
1
So for example, you may need to handle all possible cases of something, and you know you've done it, but the compiler does not, so you insert a call to a function that is guaranteed to never return rather than unsafe { unreachable() } to save an insignificant amount of space.