checkedint call removal

Daniel Murphy via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 28 14:15:50 PDT 2014


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

> The problem is that the code is not unreachable when you compile 
> with -release.

Whether or not this is a problem depends on the meaning of assert.

> > Assert says 'the program is in error if this is not true'.
>
> enforce() says: always runtime check this (?)
> assert() says: this ought to hold when I do testing
> assume() says: I have proven this to hold
> prove() says: don't generate code until you can prove this to hold

This might be how you use assert, but it is not the only possible semantics 
we could define.

> > -release says 'compile my program as if it has no errors'.
>
> -release says: compile my program without runtime checks for correctness
> -no-assume might say: ignore all assumptions, I don't trust myself
> -assume-is-assert(): turn assumptions into runtime checks
> etc.

Same thing.  Yes, disabling assertion checking is currently what -release 
does, but that doesn't mean it's the only thing it can do.

What I'm proposing is a hybrid of your definitions - in release mode assert 
becomes assume.

> Yes, if used carefully, but the language and/or compiler have to treat 
> user provided facts differently than derived knowledge that originates 
> within the executable code. assert() is not really for providing facts, it 
> is for testing them. So the threshold for providing an assertion is low if 
> it is completely free of side effects (in release), but the threshold for 
> providing an assumption should be very high.

I'm not convinced they must be treated differently.  If you define assert 
and release the way I have above it is perfectly valid.

You've argued that it's the wrong way to do things, but all that matters is 
that the advantages outweigh the downsides.  The optimization possibilities 
here are enormous.

According to the spec on 'assert(0)': "The optimization and code generation 
phases of compilation may assume that it is unreachable code.".

So we already have this in the language somewhat - you just need to write it 
like this:

if (condition)
    assert(0);

instead of:

assert(condition);

It seems like a straightforward extension to make them equivalent for this 
purpose. 



More information about the Digitalmars-d mailing list