同级调用没有出现在堆栈跟踪中?

Sibling calls don’t appear in stack trace?

我刚刚在 stack traces 上的维基百科文章中偶然发现了一行。

它说:

Sibling calls do not appear in a stack trace.

这到底是什么意思?我认为所有堆栈帧都出现在堆栈跟踪中。据我了解,即使有尾调用,新帧仍会被压入堆栈,因此是可追踪的。有没有一个例子可以让我看到这个动作,其中兄弟调用没有显示在堆栈跟踪中?

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

你误会了。

来自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.

由于"sibling calls"只是尾调用的特例,所以可以用同样的方式优化。您应该能够在编译器优化其他尾调用的任何场景中以及在上面引用的维基百科文章中描述的那些特定示例中看到这方面的示例。

根据该术语下 link 引出的引理,兄弟姐妹的称呼是 "tail calls to functions which take and return the same types as the caller"

uses a jump instead of a function call 使用当前堆栈帧。