C++ MIX #5に参加しました
2019/9/4に開催されたイベント C++ MIX #5 にて、“20分くらいでわかった気分になれるC++20コルーチン” というタイトルで20分ほど話す機会をいただきました。(Boost.勉強会を含めると5年6ヶ月(!)ぶり3回目)
感想とか
C++20導入予定のコルーチン機能について、C++プログラマの期待値とは異なるであろう実態説明を主題としました。C++標準仕様へのコルーチン導入議論は、古くは2012~2013年頃から長い歴史が積み重ねられており、さまざまな議論があったうえでC++20では現行仕様におちつきました。C++プログラマが広くコルーチンを活用できるのは未来のお話(早くとも2023年以降)になりますが、まずはC++標準ライブラリのコルーチン対応を検討するための基礎固めを優先したのだと思われます。
C++20コルーチン対応は、仕様書の文面からのみではその全体像や利用方法を理解しづらい機能の部類と思います。また議論の歴史が長いぶん関連する提案文書が大量に残っており、最終的には採用されなかった対抗仕様や改善提案も多岐にわたるため、どれを追えばよいかも判別しづらくなっています。C++20コルーチンを使ってみようと思い立ったときに、本資料が最初の取っ掛かりとなるようであれば幸いです。
Twitter上での皆さんのコメントをみるに、スタックレス(Stackless)/スタックフル(Stackful)への関心が高かったように思います。C++20コルーチンは軽量だがユーザの自由度は低い “スタックレスコルーチン” であり、より使いやすい “スタックフルコルーチン” いわゆるファイバー(Fiber)はまだ検討段階*1にあります。現時点でスタックフルコルーチンを必要とするときは、Boost.Coroutine2やBoost.Fiberなどの外部ライブラリ*2が候補となります。
提案文書
コルーチンに関連する提案文書を列挙してみました。あまりの数の多さに作業途中で後悔した('A`)
2012年
2013年
- *N3564 Resumable Functions
- *N3650 Resumable Functions
- *N3708 A proposal to add coroutines to the C++ standard library
- *N3722 Resumable Functions
2014年
- *N3858 Resumable Functions
- *N3977 Resumable Functions
- *N3985 A proposal to add coroutines to the C++ standard library (Revision 1)
- *N4024 Distinguishing coroutines and fibers
- *N4134 Resumable Functions v.2
- *N4232 Stackful Coroutines and Stackless Resumable Functions
- *N4244 Resumable Lambdas: A language extension for generators and coroutines
- *N4286 Resumable Functions (revision 3)
- *N4287 Threads, Fibers and Couroutines (slides deck)
2015年
- *N4397 A low-level API for stackful coroutines
- *N4398 A unified syntax for stackless and stackful coroutines
- *N4499 Draft wording for Coroutines (Revision 2)
- *N4453 Resumable Expressions
- P0054R0 Coroutines: reports from the fields
- P0055R0 On Interactions Between Coroutines and Networking Library
- *P0057R0 Wording for Coroutines (Revision 3)
- P0070R0 Coroutines: Return Before Await
- P0071R0 Coroutines: Keyword alternatives
- *P0073R0 On unifying the coroutines and resumable functions proposals
- *P0114R0 Resumable Expressions (revision 1)
- *P0057R1 Wording for Coroutines
- *P0162R0 A response to "P0055R0: On Interactions Between Coroutines and Networking Library"
- P0171R0 Response To: Resumable Expressions P0114R0
2016年
- P0055R1 On Interactions Between Coroutines and Networking Library
- *P0057R2 Wording for Coroutines
- *P0073R1 On unifying the coroutines and resumable functions proposals
- P0286R0 A networking library extension to support co_await-based coroutines
- *P0057R3 Wording for Coroutines
- *P0057R4 Wording for Coroutines
- *P0073R2 On unifying the coroutines and resumable functions proposals
- *P0057R5 Wording for Coroutines
- *P0057R6 Wording for Coroutines
- *N4628 Working Draft, Technical Specification on C++ Extensions for Coroutines
- N4629 Editor's report for the Coroutines TS
- *P0057R7 Wording for Coroutines
2017年
- *N4649 Working Draft, Technical Specification on C++ Extensions for Coroutines
- N4650 Editor's report for the Coroutines TS
- *N4663 Coroutines PDTS document
- *N4666 National Body Comments, SC22 N 5205, ISO/IEC PDTS 22277, C++ Extensions for Coroutines
- P0664R0 Coroutines TS Issues
- *N4678 National Body Comments for ISO/IEC PDTS 22277, C++ Extensions for Coroutines
- N4679 Editor's report for the Coroutines TS
- *N4680 C++ Extensions for Coroutines TS Document
- P0664R1 Coroutines TS Issues
2018年
- *N4723 Working Draft, C++ Extensions for Coroutines
- N4724 Editor's report for the Coroutines TS
- *P0057R8 Working Draft, C++ Extensions for Coroutines
- *P08776R0 fibers without scheduler
- P0911R0 Rebase the Coroutines TS onto the C++17 Standard
- P0912R0 Merge Coroutines TS into C++20 working draft
- P0913R0 Add symmetric coroutine control transfer
- P0914R0 Add parameter preview to coroutine promise constructor
- *N4736 Working Draft, C++ Extensions for Coroutines
- N4737 Editor's report for the Coroutines TS
- 0P0664R2 C++ Coroutine TS Issues
- P0911R1 Rebase the Coroutines TS onto the C++17 Standard ★
- P0913R1 Add symmetric coroutine control transfer ★
- P0914R1 Add parameter preview to coroutine promise constructor ★
- *P0973R0 Coroutines TS Use Cases and Design Issues
- P0975R0 Impact of coroutines on current and upcoming library facilities
- P0978R0 A Response to "P0973r0: Coroutines TS Use Cases and Design Issues"
- P0981R0 Halo: coroutine Heap Allocation eLision Optimization: the joint response
- P0991R0 Comparison of Stackful Coroutine Proposals
- P0664R3 C++ Coroutine TS Issues
- *P0876R2 fiber_context - fibers without scheduler
- P0912R1 Merge Coroutines TS into C++20 working draft
- P1056R0 Add coroutine task type
- *P1063R0 Core Coroutines
- *N4760 Working Draft, C++ Extensions for Coroutines
- N4761 Editor's report for the Coroutines TS
- P0664R4 C++ Coroutine TS Issues ★
- P0664R5 C++ Coroutine TS Issues
- *P0876R3 fiber_handle - fibers without scheduler
- P0912R2 Merge Coroutines TS into C++20 working draft
- *N4775 Working Draft, C++ Extensions for Coroutines
- N4776 Editor's report for the Coroutines TS
- P0664R6 C++ Coroutine TS Issues
- P0912R3 Merge Coroutines TS into C++20 working draft
- P1056R1 Add lazy coroutine (coroutine task) type
- *P1063R1 Core Coroutines
- P1205R0 Teleportation via co_await
- P1241R0 In support of merging coroutines into C++20
- *P1288R0 Coroutine concepts and metafunctions
- *P1316R0 A when_all() operator for coroutines
- *P1342R0 Unifying Coroutines TS and Core Coroutines
- P1356R0 Coroutine TS ready issues (25 and 27)
- *P1362R0 Incremental Approach: Coroutine TS + Core Coroutines
- *P1364R0 Fibers under the magnifying glass
- *P1365R0 Using Coroutine TS with zero dynamic allocations
2019年
- P0664R7 C++ Coroutine TS Issues
- *P0866R0 Response to "Fibers under the magnifying glass"
- *P0876R5 fiber_context - fibers without scheduler
- P0912R4 Merge Coroutines TS into C++20 working draft
- *P1063R2 Core Coroutines
- *P1329R0 On the Coroutines TS
- P1403R0 Experience Report: Implementing a Coroutines TS Frontend to an Existing Tasking Library
- *P1430R0 First-class symmetric coroutines in C++
- P1471R0 The trouble with coroutine_traits
- *P1477R0 Coroutines TS Simplifications
- P0664R8 C++ Coroutine TS Issues
- P0912R5 Merge Coroutines TS into C++20 working draft ★
- *P1430R1 First-class symmetric coroutines in C++
- *P1477R1 Coroutines TS Simplifications
- P1485R0 Better keywords for the Coroutines TS
- *P1492R0 Coroutines: Language and Implementation Impact
- *P1493R0 Coroutines: Use-cases and Trade-offs
- *P1520R0 Response to response to "Fibers under the magnifying glass"
- *P0876R6 fiber_context - fibers without scheduler
- P1485R1 Better keywords for the Coroutines
- *P1662R0 Adding async RAII support to coroutine
- *P1663R0 Supporting return-value-optimisation in coroutines
- *P1681R0 Revisiting allocator model for coroutine lazy/task/generator
- *P1713R0 Allowing both co_return; and co_return value; in the same coroutines
- *P1745R0 Coroutine changes for C++20 and beyond
- *P0876R8 fiber_context - fibers without scheduler
凡例:*印はPDF形式、★印は採択(Adopted)を表す
*1:http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0876r8.pdf
*2:両BoostライブラリのメンテナOliver Kowalke氏が、C++標準へのスタックフルコルーチン提案を行っています。