220 21744 <a44dae17-5f63-4c60-a943-d74a1332b54c@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Nicol Bolas <jmckesson@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: is await an extension of the do-notation? (was Re:
 Re: Resumable expressions p0114r0 vs async/await P0057R0)
Date: Tue, 13 Oct 2015 21:46:50 -0700 (PDT)
Lines: 251
Approved: news@gmane.org
Message-ID: <a44dae17-5f63-4c60-a943-d74a1332b54c@isocpp.org>
References: <639f0012-8cb4-4db3-82a6-8d042a3497f9@isocpp.org>
 <401aa118-ed0b-4c7b-92cf-3fbd706eff9d@isocpp.org>
 <fcbcc1c4-535c-4fa2-a17d-4acffe84a4b5@isocpp.org>
 <1d15dbc4-e0c1-4df1-86db-014e11f14d26@isocpp.org>
 <56114953.4030701@wanadoo.fr> <561B403D.4030403@gmail.com>
 <CAOfiQqkKvZfVatJ1Bz4qSvGc-g6iep0xeP1B1=J1-gCu43NXxg@mail.gmail.com>
 <561C07D1.3080304@gmail.com>
 <CAOfiQqnR4GYCttwu8G-44_UEN4WekW19uorEvf-5VC3vOpej-g@mail.gmail.com>
 <561C213F.1060009@gmail.com>
 <fb82d876-8a54-4c28-8e53-297018470cf6@isocpp.org>
 <561C3875.2050701@gmail.com>
 <86924069-44d0-447f-bf8a-a42e46579832@isocpp.org>
 <561D79A7.8080007@gmail.com>
 <894616d6-9609-4038-b2bc-d2c62df21e0f@isocpp.org>
 <99bdb3ae-9214-4440-8572-4c47a61eda46@isocpp.org>
 <58628096-14ae-42b2-89d3-c0bd2183bbc0@isocpp.org>
 <561DC957.8080603@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_6485_1764221694.1444798011001"
X-Trace: ger.gmane.org 1444798020 24620 80.91.229.3 (14 Oct 2015 04:47:00 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 14 Oct 2015 04:47:00 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCEKFTV6ZUMBBPF466YAKGQEJEPSZZA@isocpp.org Wed Oct 14 06:46:55 2015
Return-path: <std-proposals+bncBCEKFTV6ZUMBBPF466YAKGQEJEPSZZA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-io0-f198.google.com ([209.85.223.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCEKFTV6ZUMBBPF466YAKGQEJEPSZZA@isocpp.org>)
	id 1ZmDxm-0000qy-9e
	for gclcip-std-proposals@m.gmane.org; Wed, 14 Oct 2015 06:46:54 +0200
Original-Received: by iodv82 with SMTP id v82sf68945225iod.0
        for <gclcip-std-proposals@m.gmane.org>; Tue, 13 Oct 2015 21:46:53 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :content-type:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=mMqxuqur8grp1LNad4u7uE4cNK4EP0ymnVovTHWfXOo=;
        b=ZC8qhP98CQQRG3sRGt/DMHd4frvrxUr++9Rxwj8lOVyw1A92J2z2b7pCHGG+6xO8J4
         9P9SdrW1RaBBJFyG9vlPavmOU/HOU/n8j0FkXtka0h2zVwdtRP1xGFo07rHvCuWRi86D
         d53n5zWRslJsZ3ORQ4eSdY48bFI6QsDL98AQvvsCfm5kEZkEDz6aewIKl2z8NYzo/mzc
         GHXrfBBbz08agkq8mQcXWZt8b/8PvPF6UTKNXvpnr5YdxuS8DNb8Yb+XuzGpMMqM/blg
         n9UVcPZ/GzWqFjPyXoy2NQ5SlYGw9+n8zGnYQ84ceI4DmpyPM2MFQ9xi/r8zOkHaEkku
         2Ijw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:content-type:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=mMqxuqur8grp1LNad4u7uE4cNK4EP0ymnVovTHWfXOo=;
        b=H0Jpmbd30UJw6BT/aOWZ835Olpxc1CzKSNpRQYI3GboESfpCJFAvPyaiguTmpRUESg
         +YCXvD8ynJ3KN6mtK2RSSH24Y0HyVqSQqKFecYG+ehhAaA3LryPP6SXnqkMDtEFrnD/M
         lRi4LhNDknZYCmr/r57+k1Vu43K3nNcvpKC9Jiy3vm4jYhiJroivuvNFza9yp3LEAPLZ
         USqpNJQrN520FDt/njf+70JQsFcn8JJIdW4hRhIWK2HA3sIEKuJZOezv99LjT7NUeJr+
         ioymZjNgXTf4UQAM8NKNifAowk5ixYVch55gpIlbD2fFIRc0TW2qVtMBRRCUNF4ehUbe
         mfPg==
X-Gm-Message-State: ALoCoQmoR/dbxH4UhPWuNl+cviCd7EaXOP5IyxMHaeHdfK8kH3jfE4OzyxsQBJn3VWqXei32rjsk
X-Received: by 10.50.142.103 with SMTP id rv7mr20463757igb.2.1444798013051;
        Tue, 13 Oct 2015 21:46:53 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.88.73 with SMTP id be9ls1637809igb.28.canary; Tue, 13 Oct
 2015 21:46:52 -0700 (PDT)
X-Received: by 10.50.143.12 with SMTP id sa12mr293150igb.7.1444798012176;
        Tue, 13 Oct 2015 21:46:52 -0700 (PDT)
In-Reply-To: <561DC957.8080603@gmail.com>
X-Original-Sender: jmckesson@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: std-proposals@isocpp.org
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:21744
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/21744>

------=_Part_6485_1764221694.1444798011001
Content-Type: multipart/alternative; 
	boundary="----=_Part_6486_896213012.1444798011002"

------=_Part_6486_896213012.1444798011002
Content-Type: text/plain; charset=UTF-8

On Tuesday, October 13, 2015 at 11:17:53 PM UTC-4, Evgeny Panasyuk wrote:
>
> 14.10.2015 4:57, Nicol Bolas: 
> >         Except that he's already proven (in this thread no less) that a 
> >         good optimizer can elide the allocation. If the compiler can 
> >         reasonably /make/ it zero overhead, then it /is/ zero overhead. 
> > 
> > 
> > 
> >     1. It is impossible (practically) in general case. 
> >     For instance in case when we put coroutines in container, like: 
> >     | 
> >     vector<coroutine>x(N); 
> >     | 
> >     In case of coroutines with concrete types and sizeof known at 
> >     compile - this can be done within single allocation. 
> >     But if coroutine type is erased the we will have N+1 allocations in 
> >     general case - it can't be practically elided. 
> > 
> > 
> > Ignoring the rest of the discussion on this point, I never claimed that 
> > P0057 could guarantee elision in the case you present here. Before, you 
> > asked about a /specific/ problem, and I answered with a specific example 
> > showing that it was elidable. What you've shown here hardly disproves my 
> > point. 
>
> It is not zero overhead even with good optimizer/compiler, because they 
> can't elide every allocation, and I am not talking about some exotic 
> cases. 
>

Thus far, including in this post, you haven't mentioned an example that 
would actually compile.

You linked to some macro code, but macros are, basically, *cheating*. They 
get to break all kinds of C++ rules, which an actual language feature would 
not.
 

> > 
> > Also... how does `vector<coroutine>` make any kind of sense with regard 
> > to P0114? The type isn't type erased, so each coroutine has its own 
> > type. Therefore, in order to put them in a homogeneous container like 
> > `vector`, you'll have to type-erase them. Which requires memory 
> allocation. 
>  > At which point, your version gains /nothing/ over P0057. 
>
> Same coroutines have same concrete types. For instance, with P0114 it 
> may be: 
> | 
> struct concrete_coroutine 
> { 
>      resumable auto r = expression; 
>      // ... 
> }; 
> ... 
> make_unique<concrete_coroutine[]>(N); 
> |
>

`auto` doesn't work that way. Non-static data members cannot be `auto`. 
Normally I wouldn't care about a small issue like that, but it basically 
makes your code impossible.

Without `auto` NSDMI (and I wouldn't hold my breath on seeing it 
<http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3897.html>), you 
can't store a resumable expression. So you can't make containers of them.

Unless you erase their types. So again, you've gained *nothing*.

Your macro solution gets around this because it uses macros.
 

> Again, I am not talking specifically about P0114. Even P0057 can be 
> changed to have concrete coroutine type. 
>

I'd be curious to see how, exactly.

And I don't mean some macro nonsense. I mean the specific details of how 
you turn P0057's `coroutine_handle` into a type.

See, the way P0057 works is that the coroutine object is introduced in one 
specific place: the awaiter object's `await_suspend` method. That's the 
first place where user code gets to touch a coroutine, and if the method 
doesn't store it or otherwise keep it around, it's also the last.

That's what I meant when I said "adding a template". Because now, 
`await_suspend` *must* become a template function. There's no other way to 
capture a parameter of an arbitrary, compiler-generated type.

But what of generators and promises in such a scenario? A `generator<int>` 
needs to be able to store any coroutine, so it has to... type erase it. The 
promise type cannot be a template on the coroutine type, since it was 
declared long before the coroutine handle appeared. And so forth.

In short, the entirety of P0057 is designed around a type-erased 
`coroutine_handle`. You can't simply declare that it's not type-erased and 
expect everything to work reasonably. The entire design would need to be 
rethought.

If you want this done, then you're going to need to go through the effort 
of designing the feature to work without type erasure. Then you have to get 
someone to implement it. Then, you can know whether it works just as well 
as P0057, whether it's equally easy to use, and how much of a performance 
advantage it gets.

If any.

-- 

--- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_6486_896213012.1444798011002
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Tuesday, October 13, 2015 at 11:17:53 PM UTC-4, Evgeny Panasyuk wrote:<b=
lockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;borde=
r-left: 1px #ccc solid;padding-left: 1ex;">14.10.2015 4:57, Nicol Bolas:
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 Except that he&#39;s already proven (i=
n this thread no less) that a
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 good optimizer can elide the allocatio=
n. If the compiler can
<br>&gt; =C2=A0 =C2=A0 =C2=A0 =C2=A0 reasonably /make/ it zero overhead, th=
en it /is/ zero overhead.
<br>&gt;
<br>&gt;
<br>&gt;
<br>&gt; =C2=A0 =C2=A0 1. It is impossible (practically) in general case.
<br>&gt; =C2=A0 =C2=A0 For instance in case when we put coroutines in conta=
iner, like:
<br>&gt; =C2=A0 =C2=A0 |
<br>&gt; =C2=A0 =C2=A0 vector&lt;coroutine&gt;x(N);
<br>&gt; =C2=A0 =C2=A0 |
<br>&gt; =C2=A0 =C2=A0 In case of coroutines with concrete types and sizeof=
 known at
<br>&gt; =C2=A0 =C2=A0 compile - this can be done within single allocation.
<br>&gt; =C2=A0 =C2=A0 But if coroutine type is erased the we will have N+1=
 allocations in
<br>&gt; =C2=A0 =C2=A0 general case - it can&#39;t be practically elided.
<br>&gt;
<br>&gt;
<br>&gt; Ignoring the rest of the discussion on this point, I never claimed=
 that
<br>&gt; P0057 could guarantee elision in the case you present here. Before=
, you
<br>&gt; asked about a /specific/ problem, and I answered with a specific e=
xample
<br>&gt; showing that it was elidable. What you&#39;ve shown here hardly di=
sproves my
<br>&gt; point.
<br>
<br>It is not zero overhead even with good optimizer/compiler, because they=
=20
<br>can&#39;t elide every allocation, and I am not talking about some exoti=
c cases.
<br></blockquote><div><br>Thus far, including in this post, you haven&#39;t=
 mentioned an example that would actually compile.<br><br>You linked to som=
e macro code, but macros are, basically, <i>cheating</i>. They get to break=
 all kinds of C++ rules, which an actual language feature would not.<br>=C2=
=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
&gt;
<br>&gt; Also... how does `vector&lt;coroutine&gt;` make any kind of sense =
with regard
<br>&gt; to P0114? The type isn&#39;t type erased, so each coroutine has it=
s own
<br>&gt; type. Therefore, in order to put them in a homogeneous container l=
ike
<br>&gt; `vector`, you&#39;ll have to type-erase them. Which requires memor=
y allocation.
<br>=C2=A0&gt; At which point, your version gains /nothing/ over P0057.
<br>
<br>Same coroutines have same concrete types. For instance, with P0114 it=
=20
<br>may be:
<br>|
<br>struct concrete_coroutine
<br>{
<br>=C2=A0 =C2=A0 =C2=A0resumable auto r =3D expression;
<br>=C2=A0 =C2=A0 =C2=A0// ...
<br>};
<br>...
<br>make_unique&lt;concrete_<wbr>coroutine[]&gt;(N);
<br>|<br></blockquote><div><br>`auto` doesn&#39;t work that way. Non-static=
 data members cannot be `auto`. Normally I wouldn&#39;t care about a small =
issue like that, but it basically makes your code impossible.<br><br>Withou=
t `auto` NSDMI (and <a href=3D"http://www.open-std.org/JTC1/SC22/WG21/docs/=
papers/2014/n3897.html">I wouldn&#39;t hold my breath on seeing it</a>), yo=
u can&#39;t store a resumable expression. So you can&#39;t make containers =
of them.<br><br>Unless you erase their types. So again, you&#39;ve gained <=
i>nothing</i>.<br><br>Your macro solution gets around this because it uses =
macros.<br></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=
=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: =
1ex;">
Again, I am not talking specifically about P0114. Even P0057 can be=20
<br>changed to have concrete coroutine type.
<br></blockquote><div><br>I&#39;d be curious to see how, exactly.<br><br>An=
d I don&#39;t mean some macro nonsense. I mean the specific details of how =
you turn P0057&#39;s `coroutine_handle` into a type.<br><br>See, the way P0=
057 works is that the coroutine object is introduced in one specific place:=
 the awaiter object&#39;s `await_suspend` method. That&#39;s the first plac=
e where user code gets to touch a coroutine, and if the method doesn&#39;t =
store it or otherwise keep it around, it&#39;s also the last.<br><br>That&#=
39;s what I meant when I said &quot;adding a template&quot;. Because now, `=
await_suspend` <i>must</i> become a template function. There&#39;s no other=
 way to capture a parameter of an arbitrary, compiler-generated type.<br><b=
r>But what of generators and promises in such a scenario? A `generator&lt;i=
nt&gt;` needs to be able to store any coroutine, so it has to... type erase=
 it. The promise type cannot be a template on the coroutine type, since it =
was declared long before the coroutine handle appeared. And so forth.<br><b=
r>In short, the entirety of P0057 is designed around a type-erased `corouti=
ne_handle`. You can&#39;t simply declare that it&#39;s not type-erased and =
expect everything to work reasonably. The entire design would need to be re=
thought.<br><br>If you want this done, then you&#39;re going to need to go =
through the effort of designing the feature to work without type erasure. T=
hen you have to get someone to implement it. Then, you can know whether it =
works just as well as P0057, whether it&#39;s equally easy to use, and how =
much of a performance advantage it gets.<br><br>If any.<br></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_6486_896213012.1444798011002--
------=_Part_6485_1764221694.1444798011001--

.
