-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Polish std::generator
#4952
Merged
CaseyCarter
merged 15 commits into
microsoft:feature/generator
from
CaseyCarter:generator
Sep 13, 2024
Merged
Polish std::generator
#4952
CaseyCarter
merged 15 commits into
microsoft:feature/generator
from
CaseyCarter:generator
Sep 13, 2024
Conversation
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
* Update citations to N4988 * Reorder checks to specification order * Make `_RRef` more obviously reflect the wording
Simplify and correct `StatelessAlloc` * Deriving publicly from `std::allocator` not a great idea, as witnessed by the recent addition of `allocate_at_least`. * `deallocate` should be `noexcept` for a `Cpp17Allocator`. * We don't need to reimplement `std::allocator` when we can simply use it. * The domain of equality for `Cpp17Allocators` is an entire `rebind` family, i.e., `StatelessAlloc<T>` and `allocator_traits<StatelessAlloc<T>>::rebind_alloc<U>` must be comparable. PascalCase `stateful_alloc` for consistency and move into the header with `StatelessAlloc`.
"whose member `await_ready` returns `false`" in N4988 [coro.generator.promise]/11 implies the return type is exactly `bool`, not "convertible to `bool`". Update `test_yield_elements_of_range` accordingly. Move size check from `P2502R2_generator` into `P2502R2_generator_promise`
Implement a complete `generator` traits in the header to use in both `P2502R2_generator_iterator` and `P2502R2_generator`'s `static_checks`.
... which takes a generator, a description of its static properties, and the expected result of piping the generator through a provided range adaptor. `test_one` validates the static properties with `static_checks`, and confirms the output is as expected.
... from `main` into new function `test_weird_reference_types`.
* Verify the default template arguments and the alias mapping * Ensure the generator doesn't allocate with `new`
* It's no longer significant that `co_upto` wasn't an example in the proposal; strike the comment. * Enforce `co_upto`'s precondition so it's nicely documented. * Consistently prefer `same_as` to `is_same_v`. * Regroup calls to test cases in `main` topically and title each category.
These are all simple O(1) checks, there's no reason not to promote them from `_DEBUG` to `_CONTAINER_DEBUG_LEVEL`.
Including some fancy memory layout diagrams. * Rename `_Promise_allocator` to `_Coro_promise_allocator` to avoid any confusion with `_Promise`. Rename its template parameter `_Allocator` to `_Proto_allocator` to avoid confusion with the rebound allocator type `_Alloc`. * Expand `static_assert` message in `operator new`. If and when `_Coro_promise_allocator` is reused by other coroutine types we can worry about making the message more generic. * Extract block size computations.
Per N4988 [coro.generator.promise]/7.
CaseyCarter
commented
Sep 12, 2024
* Remove unused `polymorphic_allocator<void>` conversion operator from `StatelessAlloc`. * Make `StatefulAlloc::domain` private. * Remove unneeded `constexpr` from `StatefulAlloc`. Drive-by: Correct typo in `<generator>` comment.
StephanTLavavej
requested changes
Sep 12, 2024
StephanTLavavej
approved these changes
Sep 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This should complete the
generator
feature branch and get it ready to merge. There are very few product code changes here, it's mostly expanded test coverage with some cleanup and reorganization. There's also some documentation of the "stack of coroutines" and the memory layout of allocations that will make it easier for folks to get up to speed on how the code works under the covers.It's broken down nicely by commit for ease of review; I'll replicate the commit messages here as an overview. Comments without specific context refer to
P2502R2_generator
where most changes were made. TheP2502R2_generator_iterator
andP2502R2_generator_promise
tests were already very nicely complete.generator
template argument mandates_RRef
more obviously reflect the wording forRRef
in WG21-N4988 [coro.generator.class]/1.4.StatelessAlloc
std::allocator
not a great idea, as witnessed by the recent addition ofallocate_at_least
.deallocate
should benoexcept
for aCpp17Allocator
.std::allocator
when we can simply use it.Cpp17Allocators
is an entirerebind
family, i.e.,StatelessAlloc<T>
andallocator_traits<StatelessAlloc<T>>::rebind_alloc<U>
must be comparable.stateful_alloc
for consistency and move into the header withStatelessAlloc
.await_ready
returnsfalse
" in WG21-N4988 [coro.generator.promise]/11 implies the return type is exactlybool
, not "convertible tobool
". Updatetest_yield_elements_of_range
accordingly.P2502R2_generator
intoP2502R2_generator_promise
static_checks
: Implement a completegenerator
traits in the header to use in bothP2502R2_generator_iterator
andP2502R2_generator
'sstatic_checks
.test_one
template which takes a generator, a description of its static properties, and the expected result of piping the generator through a provided range adaptor.test_one
validates the static properties withstatic_checks
, and confirms the output is as expected.main
into new functiontest_weird_reference_types
.co_upto
wasn't an example in the proposal; strike the comment.co_upto
's precondition so it's nicely documented.same_as
tois_same_v
.main
topically and title each category.main
. [This is the largest individual commit; it is a pure reordering.]_CONTAINER_DEBUG_LEVEL
. These are all simple O(1) checks, there's no reason not to promote them from_DEBUG
to_CONTAINER_DEBUG_LEVEL
._Promise_allocator
to_Coro_promise_allocator
to avoid any confusion with_Promise
. Rename its template parameter_Allocator
to_Proto_allocator
to avoid confusion with the rebound allocator type_Alloc
.static_assert
message inoperator new
. If and when_Coro_promise_allocator
is reused by other coroutine types we can worry about making the message more generic.Element_awaiter
must direct-non-list-initialize its stored object, per WG21-N4988 [coro.generator.promise]/7.