Skip to content
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

sender concepts for awaitable types #305

Closed
maikel opened this issue Dec 5, 2024 · 5 comments
Closed

sender concepts for awaitable types #305

maikel opened this issue Dec 5, 2024 · 5 comments

Comments

@maikel
Copy link
Collaborator

maikel commented Dec 5, 2024

I was making my own coroutine task basic_task<Ret, Queries...> which is an awaitable for promises that have an env that is queryable for all specified Queries...

The current spec defines the following two sender concepts

template<class Sndr>
    concept enable-sender =                                     // exposition only
      is-sender<Sndr> ||
      is-awaitable<Sndr, env-promise<empty_env>>;               // [exec.awaitable]

  template<class Sndr>
    concept sender =
      bool(enable-sender<remove_cvref_t<Sndr>>) &&
      requires (const remove_cvref_t<Sndr>& sndr) {
        { get_env(sndr) } -> queryable;
      } &&
      move_constructible<remove_cvref_t<Sndr>> &&
      constructible_from<remove_cvref_t<Sndr>, Sndr>;

  template<class Sndr, class Env = empty_env>
    concept sender_in =
      sender<Sndr> &&
      queryable<Env> &&
      requires (Sndr&& sndr, Env&& env) {
        { get_completion_signatures(std::forward<Sndr>(sndr), std::forward<Env>(env)) }
          -> valid-completion-signatures;
      };

The current concepts require basic_task<Ret, Queries...> to be awaitable in env-promise<empty_env> which is too strict, IMHO. Instead we could require for sender_in:

  template<class Sndr, class Env = empty_env>
    concept sender_in =
     is-awaitable<Sndr, env-promise<Env>> ||
      sender<Sndr> &&
      queryable<Env> &&
      requires (Sndr&& sndr, Env&& env) {
        { get_completion_signatures(std::forward<Sndr>(sndr), std::forward<Env>(env)) }
          -> valid-completion-signatures;
      };

There are some places where we mandate input to satisfy the sender concept. The most used one is for connect(sndr, rcvr) expressions. The current spec states https://eel.is/c++draft/exec.snd#exec.connect-6

The expression connect(sndr, rcvr) is expression-equivalent to:
(6.1)
new_sndr.connect(rcvr) if that expression is well-formed.
Mandates: The type of the expression above satisfies operation_state.
(6.2)
Otherwise, connect-awaitable(new_sndr, rcvr).
Mandates: sender<Sndr> && receiver<Rcvr> is true.

I would like to Mandate receiver<Rcvr> && sender_in<Sndr, env_of_t<Rcvr>>

Any thoughts?

@ericniebler
Copy link
Collaborator

a type that satisfies sender_in needs to satisfy sender. otherwise subsumption is broken.

Why do we require awaitables to work with an empty env?

we don't, but we do require an opt-in to satisfy the sender concept. making your type awaitable with an empty environment is one way to opt in. if your awaitable requires an environment, you have two options:

  1. give your awaitable type a nested sender_concept typedef, or
  2. specialize enable_sender for your awaitable type.

the problem is that somewhere along the way, the enable_sender variable template was turned into an exposition-only enable-sender concept. we should roll back that change.

@maikel
Copy link
Collaborator Author

maikel commented Dec 6, 2024

Thank you for clarification!

@maikel maikel closed this as completed Dec 6, 2024
@jwakely
Copy link
Member

jwakely commented Feb 3, 2025

@ericniebler
Copy link
Collaborator

ericniebler commented Feb 3, 2025

I also sent a list of bugs to lwgchair to import, including one for this issue that has a proposed resolution.

#306

@jwakely
Copy link
Member

jwakely commented Feb 3, 2025

I don't think #306 was one of the ones you asked to be opened as an issue. I'll update LWG 4202 to include that proposed resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants