Is there a way to enable TCO for tail calls in a s...
# compiler
y
Is there a way to enable TCO for tail calls in a suspend function with multiple labels? I.e. imagine this situation:
Copy code
suspend fun foo() {
  val b = bar()
  TODO("Do other things")
}
suspend fun bar() {
  delay(1)
  suspendCoroutineUninterceptedOrReturn { 
    // I wish that it here would be foo's continuation, not bar's 
  }
}
I know that it's likely implementing this way for stack trace reasons, but assuming I don't care for stack traces, is there a magic compiler option or something to enable that? This would also allow automatic TCO for suspend functions that don't even have
tailrec
on them. Or is this feature useless in Kotlin? I'm reading up on literature from Scheme and other functional language where tail calls are very very important to have optimized well, but perhaps Kotlin code likely won't benefit from that? All thoughts appreciated!
e
đŸ‘€ 1
y
Huh, maybe I'm running into an edge-case when using
startCoroutine
because I was observing different behaviour. I shall investigate further!