[clang] Extend `retcon.once` coroutines lowering to optionally produce a normal result (PR #66333)

Anton Korobeynikov via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 14 19:52:45 PDT 2023


asl wrote:

> What make me curious is the motivation case of the PR. I mean what can be presented in retcon.once ABI after the PR which is impossible/hard before. And how do we handle that in retcon ABI.

Well, the PR allows `recon.once` coroutines to have normal results in addition to yields. While it might be possible to "emulate" this functionality returning the value indirectly, it is not very convenient for producer (instead of just returning the value we'd need to allocate stack slot, pass the address, etc.) and might incur some overhead, as we'd essentially will need to capture both value to be returned and return address in the coroutine frame only to emit the store in the continuation part.

The particular usecase from Swift is as follows:
 - Yield pointer to some internals of an object
 - Allow the caller to modify the object via exposed pointer as necessary
 - In the coroutine continuation perform some "finalization" and return e.g. a pointer to a closure object with modified object being captured

https://github.com/llvm/llvm-project/pull/66333


More information about the cfe-commits mailing list