by skybrian · 3y ago · 0 comments
It seems like a compiler could unroll a function one step, so the first internal call isn't a tail call? Then the first stack frame with the initial arguments would remain on the stack, and the stack trace would be similar to what it would be if you wrote a loop instead.
This is because stack traces are continuations; i.e. they show the future of our computation; those things which have not yet been done.
Reaching a function's tail position means, by definition, that its computations are finished. Hence why such functions don't appear in stack traces; the same way that, say, a call like 'foo(bar(42))' won't include 'bar' in a stack trace if 'foo' crashes.
> By the time an exception is thrown, or execution pauses, the tail caller frames are gone and there is no way for V8 to recover them.
This can be done by a time-travelling debugger; since that keeps a trace of past computations. It also adds overhead, though.
Also everyone: We want complete stack traces.
Imagine wanting O(call depth) stack frames after demanding that the stack can only use O(1) memory.
This is also tricky when you have indirect tail calls, because now you don't know if it's the first call to that particular function so you can't always unroll it anyway.
To match the implementation without tail calls, you probably don't want the previous instruction(s) on the stack, but all entry points into the interpreter should probably be on the stack.