DMD 2.100, bring ont he attribute soup
rikki cattermole
rikki at cattermole.co.nz
Fri May 27 05:25:16 UTC 2022
On 27/05/2022 5:06 PM, Walter Bright wrote:
> On 5/26/2022 8:07 PM, rikki cattermole wrote:
>> I want lifetime checks to work,
>
> So do I. But nobody has figured out how to make this work without
> strongly impacting the programmer.
I did come up with a design, but I'm not convinced it is entirely doable.
I explained this to Timon earlier today (so have examples).
Its basically making all memory objects (as in C definition), in
reference to other memory objects, and tieing their lifetime to them.
My worked example:
```d
int[] array = [1, 2, 3]; // ownership: []
// arg ownership: [] (not ref/out)
// return ownership: [first argument] -> [array]
int* got = func(array); // ownership: [array]
int* func(int[] source) {
int[] slice = source[1 .. 2]; // ownership: [source]
int* ptr = &slice[0]; // ownership: [slice, source] -> [source]
return ptr; // ownership: [ptr] -> [source]
}
```
A question Timon came up with that I answered:
```d
int[][] func(int[] a, int[] b){
return [a,b];
}
```
(for return value): ``// ownership: [first argument, second argument]``
This ticks a lot of the boxes I'm using as preferable acceptance criteria:
1. Inferred for anything non-virtual
2. Nothing outlives its owner
3. Fairly straight forward to understand
But yeah none of this is easy to resolve.
On that note, an issue I have found to have in practice is[0]. I haven't
been bothered to report it, but at least this shouldn't require going
back to the drawing board ;) #dbugfix
[0] https://issues.dlang.org/show_bug.cgi?id=23142
More information about the Digitalmars-d
mailing list