Skip to content

Implement p4223 attrs#2107

Closed
ispeters wants to merge 8 commits into
NVIDIA:pull-request/2089from
ispeters:implement_p4223_attrs
Closed

Implement p4223 attrs#2107
ispeters wants to merge 8 commits into
NVIDIA:pull-request/2089from
ispeters:implement_p4223_attrs

Conversation

@ispeters
Copy link
Copy Markdown
Contributor

@ispeters ispeters commented Jun 1, 2026

P4223R0 calls for function to support a type parameter of the form attrs<…> that specifies the required attributes of the type-erased sender. This PR started out as an attempt to implement this missing feature in exec::function, but, along the way, I discovered that's not as trivial as I expected when I added the requirement to the paper. Unlike exec::any_sender_of, function doesn't know the type of the sender it's erasing except in its constructor and, at that point, it knows only the type—it doesn't have the sender as a value until connect gets called—so we can't check that the erased sender's attributes meet the specified requirements.

The simplest resolution to this conflict is obviously to just not support sender attributes in function but, after consulting with @ericniebler on the subject, he pointed out that get_completion_domain is a function of a sender's attributes, and it's a critical part of the algorithm customization logic. So, this PR is an implementation of the compromise: you can specify the required completion domains of the erased sender because we need only the sender's type to validate the constraint is met, and we can do that in the function constructor.

New in this PR:

  • template <class...> exec::attrs, which is like template <class...> exec::queries but for sender attribute queries instead of receiver environment queries;
  • some more specializations of exec::__make_function to support specifying the completion domain requirements of the erased sender;
  • new constraints on function's constructor to validate that the erased sender meets the aforementioned new domain requirements; and
  • some tests to validate that everything works as intended.

The new requirement is that __common_domain_t<ExpectedDomain, ActualDomain> is the same as ExpectedDomain (i.e. the completion domain of the erased sender must be, or inherit from, the completion domain specified in the function's type).

TODO:

  • negative tests to confirm the constructor constraints prevent invalid constructions
  • more specializations of __make_function so you can specify required sender attributes without having to fully specify all of the type parameters
  • tests for the above
  • probably more documentation
  • maybe confirmation that the only required sender attributes are get_completion_domain
  • an R1 of P4223 that updates the spec to reflect this new implementation experience

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Jun 1, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ispeters ispeters force-pushed the implement_p4223_attrs branch from a89ff4f to eb4ddb6 Compare June 2, 2026 05:35
ispeters added 8 commits June 2, 2026 13:21
I realized that the completion domains reported by a `function` will be
receiver environment-independant, so I deleted `__default_attrs`'s
`_Queries` parameter, and I've updated the default to be a function of
the given completion signatures using
`completion_signatures<...>::__transform_reduce`.
It build and the existing tests pass, but I don't know if it works.
The tests confirm that we only report a completion domain on the
channels we might complete on, and I had to fix some bugs in
`function.hpp` to make the tests pass.
This diff just renames the bits and pieces that compute the completion
domain of a `function`.
This is a partial implementation of constraining `function`'s
constructor to accept only factories that produce senders that
completion in the expected domain. It's partial because:
 - we're currently checking for a "matching" domain with `__same_as`,
   but we should be checking with some function of `common_domain`; and
 - there's no way to specify any expected domain other than
   `default_domain`.

The current tests pass, which means we correctly allow factories that
produce senders that completion in the default domain. We need tests
that show we reject senders that *don't* complete in the default domain,
and we need a way to use and validate the use of non-default domains.
The implementation is incomplete because we check for identical domains
but should be checking for compatible domains with `common_domain`.
This diff modifies the `function` test that validates the domain-related
constraints on `function`'s constructor. The old test required that
`function` only erase senders with completion domains identitcal to
those specified in the `function`'s type parameters; the intended
design is that the erased sender's completion domains be _derived from_
the advertised domains. The new test requires the correct relationship,
which forced a change in `function` to make the new test pass.
@ispeters ispeters force-pushed the implement_p4223_attrs branch from eb4ddb6 to 0a52fdc Compare June 2, 2026 20:21
Comment thread include/exec/function.hpp
Comment on lines +115 to +121
-> __join_env_t<__prop_t const &, env_of_t<_Receiver>>
{
return __env::__join(*__env_, STDEXEC::get_env(*static_cast<_Receiver const *>(this)));
}

private:
__prop_t *__env_;
__prop_t const *__env_;
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, what do you think of this change? It resolves a compiler error where __join receives a __prop_t& but is expecting a __prop_t and can't find a conversion. The other thing that worked was to invoke __join like so:

return __env::__join(auto(*__env_), …);

which seemed like a bunch of unnecessary copying.

@copy-pr-bot copy-pr-bot Bot deleted the branch NVIDIA:pull-request/2089 June 2, 2026 20:46
@copy-pr-bot copy-pr-bot Bot closed this Jun 2, 2026
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

Successfully merging this pull request may close these issues.

1 participant