Should GC.malloc be considered 'pure'?

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 9 11:03:54 PDT 2011


On Thu, 09 Jun 2011 13:51:31 -0400, KennyTM~ <kennytm at gmail.com> wrote:

> Given that the 'new' expression can be used in 'pure', should it be that  
> GC allocation functions like GC.malloc, GC.qalloc and GC.extend (?) be  
> weakly pure also?

Yes.  But one of the possible issues here: weak purity is determined by  
the type of the parameters.  GC.malloc only takes non-reference types, so  
marking it as pure might make the compiler actually think these are  
strong-pure.

Don?  Any ideas here?  I'm thinking we might need an compiler pragma.   
This would be extremely seldom used.

>  And should it apply to other managed allocators as well, e.g. the  
> proposed TempAlloc?

I would say yes, but I think David should have the final say.  Definitely,  
TempAlloc cannot be pure unless GC.malloc and C's malloc are pure, since  
those are marked that way.

> I'm asking this as one of the specializations of std.conv.toImpl calls  
> GC.malloc, which is one of the 11 causes preventing std.conv.to from  
> being pure, and GC.qalloc and GC.extend (and memcpy and Array.capacity)  
> are used by std.array.appender (of pure range), and appender is also a  
> major reason why std.conv.to is not pure.

I think Appender should also be pure.

-Steve


More information about the Digitalmars-d mailing list