So, I was thinking about making a crate that basically converts stack overflow panics from abort-only to unwind panics. The reasoning behind this is that when writing certain recursive descent parsers (or recursive functions in general), it would be useful to put a limit on the possible number of recursions. The way this would work is that the user would call a function like
init_stack_overflow_check() and annotate each function with something like
#[check_stack], which inserts the proper checks.
The problem with this is that it's basically impossible to do correctly outside of the compiler. This is because large on-stack allocations (such as large arrays) would cause the abort panic to occur before my crate can catch it, as allocas occur within the function body. AFAIK it's impossible to insert code before the llvm allocas, although I may be wrong here and some trickery may allow it.
I was thinking that this wouldn't be a horrible check to allow into the compiler, if it is specifically asked for via a flag in the toml. After all, it's not different from a bounds check. However, bounds checks are also abort-only, so making this feature orthogonal would basically require making array bounds checks unwind as well.
Does anyone else find this feature useful, or am I alone in this? Personally I vastly prefer the crate solution with proc macros, because it allows the feature to be specifically applied. The sometimes-failing nature makes me feel that I need to present this idea to a broader audience first.