Escape Analysis & Owner Escape Analysis

IchorDev zxinsworld at gmail.com
Sun Sep 22 11:03:51 UTC 2024


On Thursday, 5 September 2024 at 10:28:45 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
>
> On 05/09/2024 9:53 PM, IchorDev wrote:
>> Wait, so how would one force owner escape analysis to be 
>> enabled for manually heap-allocated memory? This DIP is meant 
>> to replace @live, after all.
>
> You need to establish a strong relationship either to a 
> variable, or from it.
>
> For a method call add ``scope`` on the this pointer:
>
> ```d
> struct RC {
> 	int* borrow() scope;
> }
> ```
>
> For variable declaration:
>
> ```d
> scope int* owner = new int;
> ```
>
> Take a pointer:
>
> ```d
> struct Top {
> 	int field;
> }
>
> Top top;
> int* borrow = &top.field;
> ```

I see, thank you. So `scope x = malloc(10);`.

> I have not added meaning for ``scope`` on a field, although I 
> can see that this might be nice to add. I'm not sure if that is 
> needed. Is this a hole for you?

I can certainly think of some times where forcing certain escape 
analysis pattens when heap memory is taken from a struct would be 
useful. That said, I’d usually be wrapping that memory in a 
`@property` method anyway.

> I have a feeling that this won't be answering your question, is 
> there something I'm for whatever reason not understanding about 
> it?

I think you understood just fine.

>>>> - `@escape` is the opposite of `@escape()`, which could be 
>>>> confusing
>>>
>>> Originally I was going to make this to mean 'inferred', but 
>>> it's better if everything gets inferred by default.
>>>
>>> It needs to mean something, so got an alternative?
>> 
>> Maybe add a special case for something like `@escape(false)`?
>
> The question is for what ``@escape()`` would do. Which Dennis 
> has not counter proposal for.

I see. `@escape` is meant to tell you how the variable escapes, 
but on its own it implicitly uses a default set of escapes. If 
the parentheses are empty, surely that should just be the same as 
`@escape`?


More information about the dip.ideas mailing list