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

Don nospam at nospam.com
Sat Nov 6 07:42:52 PDT 2010


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.

In fact, you could still allow
> the optimization of pure functions in the current module.

Yes.

> I understand that by restricting the semantics we could use pure to help 
> use break cyclic imports, but, as much as I'd like a solution to this 
> cyclic import problem, I don't think it's a good idea to complicate the 
> semantics of pure further.

Indeed, it can't be the primary motivation.



More information about the Digitalmars-d mailing list