220 14306 <CAFOQpdoJOQpJkaiVL85qTfaj1H61kVEzNvMeiZJHFMjz972mxQ@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Christopher Kohlhoff <chris@kohlhoff.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: comment on n4244
Date: Thu, 30 Oct 2014 00:42:02 +1100
Lines: 223
Approved: news@gmane.org
Message-ID: <CAFOQpdoJOQpJkaiVL85qTfaj1H61kVEzNvMeiZJHFMjz972mxQ@mail.gmail.com>
References: <5d78c59b-4d67-45f6-9d99-8c4beeeac055@isocpp.org>
	<f783bffc-9810-48dd-b89c-1361ca285815@isocpp.org>
	<5344687e-e1de-4205-885c-b5c2f9580129@isocpp.org>
	<187da710-8adc-4516-bf64-263951503bc7@isocpp.org>
	<42ddf641-27c7-42a5-ab1c-772667797e5b@isocpp.org>
	<a901a369-5d04-4752-92af-b97a3a9496b2@isocpp.org>
	<05a08ac6-f9b8-4ebb-9cb8-9a37a6fd4527@isocpp.org>
	<3ff7fe35-37c6-4f95-8701-1798b0112c10@isocpp.org>
	<CAL52AavgpeZ=44VMTpUMX+wwHa922Scg9-9mvKjVhzfjivo5RA@mail.gmail.com>
	<934c6ace-40cc-484a-96ea-b05aff88482d@isocpp.org>
	<1d0b64d1-ca4b-448a-9589-01fdc0b85d55@isocpp.org>
	<804b06d1-9c63-4ef2-a3e8-ccfbdae30ebf@isocpp.org>
	<ca372c00-a7eb-4d88-921b-cd642d15ac90@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=089e0158c09aca0ec305068fed62
X-Trace: ger.gmane.org 1414590133 13989 80.91.229.3 (29 Oct 2014 13:42:13 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 29 Oct 2014 13:42:13 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCS7VEH374ORBLG5YORAKGQEPRSW3AI@isocpp.org Wed Oct 29 14:42:07 2014
Return-path: <std-proposals+bncBCS7VEH374ORBLG5YORAKGQEPRSW3AI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-la0-f72.google.com ([209.85.215.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCS7VEH374ORBLG5YORAKGQEPRSW3AI@isocpp.org>)
	id 1XjTVl-0002pI-M4
	for gclcip-std-proposals@m.gmane.org; Wed, 29 Oct 2014 14:42:05 +0100
Original-Received: by mail-la0-f72.google.com with SMTP id mc6sf1717760lab.3
        for <gclcip-std-proposals@m.gmane.org>; Wed, 29 Oct 2014 06:42:05 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:date
         :message-id:subject:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=DuL5FgmsOaK8lz6CE4HLZt6T/VOgNQy5U6msQ39RlmA=;
        b=di3yX8+pqOGUJnPEO3dXVNKaFjmSIbkcte0Lr59W6S9eeHXX9VVawDc5BNUoXuukkj
         ZyDafzRT0DFBPMgofr87I5xwjuvHayNNaNSaz9u7F4CxUaZLxJNPGk2AiGulqMJovU6M
         DPWcMqAqJ4/GFrW7lEq2tjM4Us5zYE8evzgKhbYV+mSTqoy3hNvjGmKKO+T6/idlj8lY
         2O62tiCQXFBR2dizNZ25y5YXylzRmYSr4ojzspAT3eI2vdXfSjS+Yvo3mGopOSNIpHQW
         ScrGMCF6/EugPsuzQ62VF1y/y+G8lGZXPLNrUGowgumwAF6aUkpUBd/Xr1eH57OAF3qp
         oB9w==
X-Gm-Message-State: ALoCoQlCqZlZIp/PwRpyZdWGwXMaUkRShNEalVNW8PQpiYV18J613bW08m7WoOuJqFbXIkY/YVuq
X-Received: by 10.112.41.228 with SMTP id i4mr1796918lbl.0.1414590125473;
        Wed, 29 Oct 2014 06:42:05 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.152.37.103 with SMTP id x7ls183092laj.37.gmail; Wed, 29 Oct
 2014 06:42:03 -0700 (PDT)
X-Received: by 10.152.19.133 with SMTP id f5mr11226895lae.87.1414590123709;
        Wed, 29 Oct 2014 06:42:03 -0700 (PDT)
Original-Received: from mail-la0-x233.google.com (mail-la0-x233.google.com. [2a00:1450:4010:c03::233])
        by mx.google.com with ESMTPS id wt3si7304803lbb.44.2014.10.29.06.42.03
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Wed, 29 Oct 2014 06:42:03 -0700 (PDT)
Received-SPF: pass (google.com: domain of chris.kohlhoff@gmail.com designates 2a00:1450:4010:c03::233 as permitted sender) client-ip=2a00:1450:4010:c03::233;
Original-Received: by mail-la0-f51.google.com with SMTP id q1so2515677lam.24
        for <std-proposals@isocpp.org>; Wed, 29 Oct 2014 06:42:03 -0700 (PDT)
X-Received: by 10.152.29.41 with SMTP id g9mr11597834lah.83.1414590123084;
 Wed, 29 Oct 2014 06:42:03 -0700 (PDT)
Original-Sender: chris.kohlhoff@gmail.com
Original-Received: by 10.25.33.73 with HTTP; Wed, 29 Oct 2014 06:42:02 -0700 (PDT)
In-Reply-To: <ca372c00-a7eb-4d88-921b-cd642d15ac90@isocpp.org>
X-Original-Sender: chris@kohlhoff.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of chris.kohlhoff@gmail.com designates 2a00:1450:4010:c03::233 as
 permitted sender) smtp.mail=chris.kohlhoff@gmail.com;       dkim=pass header.i=@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <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:14306
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/14306>

--089e0158c09aca0ec305068fed62
Content-Type: text/plain; charset=UTF-8

On Wed, Oct 29, 2014 at 1:00 AM, Giovanni Piero Deretta <gpderetta@gmail.com
> wrote:

>
>
> On Tuesday, October 28, 2014 1:24:20 PM UTC, Gor Nishanov wrote:
>>
>>
>>
>>>
>>> why would they be not safe? They are perfectly safe in N4244 design.  As
>>> safe as the rest of the c++ at least.
>>>
>>
>> Notice that lambda* transforms the variables form the body of
>> operator()() in a member variable of the class. Aliases may appear without
>> you noticing;
>>
>> std::string s = "hello";
>> for(ch: S) yield ch;
>>
>>
> hargh, that's pretty damning. You do not even need the string:
>
>   char s[] = "hello";
>   for(ch: S) yield ch;
>
> for this specific case the compiler *could* fix the iterator, but you can
> come up with other cases in which it is unfeasible. I agree that making
> generator copyable by default would be terribly error prone.
>
> There might be a way out that might satisfy everybody's requirements. Let
> me think about it.
>

By way of background let me say that I disagree with Gor's definition
of "stackless" as his definition includes N4134 coroutines. The
defining characteristic of stackless coroutines is that, as a user, you
make no assumptions about the stack:

- You make no assumptions that your variables have stable addresses.

- You don't do things that alias your local variables.

As soon as you stick that little "resumable" keyword on there, you are
defining an aggregate where the data members are defined as locals.

But yes, range-based for is a problem because it necessarily introduces
aliasing and yet also hides it away. It seems to me there's a simple
solution: If your resumable lambda contains a ranged-based for, and
your range-based for contains a yield, then the resumable lambda's copy
and move constructors are inhibited. Nothing of value is lost. In other
words, we can still write:

  std::vector<std::string> strings;
  ...
  auto&& f = [strings]
  {
    for (auto s: strings)
      yield s;
    ...
  };

if we are willing to accept that f is noncopyable. Please note that in
my implementation I have solved the problem of noncopyable lambdas. You
can run the lambda as a stationary object in your preferred location --
heap, stack or data member -- and not just as a lifetime-extended
temporary.

Inhibiting copyability in the presence of ranged-based for is about
maintaining correctness. I don't believe copyable or movable coroutines
are particularly error prone in general, and the yield points where one
must take care are explicitly documented in the source code. Field
experience with macro-based coroutines bears this out.

It might appear tempting to make noncopyability the default, though
whether or not there is a quantifiable benefit in doing so is
questionable. However, to insist that, due to a perception of risk,
resumable lambdas must reside on the heap is to throw the baby out with
the bath water. To me this approach seems fundamentally at odds with
the ethos and existing practice of C++. A compiler vendor knows far far
less about the specifics of the applications we develop than we do. I
use C++ because I know more about my application, because I care about
performance, and because C++ gives me flexibility to apply this
knowledge.

Lastly, the stated position that having a stationary frame means that
we must have heap allocations smells like faulty logic to me. A
stationary frame implies only that the object not be copied or moved.
C++ programmers write noncopyable classes every day, and they are
perfectly able to put them on the stack, embed them as data members in
other classes, and so on.

Cheers,
Chris

-- 

--- 
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/.

--089e0158c09aca0ec305068fed62
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo=
te">On Wed, Oct 29, 2014 at 1:00 AM, Giovanni Piero Deretta <span dir=3D"lt=
r">&lt;<a href=3D"mailto:gpderetta@gmail.com" target=3D"_blank">gpderetta@g=
mail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(20=
4,204,204);border-left-style:solid;padding-left:1ex"><div dir=3D"ltr"><span=
 class=3D""><br><br>On Tuesday, October 28, 2014 1:24:20 PM UTC, Gor Nishan=
ov wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8e=
x;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-styl=
e:solid;padding-left:1ex"><div dir=3D"ltr"><div>=C2=A0</div><blockquote cla=
ss=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;borde=
r-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid=
"><div dir=3D"ltr"><div>=C2=A0<br>why would they be not safe? They are perf=
ectly safe in N4244 design.=C2=A0 As safe as the rest of the c++ at least.<=
/div></div></blockquote><div><br></div><div>Notice that lambda* transforms =
the variables form the body of operator()() in a member variable of the cla=
ss. Aliases may appear without you noticing;</div><div><br></div><div>std::=
string s =3D &quot;hello&quot;;</div><div>for(ch: S) yield ch;</div><div><b=
r></div></div></blockquote></span><div><br>hargh, that&#39;s pretty damning=
.. You do not even need the string:<br>=C2=A0<br><div>=C2=A0 char s[] =3D &q=
uot;hello&quot;;</div><div>=C2=A0 for(ch: S) yield ch;</div><div><br>for th=
is specific case the compiler *could* fix the iterator, but you can come up=
 with other cases in which it is unfeasible. I agree that making generator =
copyable by default would be terribly error prone.<br></div></div><br>There=
 might be a way out that might satisfy everybody&#39;s requirements. Let me=
 think about it.<br></div></blockquote><blockquote class=3D"gmail_quote" st=
yle=3D"margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb=
(204,204,204);border-left-style:solid;padding-left:1ex"><div class=3D""><di=
v class=3D"h5"></div></div></blockquote></div><br></div><div class=3D"gmail=
_extra"><div class=3D"gmail_extra">By way of background let me say that I d=
isagree with Gor&#39;s definition</div><div class=3D"gmail_extra">of &quot;=
stackless&quot; as his definition includes N4134 coroutines. The</div><div =
class=3D"gmail_extra">defining characteristic of stackless coroutines is th=
at, as a user, you</div><div class=3D"gmail_extra">make no assumptions abou=
t the stack:</div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_=
extra">- You make no assumptions that your variables have stable addresses.=
</div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">- You=
 don&#39;t do things that alias your local variables.</div><div class=3D"gm=
ail_extra"><br></div><div class=3D"gmail_extra">As soon as you stick that l=
ittle &quot;resumable&quot; keyword on there, you are</div><div class=3D"gm=
ail_extra">defining an aggregate where the data members are defined as loca=
ls.</div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">Bu=
t yes, range-based for is a problem because it necessarily introduces</div>=
<div class=3D"gmail_extra">aliasing and yet also hides it away. It seems to=
 me there&#39;s a simple</div><div class=3D"gmail_extra">solution: If your =
resumable lambda contains a ranged-based for, and</div><div class=3D"gmail_=
extra">your range-based for contains a yield, then the resumable lambda&#39=
;s copy</div><div class=3D"gmail_extra">and move constructors are inhibited=
.. Nothing of value is lost. In other</div><div class=3D"gmail_extra">words,=
 we can still write:</div><div class=3D"gmail_extra"><br></div><div class=
=3D"gmail_extra">=C2=A0 std::vector&lt;std::string&gt; strings;</div><div c=
lass=3D"gmail_extra">=C2=A0 ...</div><div class=3D"gmail_extra">=C2=A0 auto=
&amp;&amp; f =3D [strings]</div><div class=3D"gmail_extra">=C2=A0 {</div><d=
iv class=3D"gmail_extra">=C2=A0 =C2=A0 for (auto s: strings)</div><div clas=
s=3D"gmail_extra">=C2=A0 =C2=A0 =C2=A0 yield s;</div><div class=3D"gmail_ex=
tra">=C2=A0 =C2=A0 ...</div><div class=3D"gmail_extra">=C2=A0 };</div><div =
class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">if we are willin=
g to accept that f is noncopyable. Please note that in</div><div class=3D"g=
mail_extra">my implementation I have solved the problem of noncopyable lamb=
das. You</div><div class=3D"gmail_extra">can run the lambda as a stationary=
 object in your preferred location --</div><div class=3D"gmail_extra">heap,=
 stack or data member -- and not just as a lifetime-extended</div><div clas=
s=3D"gmail_extra">temporary.</div><div class=3D"gmail_extra"><br></div><div=
 class=3D"gmail_extra">Inhibiting copyability in the presence of ranged-bas=
ed for is about</div><div class=3D"gmail_extra">maintaining correctness. I =
don&#39;t believe copyable or movable coroutines</div><div class=3D"gmail_e=
xtra">are particularly error prone in general, and the yield points where o=
ne</div><div class=3D"gmail_extra">must take care are explicitly documented=
 in the source code. Field</div><div class=3D"gmail_extra">experience with =
macro-based coroutines bears this out.</div><div class=3D"gmail_extra"><br>=
</div><div class=3D"gmail_extra">It might appear tempting to make noncopyab=
ility the default, though</div><div class=3D"gmail_extra">whether or not th=
ere is a quantifiable benefit in doing so is</div><div class=3D"gmail_extra=
">questionable. However, to insist that, due to a perception of risk,</div>=
<div class=3D"gmail_extra">resumable lambdas must reside on the heap is to =
throw the baby out with</div><div class=3D"gmail_extra">the bath water. To =
me this approach seems fundamentally at odds with</div><div class=3D"gmail_=
extra">the ethos and existing practice of C++. A compiler vendor knows far =
far</div><div class=3D"gmail_extra">less about the specifics of the applica=
tions we develop than we do. I</div><div class=3D"gmail_extra">use C++ beca=
use I know more about my application, because I care about</div><div class=
=3D"gmail_extra">performance, and because C++ gives me flexibility to apply=
 this</div><div class=3D"gmail_extra">knowledge.</div><div class=3D"gmail_e=
xtra"><br></div><div class=3D"gmail_extra">Lastly, the stated position that=
 having a stationary frame means that</div><div class=3D"gmail_extra">we mu=
st have heap allocations smells like faulty logic to me. A</div><div class=
=3D"gmail_extra">stationary frame implies only that the object not be copie=
d or moved.</div><div class=3D"gmail_extra">C++ programmers write noncopyab=
le classes every day, and they are</div><div class=3D"gmail_extra">perfectl=
y able to put them on the stack, embed them as data members in</div><div cl=
ass=3D"gmail_extra">other classes, and so on.</div><div class=3D"gmail_extr=
a"><br></div><div class=3D"gmail_extra">Cheers,</div><div class=3D"gmail_ex=
tra">Chris</div><div><br></div></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 />

--089e0158c09aca0ec305068fed62--

.
