220 21855 <03e98dd3-a02e-41a6-af55-f4bdff0e4326@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Gor Nishanov <gornishanov@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: Sat, 17 Oct 2015 12:29:51 -0700 (PDT)
Lines: 184
Approved: news@gmane.org
Message-ID: <03e98dd3-a02e-41a6-af55-f4bdff0e4326@isocpp.org>
References: <639f0012-8cb4-4db3-82a6-8d042a3497f9@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>
 <510ce172-976a-4e3a-ae68-31fdb40af4d7@isocpp.org>
 <9dd3f28c-4ffb-4e08-9955-242c46e14527@isocpp.org>
 <31d5f64f-8db9-4ba3-aca7-872114b9776d@isocpp.org>
 <561DE488.3040103@gmail.com>
 <5587a3fd-499c-42b3-bf05-fd5cdc2d9118@isocpp.org>
 <561EF19E.6010405@gmail.com>
 <a4eb8eb5-0ace-457c-b410-219d8c4470db@isocpp.org>
 <f679fc91-5ab5-4894-89f1-cec17361e8f1@isocpp.org>
 <7560dfa8-c77f-41ec-9c0d-c88fe65e20b5@isocpp.org>
 <a78b3900-eee5-4bc9-ab38-52e169700205@isocpp.org>
 <bb43af4f-f1a3-41c2-b14d-edda75a44458@isocpp.org>
 <9589b701-3237-4686-b11e-dc669e76f488@isocpp.org>
 <9695320b-3b02-483c-a050-5c6cad44bb1a@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_903_1617720059.1445110191276"
X-Trace: ger.gmane.org 1445110210 19927 80.91.229.3 (17 Oct 2015 19:30:10 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sat, 17 Oct 2015 19:30:10 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBC47RF4IW4GRBMGDRKYQKGQENRKIAKY@isocpp.org Sat Oct 17 21:29:55 2015
Return-path: <std-proposals+bncBC47RF4IW4GRBMGDRKYQKGQENRKIAKY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pa0-f69.google.com ([209.85.220.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC47RF4IW4GRBMGDRKYQKGQENRKIAKY@isocpp.org>)
	id 1ZnXAw-00018T-QA
	for gclcip-std-proposals@m.gmane.org; Sat, 17 Oct 2015 21:29:55 +0200
Original-Received: by padcn9 with SMTP id cn9sf6554538pad.0
        for <gclcip-std-proposals@m.gmane.org>; Sat, 17 Oct 2015 12:29: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=whlS2lMinoY444tWozi+9wNt3qE7IIff23LwEmIcWhs=;
        b=eCJCCH5zi+See/LPL2ciXaifzpxXpdNg7a83TDZOExCsR/B9fC/PYruwEyINDVoVgR
         Yh9fnGNXzk5lxEki945Ol0jTsD/ee6tnL9pUDmBvX3ePcsKjksaftswBxL6F9VGprIG4
         jrSP7CIvpf31KIVLz8cdpV2/IK4t0MWUOKrZmo2PDY7thdylUmETuhh5ZzDBHaiLfNE/
         leCusMO9lw4veANaT4VbJK0dkKoUTDf8Ftx3IZkFvkN1HYCPC0yW0dcYtajpa2XAegNw
         EDs5wjbpS77u+xhROZkk709V4iAds9pCGl8D1upbyN8QdrqulBUUMk/cq2kY9Pfxu8Ci
         XbGg==
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=whlS2lMinoY444tWozi+9wNt3qE7IIff23LwEmIcWhs=;
        b=AAieApLo757mKwlZgd7Y/nsNKE4FmQKEPf7JlIc5QdVyPcLVed7AbOXg9kJ4nAr4j4
         N+JFkJ/9ypTj3ybL5cmhX2lewD9g8bKdGD8XkwVkiSkT8xpvUUpcX9aFrfBEe7uiH6AA
         jX1BVChhGtG43KiqZfx1zfc5rv1K15p3VzQf95aOXEFFV8Ddz457HzJl9wj/RvqhBHcw
         UK4q24Aclz5D3CDUP8PchcXXXFNJCuQ2pfWpeIeTYNGzFe6vkPj77MLWA26rH96lLdhV
         wl9uxBLgBfe1FVvXvPqnu8Ijq+HEjOhLJ9J3DiSpKAzPm97qprKqmD6BzIUAyszOghB4
         BrRA==
X-Gm-Message-State: ALoCoQl0sW2FCParIYf3kB51QFcPHhXgJ5W2ACN8A1bw97GaCc0/Vnf5w/r3qCXXejYGu5fXhpxv
X-Received: by 10.68.94.1 with SMTP id cy1mr18609198pbb.14.1445110193074;
        Sat, 17 Oct 2015 12:29:53 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.133.90 with SMTP id h87ls462344iod.11.gmail; Sat, 17 Oct
 2015 12:29:52 -0700 (PDT)
X-Received: by 10.50.225.70 with SMTP id ri6mr242390igc.9.1445110192263;
        Sat, 17 Oct 2015 12:29:52 -0700 (PDT)
In-Reply-To: <9695320b-3b02-483c-a050-5c6cad44bb1a@isocpp.org>
X-Original-Sender: GorNishanov@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:21855
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/21855>

------=_Part_903_1617720059.1445110191276
Content-Type: multipart/alternative; 
	boundary="----=_Part_904_187180316.1445110191283"

------=_Part_904_187180316.1445110191283
Content-Type: text/plain; charset=UTF-8



Hi Nicol:

On Saturday, October 17, 2015 at 12:08:39 PM UTC-7, Nicol Bolas wrote:

The problem is that the kludge doesn't work. Or at least, it doesn't work 
> the same way. We discussed this earlier.
>

That was probably my fault in not explaining it more clearly. 


> In P0114, the entire call stack is taken as a single coroutine. So when 
> you resume the coroutine, the resume will *always* take you to the exact 
> cite of the `break resumable` call that suspended it.
>

"entire call stack" here is an illusion. The same illusion that kludge is 
doing. What effectively happens in P0114 is that all state machines are 
inlined into each other. You don't have a stack. You have a single 
"resumable" function that does entire thing.

Similar things happen in P0057 (whether with explicit or implicit awaits). 
Since in this particular case coroutine lifetime does not escape the full 
expression it is used in the same heap elision rules apply as for generator 
case.

In a generator case:

void f(){
   auto g = gen();
    ... bla
} // generator is destroyed, hence we can use automatic storage of f for 
the generator

In the well-behaved sub-coroutine case (RAII semantics, destructor calls 
coroutine_handle::destroy())

well_behaved_future<void> h() {
  await async_io();
}
well_behaved_future<void> g() {
  await h(); // life time starts and ends here, alloc elision applies here
}
well_behaved_future<void> f() { 
  await g(); // life time starts and ends here, alloc elision applies here
};

Just like with P0114, it is only possible in non-recursive scenarios where 
things get inlined into each other.

-- 

--- 
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_904_187180316.1445110191283
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><p>Hi Nicol:<br><br>On Saturday, October 17, 2015 at 12:08=
:39 PM UTC-7, Nicol Bolas wrote:</p><div><br></div><blockquote class=3D"gma=
il_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-lef=
t-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: sol=
id;"><div dir=3D"ltr">The problem is that the kludge doesn&#39;t work. Or a=
t least, it doesn&#39;t work the same way. We discussed this earlier.<br></=
div></blockquote><div><br></div><div>That was probably my fault=C2=A0in not=
=C2=A0explaining it more=C2=A0clearly.=C2=A0</div><div><br></div><blockquot=
e class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1=
ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-l=
eft-style: solid;"><div dir=3D"ltr"><br>In P0114, the entire call stack is =
taken as a single coroutine. So when you resume the coroutine, the resume w=
ill <i>always</i> take you to the exact cite of the `break resumable` call =
that suspended it.<br></div></blockquote><div><br></div><div>&quot;entire c=
all stack&quot; here is an illusion. The same illusion that kludge is doing=
.. What effectively happens in P0114 is that all state machines are inlined =
into each other. You don&#39;t have a stack. You have a single &quot;resuma=
ble&quot; function that does entire thing.</div><div><br></div><div>Similar=
 things happen in P0057 (whether with explicit or implicit awaits). Since i=
n this particular case coroutine lifetime does not escape the full expressi=
on it is used in the same heap elision rules apply as for generator case.</=
div><div><br></div><div>In a generator case:</div><div><br></div><div class=
=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); border-imag=
e: none; -ms-word-wrap: break-word; background-color: rgb(250, 250, 250);">=
<code class=3D"prettyprint"><div class=3D"subprettyprint"><span class=3D"st=
yled-by-prettify" style=3D"color: rgb(0, 0, 136);">void</span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> f</span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">(){</span><span =
class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"><br>=C2=A0 =C2=
=A0</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 136)=
;">auto</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, =
0);"> g </span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, =
102, 0);">=3D</span><span class=3D"styled-by-prettify" style=3D"color: rgb(=
0, 0, 0);"> gen</span><span class=3D"styled-by-prettify" style=3D"color: rg=
b(102, 102, 0);">();</span><span class=3D"styled-by-prettify" style=3D"colo=
r: rgb(0, 0, 0);"><br>=C2=A0 =C2=A0 </span><span class=3D"styled-by-prettif=
y" style=3D"color: rgb(102, 102, 0);">...</span><span class=3D"styled-by-pr=
ettify" style=3D"color: rgb(0, 0, 0);"> bla<br></span><span class=3D"styled=
-by-prettify" style=3D"color: rgb(102, 102, 0);">}</span><span class=3D"sty=
led-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styl=
ed-by-prettify" style=3D"color: rgb(136, 0, 0);">// generator is destroyed,=
 hence we can use automatic storage of f for the generator</span><span clas=
s=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"><br></span></div></=
code></div><div><br></div><div>In the well-behaved sub-coroutine case (RAII=
 semantics, destructor calls coroutine_handle::destroy())</div><div><br></d=
iv><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187)=
; border-image: none; -ms-word-wrap: break-word; background-color: rgb(250,=
 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><spa=
n class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">well_behaved_=
future</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 136,=
 0);">&lt;void&gt;</span><span class=3D"styled-by-prettify" style=3D"color:=
 rgb(0, 0, 0);"> h</span><span class=3D"styled-by-prettify" style=3D"color:=
 rgb(102, 102, 0);">()</span><span class=3D"styled-by-prettify" style=3D"co=
lor: rgb(0, 0, 0);"> </span><span class=3D"styled-by-prettify" style=3D"col=
or: rgb(102, 102, 0);">{</span><span class=3D"styled-by-prettify" style=3D"=
color: rgb(0, 0, 0);"><br></span><font color=3D"#000000"><span class=3D"sty=
led-by-prettify" style=3D"color: rgb(0, 0, 0);">=C2=A0 await async_io</span=
><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">();<=
/span></font><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0=
);"><br></span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, =
102, 0);">}</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0,=
 0, 0);"><br>well_behaved_future</span><span class=3D"styled-by-prettify" s=
tyle=3D"color: rgb(0, 136, 0);">&lt;void&gt;</span><span class=3D"styled-by=
-prettify" style=3D"color: rgb(0, 0, 0);"> g</span><span class=3D"styled-by=
-prettify" style=3D"color: rgb(102, 102, 0);">()</span><span class=3D"style=
d-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styled=
-by-prettify" style=3D"color: rgb(102, 102, 0);">{</span><span class=3D"sty=
led-by-prettify" style=3D"color: rgb(0, 0, 0);"><br></span><font color=3D"#=
000000"><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);">=
=C2=A0 await h</span></font><span class=3D"styled-by-prettify" style=3D"col=
or: rgb(102, 102, 0);">();</span><span class=3D"styled-by-prettify" style=
=3D"color: rgb(0, 0, 0);"> </span><span class=3D"styled-by-prettify" style=
=3D"color: rgb(136, 0, 0);">// life time starts and ends here, alloc elisio=
n applies here</span><span class=3D"styled-by-prettify" style=3D"color: rgb=
(0, 0, 0);"><br></span><span class=3D"styled-by-prettify" style=3D"color: r=
gb(102, 102, 0);">}</span><span class=3D"styled-by-prettify" style=3D"color=
: rgb(0, 0, 0);"><br>well_behaved_future</span><span class=3D"styled-by-pre=
ttify" style=3D"color: rgb(0, 136, 0);">&lt;void&gt;</span><span class=3D"s=
tyled-by-prettify" style=3D"color: rgb(0, 0, 0);"> f</span><span class=3D"s=
tyled-by-prettify" style=3D"color: rgb(102, 102, 0);">()</span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> </span><span class=
=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">{</span><span cl=
ass=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"> <br>=C2=A0 await=
 g</span><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0=
);">();</span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, =
0);"> </span><span class=3D"styled-by-prettify" style=3D"color: rgb(136, 0,=
 0);">// life time starts and ends here, alloc elision applies here</span><=
span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"><br></span=
><span class=3D"styled-by-prettify" style=3D"color: rgb(102, 102, 0);">};</=
span><span class=3D"styled-by-prettify" style=3D"color: rgb(0, 0, 0);"><br>=
</span></div></code></div><br><div>Just like with P0114, it is only possibl=
e in non-recursive scenarios where things get inlined into each other.</div=
></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_904_187180316.1445110191283--
------=_Part_903_1617720059.1445110191276--

.
