www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - blocks with attributes vs inlined lambda

reply "monarch_dodra" <monarchdodra gmail.com> writes:
I remember think that being able to mark specific parts of code 
with certain attributes, inside a block, could be very useful.

for example:

--------
void foo()
{
    //Code

    /Critical section
    nothrow {
        //code here can't throw
    }

    //More code
}
--------

I have since learned that you can do this with lambda's instead, 
declaring and calling them in a single line:

--------
void foo()
{
    //Code

    /Critical section
    () nothrow
{
        //code here can't throw
    }

    //More code
}
--------
Jun 08 2013
next sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
EDIT: Sorry: stupid computer sent before I was finished. I was 
saying...

I have since learned that you can do this with lambda's
instead, declaring and calling them in a single line:

--------
void foo()
{
    //Code

    //Critical section
    () nothrow //declaration
    { //body
        //code here can't throw
    } () //actual call

     //More code
}
--------

This works. This feature is appearing with higher frequency 
inside phobos, which is proof it is a good feature, and that it 
has uses, and is becoming popular.

My beef though is that the syntax is a bit opaque, and not really 
idiomatic. It looks more like a hacker's trick than a real 
language feature. It's not something you'd do "naturally". At 
least, I know a beginner may not feal comfortable with this.

Given that users are now actually doing this, that we have proof 
it works and is a useful feature, shouldn't we push to have 
actual blocks with attributes in the language?

I think we should... Thoughts?
Jun 08 2013
prev sibling next sibling parent reply "deadalnix" <deadalnix gmail.com> writes:
On Saturday, 8 June 2013 at 14:52:23 UTC, monarch_dodra wrote:
 I remember think that being able to mark specific parts of code 
 with certain attributes, inside a block, could be very useful.

 for example:

 --------
 void foo()
 {
    //Code

    /Critical section
    nothrow {
        //code here can't throw
    }

    //More code
 }
 --------

 I have since learned that you can do this with lambda's 
 instead, declaring and calling them in a single line:

 --------
 void foo()
 {
    //Code

    /Critical section
    () nothrow
 {
        //code here can't throw
    }

    //More code
 }
 --------

Sound like a nice idiom. Why is the first set of () needed ? Can we change the grammar to remove them ?
Jun 08 2013
parent Timon Gehr <timon.gehr gmx.ch> writes:
On 06/18/2013 09:57 AM, Kenji Hara wrote:
     # Purity
     Because a lambda needs to access the frame, any function using the
     lambda trick can't be made pure:
     void foo(T)(T a)  safe
     {
          (){
              ++a;
          }();
     }
     Error: pure function 'main.foo' cannot call impure function literal
     '__lambda1'

     The workaround is to explicitly pass the arguments, *preferably*,
     shadowing them for clarity:
     void foo(int a) pure
     {
          (ref int a){
              ++a;
          }(a);
     }
     This is already *much* less convenient. Imagine if the block needed
     to access 3, 5 or even more variabes ! Also, if one of those
     variables is declared as "auto", then you bring in the "ref
     typeof(a) a" ugliness. Just no.


 This is a compiler bug, and I recently fixed it in git master. Explicit
 argument passing does not need anymore.

Great. Does the fix also introduce the 'immutable' storage class for function literals for the case where a strongly pure literal is wanted?
Jun 30 2013
prev sibling next sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Saturday, 8 June 2013 at 15:56:47 UTC, deadalnix wrote:
 Sound like a nice idiom. Why is the first set of () needed ? 
 Can we change the grammar to remove them ?

It's because you are actually declaring a lambda that takes no arguments, and has no name, and contains a body. BTW, you quoted my incomplete code, the correct code I wanted to post was: () nothrow {//anonymous lambade declaration //Body of the lambde }() //actual call to lambda I'd want to be able to do this, without either the first or last set of (). The required change of grammar would mean there'd be no lambda at all afterwards.
Jun 08 2013
prev sibling next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Saturday, 8 June 2013 at 16:13:28 UTC, monarch_dodra wrote:
 On Saturday, 8 June 2013 at 15:56:47 UTC, deadalnix wrote:
 Sound like a nice idiom. Why is the first set of () needed ? 
 Can we change the grammar to remove them ?

It's because you are actually declaring a lambda that takes no arguments, and has no name, and contains a body. BTW, you quoted my incomplete code, the correct code I wanted to post was: () nothrow {//anonymous lambade declaration //Body of the lambde }() //actual call to lambda I'd want to be able to do this, without either the first or last set of (). The required change of grammar would mean there'd be no lambda at all afterwards.

{} is a lambda already. The first set of () is optional.
Jun 08 2013
prev sibling next sibling parent "Idan Arye" <GenericNPC gmail.com> writes:
On Saturday, 8 June 2013 at 16:21:26 UTC, deadalnix wrote:
 On Saturday, 8 June 2013 at 16:13:28 UTC, monarch_dodra wrote:
 On Saturday, 8 June 2013 at 15:56:47 UTC, deadalnix wrote:
 Sound like a nice idiom. Why is the first set of () needed ? 
 Can we change the grammar to remove them ?

It's because you are actually declaring a lambda that takes no arguments, and has no name, and contains a body. BTW, you quoted my incomplete code, the correct code I wanted to post was: () nothrow {//anonymous lambade declaration //Body of the lambde }() //actual call to lambda I'd want to be able to do this, without either the first or last set of (). The required change of grammar would mean there'd be no lambda at all afterwards.

{} is a lambda already. The first set of () is optional.

Actually, the first set of `()` is required because of the `nothrow`. You can't write: nothrow { //body }(); because the `nothrow` in lambdas needs to be placed after the argument list - so you need an argument list.
Jun 08 2013
prev sibling next sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Saturday, 8 June 2013 at 16:21:26 UTC, deadalnix wrote:
 {} is a lambda already. The first set of () is optional.

Oh Yeah. Didn't know that. You learn something new every day. ...but for that to work, (it seems) you have actually store or pass the lambda, or all the parser sees is a plain "block". ------- void main() { int i; auto y = {++i;}; //lambde (not called) {++i;}; //simple block (){++i;}(); //inline lambda call writeln(i); //prints 2 } -------
Jun 08 2013
prev sibling next sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Saturday, 8 June 2013 at 17:27:48 UTC, monarch_dodra wrote:
 On Saturday, 8 June 2013 at 16:21:26 UTC, deadalnix wrote:
 {} is a lambda already. The first set of () is optional.

Oh Yeah. Didn't know that. You learn something new every day. ...but for that to work, (it seems) you have actually store or pass the lambda, or all the parser sees is a plain "block".

Improved example: ------- void main() { int i; auto y = {++i;}; //lambde (not called) {++i;}; //simple block (){++i;}(); //inline lambda call // {++i;}(); //Un-recognized writeln(i); //prints 2 } -------
Jun 08 2013
prev sibling next sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Saturday, 8 June 2013 at 15:56:47 UTC, deadalnix wrote:
 On Saturday, 8 June 2013 at 14:52:23 UTC, monarch_dodra wrote:

 Sound like a nice idiom. Why is the first set of () needed ? 
 Can we change the grammar to remove them ?

I've been playing around with this idiom some more, and found some pretty serious limitations: # Scoped block: Using a lambda functions creates a new scope. Having a "true" labeled block, just like static ifs, should not create a new scope. This is relevant if you want to make sure a constructor or destructor is nothrow, for example (destructor could be handled via a simple attribute followed by a colon. eg: void foo() { nothrow { Sentinel s; //declare sentinel } code_goes_here nothrow: clean_up_goes_here_code destructors_are_nothrow } A lambda would not allow these two constructs. # Purity Because a lambda needs to access the frame, any function using the lambda trick can't be made pure: void foo(T)(T a) safe { (){ ++a; }(); } Error: pure function 'main.foo' cannot call impure function literal '__lambda1' The workaround is to explicitly pass the arguments, *preferably*, shadowing them for clarity: void foo(int a) pure { (ref int a){ ++a; }(a); } This is already *much* less convenient. Imagine if the block needed to access 3, 5 or even more variabes ! Also, if one of those variables is declared as "auto", then you bring in the "ref typeof(a) a" ugliness. Just no. # Performance I haven't actually tested this one, but I'd be inclined to think there is a performance hit for non-release and non-inline builds. inline builds *may* optimize it away, but I'm not sure... ---------------- So my conclusion is that the lambda tric is a partial workaround. We'd need real support for being able to have specific qualification inside bodies. I've decided to write a DIP for this.
Jun 17 2013
prev sibling next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Monday, 17 June 2013 at 19:05:07 UTC, monarch_dodra wrote:
 # Purity
 Because a lambda needs to access the frame, any function using 
 the lambda trick can't be made pure:
 void foo(T)(T a)  safe
 {
     (){
         ++a;
     }();
 }
 Error: pure function 'main.foo' cannot call impure function 
 literal '__lambda1'

In case of lambda, purity does the wrong thing. The behavior is bogous.
Jun 17 2013
prev sibling next sibling parent Kenji Hara <k.hara.pg gmail.com> writes:
--001a11c38182eb2c9f04df6911a5
Content-Type: text/plain; charset=UTF-8

2013/6/18 monarch_dodra <monarchdodra gmail.com>

 On Saturday, 8 June 2013 at 15:56:47 UTC, deadalnix wrote:

 On Saturday, 8 June 2013 at 14:52:23 UTC, monarch_dodra wrote:

 Sound like a nice idiom. Why is the first set of () needed ? Can we
 change the grammar to remove them ?

I've been playing around with this idiom some more, and found some pretty serious limitations: # Scoped block: Using a lambda functions creates a new scope. Having a "true" labeled block, just like static ifs, should not create a new scope. This is relevant if you want to make sure a constructor or destructor is nothrow, for example (destructor could be handled via a simple attribute followed by a colon. eg: void foo() { nothrow { Sentinel s; //declare sentinel } code_goes_here nothrow: clean_up_goes_here_code destructors_are_nothrow } A lambda would not allow these two constructs.

In D, variable declaration with default construction is always nothrow. So, enclosing the declaration of s by nothrow block is unnecessary. For nothrow destruction, you can add following static assert in foo(). static assert(__traits(compiles, ()nothrow{ Sentinel s; }), "Sentinel dtor is not nothrow"); # Purity
 Because a lambda needs to access the frame, any function using the lambda
 trick can't be made pure:
 void foo(T)(T a)  safe
 {
     (){
         ++a;
     }();
 }
 Error: pure function 'main.foo' cannot call impure function literal
 '__lambda1'

 The workaround is to explicitly pass the arguments, *preferably*,
 shadowing them for clarity:
 void foo(int a) pure
 {
     (ref int a){
         ++a;
     }(a);
 }
 This is already *much* less convenient. Imagine if the block needed to
 access 3, 5 or even more variabes ! Also, if one of those variables is
 declared as "auto", then you bring in the "ref typeof(a) a" ugliness. Just
 no.

This is a compiler bug, and I recently fixed it in git master. Explicit argument passing does not need anymore.
 # Performance
 I haven't actually tested this one, but I'd be inclined to think there is
 a performance hit for non-release and non-inline builds. inline builds
 *may* optimize it away, but I'm not sure...

Inlining should remove performance penalty. Nobody holds the immediately called lambda, so it should be treated as a 'scope delegate'. For that, we would need to add a section in language spec to support it.
 ----------------
 So my conclusion is that the lambda tric is a partial workaround. We'd
 need real support for being able to have specific qualification inside
 bodies.

I don't think so. We can sufficiently use lambda for the "attribute block". Kenji Hara --001a11c38182eb2c9f04df6911a5 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">2013= /6/18 monarch_dodra <span dir=3D"ltr">&lt;<a href=3D"mailto:monarchdodra gm= ail.com" target=3D"_blank">monarchdodra gmail.com</a>&gt;</span><br><blockq= uote class=3D"gmail_quote" style=3D"margin-top:0px;margin-right:0px;margin-= bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(20= 4,204,204);border-left-style:solid;padding-left:1ex"> <div class=3D"im">On Saturday, 8 June 2013 at 15:56:47 UTC, deadalnix wrote= :<br> </div><blockquote class=3D"gmail_quote" style=3D"margin-top:0px;margin-righ= t:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left= -color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div clas= s=3D"im"> On Saturday, 8 June 2013 at 14:52:23 UTC, monarch_dodra wrote:<br> <br></div><div class=3D"im"> Sound like a nice idiom. Why is the first set of () needed ? Can we change = the grammar to remove them ?<br> </div></blockquote> <br> I&#39;ve been playing around with this idiom some more, and found some pret= ty serious limitations:<br> <br> # Scoped block:<br> Using a lambda functions creates a new scope. Having a &quot;true&quot; lab= eled block, just like static ifs, should not create a new scope. This is re= levant if you want to make sure a constructor or destructor is nothrow, for= example (destructor could be handled via a simple attribute followed by a = colon. eg:<br> <br> void foo()<br> {<br> =C2=A0 =C2=A0 nothrow {<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 Sentinel s; //declare sentinel<br> =C2=A0 =C2=A0 }<br> <br> =C2=A0 =C2=A0 code_goes_here<br> <br> =C2=A0 =C2=A0 nothrow:<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 clean_up_goes_here_code<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 destructors_are_nothrow<br> }<br> <br> A lambda would not allow these two constructs.<br></blockquote><div><br></d= iv><div>In D, variable declaration with default construction is always noth= row.=C2=A0</div><div>So, enclosing the declaration of s by nothrow block is= unnecessary.</div> <div><br></div><div>For nothrow destruction, you can add following static a= ssert in foo().</div><div><br></div><div><div>=C2=A0 =C2=A0 static assert(_= _traits(compiles, ()nothrow{ Sentinel s; }), &quot;Sentinel dtor is not not= hrow&quot;);</div> </div><div><br></div><blockquote class=3D"gmail_quote" style=3D"margin-top:= 0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:= 1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left= :1ex"> # Purity<br> Because a lambda needs to access the frame, any function using the lambda t= rick can&#39;t be made pure:<br> void foo(T)(T a) safe<br> {<br> =C2=A0 =C2=A0 (){<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ++a;<br> =C2=A0 =C2=A0 }();<br> }<br> Error: pure function &#39;main.foo&#39; cannot call impure function literal= &#39;__lambda1&#39;<br> <br> The workaround is to explicitly pass the arguments, *preferably*, shadowing= them for clarity:<br> void foo(int a) pure<br> {<br> =C2=A0 =C2=A0 (ref int a){<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 ++a;<br> =C2=A0 =C2=A0 }(a);<br> }<br> This is already *much* less convenient. Imagine if the block needed to acce= ss 3, 5 or even more variabes ! Also, if one of those variables is declared= as &quot;auto&quot;, then you bring in the &quot;ref typeof(a) a&quot; ugl= iness. Just no.</blockquote> <div><br></div><div>This is a compiler bug, and I recently fixed it in git = master. Explicit argument passing does not need anymore.</div><div>=C2=A0= =C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin-top:0px;margi= n-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;borde= r-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> # Performance<br> I haven&#39;t actually tested this one, but I&#39;d be inclined to think th= ere is a performance hit for non-release and non-inline builds. inline buil= ds *may* optimize it away, but I&#39;m not sure...<br></blockquote><div> <br></div><div>Inlining should remove performance penalty. Nobody holds the= immediately called lambda, so it should be treated as a &#39;scope delegat= e&#39;. For that, we would need to add a section in language spec to suppor= t it.<br> </div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin-to= p:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-widt= h:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-le= ft:1ex"> ----------------<br> So my conclusion is that the lambda tric is a partial workaround. We&#39;d = need real support for being able to have specific qualification inside bodi= es.<br></blockquote><div><br></div><div>I don&#39;t think so. We can suffic= iently use lambda for the &quot;attribute block&quot;.</div> <div><br></div><div>Kenji Hara</div></div></div></div> --001a11c38182eb2c9f04df6911a5--
Jun 18 2013
prev sibling next sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Tuesday, 18 June 2013 at 07:58:06 UTC, Kenji Hara wrote:
 In D, variable declaration with default construction is always 
 nothrow.
 So, enclosing the declaration of s by nothrow block is 
 unnecessary.

Well, what about construction with args...
 For nothrow destruction, you can add following static assert in 
 foo().

     static assert(__traits(compiles, ()nothrow{ Sentinel s; }), 
 "Sentinel
 dtor is not nothrow");

Right. Good point.
 This is a compiler bug, and I recently fixed it in git master. 
 Explicit
 argument passing does not need anymore.

Cool, thanks.
 Inlining should remove performance penalty. Nobody holds the 
 immediately
 called lambda, so it should be treated as a 'scope delegate'. 
 For that, we
 would need to add a section in language spec to support it.

Alright.
 ----------------
 So my conclusion is that the lambda tric is a partial 
 workaround. We'd
 need real support for being able to have specific 
 qualification inside
 bodies.

I don't think so. We can sufficiently use lambda for the "attribute block". Kenji Hara

Maybe you are right. I will keep using it for now.
Jun 18 2013
prev sibling next sibling parent "Robert Clipsham" <robert octarineparrot.com> writes:
On Saturday, 8 June 2013 at 14:57:17 UTC, monarch_dodra wrote:
 My beef though is that the syntax is a bit opaque, and not 
 really idiomatic. It looks more like a hacker's trick than a 
 real language feature. It's not something you'd do "naturally". 
 At least, I know a beginner may not feal comfortable with this.

 Given that users are now actually doing this, that we have 
 proof it works and is a useful feature, shouldn't we push to 
 have actual blocks with attributes in the language?

 I think we should... Thoughts?

Here's my go at cleaning up the syntax a bit: ---- auto block(string attr)() { static struct Blk { mixin(q{ void opBinary(string op:"in", T)(T dg) } ~ attr ~ q{ if (is(typeof(() } ~ attr ~ q{ { dg(); }))) { dg(); } void opBinary(string op:"in", T)(T dg) if (!is(typeof(() } ~ attr ~ ` { dg(); }))) { static assert(false, "Provided delegate is not " ~ "` ~ attr ~ `"); } `); } return Blk(); } void main() { // Works block!"nothrow" in { // Doesn't throw }; // Fails block!"nothrow" in { throw new Exception(""); }; } ---- Downsides are the required semicolon (needed for your method too) and abuse of operator overloading.
Jun 18 2013
prev sibling next sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Tuesday, 18 June 2013 at 08:10:24 UTC, monarch_dodra wrote:
 Inlining should remove performance penalty. Nobody holds the 
 immediately
 called lambda, so it should be treated as a 'scope delegate'. 
 For that, we
 would need to add a section in language spec to support it.

Alright.

I did some benching, and they aren't getting inline (well... I don't *think* they are): Code with an inline lambda call is definitely slower (in my case, with no args passed). My tests are somewhat synthetic, (I'm testing a rather short function with a lambda) but the overall slowdown is quite noticeable. I don't worry about it much, but I guess these could scale in the grand scheme of things, and is a bit vexing when all you wanted to was mark something as trusted :/ Shouldn't an inlined lambda call *always* be... inlined? I really don't see a reason not to do so, but I'm outside my field of competence at that point.
Jun 19 2013
prev sibling next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Sunday, 30 June 2013 at 20:29:07 UTC, Timon Gehr wrote:
 This is a compiler bug, and I recently fixed it in git master. 
 Explicit
 argument passing does not need anymore.

Great. Does the fix also introduce the 'immutable' storage class for function literals for the case where a strongly pure literal is wanted?

You may want to discuss that issue with Andrei. We had a discussion at DConf about this.
Jun 30 2013
prev sibling next sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Tuesday, 18 June 2013 at 07:58:06 UTC, Kenji Hara wrote:
 Inlining should remove performance penalty. Nobody holds the 
 immediately
 called lambda, so it should be treated as a 'scope delegate'. 
 For that, we
 would need to add a section in language spec to support it.

Kenji: I've been doing some benchmarks recently: Using an "inlined lambda" seems to really kill performance, both with or without "-inline" (tested with both dmd and gdc). However, using a named function, and then immediately calling it, there is 0 performance penalty (both w/ and w/o -inline). Is this a bug? Can it be fixed? Should I file and ER?
Aug 18 2013
prev sibling next sibling parent Kenji Hara <k.hara.pg gmail.com> writes:
--f46d043bddc643561404e443c4e6
Content-Type: text/plain; charset=UTF-8

2013/8/18 monarch_dodra <monarchdodra gmail.com>

 On Tuesday, 18 June 2013 at 07:58:06 UTC, Kenji Hara wrote:

 Inlining should remove performance penalty. Nobody holds the immediately
 called lambda, so it should be treated as a 'scope delegate'. For that, we
 would need to add a section in language spec to support it.

Kenji: I've been doing some benchmarks recently: Using an "inlined lambda" seems to really kill performance, both with or without "-inline" (tested with both dmd and gdc). However, using a named function, and then immediately calling it, there is 0 performance penalty (both w/ and w/o -inline). Is this a bug? Can it be fixed? Should I file and ER?

I opened a new bugzilla issue: http://d.puremagic.com/issues/show_bug.cgi?id=10848 And start working for the compiler and doc fix: https://github.com/D-Programming-Language/dlang.org/pull/372 https://github.com/D-Programming-Language/dmd/pull/2483 Kenji Hara --f46d043bddc643561404e443c4e6 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">2013= /8/18 monarch_dodra <span dir=3D"ltr">&lt;<a href=3D"mailto:monarchdodra gm= ail.com" target=3D"_blank">monarchdodra gmail.com</a>&gt;</span><br><blockq= uote class=3D"gmail_quote" style=3D"margin-top:0px;margin-right:0px;margin-= bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(20= 4,204,204);border-left-style:solid;padding-left:1ex"> <div class=3D"im">On Tuesday, 18 June 2013 at 07:58:06 UTC, Kenji Hara wrot= e:<br> <blockquote class=3D"gmail_quote" style=3D"margin-top:0px;margin-right:0px;= margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color= :rgb(204,204,204);border-left-style:solid;padding-left:1ex"> Inlining should remove performance penalty. Nobody holds the immediately<br=

hat, we<br> would need to add a section in language spec to support it.<br> </blockquote> <br></div> Kenji:<br> <br> I&#39;ve been doing some benchmarks recently: Using an &quot;inlined lambda= &quot; seems to really kill performance, both with or without &quot;-inline= &quot; (tested with both dmd and gdc).<br> <br> However, using a named function, and then immediately calling it, there is = 0 performance penalty (both w/ and w/o -inline).<br> <br> Is this a bug? Can it be fixed? Should I file and ER?<br> </blockquote></div><br></div><div class=3D"gmail_extra">I opened a new bugz= illa issue:</div><div class=3D"gmail_extra"><a href=3D"http://d.puremagic.c= om/issues/show_bug.cgi?id=3D10848">http://d.puremagic.com/issues/show_bug.c= gi?id=3D10848</a>=C2=A0<br> </div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_extra">And s= tart working for the compiler and doc fix:</div><div class=3D"gmail_extra">= <a href=3D"https://github.com/D-Programming-Language/dlang.org/pull/372">ht= tps://github.com/D-Programming-Language/dlang.org/pull/372</a>=C2=A0<br> </div><div class=3D"gmail_extra"><a href=3D"https://github.com/D-Programmin= g-Language/dmd/pull/2483">https://github.com/D-Programming-Language/dmd/pul= l/2483</a>=C2=A0<br></div><div class=3D"gmail_extra"><br></div><div class= =3D"gmail_extra"> Kenji Hara</div></div> --f46d043bddc643561404e443c4e6--
Aug 18 2013
prev sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Monday, 19 August 2013 at 02:33:43 UTC, Kenji Hara wrote:
 2013/8/18 monarch_dodra <monarchdodra gmail.com>

 On Tuesday, 18 June 2013 at 07:58:06 UTC, Kenji Hara wrote:

 Inlining should remove performance penalty. Nobody holds the 
 immediately
 called lambda, so it should be treated as a 'scope delegate'. 
 For that, we
 would need to add a section in language spec to support it.

Kenji: I've been doing some benchmarks recently: Using an "inlined lambda" seems to really kill performance, both with or without "-inline" (tested with both dmd and gdc). However, using a named function, and then immediately calling it, there is 0 performance penalty (both w/ and w/o -inline). Is this a bug? Can it be fixed? Should I file and ER?

I opened a new bugzilla issue: http://d.puremagic.com/issues/show_bug.cgi?id=10848 And start working for the compiler and doc fix: https://github.com/D-Programming-Language/dlang.org/pull/372 https://github.com/D-Programming-Language/dmd/pull/2483 Kenji Hara

As always, thank you *very* much.
Aug 18 2013