Proposal: Relax rules for 'pure'

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Oct 25 08:08:56 PDT 2010


On 10/25/10 8:44 CDT, Bruno Medeiros wrote:
> I think we need to be more realistic with what kinds of optimizations
> we could expect from a D compiler and pure functions.
> Caching might be done, but only a temporary sense (caching under a
> limited execution scope). I doubt we would ever have something like
> memoization, which would incur memory costs (potentially quite big
> ones), and so the compiler almost certainly would not be able to know
> (without additional metadata/anotations or compile options) if that
> trade-off is acceptable.

Speaking of which - memoization should be implementable safely and 
efficiently in a library. I'm thinking of something like this:

alias memoize!sin msin;
...
double x = msin(angle);

It does get tricky though. For example, for doubles you'd need to do 
some interpolation and there are several ways of interpolating. For 
other types you need to make sure there's no undue aliasing, etc.


Andrei


More information about the Digitalmars-d mailing list