Should pure functions be prevented from reading changeable immutable static variables?

Jonathan M Davis jmdavisProg at gmx.com
Sat Nov 6 17:41:22 PDT 2010


On Saturday 06 November 2010 07:42:52 Don wrote:
> Michel Fortin wrote:
> > On 2010-11-05 21:32:47 -0400, Don <nospam at nospam.com> said:
> >> The motivation for wanting to ban them is to prevent the optimiser
> >> from generating bad code.
> > 
> > It seems to me that disabling pure optimizations inside 'static this()'
> > would be enough to prevent generating bad code. It's not like pure
> > optimizations cross function boundaries.
> 
> That's probably doable, if we largely abandon the idea that the return
> value of a pure function can be cacheable. Which I think is a bit of a
> fanciful idea anyway.

If they're not cacheable, what's the point of pure? I thought that that was the 
entire point. You could avoid extra calls to the function by just re-using its 
value - at least within the current expression if not the current function. I 
quite understand avoiding caching a result for the entire run of the program (if 
nothing else, that could use up a lot of memory), but I thought that avoiding 
extra function calls was the whole point of pure.

- Jonathan M Davis


More information about the Digitalmars-d mailing list