Second Draft: Turn properties into first class accessors
Dom DiSc
dominikus at scherkl.de
Thu Feb 6 10:36:47 UTC 2025
On Thursday, 6 February 2025 at 03:34:22 UTC, Paul Backus wrote:
> On Thursday, 6 February 2025 at 00:52:55 UTC, Richard (Rikki)
> Andrew Cattermole wrote:
>> ```d
>> value += 2 + value;
>> ```
should become:
```d
{
int __tmp1 = 2 + value; // as usual - the result of a binary
operator
int __tmp2 = value; // the new normal lowering
value(__tmp2 + __tmp1); // of opOpAssign!"+"
__tmp2 = value; // with return value (which can be
discarded if not used later on)
}
```
And nested operations
```d
value += value += 2; // what now??
```
should become:
```d
{
int __tmp1 = value;
value(__tmp1 + 2); // the inner +=
__tmp1 = value; // here the return value is needed
int __tmp2 = value;
value(__tmp2 + __tmp1); // the outer +=
__tmp2 = value; // return value can be optimized away
}
```
I do not consider this problematic (and it's something that you
might find often in my code).
Parantheses are not necessary here, using the normal operator
precedence and order.
Maybe the optimizer can simplify this a little, as __tmp1 and
__tmp2 refer to the same property in this case, but if the result
of the inner += is assigned to another property, it is necessary
to do the lowering this verbose:
```d
propB += propA += 2;
```
is lowered to:
```d
{
int __tmp1 = propA;
propA(__tmp1 + 2);
__tmp1 = propA;
int __tmp2 = propB;
propB(__tmp2 + __tmp1);
__tmp2 = propB;
}
```
More information about the dip.development
mailing list