-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce get_return_object_on_allocation_failure to Lazy (#338)
This patch tries to introduce `get_return_object_on_allocation_failure()` to the promise_type of Lazy. Why do we want to introduce `get_return_object_on_allocation_failure()`? Since a coroutine will be roughly converted to: ```C++ void *frame_addr = ::operator new(required size); __promise_ = new (frame_addr) __promise_type(...); __return_object_ = __promise_.get_return_object(); co_await __promise_.initial_suspend(); try { function-body } catch (...) { __promise_.unhandled_exception(); } co_await __promise_.final_suspend(); ``` Then we can find that the coroutine should be nounwind (noexcept) naturally if the constructor of the promise_type, the get_return_object() function, the initial_suspend, the unhandled_exception(), the final_suspend and the allocation function is noexcept. For the specific coroutine type, Lazy, all the above except the allocation function is noexcept. So that we can make every Lazy function noexcept naturally if we make the allocation function nothrow. This is the reason why we want to introduce `get_return_object_on_allocation_failure()` to Lazy. Note that the optimization may not work in some platforms due the ABI limitations. Since they need to consider the case that the destructor of an exception can throw exceptions.
- Loading branch information
1 parent
584e1f1
commit 1661fe5
Showing
1 changed file
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters