Stackful coroutines design


The second revision of coroutines seems to have switched to a stackful implementation. Is the rationale behind this decision documented somewhere? Are the arguments in Issue 35 still valid?



It really depends on your definition of “stackfull coroutines”. The discussion at issue 35 seems to proceed without the actual definition of what stackfull coroutines are, so there are a lot of seemly confusing and contradicting statements.

The second revision was not a significant change in the design of the Kotlin coroutines. You were able write some helper code to invoke suspending function from other suspending functions in the original revision and it worked just as fine, albeit it was less pleasing from syntactic standpoint. In the second revision it became more straightforward, due to the overall simplification and composability of design. The later two things (simplicity and composability) were the actual goals of the revision, with the rest being a nice side-effect.

Just to make it clear. There are no thread-locals nor any other heavy-weight objects of this kind in the second revision. It is all still extremely light-weight and down-to-the-metal. You still cannot suspend though the ordinary Java or Kotlin methods – you can call suspending function only from other suspending functions.