220 21796 <8a973164-304b-4ddc-85e7-fecc20b9c586@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Evgeny Panasyuk <evgeny.panasyuk@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: Wed, 14 Oct 2015 14:46:34 -0700 (PDT)
Lines: 299
Approved: news@gmane.org
Message-ID: <8a973164-304b-4ddc-85e7-fecc20b9c586@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>
 <510ce172-976a-4e3a-ae68-31fdb40af4d7@isocpp.org>
 <9dd3f28c-4ffb-4e08-9955-242c46e14527@isocpp.org>
 <CAFk2RUZWb+AaXQSPreat6LW9PVi-5V8zTFNDt-kJbigJbXsTPg@mail.gmail.com>
 <561DEFFD.2010802@gmail.com>
 <CAFk2RUZ9OvORFei7oBE3ntYcw6tsWW9tJYW=is_WjLXzdj-wZg@mail.gmail.com>
 <76d7c4dd-0ebc-4785-9559-34832ec5b884@isocpp.org>
 <CAFk2RUaUopb-nOswDcbvNs8ays96r8DEPDR+dQFUWEn0GnTtjg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_13_761263283.1444859194339"
X-Trace: ger.gmane.org 1444859200 31765 80.91.229.3 (14 Oct 2015 21:46:40 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 14 Oct 2015 21:46:40 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBC54TLGKR4LBBO427OYAKGQEAHBNJRQ@isocpp.org Wed Oct 14 23:46:40 2015
Return-path: <std-proposals+bncBC54TLGKR4LBBO427OYAKGQEAHBNJRQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ig0-f198.google.com ([209.85.213.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC54TLGKR4LBBO427OYAKGQEAHBNJRQ@isocpp.org>)
	id 1ZmTsb-0002Nt-CN
	for gclcip-std-proposals@m.gmane.org; Wed, 14 Oct 2015 23:46:37 +0200
Original-Received: by igcsm6 with SMTP id sm6sf3631168igc.2
        for <gclcip-std-proposals@m.gmane.org>; Wed, 14 Oct 2015 14:46:36 -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=iFgonVBASEJStUyI941/3zVnHVVlX0LKYubPA+bOD7o=;
        b=AvsZvoXCdxJyAAkIiDcxvxmcg0pmvVZQRghYB1VGrkfoZeP0Et6sIhtM2nvDOWo+B+
         kGHZ7zH/lCgIWB3WR6CYP+w6l/DKUGIJp8VUnWiGP/XavWICD78w1gTCC8Qj5s6GyP8P
         HqK9tIK21JaRYvfTFnVm++bYcU32UZIQ2iCLKrvk6BztvlciJKow+HGKrrb3tfHFcRPU
         aaw1J6RXFMH7+E+zxvEjzyscNMYIU+aBXFncVUD8EvuSAY0FwyjpJFfuXO0m828dMVFG
         wJwIwS0MYNs6JCGxUB+/nEtsOhyR6wbwbrYv94H/ZOGwsoWElNILncJwb/LAqARTOzSO
         z1yg==
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=iFgonVBASEJStUyI941/3zVnHVVlX0LKYubPA+bOD7o=;
        b=NKkifDlc5RV4+NW1krokfqRWfOT7jHBo8RWpwdM8XHkxzZv1ixImJ0UI7Wq/KuK4Jc
         W8FisUkC6dwbRF3r30kEs2W5WQ5gvZ/Oy0naXyJhQmz6y6qJc3/se98y4OqFe+s9kneC
         fx90q6FFpzyO86JPK4Qa9KnbM3yLLoZj0FAud9/84Wujny2yEvFWUEJvvQcxPA6ODYon
         HZsVqZ0E+hM+4/beA/zUgPtF5yN+qJJZCkUgswN6zcCEj7l+KZaRBbK3zrWtGMNMyBJU
         glW4kTL76zyeZHsneQBoOszb1RchWHoYW3bDFjmaBpRzUkmzod+dNamqQghs+VDavmE8
         VS9w==
X-Gm-Message-State: ALoCoQnKlCFqBV8KCyzvzwi6RrykNrReSJY0HhSv7p0b1PP9D5jdyh22MedCrpSmzeEav75/oRIH
X-Received: by 10.182.52.132 with SMTP id t4mr4627248obo.16.1444859196319;
        Wed, 14 Oct 2015 14:46:36 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.33.9 with SMTP id h9ls298763ioh.73.gmail; Wed, 14 Oct 2015
 14:46:35 -0700 (PDT)
X-Received: by 10.50.131.164 with SMTP id on4mr424952igb.8.1444859195551;
        Wed, 14 Oct 2015 14:46:35 -0700 (PDT)
In-Reply-To: <CAFk2RUaUopb-nOswDcbvNs8ays96r8DEPDR+dQFUWEn0GnTtjg@mail.gmail.com>
X-Original-Sender: Evgeny.Panasyuk@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:21796
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/21796>

------=_Part_13_761263283.1444859194339
Content-Type: multipart/alternative; 
	boundary="----=_Part_14_914823304.1444859194340"

------=_Part_14_914823304.1444859194340
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

15 October 2015 =D0=B3., 0:18:21 UTC+3 Ville Voutilainen:
>
> On 15 October 2015 at 00:09, Evgeny Panasyuk <evgeny....@gmail.com=20
> <javascript:>> wrote:=20
> >  14 October 2015 =D0=B3., 10:42:53 UTC+3 Ville Voutilainen :=20
> >>=20
> >>=20
> >> As far as having the concrete type goes, that sounds like it requires=
=20
> even=20
> >> more inlining and across-call-stack transparency.=20
> >=20
> >=20
> > It actually requires less inlining and transparency. For instance, this=
=20
> > code:=20
> > future<int> concrete_coroutine()=20
> > {=20
> >     int local =3D await async_operation();=20
> >     return local;=20
> > }=20
> > Can be straightforwardly transformed to something like:=20
> > struct concrete_coroutine=20
> > {=20
> >     state_value_type current_state;=20
> >     int local;=20
> >=20
> >     future<int> method_state_machine(); // or operator()()=20
> > };=20
> > Where method_state_machine can be compiled separately, in another=20
> > translation unit.=20
> > And actually this approach is already implementable with macros, to som=
e=20
> > extent (it works, but compiler-side transformation will give better=20
> result).=20
>
> Where does this transformation happen translation-unit-wise, and how=20
> would the method_state_machine get compiled in a different translation=20
> unit?


This is a good point. Looks like such transformation should happen in each=
=20
translation unit which uses it - in order to deduce size of structure=20
(maybe not full code generation, just analysis of locals). Method itself=20
can be compiled only in one of translation units using mechanism similar to=
=20
extern and explicit instantiation.
But my point still holds, this method can be not inlined (in optimizer=20
sense) and still produce zero allocations.
=20

> What type does the caller of the previous concrete_coroutine() see?=20
>
>
What do you mean? Which "previous"?
=20

> >> In a stackless coroutine,=20
> >> the erased type combined with elision of the erasure and allocations=
=20
> >> avoids=20
> >> having all coroutines have a different type.=20
> > Yes, but it is easy to get erased type from concrete when needed.=20
> > For instance different lambdas have different types, but can be easily=
=20
> > placed into std::function (if has appropriate signature).=20
>
> For some values of "easily". For the many users who don't care about the=
=20
> underlying type of the coroutine, it's not so easy when they have to wrap=
=20
> every=20
> time they use a coroutine.=20
>

It can be done even without explicit wrapping, but just relying on=20
different coroutine_traits specializations. One trait may give concrete=20
coroutine type, and another can erase concrete and give erased type to user=
..
For instance:
concrete_generator<int> cg1()
{
    yield 1;
}

concrete_generator<int> cg2()
{
    yield 2;
}
Here cg1 and cg2 are different types.

But here:
type_erased_generator<int> teg1()
{
    yield 1;
}

type_erased_generator<int> teg2()
{
    yield 2;
}
teg1 and teg2 would have same type.

User do not have to wrap manually cg1 and cg2 (but he can do this also) -=
=20
instead he may use type_erased_generator from the start, and it will do=20
type erasure itself via coroutine_traits mechanism.

--=20

---=20
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 e=
mail 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-proposa=
ls/.

------=_Part_14_914823304.1444859194340
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

15 October 2015 =D0=B3., 0:18:21 UTC+3 Ville Voutilainen:<blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;">On 15 October 2015 at 00:09, Evgeny Panasyuk &l=
t;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"8j9LEh=
OvDgAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;javascript:&#39;;r=
eturn true;" onclick=3D"this.href=3D&#39;javascript:&#39;;return true;">evg=
eny....@gmail.com</a>&gt; wrote:
<br>&gt; =C2=A014 October 2015 =D0=B3., 10:42:53 UTC+3 Ville Voutilainen :
<br>&gt;&gt;
<br>&gt;&gt;
<br>&gt;&gt; As far as having the concrete type goes, that sounds like it r=
equires even
<br>&gt;&gt; more inlining and across-call-stack transparency.
<br>&gt;
<br>&gt;
<br>&gt; It actually requires less inlining and transparency. For instance,=
 this
<br>&gt; code:
<br>&gt; future&lt;int&gt; concrete_coroutine()
<br>&gt; {
<br>&gt; =C2=A0 =C2=A0 int local =3D await async_operation();
<br>&gt; =C2=A0 =C2=A0 return local;
<br>&gt; }
<br>&gt; Can be straightforwardly transformed to something like:
<br>&gt; struct concrete_coroutine
<br>&gt; {
<br>&gt; =C2=A0 =C2=A0 state_value_type current_state;
<br>&gt; =C2=A0 =C2=A0 int local;
<br>&gt;
<br>&gt; =C2=A0 =C2=A0 future&lt;int&gt; method_state_machine(); // or oper=
ator()()
<br>&gt; };
<br>&gt; Where method_state_machine can be compiled separately, in another
<br>&gt; translation unit.
<br>&gt; And actually this approach is already implementable with macros, t=
o some
<br>&gt; extent (it works, but compiler-side transformation will give bette=
r result).
<br>
<br>Where does this transformation happen translation-unit-wise, and how
<br>would the method_state_machine get compiled in a different translation
<br>unit?</blockquote><div><br>This is a good point. Looks like such transf=
ormation should happen in each translation unit which uses it - in order to=
 deduce size of structure (maybe not full code generation, just analysis of=
 locals). Method itself can be compiled only in one of translation units us=
ing mechanism similar to extern and explicit instantiation.<br>But my point=
 still holds, this method can be not inlined (in optimizer sense) and still=
 produce zero allocations.<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;">What type does the caller of the previous concrete_coroutine() =
see?
<br>
<br></blockquote><div><br>What do you mean? Which &quot;previous&quot;?<br>=
=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">&gt;&gt; In a stac=
kless coroutine,
<br>&gt;&gt; the erased type combined with elision of the erasure and alloc=
ations
<br>&gt;&gt; avoids
<br>&gt;&gt; having all coroutines have a different type.
<br>&gt; Yes, but it is easy to get erased type from concrete when needed.
<br>&gt; For instance different lambdas have different types, but can be ea=
sily
<br>&gt; placed into std::function (if has appropriate signature).
<br>
<br>For some values of &quot;easily&quot;. For the many users who don&#39;t=
 care about the
<br>underlying type of the coroutine, it&#39;s not so easy when they have t=
o wrap every
<br>time they use a coroutine.
<br></blockquote><div><br>It can be done even without explicit wrapping, bu=
t just relying on different coroutine_traits specializations. One trait may=
 give concrete coroutine type, and another can erase concrete and give eras=
ed type to user.<br>For instance:<br><div class=3D"prettyprint" style=3D"ba=
ckground-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); borde=
r-style: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"p=
rettyprint"><div class=3D"subprettyprint"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">concrete_generator</span><span style=3D"color: #08=
0;" class=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> cg1</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">yield</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">1=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br></span><br><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"><code class=3D"prettyprint"><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">concrete_generator</span>=
<span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&gt;</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> cg2</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">yield</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" cla=
ss=3D"styled-by-prettify">2</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">}</span><span style=3D"color: #000;" class=3D"styled-by-prettify"></span>=
</code><br></span></div></code></div>Here cg1 and cg2 are different types.<=
br><br>But here:<br><div class=3D"prettyprint" style=3D"background-color: r=
gb(250, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; b=
order-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div =
class=3D"subprettyprint"><code class=3D"prettyprint"><span style=3D"color: =
#000;" class=3D"styled-by-prettify">type_erased_generator</span><span style=
=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&gt;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> teg1</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">yield</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">1</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br=
></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><br><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><code class=3D"prett=
yprint"><span style=3D"color: #000;" class=3D"styled-by-prettify"></span></=
code></span></code><code class=3D"prettyprint"><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><code class=3D"prettyprint"><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><code class=3D"prettyprint"><code =
class=3D"prettyprint"><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">type_erased_generator</span><span style=3D"color: #080;" class=3D"styl=
ed-by-prettify"></span></code></code></span><span style=3D"color: #080;" cl=
ass=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> teg2</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-p=
rettify">yield</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #066;" class=3D"styled-by-prettify">2</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"></span></code></span></code><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify"></span></div></code></div>=
teg1 and teg2 would have same type.<br><br>User do not have to wrap manuall=
y cg1 and cg2 (but he can do this also) - instead he may use type_erased_ge=
nerator from the start, and it will do type erasure itself via coroutine_tr=
aits mechanism.<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_14_914823304.1444859194340--
------=_Part_13_761263283.1444859194339--

.
