Create a stdexec module#2138
Conversation
This diff doesn't build, but it doesn't build for a good reason: it's successfully invoking the "build with modules" machinery, which is exposing implementation gaps. It looks like the next step is to start updating `stdexec` headers that include std headers to conditionally rely on `import std` instead, at least when `STDEXEC_IN_MODULE_PURVIEW` is defined.
This diff doesn't build for a very exciting reson: the new modules-only test shows that `stdexec::just_t` hasn't been exported from the module.
This diff makes both the modules and non-modules builds pass. The tests pass in both builds, too!
|
Looks good! Thoughts:
Either approach is fine; the export-everything approach is less work but is sloppier. I imagine that your Claude may have come up with a reason to prefer the
The place where this logic lives in the Beman project is this file, if you want to refer to it in the future to try to adapt its logic. |
Thanks for looking!
Yeah, this is intentional. I don't think modules support is a high-priority need for stdexec so I want @ericniebler to have a chance to weigh in on the design, direction, etc. before I invest a whole lot of time in this. Once we agree on a plan, I'll extend things to support more of the library. Regarding that specific issue that Claude raised, I'm hoping that by defining the module from within the stdexec project rather than trying to create one non-invasively from outside the problems will be smaller. As it is, the stdexec patch you shared with me that did things like name previously-anonymous types and namespaces isn't necessary in this diff. I'm hoping that's a sign that it's OK for
I came up with the idea to try this approach in hopes that it would allow me to keep the various anonymous things in stdexec anonymous as long as they remain reachable-but-not-visible (I think that's the modules term for things declared in the module definition unit but not exported from it). When I asked Claude if it was a viable strategy, it claimed that it's the strategy Microsoft took in modularizing their stdlib, which I take as a good sign.
Thanks! I'll take a look. |
Summary
This diff starts the process of modularizing stdexec so that consumers can say
import stdexec;rather than
The initial module exports nothing except
stdexec::just_tso there's a test that confirms consumers can utterstdexec::just_t:It builds and passes on my machine.
I've tried to add the above test to CI with the idea that, if this PR is going in the right direction and we merge it with an incomplete module then at least other changes won't break the modularization effort.
Strategy
I'm aping the conditional modules support that the Beman Project's exemplar project scaffolds for new repos. As I understand it, the idea is:
stdexecfor the contents ofexecution.hppand something likestdexec.execorstdexec.experimentalfor everything in theexecnamespace. This diff introduces onlystdexecand it's defined in a new file namedmodules/stdexec.cppm.#define STDEXEC_IN_MODULE_PURVIEW, which is the signal we're in the "we're defining the module" mode.#include <stdexec/execution.hpp>STDEXEC_USE_MODULES()is false)STDEXEC_USE_MODULES()is true andSTDEXEC_IN_MODULE_PURVIEWis defined)STDEXEC_USE_MODULES()is true andSTDEXEC_IN_MODULE_PURVIEWis not defined)import stdexec.STDEXEC_MODULE_EXPORT; when the header is being included to define the module, that macro will expand toexportotherwise it's the empty token otherwise.Acknowledgements
Claude Sonnet 5 helped me come up with the implementation strategy: https://claude.ai/share/0b35126c-294a-4f5d-844a-3b636381caa8, and @ednolan taught me about The Beman Project's CMake and modules infrastructure.