On Friday, 1 July 2016 at 10:35:04 UTC, Nordlöw wrote:
I think this is a important issue since asserts are not optimized away in release mode and D is very much about performance.

Asserts are removed in release mode, enforce isn't. Here's an example:

=====
void main(string[] args)
{
        assert(args.length >= 1);
}
=====

dmd testfile.d

This calls the assert function as expected:
=====
_Dmain:
  0000000000000000: 55                 push        rbp
  0000000000000001: 48 8B EC           mov         rbp,rsp
0000000000000004: 48 83 39 01 cmp qword ptr [rcx],1 0000000000000008: 73 0E jae 0000000000000018
  000000000000000A: B9 03 00 00 00     mov         ecx,3
  000000000000000F: 48 83 EC 20        sub         rsp,20h
0000000000000013: E8 00 00 00 00 call _D5test28__assertFiZv
  0000000000000018: 31 C0              xor         eax,eax
  000000000000001A: 5D                 pop         rbp
  000000000000001B: C3                 ret
=====

Now compiling in release mode:
dmd -release testfile.d

No assert in sight:
=====
_Dmain:
  0000000000000000: 55                 push        rbp
  0000000000000001: 48 8B EC           mov         rbp,rsp
  0000000000000004: 31 C0              xor         eax,eax
  0000000000000006: 5D                 pop         rbp
  0000000000000007: C3                 ret
=====

Reply via email to