Fully transitive const is not necessary

Steven Schveighoffer schveiguy at yahoo.com
Fri Apr 4 10:45:47 PDT 2008


"guslay" wrote
> Walter Bright Wrote:
>
>>
>> Logical const just utterly breaks the whole system.
>
>
> I think we had a different expectations about invariant and pure.
>
> Do you believe that (A),
>
>   invariant A a;
>   int x = f_pure(a);
>   g_not_pure(a); // potentially mutating mutable members of A
>   int y = f_pure(a);
>   int z = f_pure(a);
>
> which is can be transformed without problem to (B),
>
>   invariant A a;
>   int x = f_pure(a);
>   g_not_pure(a);
>   int y = f_pure(a);
>   int z = y;
>
> MUST also be equivalent to (C) ?
>
>   invariant A a;
>   int x = f_pure(a);
>   int y = x;
>   int z = x;
>   g_not_pure(a);
>
>
> A = B = C is only possible if invariant A as no mutable part. I agree. Is 
> this your position?
>
> I was expecting a weaker pure model, where only A = B is true 
> (optimization based on purity only possible inside a contiguous block of 
> pure functions).
>
> If this is correct then I understand your concerns against logical const.

If we say that the mutable part of invariant A is not accessible during pure 
functions, then (A = B = C) holds true.  In fact, I would argue that for 
logical const, the mutable part is not part of the invariant A instance, but 
is an 'associated' or 'tacked-on' piece that happens to be carried around 
with A.  It is used by A to help for various tools such as syncrhonization, 
memoization, etc, but it is not part of A's state.  Think of it as living in 
A's namespace, but not in the instance, and so it is inaccessible to pure 
functions.

-Steve 





More information about the Digitalmars-d mailing list