Equality of Recursive Structures [Was: Closure Compiler in 3.9 ?]

Lex Spoon lex at lexspoon.org
Sun May 13 10:06:28 UTC 2007


Colin Putney <cputney at wiresong.ca> writes:
> Now, you might say that none of that makes it impossible to do tail-
> call elimination, you just have to work hard to avoid getting caught.
> The VM could perform the dispatch and only reuse the stack frame if
> the message resolves to the same method. Ok, this is true. But tail-
> call elimination is Smalltalk isn't the clear win that it is in, say,
> Scheme.

A tail call does not have to be to the same method to be optimized!

In fact there is not even a special opcode needed.  Whenever you
do [^ x message] then the send of "message" is a tail call.  Since
message-passing is about all you can do in Smalltalk, most return
statements are in fact tail calls.

What the optimization can do is create the new stack frame as normal,
but set its return pointer to skip over the current frame.  Then, the
calling frame can be returned to the free list before jumping to the
new method.  (Assuming, that is, that no closure has captured the
frame....)

What cannot be done in Lukas' interesting examples is to reuse the
same stack frame object, thus compiling the method as a loop.
However, given a linear stack (unlike Squeak's heap-based stack), you
could still implement the call as a jump....


Lex




More information about the Squeak-dev mailing list