NVIDIA / NVIDIA/stdexec

Compile Error When Wrapping Receiver by Derivation

Open
#1,408 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.4k
Forks
270
Avg merge
3d 6h
Merged PRs (30d)
39

Description

Given:

template<::stdexec::receiver Receiver>
struct receiver : Receiver {
  template<typename T>
    requires std::constructible_from<Receiver, T>
  explicit constexpr receiver(T&& t) noexcept(
    std::is_nothrow_constructible_v<Receiver, T>)
    : Receiver(std::forward<T>(t))
  {}
};

template<::stdexec::sender Sender>
struct sender {
  using sender_concept = ::stdexec::sender_t;
  template<typename T>
    requires std::constructible_from<Sender, T>
  explicit constexpr sender(T&& t) noexcept(
    std::is_nothrow_constructible_v<Sender, T>)
    : sender_(std::forward<T>(t))
  {}
  template<typename Self, typename Env>
  ::stdexec::completion_signatures_of_t<
    decltype(std::declval<Self>().sender_),
    Env> get_completion_signatures(this Self&&, const Env&);
  template<typename Self, typename Receiver>
    requires ::stdexec::sender_to<
      Sender,
      receiver<std::remove_cvref_t<Receiver>>>
  auto connect(this Self&& self, Receiver&& r) noexcept(
    noexcept(
      ::stdexec::connect(
        std::declval<Self>().sender_,
        receiver<std::remove_cvref_t<Receiver>>(std::declval<Receiver>()))))
  {
    return ::stdexec::connect(
      std::forward<Self>(self).sender_,
      receiver<std::remove_cvref_t<Receiver>>(std::forward<Receiver>(r)));
  }
private:
  Sender sender_;
};

template<typename T>
explicit sender(T) -> sender<T>;

The following fails to compile (at least on GCC 14.1.0):

auto op = ::stdexec::connect(
  ::stdexec::just() | ::stdexec::let_value([]() {
    return sender(
      ::stdexec::just() | ::stdexec::then([]() noexcept {
        return 5;
      }));
  }),
  make_receiver([](auto&&...) noexcept {}));

Where the make_receiver invocation simply creates a receiver that accepts anything.

Internally the machinery seems to be confusing the derived type with the base type:

/scratch/mdx/src/../include/stdexec/__detail/__basic_sender.hpp:362:84: error: cannot convert ‘stdexec::__detail::__op_state<stdexec::__sexpr<<lambda closure object>stdexec::{anonymous}::<lambda()>(), stdexec::{anonymous}::__anon>, mdx::execution::tests::{anonymous}::receiver<stdexec::__any_::__receiver_ref<stdexec::completion_signatures<stdexec::__rcvrs::set_value_t(int)> > > >* const’ to ‘stdexec::__detail::__receiver<stdexec::__any_::__receiver_ref<stdexec::completion_signatures<stdexec::__rcvrs::set_value_t(int)> >, stdexec::__sexpr<<lambda closure object>stdexec::{anonymous}::<lambda()>(), stdexec::{anonymous}::__anon>, stdexec::__muchar (*)[1]>::__t::__parent_op_t*’ {aka ‘stdexec::__detail::__op_state<stdexec::__sexpr<<lambda closure object>stdexec::{anonymous}::<lambda()>(), stdexec::{anonymous}::__anon>, stdexec::__any_::__receiver_ref<stdexec::completion_signatures<stdexec::__rcvrs::set_value_t(int)> > >*’} in initialization
  362 |           return __tuple{connect(static_cast<_Child&&>(__child), __receiver_t<_Is>{__op_})...};
      |                                                                                    ^~~~~
      |                                                                                    |
      |                                                                                    stdexec::__detail::__op_state<stdexec::__sexpr<<lambda closure object>stdexec::{anonymous}::<lambda()>(), stdexec::{anonymous}::__anon>, mdx::execution::tests::{anonymous}::receiver<stdexec::__any_::__receiver_ref<stdexec::completion_signatures<stdexec::__rcvrs::set_value_t(int)> > > >* const

Full compilation output attached.

build.log

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the sender and receiver example, using the attached build.log as the expected diagnostic. Start at include/stdexec/__detail/__basic_sender.hpp line 362 and trace how the derived receiver type is used when connecting the operation. Done means the example compiles without confusing the derived receiver with its base type.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.