www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Inlining of immediately called function literals

reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
The language reference on functions [1] says:

"If a FunctionLiteral is immediately called, its inlining would 
be enforced normally."

How is this to be interpreted?

[1] http://dlang.org/function
Jul 26 2014
next sibling parent "w0rp" <devw0rp gmail.com> writes:
On Saturday, 26 July 2014 at 17:55:55 UTC, Marc Schütz wrote:
 The language reference on functions [1] says:

 "If a FunctionLiteral is immediately called, its inlining would 
 be enforced normally."

 How is this to be interpreted?

 [1] http://dlang.org/function
I would interpret that as saying it's a pretty fair bet that it will be inlined by an optimising compiler. Especially with LDC or GDC. DMD I think is often lacking in optimisations, but I use it during development pretty excessively due to its compilation speed and DMD always being the first to support all recent language features.
Jul 26 2014
prev sibling parent reply "Dicebot" <public dicebot.lv> writes:
On Saturday, 26 July 2014 at 17:55:55 UTC, Marc Schütz wrote:
 The language reference on functions [1] says:

 "If a FunctionLiteral is immediately called, its inlining would 
 be enforced normally."

 How is this to be interpreted?

 [1] http://dlang.org/function
I can't PR but there were one by Kenji that did inline of such calls in the frontend providing 100% gurantee whatever backend is used.
Jul 26 2014
next sibling parent "w0rp" <devw0rp gmail.com> writes:
On Saturday, 26 July 2014 at 22:24:40 UTC, Dicebot wrote:
 On Saturday, 26 July 2014 at 17:55:55 UTC, Marc Schütz wrote:
 The language reference on functions [1] says:

 "If a FunctionLiteral is immediately called, its inlining 
 would be enforced normally."

 How is this to be interpreted?

 [1] http://dlang.org/function
I can't PR but there were one by Kenji that did inline of such calls in the frontend providing 100% gurantee whatever backend is used.
Nice, that's a pretty good guarantee to have.
Jul 26 2014
prev sibling next sibling parent reply Iain Buclaw via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 26 July 2014 23:24, Dicebot via Digitalmars-d
<digitalmars-d puremagic.com> wrote:
 On Saturday, 26 July 2014 at 17:55:55 UTC, Marc Schütz wrote:
 The language reference on functions [1] says:

 "If a FunctionLiteral is immediately called, its inlining would be
 enforced normally."

 How is this to be interpreted?

 [1] http://dlang.org/function
I can't PR but there were one by Kenji that did inline of such calls in the frontend providing 100% gurantee whatever backend is used.
I'd be the sceptic of that. Which file exactly did he change? (hint: It may be ignored by other compilers).
Jul 26 2014
parent reply "Dicebot" <public dicebot.lv> writes:
On Sunday, 27 July 2014 at 00:43:41 UTC, Iain Buclaw via 
Digitalmars-d wrote:
 I'd be the sceptic of that. Which file exactly did he change? 
 (hint:
 It may be ignored by other compilers).
Oh crap it is still open :D (and judging by comments there you should more aware of what does than me) : https://github.com/D-Programming-Language/dmd/pull/2483
Jul 26 2014
next sibling parent Iain Buclaw via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 27 Jul 2014 02:10, "Dicebot via Digitalmars-d" <
digitalmars-d puremagic.com> wrote:
 On Sunday, 27 July 2014 at 00:43:41 UTC, Iain Buclaw via Digitalmars-d
wrote:
 I'd be the sceptic of that. Which file exactly did he change? (hint:
 It may be ignored by other compilers).
Oh crap it is still open :D (and judging by comments there you should
more aware of what does than me) : https://github.com/D-Programming-Language/dmd/pull/2483 Oh yes, I think I recall that. As per my old comments, it uses frontend inlining to fix the issue. As per mine and David's old comments, frontend inlining is bad for GDC and LDC. It almost always results in strange codegen, or triggers asserts for internal tree checking, or just ICE's the compiler. Iain.
Jul 26 2014
prev sibling parent "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Sunday, 27 July 2014 at 01:06:43 UTC, Dicebot wrote:
 On Sunday, 27 July 2014 at 00:43:41 UTC, Iain Buclaw via 
 Digitalmars-d wrote:
 I'd be the sceptic of that. Which file exactly did he change? 
 (hint:
 It may be ignored by other compilers).
Oh crap it is still open :D (and judging by comments there you should more aware of what does than me) : https://github.com/D-Programming-Language/dmd/pull/2483
Ok, so the documentation changes went in before the actual feature was merged. I think they need to be more clear, anyway. It should at least explain why there is no guarantee, or better yet, describe which subset of functions is guaranteed to be inlined.
Jul 27 2014
prev sibling parent reply "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Dicebot"  wrote in message news:xpjsskmamagclzoiwtxb forum.dlang.org...

 I can't PR but there were one by Kenji that did inline of such calls in 
 the frontend providing 100% gurantee whatever backend is used.
There is no 100% guarantee, the frontend's inliner is not capable of inlining the majority of function calls. The only guarantee is that it will try to inline the lambda whether or not the -inline switch is used.
Jul 27 2014
parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Sunday, 27 July 2014 at 07:01:52 UTC, Daniel Murphy wrote:
 "Dicebot"  wrote in message 
 news:xpjsskmamagclzoiwtxb forum.dlang.org...

 I can't PR but there were one by Kenji that did inline of such 
 calls in the frontend providing 100% gurantee whatever backend 
 is used.
There is no 100% guarantee, the frontend's inliner is not capable of inlining the majority of function calls. The only guarantee is that it will try to inline the lambda whether or not the -inline switch is used.
Too bad... If it was guaranteed, there would then be a compiler independent way to force inlining. Is there a chance that the limits to inlining in DMD will ever be removed?
Jul 27 2014
parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Sunday, 27 July 2014 at 07:48:18 UTC, Marc Schütz wrote:
 On Sunday, 27 July 2014 at 07:01:52 UTC, Daniel Murphy wrote:
 "Dicebot"  wrote in message 
 news:xpjsskmamagclzoiwtxb forum.dlang.org...

 I can't PR but there were one by Kenji that did inline of 
 such calls in the frontend providing 100% gurantee whatever 
 backend is used.
There is no 100% guarantee, the frontend's inliner is not capable of inlining the majority of function calls. The only guarantee is that it will try to inline the lambda whether or not the -inline switch is used.
Too bad... If it was guaranteed, there would then be a compiler independent way to force inlining. Is there a chance that the limits to inlining in DMD will ever be removed?
IIRC the core reason is that expression nodes in the AST cannot contain statements. Isn't it possible to create a "bridge" node type that is allowed to appear in expressions, but may also contain statements?
Jul 27 2014
parent reply "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Marc Schütz" " wrote in message 
news:gefktpkzfnlryljvwmqa forum.dlang.org...

 IIRC the core reason is that expression nodes in the AST cannot contain 
 statements. Isn't it possible to create a "bridge" node type that is 
 allowed to appear in expressions, but may also contain statements?
Sure, but that would be horrible (from an implementation point of view). The better way is to use an ir/backend inliner, ie use gdc or ldc.
Jul 27 2014
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 7/27/14, 1:35 AM, Daniel Murphy wrote:
 "Marc Schütz" " wrote in message
 news:gefktpkzfnlryljvwmqa forum.dlang.org...

 IIRC the core reason is that expression nodes in the AST cannot
 contain statements. Isn't it possible to create a "bridge" node type
 that is allowed to appear in expressions, but may also contain
 statements?
Sure, but that would be horrible (from an implementation point of view). The better way is to use an ir/backend inliner, ie use gdc or ldc.
Ionno. There are a few high-level constructs in D that are amenable to front-end inlining - doing so in the backend entails quite a bit of assembling the cow back from the burger. -- Andrei
Jul 27 2014