GC.malloc is pure - wat
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Fri Apr 1 13:27:39 PDT 2016
On Friday, 1 April 2016 at 01:19:01 UTC, Timon Gehr wrote:
> 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.)
I can see the logic. Yet, the only thing that can be returned if
no state is exposed is either a constant or something computed
from 1 (cast(void*) 1).
But yeah, the optimization should probably not be done if the
return type is mutable.
More information about the Digitalmars-d
mailing list