3 ms·
> Rust is supposed to be as fast as C/C++ and TCO will slow it down. TCO doesn't slow programs down. If anything, it might even make them a tiny bit faster.
by groovy2shoes 14y ago
> Rust is supposed to be as fast as C/C++ and TCO will slow it down.
TCO doesn't slow programs down. If anything, it might even make them a tiny bit faster. But speed isn't the reason you'd want TCO: you want it as a stack optimization so that tail-recursive functions use constant stack space. Furthermore, although the C specification places no TCO requirement on implementors, it's actually a very reasonable optimization even in C. GCC actually does do TCO in some cases (I'm using 4.5.3, and tail-call elimination occurs with -O2 and higher).
> Clojure can't have TCO because the Java Virtual Machine doesn't support it. So they have a workaround (trampolines).
This is true. There was a time when TCO support was slated for Java 7. That time has come and gone; unofficially, it looks like it may make an appearance in Java 9 at the earliest.
> Python doesn't support TCO because... it screws up stack traces?
That's the cited reason, but it's horseshit. As others have pointed out on this thread, it's feasible to simply disable TCO when doing debugging if you need a stack trace. Even fancier, there are algorithms to recover the stack even after the calls have been eliminated (see Lua for example).
- pasquinelli 14y ago"TCO doesn't slow programs down. If anything, it might even make them a tiny bit faster." right, but i think they were saying that, in this case, because of dependencies out of the rust team's control, they would have to use a different, slower calling convention to support proper tail calls.
- fhars 14y agoWell, according to a quick perusal of the LLVM documentation, the only llvm calling convention that allows TCO on all platforms seems to be fastcc, whose main purpose is to have calls that are a fast as possible, at the cost of not being compatible with the slower, but more common calling conventions of C. http://llvm.org/docs/LangRef.html#calling-conventions http://llvm.org/docs/LangRef.html#calling-conventions
- qznc 14y agoWhat does fastcc do when there are more arguments than registers? These cases are the reason for Pascal-convention according to Walton. https://mail.mozilla.org/pipermail/rust-dev/2012-January/001281.html https://mail.mozilla.org/pipermail/rust-dev/2012-January/001...
- jevinskie 14y agoIn that case you can clone the function. Internal linkage calls can use the fastcc calling convention while you leave either a whole clone with the non-fastcc calling convention or a non-fastcc wrapper of the fastcc function for calls from external linkage.
- pcwalton 14y ago"GCC actually does do TCO in some cases (I'm using 4.5.3, and tail-call elimination occurs with -O2 and higher)." Only sibling call optimization, as cdecl doesn't allow TCO in the general case. Rust will do this too.