-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
coroutine frame from lambda #91123
Comments
@llvm/issue-subscribers-coroutines Author: None (kelbon)
I think there are should be a way to create coroutine frame from lambda. There are use cases:
I have "implementation", but for obvious reasons it is not good: it contains undefined behavior. And i dont know is it intentional, but clang ignores all noinline and std::launder hacks and just optimizes out all code every time (with O1/O2/O3): template <typename F>
struct alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) coroutine_frame {
void (*resume)(void*) = &do_resume<std::decay_t<coroutine_frame>>;
void (*destroy)(void*) = &do_destroy<std::decay_t<coroutine_frame>>;
F f;
coroutine_frame(F value) : f(std::move(value)) {}
[[gnu::noinline]] std::coroutine_handle<> handle() noexcept {
return std::coroutine_handle<>::from_address(std::launder(this));
}
}; |
From the perspective of compilers, there is not a lot of things we can do here. |
im about just using internal knowledge about how coroutines implemented and using this information to create a struct without UB, it seems possible |
It looks like other optimizations clear such uses somehow... I am not sure why it can't works. |
I think there are should be a way to create coroutine frame from lambda. There are use cases:
I have "implementation", but for obvious reasons it is not good: it contains undefined behavior. And i dont know is it intentional, but clang ignores all noinline and std::launder hacks and just optimizes out all code every time (with O1/O2/O3):
https://godbolt.org/z/EP1b8Eb9x
The text was updated successfully, but these errors were encountered: