On Borrow Checking

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Sun May 11 00:25:19 UTC 2025


On 11/05/2025 11:40 AM, Walter Bright wrote:
> On 5/10/2025 1:17 PM, Richard (Rikki) Andrew Cattermole wrote:
>> There is also the mess with ``return ref`` vs ``return``, that can be 
>> written as ``return scope`` and ``scope return``.
> 
> That came about because of the existence of `ref`. Consider `ref int* 
> p`. How do you model the scope-ness of the reference and the scope-ness 
> of the pointer?

I know what I want my DFA to do, but my understanding is taking a 
pointer is rewritten out of the AST by the time semantic 3 has finished 
and that makes things more difficult.

>> These both have the same escape set, just a different relationship 
>> strength.
> 
> Strength??

I.e. taking a pointer to a variable has a stronger relationship than 
just copying the value stored in said variable.

So the difference between ``return scope`` and ``scope return``.

>> This is also a good time to remember that DIP1000 only understands no 
>> escape, escape into return value OR this pointer.
> 
> That's sufficient to prevent an escaping pointer to the stack. It's 
> quite solid. If you disagree, post a code snippet demonstrating it.

We've covered this before, stack is one thing, but stack becomes heap 
the moment it crosses the function boundary and the things people 
actually want to use it for? Heap.

>> No multiple output support, which severely limits its capabilities.
> 
> It does not severely limit it. Even the Rust manual says it's a rare 
> case. It's a minor inconvenience that can be refactored away.

Its rare enough that it doesn't need short syntax that could interfere 
with existing syntax.

Its not rare enough for me to drop it.



More information about the Digitalmars-d mailing list