Improvement in pure functions specification

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Thu Dec 22 12:53:37 PST 2016


On Wednesday, 21 December 2016 at 21:34:04 UTC, Andrei 
Alexandrescu wrote:
>> Instead of
>>   "Any `pure` function that is not strongly pure cannot be 
>> memoized."
>> why not
>>   "Any `pure` function that is not strongly pure _may not be 
>> assumed to
>> be_ memoizable."
>
> Got it. Good point. Will do.
>

That worse than the current wording.

Strongly pure function can be memoized doesn't mean that non 
strongly pure function can never be, just that the compiler would 
have to prove it is correct to do so before doing it.

On the other hand, this new wording do not guarantee that the 
compiler can do memorization on strongly pure functions. I don't 
think this is reasonable and in effect, makes pure useless for 
the optimizer outside of trivial cases. If you lie to the 
compiler by bypassing the type system in the pure function, 
that's on you. All user should not be penalized because someone 
decided they were very smart and got hoisted by their own petard.



More information about the Digitalmars-d mailing list