On Jul 4, 2010, at 11:15 AM, Lukas Renggli wrote:
What would it take to implement tail-call optimization?
Implementing tail recursion is easily doable and could be transparently done at the compiler level. The basic idea (at the language level) is described here:
http://stackoverflow.com/questions/2500483?tab=oldest#tab-top
However, tail call optimization is not a good match for Smalltalk code. You arbitrarily loose stack frames that you might want for debugging (and other kinds of reflection). Also the code in the above article kills the performance of modern VMs, because it manipulates the runtime stack (if you do the jump using bytecodes that wouldn't be a problem though). Furthermore you need to take a lot of care to keep your code correct, because these kind of optimization can easily break with polymorphism and reflective code.
Excellent this is now what was the conclusion of the discussion :)
I would really like to know what would be gain and the cost (implementation wise to do that).
I did some analysis in a Squeak 3.9 image a long time ago and I came to the following conclusion: "In my Squeak image there are 160464 send locations of which 8884 are possible tail call locations (5.5%). I guess this does not really make it worth the trouble."
Lukas
-- Lukas Renggli www.lukas-renggli.ch
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project