Repository navigation
Fix task allocation - #341
Conversation
8eb71dd to
85c5e3e
Compare
dietmarkuehl
left a comment
There was a problem hiding this comment.
I think this PR look OK - although I'd be interested in the reason for calling query directly.
| template <typename Q, typename... Args> | ||
| requires(::beman::execution::forwarding_query(Q())) && requires(const Promise* p, Q q, Args&&... args) { | ||
| q(p->get_environment(), ::std::forward<Args>(args)...); | ||
| p->get_environment().query(q, ::std::forward<Args>(args)...); |
There was a problem hiding this comment.
Why is the query called directly? Going through the CPO does allow use of an instrumented CPO. That's similar to not calling virtual functions directly but rather through an inline function.
Is the intention to inhibit the forward_query set up ?
There was a problem hiding this comment.
Two reasons:
-
It aligns with https://eel.is/c++draft/exec.task#task.promise-12.4, which specifies forwarding via
environment.query(q, a...)rather thanq(environment, a...). -
The two are not equivalent. For example,
get_domainis a callable with its own fallback logic, not a pure member query. With the oldq(env, args...), if the task'sEnvironmentprovides noget_domainquery (e.g. the defaultenv<>), the call always fell back todefault_domain, because the inner env has noget_start_scheduler, so the completion domain of the start scheduler was never considered. For example:auto foo() -> ex::task<> { auto d = co_await ex::read_env(ex::get_domain); }
Here
dshould betask_scheduler::domain, but with the old implementation it wasdefault_domain. Withenv.query(q, args...), the query is simply not forwarded when theEnvironmentdoesn't support it, soget_domainfalls back to the start scheduler's completion domain, as intended.
Per https://eel.is/c++draft/exec.task#task.promise-14, no longer require the allocator used for coroutine state allocation to be convertible to
task::allocator_typewhen using the leading-allocator convention.