On Wednesday, 30 July 2014 at 15:12:58 UTC, Ary Borenszweig wrote:
On 7/30/14, 11:44 AM, Daniel Murphy wrote:
"Ary Borenszweig" wrote in message
news:[email protected]...
Now, if you compile in release mode, according to Walter, all
the
"asserts" are gone (which, as a side note, is something I
don't like:
in every case it should throw an AssertError). So the
question is: can
the compiler still replace that writeln call? It should, but
since
there's nothing there preventing x + y to be different than 3
(the
assertion is gone), the compiler can't replace it anymore.
That's the whole point - the compiler theoretically can
optimize as if
the assert is checked.
(This example uses assert(0) because this behaviour is
actually in the
spec)
if (x != 3) assert(0);
if (x == 3) deleteAllMyFiles();
The compiler is allowed to treat assert(0) as unreachable -
and if it's
unreachable then it must be impossible for x to be != 3.
So it becomes:
deleteAllMyFiles();
He's asking for assert to mean 'check this condition' and
assume to mean
'optimize as if this is a mathematical identity'.
And how is that different if instead of:
if (x != 3) assert(0);
you write:
assume(x != 3);
?
assert(0) is treated as a special case, different from
assert(someRuntimeExpression)