assert semantic change proposal

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 5 13:26:16 PDT 2014


On Tue, Aug 05, 2014 at 05:09:43PM -0300, Ary Borenszweig via Digitalmars-d 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

Even better, so there's precedent for this. Even if it's only exposed at
the LLVM level, rather than the source language. Introducing this at the
source language level (like proposed in D) is a good step forward IMO.


> 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...

If the code already does this, then what are we arguing about?


> 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.

Automatic attribute inference is the way to go. More and more, I'm
beginning to be convinced that manually-specified attributes are a dead
end.

Having said that, though, I'm pretty sure the compiler could (and
should) do more with pure/nothrow/const, etc.. I think it may already be
taking advantage of nothrow/const (nothrow elides throw/catch
scaffolding, e.g., which could be important in high-performance inner
loops). With pure the current situation could be improved, since it
currently only has effect when you call the same pure function multiple
times within a single expression. But there are lots more things that
could be done with it, e.g., memoization across different statements in
the function body.

PR's would be welcome. ;-)


T
-- 
What do you mean the Internet isn't filled with subliminal messages? What about all those buttons marked "submit"??


More information about the Digitalmars-d mailing list