GC.malloc is pure - wat

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 31 18:19:01 PDT 2016


On 01.04.2016 00:52, deadalnix wrote:
>
>
> DMD optimizes malloc because the only reason it would have to return a
> different pointer would be internal state (and in fact, it indeed has
> internal state).

It's the other way around. Without the "optimization" there is no way 
for a 'pure' function to return a reference to the same mutable memory 
block independent of its arguments more than once. In the end it is up 
to the spec, but IMO compiler optimizations should not be able to 
introduce mutable aliasing that was not there before. (Even for 
immutable references, sharing the same result is moot, as D supports 
checking for reference equality.)


More information about the Digitalmars-d mailing list