On Wed, Apr 6, 2022 at 3:18 AM ben...@gmail.com <benh...@gmail.com> wrote:
> Normally the Go Playground gives errors when a runtime panic or other > error occurs, including "timeout running program" for programs that run too > long. I'm wondering why the Playground doesn't show a stack overflow error > (or any error) for this infinitely-recursing program? > > Depending on implementation, infinite recursion is not guaranteed to blow the stack for the program given. The function call is in tail position, so a tail-call optimization (TCO) pass would be able to rewrite the program into an infinite loop by reusing the existing stack frame for each invocation of f[0]. I don't think the spec explicitly rejects such optimizations, but you can't rely on TCO either, because it isn't mandated, like it is in e.g., the specification of the programming language Scheme. [0] One of the flip sides of such rewriting are that the stack might not exactly represent the control flow of the program, so in a debugging situation you have to apply more imagination to figure out what the program did. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAGrdgiXRx-8dkASeZS5xWohEfgOY8vqCNzSJSgzXyBH9uE6tog%40mail.gmail.com.