Memory allocation purity

Don via Digitalmars-d digitalmars-d at puremagic.com
Thu May 15 04:03:34 PDT 2014


On Thursday, 15 May 2014 at 10:46:21 UTC, Ola Fosheim Grøstad 
wrote:
> On Thursday, 15 May 2014 at 09:45:52 UTC, Don wrote:
>> But it turns out that @memoizable isn't actually an 
>> interesting property, whereas '@noglobal' is.
>>
>> "No global state" is a deep, transitive property of a 
>> function. "Memoizable" is a superficial supersetextra property 
>> which the compiler can trivially determine from @noglobal.
>
> Uhm. That is a pretty strong assumption. "memoizable" is very 
> useful property when you do multihreading, transactions or 
> anything that requires locking.

It's useful, but it's not a deep property, and importantly, it 
isn't transient. The compiler can trivially work it out if it 
knows the function is @noglobal.

> And you can still access globals, you just need a guarantee 
> that globals don't change until you are done.

Sure, but how can the compiler statically check that? It's a 
tough problem.
(That's not a rhetorical question, BTW. If you have a solution, 
that would be awesome).

> Considering that > 90% of the functions I write don't do IO or 
> globals I'd rather specify the opposite. "io", "global" 
> whatever. That is also easy to enforce, i.e. you don't get to 
> access IO/globals if you don't annotate the function.

I agree, I'd personally like to have an annotation '@global', and 
put 'pure:' at the top of every module.


More information about the Digitalmars-d mailing list