microsoft / microsoft/STL

`<future>`: Divorce `packaged_task` from `function`

Open
#5,009 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug vNext
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Currently, the internal state class _Packaged_state used by packaged_task stores a function.

https://github.com/microsoft/STL/blob/37120edc7b57e044817251c13b5c19a130a3c9c7/stl/inc/future#L481-L486
https://github.com/microsoft/STL/blob/37120edc7b57e044817251c13b5c19a130a3c9c7/stl/inc/future#L550-L551

However, function requires the stored target object to be copy constructible while packaged_task doesn't, which rendered our implementation strategy non-conforming (reject-valid) for a long while, see #321.

#4946 partially fixed the non-conformance. However, the fix was imperfect:

  • it introduced handling for move-only functors which function isn't supposed to support,
  • it was broken when one specializes function for program-defined types, although I don't think anyone should do this, and
  • when the functor's copy constructor is eligible but ill-formed, there's still hard error from it, which isn't supposed to happen for packaged_task.

In vNext where ABI breakage is available, we need to change the internal storage type. It seems that the implementation details of that type can be shared with move_only_function, but it doesn't seem possible to directly use move_only_function because move_only_function is only available since C++23.

vNext note: Resolving this issue will require breaking binary compatibility. We won't be able to accept pull requests for this issue until the vNext branch is available. See #169 for more information.

Contributor guide

Open the contributing guide

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

Start with stl/inc/future around lines 481-486 and 550-551, then review #4946 and #321 to understand the existing packaged_task storage and its conformance failures. When the vNext branch is available, compare the applicable move_only_function implementation details and replace the function-based storage. Done means packaged_task accepts valid move-only and otherwise non-copyable callables without the listed hard errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.