www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14164] New: trivial lambdas are not inlined

https://issues.dlang.org/show_bug.cgi?id=14164

          Issue ID: 14164
           Summary: trivial lambdas are not inlined
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

import std.stdio;

void foo()  system
{
    writeln("foo");
}

void main()  safe
{
    ()  trusted { foo(); } ();
}

// dmd -inline -O -g test.d

Breakpoint 1, D main () at test.d:10
10        ()  trusted { foo(); } ();
(gdb) disassemble
Dump of assembler code for function _Dmain:
   0x000000000046d3f0 <+0>:    push   %rbp
   0x000000000046d3f1 <+1>:    mov    %rsp,%rbp
=> 0x000000000046d3f4 <+4>:    callq  0x46d400
<_D4test4mainFNfZ9__lambda1FNeZv>
   0x000000000046d3f9 <+9>:    xor    %eax,%eax
   0x000000000046d3fb <+11>:    pop    %rbp
   0x000000000046d3fc <+12>:    retq
End of assembler dump.\

As you may see in generated call it actually calls lambda function
(_D4test4mainFNfZ9__lambda1FNeZv) instead of calling _D4test3fooFZv directly

--
Feb 10 2015