-
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.
Browse files
Browse the repository at this point in the history
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
39e9e23
commit fe847c3
Showing
1 changed file
with
64 additions
and
6 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