2

I just stumbled upon a line in the Wikipedia article on stack traces.

It says:

Sibling calls do not appear in a stack trace.

What exactly does this mean? I thought all stack frames appeared in a stack trace. From my understanding, even with a tail call, new frames are still pushed onto the stack, and are thus traceable. Is there an example where I can see this in action, where sibling calls are not shown in the stack trace?

rb612
  • 5,280
  • 3
  • 30
  • 68

2 Answers2

3

From my understanding, even with a tail call, new frames are still pushed onto the stack, and are thus traceable

You misunderstand.

From Wikipedia:

Tail calls can be implemented without adding a new stack frame to the call stack. [emphasis mine] Most of the frame of the current procedure is no longer needed, and can be replaced by the frame of the tail call, modified as appropriate (similar to overlay for processes, but for function calls). The program can then jump to the called subroutine. Producing such code instead of a standard call sequence is called tail call elimination.

As "sibling calls" are just a special case of tail calls, they can be optimized in the same way. You should be able to see examples of this in any scenario where the compiler would optimize other tail calls, as well as in those specific examples such as described in the above-referenced Wikipedia article.

Peter Duniho
  • 68,759
  • 7
  • 102
  • 136
1

Sibling calls are, according to the lemma led to by the link under that term, "tail calls to functions which take and return the same types as the caller".

This uses a jump instead of a function call using the current stack frame.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272