On Borrow Checking

Walter Bright newshound2 at digitalmars.com
Sat May 10 04:21:01 UTC 2025


On 5/4/2025 3:49 PM, Richard (Rikki) Andrew Cattermole wrote:
> On 05/05/2025 8:50 AM, Walter Bright wrote:
>> The point of the borrow checker is to ensure there is exactly one point of 
>> origin for a pointer and exactly one point of termination for it.
> 
> Hang on, that isn't the point of it at all.
> 
> A borrow checker has got the _side effect_ of only having one entry and exit 
> point for an object.
> 
> But the _objective_ is to loosen the restrictions that an _ownership transfer 
> system_ imposes on the type system whilst keeping its guarantees.

I don't see how that would be workable.


> We do not have an ownership transfer system in D.

Yes we do, in @live code. That's exactly what it does. A pointer assignment to 
another pointer transfers the ownership to the lvalue, and the rvalue becomes 
"dead".


> herefore we cannnot have a 
> borrow checker.

The implementation shows it works.


> What we do have is a liveliness analysis with guaranteed modelability, and we do 
> have a use for that, @restrict.
> 
> Enforcing @restrict could be an incredibly useful tool to those who do data 
> processing with simd, right now they are doing this by hand.

Restricted pointers in C are guaranteed only by the user, the compiler does no 
checking.

You cannot vet restricted pointers without a borrow checker.


More information about the Digitalmars-d mailing list