[RFC] Async/Await dialect targeting LLVM coroutines

In Zig (and I believe Rust had the same experimence), the LLVM implementation of co-routines was tried and we learned it was broken because it does not seperate the allocation and deallocation of memory (the co-routine frame) from the execution of said co-routine.

Do you have any pointers to discussion? Don’t quite get what does it mean in practice.

  • Because Zig uses LLVM’s coroutine support, it has to follow the paradigm they set, which is that the coroutine allocates its own memory and destroys itself. In Zig this means that calling a coroutine can fail, even though that doesn’t have to be possible. It also causes issues such as #1194.
  • It also means that every coroutine has to be generic and accept a hidden allocator parameter. This makes it difficult to take advantage of coroutines to solve safe recursion (#1006).
  • One of the slowest things LLVM does in debug builds, discovered with -ftime-report , is the coroutine splitting pass. Putting the pass in zig frontend code will speed it up. I examined the implementation of LLVM’s coroutine support, and it does not appear to provide any advantages over doing the splitting in the frontend.
  • Optimizations are completely disabled due to LLVM bugs with coroutines (#802)

That last bug is particularly nasty https://bugs.llvm.org/show_bug.cgi?id=36578