Allocator-aware @safe reference counting is still not possible

FeepingCreature feepingcreature at gmail.com
Thu Jan 26 06:55:41 UTC 2023


On Monday, 23 January 2023 at 08:49:50 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> ```d
> Vector!int vector;
> vector ~= 3;
>
> auto borrowed = vector[0];
> func(borrowed);
>
> void func(scope ref int value) {
> 	
> }
> ```
>
> Basically right now we're missing the lifetime checks 
> surrounding borrowed & function parameter. Everything else is 
> do-able right now, even if it isn't as cheap as it could be 
> (like RC eliding).

I'm writing a language with borrowing and ref counting (Neat), 
and this is not a valid borrow. Basically you don't want to take 
on borrowing with variables that are mutable by default, because 
then you're asking for things like:

```d
Vector!int vector;
vector ~= 3;
void evil() { vector = Vector!int.init; }

auto borrowed = vector[0];
func(borrowed);

void func(scope ref int value) {
   // destroy the last non-borrowed reference to vector, where is 
your God now?
   evil;
```


More information about the Digitalmars-d mailing list