checkedint call removal

Daniel Murphy via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 28 09:32:46 PDT 2014


"Ola Fosheim Grøstad" " wrote in message 
news:cgljkngsjwkspfixdfgy at forum.dlang.org...

> On Monday, 28 July 2014 at 15:07:07 UTC, Daniel Murphy wrote:
> > Let's say you want to add two numbers, but instead of writing 'a + b' 
> > you write 'a - b'!!!!  The program fails even though you totally meant 
> > to write the correct code.
>
> You are trolling me. :-[

Yes.  I think you'll find advanced optimizers are already doing this sort of 
thing to your code, when it decides code is unreachable.

Enabling optimizations can make code-gen unpredictable, especially when used 
on broken code.  In C/C++ this is often due to undefined behaviour.  Using 
assert to pass arbitrary information to the optimizer would allow for some 
fantastic opportunities.

Just imagine how close to perfection the compiler can get with these 
constraints:

void vectorizedFunction(int* a, int* b, size_t len)
in
{
    assert(noOverlap(a, b, len));
    assert(len % 16 == 0);
}
body
{
    < some kind of code that can benefit from vectorization >
}

Sure, we could add a new construct (ie 'assume') to the language, and use 
that to pass information.  But are they really different?

Assert says 'the program is in error if this is not true'.  -release says 
'compile my program as if it has no errors'.

These two combined give the compiler a huge amount of power. 



More information about the Digitalmars-d mailing list