Skip to content

Fix any_of returning true for an empty range with parallel policies - #7880

Open
Ishaan400 wants to merge 1 commit into
TheHPXProject:masterfrom
Ishaan400:any-of-empty-range
Open

Ishaan400 wants to merge 1 commit into
TheHPXProject:masterfrom
Ishaan400:any-of-empty-range

Conversation

@Ishaan400

Copy link
Copy Markdown
Contributor

Proposed Changes

  • Return false instead of true from the empty-range shortcut in the parallel any_of. The shortcut is the same as the one in all_of and none_of, where true is right, but any_of of an empty range has to be false.
  • Add empty-range checks to the parallel, ranges and async any_of tests.

Any background context you want to provide?

hpx::any_of(hpx::execution::par, v.begin(), v.end(), pred) with an empty v returned true, while the sequential version and std::any_of return false. The same happened for par_unseq, hpx::ranges::any_of and the task policies, since they go through the same code.

I came across this while comparing the parallel algorithms with the standard library on random inputs. Without the fix, 10 of the new checks fail; with it, the any_of, any_of_range and any_of_sender tests pass.

Checklist

Not all points below apply to all pull requests.

  • I have added a new feature and have added tests to go along with it.
  • I have fixed a bug and have added a regression test.
  • I have added a test using random numbers; I have made sure it uses a seed, and that random numbers generated are valid inputs for the tests.

The parallel implementation of any_of returned true when first == last,
like all_of and none_of do. For any_of the result has to be false, since
no element of an empty range satisfies the predicate. This affected
hpx::any_of and hpx::ranges::any_of with par, par_unseq and the task
policies; the sequential path was already correct.

Add empty-range checks to the parallel, ranges and async tests.

Signed-off-by: Ishaan400 <[email protected]>
@Ishaan400
Ishaan400 requested a review from hkaiser as a code owner October 26, 2026 15:03
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ba8b438e-20cc-43c1-b97f-b4acece9bb62
Commits

Reviewing files that changed from the base of the PR and between 55ef914 and d909fc8.

Files selected for processing: 2
  • libs/core/algorithms/include/hpx/parallel/algorithms/all_any_none.hpp
  • libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Corrected any_of behavior for empty ranges when using execution policies without a scheduler executor. It now returns false, as expected when no elements satisfy the predicate. This makes the result consistent with the behavior users expect for an empty range; other execution policies continue to use their existing behavior.

The empty-range fast path for any_of now returns false for policies without scheduler executors. Tests cover policy-based, ranges, and asynchronous calls with an always-true predicate.

Changes: Empty-range any_of behavior

Layer / File(s) Summary
Correct and test empty-range results
libs/core/algorithms/include/hpx/parallel/algorithms/all_any_none.hpp, libs/core/algorithms/tests/unit/algorithms/any_of_tests.hpp
The fast path returns false for an empty range. Tests check policy-based, ranges, and asynchronous any_of calls with an always-true predicate.

Priority: Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested labels: type: defect, category: algorithms

Merge Risk: Minimal · up to d909f

No actionable merge-blocking risk is established by the supplied change context.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main bug fix: correcting empty-range results for parallel any_of policies.
Description check Passed The description directly explains the bug, the fix, affected policies, and added regression tests.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants