--- Comment #10 from ---
(In reply to Walter Bright from comment #7)
> Yeah, my mistake. The compiler should consider @nogc when marking a pure
> function as a common subexpression.

I think approaching this with @nogc would be a mistake. Considering mutable
indirections in the return type seems superior to me.

You can have a function that allocates via the GC but doesn't return any
mutable indirections. Either it allocates for internal use only, or it casts to
immutable when returning. You can reuse the result of such a function for
another identical call.

I'm only rehashing David Nadlinger's article on this matter, of course.

Considering the indirections in the return type would also leave the door open
for other allocators to be used in `pure` code. Tying this to @nogc would only
add to the arbitrary divide between the GC and others. As far as I see, the GC
isn't actually more pure than other allocators, it's just recognized by the
language which makes it seem natural to special case it.


Reply via email to