Skip to content

Fix __query_or CPO - #7266

Merged
miscco merged 5 commits into
NVIDIA:mainfrom
miscco:fix__query_or
Jan 19, 2026
Merged

miscco merged 5 commits into
NVIDIA:mainfrom
miscco:fix__query_or

Conversation

@miscco

@miscco miscco commented Jan 16, 2026

Copy link
Copy Markdown
Contributor

The __query_or currently requires that the query is always of the form env.query(CPO, args...)

However, we also want that to work with types that are their own query, which would satisfy cpo(env, args...)

This is the case for ::cuda::get_stream(::cudaStream_t) and also for our memory resources

@miscco
miscco requested a review from a team as a code owner January 16, 2026 08:48
@miscco
miscco requested a review from davebayer January 16, 2026 08:48
@github-project-automation github-project-automation Bot moved this to Todo in CCCL Jan 16, 2026
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Review in CCCL Jan 16, 2026
@miscco
miscco requested a review from ericniebler January 16, 2026 08:48
@miscco
miscco force-pushed the fix__query_or branch 2 times, most recently from 8e6b67a to 6d36804 Compare January 16, 2026 09:54
@davebayer

Copy link
Copy Markdown
Contributor

pre-commit.ci autofix

@ericniebler

ericniebler commented Jan 16, 2026 •

Copy link
Copy Markdown
Contributor

today, given a query q and an env, there are two reasons why q(env) might be well-formed:

  1. env.query(q) is well-formed, or
  2. q has a fallback that returns a default value

today, __query_or is useful because it distinguishes between these cases. this change breaks that property.

the current semantics of __query_or also make it useful for implementing queries. get_allocator_t might look like this:

struct get_allocator_t {
  template <class Env>
  auto query(const Env& env, auto&&...) const noexcept {
    return __query_or(env, *this, std::allocator<std::byte>());
  }
};

the change proposed here would make this infinitely recurse.

would a __call_or or __invoke_or function, or a __with_default callable adaptor, meet your needs?

@miscco

miscco commented Jan 16, 2026

Copy link
Copy Markdown
Contributor Author

would a __call_or or __invoke_or function, or a __with_default callable adaptor, meet your needs?

I am impartial to what solution we use, but we need one that we can use uniformly in CCCL

@miscco
miscco requested a review from a team as a code owner January 16, 2026 18:37
@miscco
miscco requested a review from NaderAlAwar January 16, 2026 18:37
_CCCL_REQUIRES(__queryable_with<_Env, _Query, _Args...>)
[[nodiscard]] _CCCL_API constexpr auto operator()(const _Env& __env, _Query, _Default&&, _Args&&... __args) const
noexcept(__nothrow_queryable_with<_Env, _Query, _Args...>) -> __query_result_t<_Env, _Query, _Args...>
_CCCL_REQUIRES(__queryable_with<const _Env&, _Query, _Args...>)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericniebler I believe that is a bugfix, because a query with a non-const query method would satisfy __queryable_with<_Env, _Query, _Args...> but cannot be called here

@ericniebler ericniebler Jan 16, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true. a different fix would be for __queryable_with and friends to automatically const & qualify the Env argument.

@miscco
miscco enabled auto-merge (squash) January 16, 2026 18:44
@miscco
miscco disabled auto-merge January 16, 2026 18:44
We want to be able to also handle fallbacks, so add those CPOs
@pciolkosz

Copy link
Copy Markdown
Contributor

the change proposed here would make this infinitely recurse.

This is exactly what happened when I was trying a similar approach in #7113

@bernhardmgruber

Copy link
Copy Markdown
Contributor

Btw, #7278 will add a bunch of tests for extracting streams from environments in CUB.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 5h 05m: Pass: 100%/126 | Total: 4d 15h | Max: 5h 05m | Hits: 92%/250281

See results here.

@miscco
miscco merged commit 952afd6 into NVIDIA:main Jan 19, 2026
@miscco
miscco deleted the fix__query_or branch January 19, 2026 16:47
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Jan 19, 2026
@gevtushenko gevtushenko mentioned this pull request Feb 26, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants