Fix sentinel return type mismatch in hpx::ranges container algorithm CPOs#7322
Conversation
f6dc14e to
16a972c
Compare
Up to standards ✅🟢 Issues
|
16a972c to
227d4ae
Compare
|
Can one of the admins verify this patch? |
227d4ae to
215245d
Compare
5f740ee to
c1c4cc9
Compare
|
@aneek22112007-tech please address the compilation issues reported by the CIs. Also, please always have an eye on the CI results yourself. clang-format is unhappy as well, BTW. |
d7d6615 to
c48ab8a
Compare
|
@aneek22112007-tech FWIW, clang-format and inspect are still reporting problems. The changes to one of the tests you did cause compilation issues as well. |
6137a5d to
e159a21
Compare
|
@aneek22112007-tech inspect is unhappy: |
4b0b8ed to
4405e9a
Compare
|
@aneek22112007-tech please rebase onto master and resolve the conflicts. Also, the clang-format CI fails and one of the tests doesn't compile.. |
e680cfa to
5488a6b
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (15)
🚧 Files skipped from review as they are similar to previous changes (12)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR corrects iterator/sentinel result handling in find-family and range algorithms, centralizes ChangesSentinel-aware algorithm results
Estimated code review effort: 3 (Moderate) | ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
libs/core/algorithms/tests/unit/algorithms/find_tests.hpp (1)
76-136: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winGuard the sender test wrappers as well
find_tests.hppnow hides the sender helpers behindHPX_HAVE_STDEXEC, butlibs/core/algorithms/tests/unit/algorithms/find_sender.cppstill defines and calls the wrapper functions unconditionally. Without that macro, this test target will fail to compile.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@libs/core/algorithms/tests/unit/algorithms/find_tests.hpp` around lines 76 - 136, The sender test wrappers in find_tests.hpp are now conditional on HPX_HAVE_STDEXEC, but find_sender.cpp still defines and calls test_find_explicit_sender_direct and test_find_explicit_sender unconditionally. Guard the corresponding definitions and invocation sites in find_sender.cpp with the same HPX_HAVE_STDEXEC check, or otherwise compile them only when the sender-related helpers are available. This will keep the test target from referencing symbols that are absent in non-stDEXEC builds.
🧹 Nitpick comments (1)
libs/core/algorithms/tests/unit/container_algorithms/test_utils.hpp (1)
154-207: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider factoring out common logic between
test_containerandtest_sentinel_container.Both structs duplicate the constructor,
base(), andbegin()/cbegin()implementations verbatim; onlyend()/cend()/the sentinel typedefs differ. A shared base (CRTP or simple composition) would reduce duplication, though this is purely test-utility code with low risk.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@libs/core/algorithms/tests/unit/container_algorithms/test_utils.hpp` around lines 154 - 207, The test utilities in test_sentinel_container duplicate the constructor, base(), and begin()/cbegin() logic already present in test_container. Refactor the shared parts into a common base/helper used by both test_container and test_sentinel_container, and keep only the differing end()/cend() and sentinel typedefs in test_sentinel_container so the two types stay aligned without repeated implementations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@libs/core/algorithms/include/hpx/parallel/container_algorithms/find.hpp`:
- Around line 2598-2609: The async branch in find’s result handling only chains
with future-based results, but algorithm_result_t<ExPolicy, Iter> can also be
sender-backed for scheduler-executor policies. Update the logic in the
result/subrange return path to either use sender-compatible continuation
chaining for HPX_MOVE(result) or split the branch using
execution_policy_has_scheduler_executor_v<ExPolicy> so sender-backed async
policies are handled correctly while preserving the existing future-based path.
In `@libs/core/algorithms/tests/unit/container_algorithms/find_range.cpp`:
- Around line 380-389: The first find_last_if_not test block computes result and
test_index but never verifies them, so the original unmodified call is not
covered. In the find_last_if_not section of the container_algorithms test, add
an assertion for the initial hpx::ranges::find_last_if_not(c, pred) result using
the existing iterator/base_iterator expectations, and either use test_index in
that check or remove it if unnecessary; keep the later result2 assertion for the
mutated c.base().back() case.
---
Outside diff comments:
In `@libs/core/algorithms/tests/unit/algorithms/find_tests.hpp`:
- Around line 76-136: The sender test wrappers in find_tests.hpp are now
conditional on HPX_HAVE_STDEXEC, but find_sender.cpp still defines and calls
test_find_explicit_sender_direct and test_find_explicit_sender unconditionally.
Guard the corresponding definitions and invocation sites in find_sender.cpp with
the same HPX_HAVE_STDEXEC check, or otherwise compile them only when the
sender-related helpers are available. This will keep the test target from
referencing symbols that are absent in non-stDEXEC builds.
---
Nitpick comments:
In `@libs/core/algorithms/tests/unit/container_algorithms/test_utils.hpp`:
- Around line 154-207: The test utilities in test_sentinel_container duplicate
the constructor, base(), and begin()/cbegin() logic already present in
test_container. Refactor the shared parts into a common base/helper used by both
test_container and test_sentinel_container, and keep only the differing
end()/cend() and sentinel typedefs in test_sentinel_container so the two types
stay aligned without repeated implementations.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 414753ed-7ef9-4446-a9dc-4de3938220b3
📒 Files selected for processing (54)
libs/core/algorithms/include/hpx/parallel/algorithms/find.hpplibs/core/algorithms/include/hpx/parallel/container_algorithms/find.hpplibs/core/algorithms/include/hpx/parallel/container_algorithms/iota.hpplibs/core/algorithms/include/hpx/parallel/container_algorithms/is_partitioned.hpplibs/core/algorithms/include/hpx/parallel/container_algorithms/partition.hpplibs/core/algorithms/include/hpx/parallel/container_algorithms/remove.hpplibs/core/algorithms/include/hpx/parallel/container_algorithms/rotate.hpplibs/core/algorithms/include/hpx/parallel/container_algorithms/unique.hpplibs/core/algorithms/tests/unit/algorithms/adjacentdifference_tests.hpplibs/core/algorithms/tests/unit/algorithms/adjacentfind_tests.hpplibs/core/algorithms/tests/unit/algorithms/all_of_tests.hpplibs/core/algorithms/tests/unit/algorithms/any_of_tests.hpplibs/core/algorithms/tests/unit/algorithms/count_tests.hpplibs/core/algorithms/tests/unit/algorithms/countif_tests.hpplibs/core/algorithms/tests/unit/algorithms/ends_with_sender.cpplibs/core/algorithms/tests/unit/algorithms/equal_binary_tests.hpplibs/core/algorithms/tests/unit/algorithms/equal_tests.hpplibs/core/algorithms/tests/unit/algorithms/find_tests.hpplibs/core/algorithms/tests/unit/algorithms/findend_tests.hpplibs/core/algorithms/tests/unit/algorithms/findfirstof_tests.hpplibs/core/algorithms/tests/unit/algorithms/findif_tests.hpplibs/core/algorithms/tests/unit/algorithms/findifnot_tests.hpplibs/core/algorithms/tests/unit/algorithms/foreach_sender.cpplibs/core/algorithms/tests/unit/algorithms/foreach_tests.hpplibs/core/algorithms/tests/unit/algorithms/includes_sender.cpplibs/core/algorithms/tests/unit/algorithms/is_heap_tests.hpplibs/core/algorithms/tests/unit/algorithms/is_partitioned_sender.cpplibs/core/algorithms/tests/unit/algorithms/is_sorted_tests.hpplibs/core/algorithms/tests/unit/algorithms/is_sorted_until_sender.cpplibs/core/algorithms/tests/unit/algorithms/lexicographical_compare_sender.cpplibs/core/algorithms/tests/unit/algorithms/max_element_sender.cpplibs/core/algorithms/tests/unit/algorithms/min_element_sender.cpplibs/core/algorithms/tests/unit/algorithms/minmax_element_sender.cpplibs/core/algorithms/tests/unit/algorithms/mismatch_binary_tests.hpplibs/core/algorithms/tests/unit/algorithms/mismatch_tests.hpplibs/core/algorithms/tests/unit/algorithms/none_of_tests.hpplibs/core/algorithms/tests/unit/algorithms/reduce_tests.hpplibs/core/algorithms/tests/unit/algorithms/remove_tests.hpplibs/core/algorithms/tests/unit/algorithms/search_sender.cpplibs/core/algorithms/tests/unit/algorithms/starts_with_sender.cpplibs/core/algorithms/tests/unit/algorithms/transform_binary2_tests.hpplibs/core/algorithms/tests/unit/algorithms/transform_binary_tests.hpplibs/core/algorithms/tests/unit/algorithms/transform_reduce_binary_tests.hpplibs/core/algorithms/tests/unit/algorithms/transform_reduce_sender.cpplibs/core/algorithms/tests/unit/algorithms/transform_tests.hpplibs/core/algorithms/tests/unit/algorithms/unique_tests.hpplibs/core/algorithms/tests/unit/container_algorithms/find_range.cpplibs/core/algorithms/tests/unit/container_algorithms/partition_range.cpplibs/core/algorithms/tests/unit/container_algorithms/remove_if_range.cpplibs/core/algorithms/tests/unit/container_algorithms/remove_range.cpplibs/core/algorithms/tests/unit/container_algorithms/rotate_range.cpplibs/core/algorithms/tests/unit/container_algorithms/stable_partition_range.cpplibs/core/algorithms/tests/unit/container_algorithms/test_utils.hpplibs/core/algorithms/tests/unit/container_algorithms/unique_range.cpp
70476f5 to
2d07e86
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
libs/core/algorithms/tests/unit/algorithms/filln_tests.hpp (1)
73-103: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winGuard
filln_sender.cppbehindHPX_HAVE_STDEXEC.filln_tests.hppis already protected, butlibs/core/algorithms/tests/unit/algorithms/filln_sender.cppis still added unconditionally inlibs/core/algorithms/tests/unit/algorithms/CMakeLists.txt, so non-HPX_HAVE_STDEXECbuilds will still try to instantiate these sender tests and fail.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@libs/core/algorithms/tests/unit/algorithms/filln_tests.hpp` around lines 73 - 103, Guard the sender test target behind HPX_HAVE_STDEXEC in the algorithms test CMake setup, because filln_tests.hpp is already conditional but filln_sender.cpp is still always added and will break non-stdexec builds. Update the logic in the CMakeLists for the algorithms unit tests so the filln_sender.cpp source is only included when HPX_HAVE_STDEXEC is enabled, matching the existing `#if` defined(HPX_HAVE_STDEXEC) protection around test_fill_n_sender.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@libs/core/algorithms/tests/unit/algorithms/filln_tests.hpp`:
- Around line 73-103: Guard the sender test target behind HPX_HAVE_STDEXEC in
the algorithms test CMake setup, because filln_tests.hpp is already conditional
but filln_sender.cpp is still always added and will break non-stdexec builds.
Update the logic in the CMakeLists for the algorithms unit tests so the
filln_sender.cpp source is only included when HPX_HAVE_STDEXEC is enabled,
matching the existing `#if` defined(HPX_HAVE_STDEXEC) protection around
test_fill_n_sender.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3c8dfb30-6383-46ef-b761-99b99f1738a9
📒 Files selected for processing (36)
libs/core/algorithms/tests/unit/algorithms/adjacentdifference_tests.hpplibs/core/algorithms/tests/unit/algorithms/adjacentfind_tests.hpplibs/core/algorithms/tests/unit/algorithms/all_of_tests.hpplibs/core/algorithms/tests/unit/algorithms/any_of_tests.hpplibs/core/algorithms/tests/unit/algorithms/copy_tests.hpplibs/core/algorithms/tests/unit/algorithms/copyn_tests.hpplibs/core/algorithms/tests/unit/algorithms/count_tests.hpplibs/core/algorithms/tests/unit/algorithms/countif_tests.hpplibs/core/algorithms/tests/unit/algorithms/destroy_tests.hpplibs/core/algorithms/tests/unit/algorithms/equal_binary_tests.hpplibs/core/algorithms/tests/unit/algorithms/equal_tests.hpplibs/core/algorithms/tests/unit/algorithms/fill_tests.hpplibs/core/algorithms/tests/unit/algorithms/filln_tests.hpplibs/core/algorithms/tests/unit/algorithms/findend_tests.hpplibs/core/algorithms/tests/unit/algorithms/findfirstof_tests.hpplibs/core/algorithms/tests/unit/algorithms/findif_tests.hpplibs/core/algorithms/tests/unit/algorithms/findifnot_tests.hpplibs/core/algorithms/tests/unit/algorithms/foreach_tests.hpplibs/core/algorithms/tests/unit/algorithms/generate_tests.hpplibs/core/algorithms/tests/unit/algorithms/generaten_tests.hpplibs/core/algorithms/tests/unit/algorithms/is_heap_tests.hpplibs/core/algorithms/tests/unit/algorithms/is_sorted_tests.hpplibs/core/algorithms/tests/unit/algorithms/mismatch_binary_tests.hpplibs/core/algorithms/tests/unit/algorithms/mismatch_tests.hpplibs/core/algorithms/tests/unit/algorithms/none_of_tests.hpplibs/core/algorithms/tests/unit/algorithms/reduce_tests.hpplibs/core/algorithms/tests/unit/algorithms/remove_tests.hpplibs/core/algorithms/tests/unit/algorithms/transform_binary2_tests.hpplibs/core/algorithms/tests/unit/algorithms/transform_binary_tests.hpplibs/core/algorithms/tests/unit/algorithms/transform_reduce_binary_tests.hpplibs/core/algorithms/tests/unit/algorithms/transform_tests.hpplibs/core/algorithms/tests/unit/algorithms/uninitialized_copy_tests.hpplibs/core/algorithms/tests/unit/algorithms/uninitialized_default_construct_tests.hpplibs/core/algorithms/tests/unit/algorithms/uninitialized_move_tests.hpplibs/core/algorithms/tests/unit/algorithms/uninitialized_value_construct_tests.hpplibs/core/algorithms/tests/unit/algorithms/unique_tests.hpp
🚧 Files skipped from review as they are similar to previous changes (16)
- libs/core/algorithms/tests/unit/algorithms/findifnot_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/transform_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/countif_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/all_of_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/is_sorted_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/transform_binary_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/adjacentfind_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/findfirstof_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/unique_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/reduce_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/adjacentdifference_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/equal_binary_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/count_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/is_heap_tests.hpp
- libs/core/algorithms/tests/unit/algorithms/equal_tests.hpp
hkaiser
left a comment
There was a problem hiding this comment.
Please address the AI generated comments as well.
|
Also, some CIs are failing still. Please have a look. |
cda9b61 to
858d28a
Compare
|
Please address the clang-format issues. |
0a59c4e to
73c067b
Compare
73c067b to
16c3a87
Compare
|
@aneek22112007-tech Some of the tests fail running, e.g., https://github.com/TheHPXProject/hpx/actions/runs/29145433533/job/86529026877?pr=7322 |
…CPOs
Several hpx::ranges container algorithm CPOs had return type declarations where
the sentinel parameter was silently defaulted to iterator_t<Rng> when using
container range overloads. This caused type-safety violations when the container
uses a sentinel type distinct from its iterator type, which is a standard-compliant
scenario per C++20.
This commit fixes the return types to use
subrange_t<iterator_t<Rng>, sentinel_t<Rng>> as required by the C++20/23 standard
for the following algorithms:
- hpx::ranges::rotate
- hpx::ranges::unique
- hpx::ranges::partition / hpx::ranges::stable_partition
- hpx::ranges::remove / hpx::ranges::remove_if
- hpx::ranges::find_last / hpx::ranges::find_last_if / hpx::ranges::find_last_if_not
For find_last algorithms specifically:
- Fixed parallel dispatch implementations to return HPX_MOVE(first) instead of
HPX_MOVE(last) when the range is empty (last has sentinel type, return type
expects iterator type)
- Added proper async wrapping of the inner Iter result into subrange_t<Iter, Sent>
for all three parallel range overloads
A reusable test::test_sentinel_container<Container, IteratorTag> helper is added
to test_utils.hpp to enable sentinel-aware algorithm tests. Sentinel regression
test cases are added to all seven affected test files and verified to pass.
Signed-off-by: Aneek22112007 <das.aneek007@gmail.com>
- Fix stdexec guards in find_tests.hpp - Fix return type mismatch in non-policy overloads - Apply clang-format-20 to all changed files Signed-off-by: Aneek22112007 <das.aneek007@gmail.com>
Signed-off-by: Aneek22112007 <das.aneek007@gmail.com>
d8df77c to
8a99ce8
Compare
DONE |
Summary
Several
hpx::rangescontainer algorithm CPOs had return type declarations wherethe
Sent(sentinel) template parameter was silently defaulted toiterator_t<Rng>when the range overload deduced the sentinel from the range type. This caused
type-safety violations when the container used a sentinel type that differs from
its iterator (a standard-compliant scenario per C++20).
This PR fixes the return types to use
subrange_t<iterator_t<Rng>, sentinel_t<Rng>>as mandated by the C++20 standard.
Affected Algorithms
hpx::ranges::rotatehpx::ranges::uniquehpx::ranges::partition/hpx::ranges::stable_partitionhpx::ranges::remove/hpx::ranges::remove_ifhpx::ranges::find_last/hpx::ranges::find_last_if/hpx::ranges::find_last_if_notChanges
Algorithm Headers
container_algorithms/rotate.hpp,unique.hpp,partition.hpp,remove.hpp,find.hpp:tag_fallback_invokewithRng&¶meter)to declare their return type as
subrange_t<iterator_t<Rng>, sentinel_t<Rng>>instead ofsubrange_t<iterator_t<Rng>>(which collapsed the sentinel to the iterator type).parallel/algorithms/find.hpp:find_last,find_last_if, andfind_last_if_notparallel dispatchimplementations to return
HPX_MOVE(first)(the iterator) instead ofHPX_MOVE(last)(the sentinel) when the range is empty, matching the declaredreturn type
Iter.Iterresult intosubrange_t<Iter, Sent>for all three parallel range overloads.Tests
tests/unit/container_algorithms/test_utils.hpp:test::test_sentinel_container<Container, IteratorTag>— a lightweightrange wrapper that exposes
test::test_iterator<I, Tag>as its iterator andtest::sentinel_from_iterator<I>as its sentinel, enabling sentinel-awarealgorithm tests.
Sentinel regression cases added to each test file:
rotate_range.cpp,unique_range.cpp,partition_range.cpp,stable_partition_range.cpp,remove_range.cpp,remove_if_range.cpp,find_range.cppEach test exercises both
seqand (where applicable)parexecution policiesagainst a range whose sentinel type differs from its iterator type, verifying
that the returned
subrangehas the correctbegin()/end()values.Testing
All seven affected test targets built and passed:
Standard Compliance
The corrected signatures match the return types specified in
[range.rotate],[range.unique],[range.partition],[range.remove], and[range.find.last]of the C++23 working draft.Notes