[rust-dev] Fall-through in alt, break&continue by label

Stefan Plantikow stefan.plantikow at googlemail.com
Mon Apr 16 16:07:43 PDT 2012


Am Montag, 16. April 2012 um 20:54 schrieb Graydon Hoare: 
> On 12-04-16 11:49 AM, Patrick Walton wrote:
> > On 4/16/12 11:46 AM, Graydon Hoare wrote:
> > > They're already "present" (were from the beginning) but they broke when
> > > we shifted from rustboot (hand-rolled code generator) to rustc (LLVM).
> > > It turns out that you have to adopt a somewhat pessimistic ABI in all
> > > cases if your functions are to be tail-callable. There's a bug open on
> > > this[1] that discusses in some more detail, but I think the feature is
> > > drifting towards a decision to remove the feature altogether.
> > 
> > 
> > 
> > I actually disagree with this; I think that we should measure. I'm not
> > sure that the Pascal calling convention is worse than the C calling
> > convention in practice.
> > 
> > In any case, I believe we're doing sibling call optimization already.
> Ok! I certainly don't _dislike_ tail calls (put them in intentionally),
> I just thought the mood had mostly soured on them due to the assumed
> perf overhead. I'm happy to dig further and try to get this working again.
Some algorithms just yearn for being written in a recursive style.

I imagine a new user who first discovers rust type classes will be quite surprised to find out that there are no tail calls, it goes quite against the idea of being able to program in a functional style and recursion seems to be quite a perfect match for a language that already has pattern matching over immutable variables.

In erlang there is an interesting use of tail calls related to atomic code migration: Actors spin on a tail-callable function. This recursive call serves as the handover point during code migration, i.e. the loop state is passed on but the code changes. To achieve something similar with an actor that loops over requests via while seems more involved to me.

I'd rather see tail calllibility remain as a feature that has to be requested explicitly by the user than to nick it completely. At one point I wrote a wiki page that discusses the idea of making "tail callability" a part of the function type. This would allow to switch to the proper calling convention on the call site. While that is agreeably awkward and limiting it should still be enough for many useful scenarios (module-local recursion, and recursively written main loops).



More information about the Rust-dev mailing list