4 ms·
Can't one fake TCO by hoisting things out into a loop? > Tail calls: I can't think of a Rust or C++ abstraction that relies on TCO to be zero-cost. Rust doesn
by swsieber 6y ago
Can't one fake TCO by hoisting things out into a loop?
> Tail calls: I can't think of a Rust or C++ abstraction that relies on TCO to be zero-cost.
Rust doesn't have TCO, so it's hard to rely on something that doesn't exist (unless it's on nightly and I missed it).
- steveklabnik 6y agoRust doesn't guarantee TCO, but LLVM may decide to do it if it wishes.
- Gibbon1 6y agoLack of a guarantee says you should use explicit loops.
- majewsky 6y agoThat's assuming the tail call is visible in human-level source code. You could also have a situation where A tail-calls B, B tail-calls C and C tail-calls A. If B and C get inlined, you now have the opportunity to convert A's self-tail-call into a loop. Refactoring A manually may not be desirable, e.g. if inlining B and C cause significant code duplication, or if they live in entirely different libraries.
- heavenlyblue 6y agoThis is obviously a mistake if that happened, are you proposing for the compilers to “fix” this bug automatically until someone changes one of these functions to not do a tail call and it explodes out of the blue?
- majewsky 6y agoWhy would that be a mistake?
- steveklabnik 6y agoI agree. Not sure why you're downvoted.