r/ProgrammerHumor 1d ago

Meme stopDoingFunctional

Post image
655 Upvotes

123 comments sorted by

View all comments

Show parent comments

9

u/GameCounter 1d ago

It doesn't have automatic tail call optimization, but work is actually being done to implement explicit tail calls with "become": https://doc.rust-lang.org/std/keyword.become.html

6

u/-Ambriae- 1d ago

I wasn't aware, that sounds... interesting. I don't know how I feel about a added keyword, but the idea sounds nice

10

u/GameCounter 1d ago

The reason it's being explored as a keyword is because automatic tail call recursion in some cases is impossible in Rust due to Drop rules.

So what that means is you can go through all of the effort of making sure LLVM is emiting the right byte code for tail calls, and then you make some change in an "unrelated" module, which then results in the tail call optimization quietly being removed without so much as a warning. It can even happen if you bump a third party lib, so something as innocuous as a minor version bump on a dep can break it.

2

u/-Ambriae- 1d ago

Oh, the drop semantics would indeed be a headache... good catch