On Thu, 16 Jun 2011 16:36:01 -0400, Jonathan M Davis <[email protected]> wrote:

On 2011-06-16 11:59, Steven Schveighoffer wrote:
On Thu, 16 Jun 2011 14:33:17 -0400, Jonathan M Davis <[email protected]>

wrote:
> On 2011-06-16 10:38, Charles McAnany wrote:
>> Ok, I think I get it. That cleared it up. =).
>> So, if you have a functioned labelled pure, it's your job to not pass it >> mutable arguments, but the compiler's job to make sure it doesn't mutate >> anything not in the arguments. And that's why a strongly pure function
>> can
>> call a weakly pure one - only the first function's internal state can be
>> mutated by a weakly pure function. Thanks!
>
> Well, essentially. But it's a question of parameters, not arguments. It
> doesn't matter whether you pass the function mutable arguments or not.

Actually, it can matter.  For instance, a pure function like this:

pure int foo(const(int)* m);

can be strong pure if you pass it a pointer to immutable data.

I believe that every time that Don has discussed it, he has made it clear that it's entirely a matter of the function's signature and that all parameters must be immutable or implicitly convertible to immutable for a function to be strongly pure. So, that's what I'm going by. However, I can see how passing immutable values to a pure function with const parameters could be optimized out just like if the parameters were actually immutable. So, it may be that things were changed so that that counts as well. Everything that I've seen
discussed on it though has been about the parameters all having to be
immutable or implicitly convertible to immutable.

Don's the one who brought it to my attention (have no idea what thread it was in...) that the optimizations could be done based on this.

AFAIK, this optimization is not implemented.

-Steve

Reply via email to