Skip to content

Fix task allocation - #341

Merged
Cra3z merged 3 commits into
bemanproject:mainfrom
Cra3z:fix-task-allocation
Nov 18, 2026
Merged

Cra3z merged 3 commits into
bemanproject:mainfrom
Cra3z:fix-task-allocation

Conversation

@Cra3z

@Cra3z Cra3z commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

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_type when using the leading-allocator convention.

@coveralls

coveralls commented Nov 16, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 92.722% (+0.08%) from 92.639% — Cra3z:fix-task-allocation into bemanproject:main

@Cra3z
Cra3z force-pushed the fix-task-allocation branch from 8eb71dd to 85c5e3e Compare November 16, 2026 09:28

@dietmarkuehl dietmarkuehl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)...);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

@Cra3z Cra3z Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two reasons:

  1. It aligns with https://eel.is/c++draft/exec.task#task.promise-12.4, which specifies forwarding via environment.query(q, a...) rather than q(environment, a...).

  2. The two are not equivalent. For example, get_domain is a callable with its own fallback logic, not a pure member query. With the old q(env, args...), if the task's Environment provides no get_domain query (e.g. the default env<>), the call always fell back to default_domain, because the inner env has no get_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 d should be task_scheduler::domain, but with the old implementation it was default_domain. With env.query(q, args...), the query is simply not forwarded when the Environment doesn't support it, so get_domain falls back to the start scheduler's completion domain, as intended.

@Cra3z
Cra3z merged commit fc1f879 into bemanproject:main Nov 18, 2026
42 checks passed
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.

3 participants