Trusted Manifesto

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Mon Feb 9 23:27:48 PST 2015


On Tuesday, 10 February 2015 at 07:02:23 UTC, Walter Bright wrote:
> On 2/9/2015 9:06 PM, Dicebot wrote:
>> This was exactly how all those trustedFoo() nested functions 
>> have appeared
>> - we wanted to localized unsafe operations with `() @trusted 
>> {}` but it wasn't
>> properly inlined by DMD.
>
> DMD will inline trivial functions like that. In what case does 
> it not?

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


More information about the Digitalmars-d mailing list