[clang] [llvm] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 07:36:58 PDT 2023


================
@@ -7416,3 +7416,69 @@ that ``p->array`` must have at least ``p->count`` number of elements available:
 
   }];
 }
+
+def CoroOnlyDestroyWhenCompleteDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+The `coro_only_destroy_when_complete` attribute should be marked on a C++ class. The coroutines
+whose return type is marked as the attribute are assumed to be destroyed only after then coroutines
+reached to the final suspend point.
+
+This is helpful for the optimizers to perform more optimizations.
----------------
ChuanqiXu9 wrote:

I changed this to `This is helpful for the optimizers to reduce the size of the destroy function for the coroutines`.

To be honest, I didn't think this is a problem. For example, [[likey]], [[unlikely]] and [[assume]] don't explain what optimization would be performed actually. The contract between the users and the compilers is: the users should provide the correct information then the compiler at least shouldn't generate worse code.

BTW, an interesting point here is that, according to the design intention of coroutines, users shouldn't care about what is `destroy` function of coroutines. But actually, many C++ programmers (who don't know about compilers) understand the concept of `destroy` functions. This may be the culture of C++ : )

https://github.com/llvm/llvm-project/pull/71014


More information about the cfe-commits mailing list