← Back to context

Comment by slver

5 years ago

You'd get equivalent performance with "goto", but not depend on implicit compiler optimizations to save you from stack overflow.

I like the idea of tail calls, but I don't like it being an implicit "maybe" optimization of the compiler. Make it part of the standard, make the syntax explicit, and then both hands in.

You really wouldn't. We tried many approaches, including computed goto, but none of them were able to generate satisfactory code when compared with tail calls: https://gcc.gnu.org/pipermail/gcc/2021-April/235891.html

Also, it is not an implicit optimization when "musttail" support is available in the compiler.

  • Tailcall optimization is compiled as a JMP, so is goto, so I'm curious where would the difference come from?

    • The tail call design gives more control over register allocation, and gets the compiler to generate better code by putting fast paths and slow paths in separate functions. I tried to explain this in the article and in my link upthread.