Jump to page: 1 2
Thread overview
Second Draft: Turn properties into first class accessors
Feb 06
Dom DiSc
Feb 08
IchorDev
Feb 13
user1234
18 hours ago
12345swordy
February 05

Per request via email, I managed to port it to a markdown document.

https://github.com/12345swordy/Public-Documents/blob/main/properties.md

Destroy!

February 06
There is a guarantee that I want for this.

The compiler will guarantee that for every assignment that has a paired read, that there will be no other reads.

```d
@property {
    int value();
    void value(int);
}
```

```d
value += 2 + value;
```

Would be:

```d
{
    int __generatedName = value;
    value(__generatedName + 2 + __generatedName);
}
```

Not:

```d
value(value + 2 + value);
```

Furthermore, the loaded value must not escape the load statement.

This may seem unnecessary, but without this, I cannot think of a way for escape analysis to work with it.

With these guarantees, we might be able to special case it just enough for it to be modelable.

February 06
On Thursday, 6 February 2025 at 00:52:55 UTC, Richard (Rikki) Andrew Cattermole wrote:
> There is a guarantee that I want for this.
>
> The compiler will guarantee that for every assignment that has a paired read, that there will be no other reads.
>
> ```d
> @property {
>     int value();
>     void value(int);
> }
> ```
>
> ```d
> value += 2 + value;
> ```
>
> Would be:
>
> ```d
> {
>     int __generatedName = value;
>     value(__generatedName + 2 + __generatedName);
> }
> ```

Descending into the RHS expression and rewriting occurences of `value` there is complete insanity. Not only does it fall apart the instant you try to nest an expression like this recursively:

    value += (value += 2); // what now??

...it also has the potential to remove observable side effects from a program, which is, of course, completely unacceptable.

At the end of the day, all of this @property stuff is just syntax sugar for normal function calls. If you can't figure out how to make escape analysis work with function calls, that's a problem for your design. Leave @property out of it.
February 06
On 06/02/2025 4:34 PM, Paul Backus wrote:
> ...it also has the potential to remove observable side effects from a program, which is, of course, completely unacceptable.

In this case, what I am suggesting that yes, we must remove side effects that involve an owning objects lifetime.

If we do not, it will not be equivalent to operator overloads in terms of lifetime management and that is quite a bad situation to be in.

A ``@property`` method is for all intents and purposes is a borrowing action. Even if it isn't returning by-ref. Although some people may want to restrict this notion to only if you assign like this DIP proposes the ability to do so.


February 06
On Thursday, 6 February 2025 at 04:14:14 UTC, Richard (Rikki) Andrew Cattermole wrote:
> On 06/02/2025 4:34 PM, Paul Backus wrote:
>> ...it also has the potential to remove observable side effects from a program, which is, of course, completely unacceptable.
>
> In this case, what I am suggesting that yes, we must remove side effects that involve an owning objects lifetime.
>
> If we do not, it will not be equivalent to operator overloads in terms of lifetime management and that is quite a bad situation to be in.
>
> A ``@property`` method is for all intents and purposes is a borrowing action. Even if it isn't returning by-ref. Although some people may want to restrict this notion to only if you assign like this DIP proposes the ability to do so.

All of this stuff you're talking about is just function calls. Operator overloading is function calls. @property is function calls.

A function call is one of the most basic, fundamental language constructs that there is. If your design for escape analysis can't handle function calls, then you need a better design.

The fact that your current design is (apparently) deficient should not impede us from adding useful language features.
February 06
On 06/02/2025 5:19 PM, Paul Backus wrote:
> On Thursday, 6 February 2025 at 04:14:14 UTC, Richard (Rikki) Andrew Cattermole wrote:
>> On 06/02/2025 4:34 PM, Paul Backus wrote:
>>> ...it also has the potential to remove observable side effects from a program, which is, of course, completely unacceptable.
>>
>> In this case, what I am suggesting that yes, we must remove side effects that involve an owning objects lifetime.
>>
>> If we do not, it will not be equivalent to operator overloads in terms of lifetime management and that is quite a bad situation to be in.
>>
>> A ``@property`` method is for all intents and purposes is a borrowing action. Even if it isn't returning by-ref. Although some people may want to restrict this notion to only if you assign like this DIP proposes the ability to do so.
> 
> All of this stuff you're talking about is just function calls. Operator overloading is function calls. @property is function calls.
> 
> A function call is one of the most basic, fundamental language constructs that there is. If your design for escape analysis can't handle function calls, then you need a better design.
> 
> The fact that your current design is (apparently) deficient should not impede us from adding useful language features.

This has nothing to do with with what my design can or cannot do (although it could catch it, it would be more picky is all).

I bring this stuff up to make sure we have enough wiggle room in _any_ design to ensure understandable behavior without safety issues.

February 06

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:

>
value += 2 + value;

should become:

{
    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

   value += value += 2; // what now??

should become:

{
   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:

   propB += propA += 2;

is lowered to:

{
   int __tmp1 = propA;
   propA(__tmp1 + 2);
   __tmp1 = propA;
   int __tmp2 = propB;
   propB(__tmp2 + __tmp1);
   __tmp2 = propB;
}
February 08

On Wednesday, 5 February 2025 at 20:37:30 UTC, 12345swordy wrote:

>

Per request via email, I managed to port it to a markdown document.

https://github.com/12345swordy/Public-Documents/blob/main/properties.md

Destroy!

This is cool but

  1. Can you define how exactly does this interact with operator overloads? Especially how with regards to op[Index/Op]Assign, opCall, and opDispatch?
  2. Do you think the current ‘getters should be O(1)’ rule in the spec should remain or be abolished? (I’m in favour of the latter, since I frequently find that getters are great for lazy evaluation)
February 10

On Saturday, 8 February 2025 at 02:45:58 UTC, IchorDev wrote:

>

On Wednesday, 5 February 2025 at 20:37:30 UTC, 12345swordy wrote:

>

Per request via email, I managed to port it to a markdown document.

https://github.com/12345swordy/Public-Documents/blob/main/properties.md

Destroy!

This is cool but

  1. Can you define how exactly does this interact with operator overloads? Especially how with regards to op[Index/Op]Assign, opCall, and opDispatch?
  2. Do you think the current ‘getters should be O(1)’ rule in the spec should remain or be abolished? (I’m in favour of the latter, since I frequently find that getters are great for lazy evaluation)
  1. Good question. I was thinking about the interaction with arrays and the opindex/ opIndexAssign are the ones that pop in mind. I was thinking about custom syntax for get/set function when it comes to the array index using [].
  2. Removed. That should be an implementation defined by the programmer, not language defined.
February 13

On Wednesday, 5 February 2025 at 20:37:30 UTC, 12345swordy wrote:

>

Per request via email, I managed to port it to a markdown document.

https://github.com/12345swordy/Public-Documents/blob/main/properties.md

Destroy!

After having read the document twice, I still find that the relationship with CTFE very unclear. Do you mean UFCS instead ?

« First   ‹ Prev
1 2