Can beam TCR through (N) functions?

Looking through the :gen_server code, it looks like loop() calls decode_msg() which then in turn calls loop(). I presume this will be TCR-optimized; so is it generally the case that the BEAM can TCR through multiple functions?

Yes, as long as your function calls another function as its last statement, you can loop forever.

It does not matter whether it is tail recursion (calling the same function) or a tail call to any other function.

There is even an erlang type, no_return() for functions that will never return (or will always throw).

1 Like