Type-level bounded recursion in Rust
a year ago
- #Recursion
- #Rust
- #Stack Overflow
- Blowing the stack in Rust leads to an unrecoverable program termination due to a guard page mechanism.
- Rust installs a signal handler for stack overflow, triggering an abort to maintain safety guarantees.
- Languages with runtimes can manually check stack usage, but Rust lacks this capability.
- A depth counter is a simple solution for preventing stack overflow in recursive calls.
- Type-level recursion using Peano encoding and traits is explored for more advanced solutions.
- Macros are used to simplify the implementation of guarded recursion, though with some trade-offs.
- The approach increases codegen time and binary size due to generating multiple function instances.