Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpp coro recursively task "coroutine transformation" wrong #518

Closed
oncealong opened this issue Feb 28, 2023 · 1 comment
Closed

cpp coro recursively task "coroutine transformation" wrong #518

oncealong opened this issue Feb 28, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@oncealong
Copy link

https://godbolt.org/z/fcsPfevzW

the code above is from noop_coroutine.
when "coroutine transformation", the code

    task<int> v = get_random();
    task<int> u = get_random();
    std::cout << "in test()\n";
    int x = (co_await v + co_await u);

transform to

        __f->v = get_random();
        __f->u = get_random();
        std::operator<<(std::cout, "in test()\n");
        __f->x = (
                /* co_await insights.cpp:103 */
                __f->__suspend_103_14 = __f->v.operatorco_await();
        if(!__f->__suspend_103_14.await_ready()) {
            __builtin_coro_resume(__f->__suspend_103_14.await_suspend(std::coroutine_handle<task<int>::promise_type>::from_address(static_cast<void *>(__f)).operator coroutine_handle()).address());
            __f->__suspend_index = 2;
            return;
        }

        __resume_test_2:
        __f->__suspend_103_14_res = __f->__suspend_103_14.await_resume();

        /* co_await insights.cpp:103 */
        __f->__suspend_103_27 = __f->u.operator co_await();
        if(!__f->__suspend_103_27.await_ready()) {
            __builtin_coro_resume(__f->__suspend_103_27.await_suspend(std::coroutine_handle<task<int>::promise_type>::from_address(static_cast<void *>(__f)).operator coroutine_handle()).address());
            __f->__suspend_index = 3;
            return;
        }

        __resume_test_3:
        __f->__suspend_103_27_res = __f->__suspend_103_27.await_resume();
        );

the transform code __f->x = not grammatical.

@andreasfertig
Copy link
Owner

Hello @oncealong,

thanks for reporting this! I'll look into that issue.

Andreas

@andreasfertig andreasfertig added the bug Something isn't working label Mar 10, 2023
andreasfertig added a commit that referenced this issue Jun 20, 2023
The original issue uncovered more shortcomings in the coroutine
transformation.

a) It appears that `operator co_await` is the _only_ operator so far
   which must have a space between "operator" and the operator name.

b) Since `co_await` is an expression the keyword can occur in a lot of
   places, like lambdas. One limitation over lambdas is that a
   `co_await` occurs only in a `CoroutineBodyStmt`.

   This patch adds support for more case, however, some are of these
   transformations lead to code that is not logically correct. For
   example, all loop related statements with a `co_await` as a condition
   or increment expression are logically incorrect and I don't know a
   way to make them correct.
andreasfertig added a commit that referenced this issue Jun 20, 2023
The original issue uncovered more shortcomings in the coroutine
transformation.

a) It appears that `operator co_await` is the _only_ operator so far
   which must have a space between "operator" and the operator name.

b) Since `co_await` is an expression the keyword can occur in a lot of
   places, like lambdas. One limitation over lambdas is that a
   `co_await` occurs only in a `CoroutineBodyStmt`.

   This patch adds support for more case, however, some are of these
   transformations lead to code that is not logically correct. For
   example, all loop related statements with a `co_await` as a condition
   or increment expression are logically incorrect and I don't know a
   way to make them correct.
andreasfertig added a commit that referenced this issue Jun 20, 2023
Fixed #518: Support for `co_await` in a `VarDecl` and more.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants