To help LDC/GDC

Iain Buclaw ibuclaw at ubuntu.com
Mon Apr 8 08:40:34 PDT 2013


On 8 April 2013 13:37, Manu <turkeyman at gmail.com> wrote:

> Oh my god... ..... this is the most upsetting thing I've heard all day! :(
> No really, I have been SOOOO excited for so long about this optimisation
> potential in D!
> There's gotta be something that can be done! >_<
>
> Does the front end know if the function actually DOES assign to any state?
> The compiler could easily work that out, and in the event it doesn't
> actually perform any such assignment, it could be marked pure for reals...
>
>
Haven't looked, but it appears to have a general idea of this.  D 'weak
pure' and 'const pure' may update an internal state (had the latter bite me
hard once).  The only case where 'strong pure' might do this is by throwing
an exception or an assert being thrown - this changes program state so
can't be marked pure.

So having identified this, we can safely say that functions could only be
'C pure' in the following case:
- Compiled function is 'strong pure'
- Compiled function is 'nothrow'
- We are compiling in release mode.

Only then we (the frontend) can safely say that 'this function has
*absolutely* no side effects, so can be marked as pure'.   Pure is never
inferred.

-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130408/f51f4ffa/attachment.html>


More information about the Digitalmars-d mailing list