[llvm-dev] RFC: LLVM Coroutine Representation, Round 2

Antoine Pitrou via llvm-dev llvm-dev at lists.llvm.org
Wed Jul 20 14:44:53 PDT 2016


On Wed, 20 Jul 2016 14:23:29 -0700
Gor Nishanov via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> If you have a coroutine that looks like this:
> 
>    genenerator<int> g(int n) {
>       <initial-suspend>
>       for (int i = 0;;) yield ++i;
>       <final-suspend> // marked as final suspend
>   }
> 
> It will never reach the final suspend and thus coro.done will never evaluate
> to true. Thus, coroutine will produce an infinite sequence of values.

I don't think this answers my question.  Say I have (Python notation):

def coroutine(n):
    for i in range(n):
        yield i

def consumer(n):
    for val in coroutine(n):
        # do something with val

How does consumer() know the coroutine has exited after the n'th
iteration?  It can't call @coro.done() as there is a single suspend
point...

Regards

Antoine.




More information about the llvm-dev mailing list