On Borrow Checking

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Sat May 17 14:03:05 UTC 2025


On 17/05/2025 10:05 PM, claptrap wrote:
> On Wednesday, 30 April 2025 at 02:58:37 UTC, Walter Bright wrote:
>> On 4/29/2025 6:26 PM, jmh530 wrote:
>>
>>
>> We spent a considerable time thinking about safe reference-counting. 
>> We could not find a way around its considerable performance penalties, 
>> and its unsafety, and so abandoned it.
> 
> Why is safe ref counting not feasible with D?

Because we don't have a borrow checker.

Any kind of pointer originating from the ``this`` pointer of a RC type, 
must not outlive the RC owner.

A borrow checker guarantees that the RC owner will not be modified and 
will outlive the borrow.

This is the origin story of my DFA/escape analysis work.

> Wouldn't the fact that most data is thread local in D mitigate the 
> majority of the performance penalties? You dont need atomic inc/dec if 
> its thread local do you?

I evaluated this ages ago, with a simple bit of value tracking + moving 
the reference add into the called function, you can get rid of a ton of 
those deltas.

Anyway, atomic add/sub have gotten much cheaper on recent hardware, like 
1uop. Still good to optimize unnecessary work away though!



More information about the Digitalmars-d mailing list