Tail call optimization TCO
When a function call is the last thing that happens, the compiler can reuse the existing stack frame instead of pushing a new one. Recursion then becomes a loop.
The condition is that the call sits in tail position, meaning no work remains after it returns — return f(x) qualifies, return f(x) + 1 does not, because the addition must happen afterwards. When it holds there is no reason to save a return address, and recursion of arbitrary depth runs in constant stack space. In Scheme this is mandated by the standard and is the basis for expressing all iteration as recursion. In C, C++ and Rust the compilers do it when optimisation is on, but without any guarantee — so the same code can blow the stack in a debug build. JavaScript specified it in ES6, but only Safari ever implemented it.