3 ms·
Rust does have code in the compiler to make sure your code "cleanly" segfaults when you stack overflow, so while you can't catch up, you won't (as you do in som
by CJefferson 6y ago
Rust does have code in the compiler to make sure your code "cleanly" segfaults when you stack overflow, so while you can't catch up, you won't (as you do in some other languages) start corrupting the heap, or any other pieces of memory.
However, you still can't recover.
- souprock 6y agoThat is actually worse than C on Linux. For C, that segfault is provided by the kernel placing a guard page off the end of the stack. C programs recover via sigaltstack, sigaction, and siglongjmp. The C program can continue running safely afterward. I was expecting Rust to give a compile-time error. Rust should refuse to compile a program that would overflow the stack. Unbounded recursion is such a case. Another case would be recursion that is bounded but very large. For example, if the recursion depth can be 128, then on Linux (with the 8 MiB stack default) it would not be allowable to have the stack frames be 64 kilobytes each. That should not compile. Rust is not a memory-safe language.