assert semantic change proposal

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 5 14:39:25 PDT 2014


On 8/5/2014 1:09 PM, Ary Borenszweig wrote:
> On 8/5/14, 3:55 PM, H. S. Teoh via Digitalmars-d wrote:
>> On Tue, Aug 05, 2014 at 11:18:46AM -0700, Jeremy Powers via Digitalmars-d wrote:
>
>> Furthermore, I think Walter's idea to use asserts as a source of
>> optimizer hints is a very powerful concept that may turn out to be a
>> revolutionary feature in D.
>
> LLVM already has it. It's not revolutionary:
>
> http://llvm.org/docs/LangRef.html#llvm-assume-intrinsic

That's a language extension. A language extension is not a language feature. But 
it is strong evidence supporting my assertion that these sorts of things are 
inexorably coming. As bearophile posted, Microsoft also has such an intrinsic 
for their C++.


> By the way, I think Walter said "assert can be potentially used to make
> optimizations" not "Oh, I just had an idea! We could use assert to optimize
> code". I think the code already does this. Of course, we would have to look at
> the source code to find out...

It is hardly a new idea, or my idea. I got it from this 1981 book:

http://www.amazon.com/Program-Flow-Analysis-Application-Prentice-Hall/dp/0137296819/

which I've had a copy of since '82 or so. My notions on asserts being contracts, 
regardless of switch settings, date to a similar time, see "Object Oriented 
Software Construction", a 1985 book.


> By the way, most of the time in this list I hear "We could use this and that
> feature to allow better optimizations" and no optimizations are ever
> implemented. Look at all those @pure nosafe nothrow const that you have to put
> and yet you don't get any performance boost from that.

Not only is that currently quite incorrect, don't put the chicken before the 
egg. The 'nothrow', etc., feature must exist before it can be taken advantage of.


More information about the Digitalmars-d mailing list