The non-intrusive ad-hoc borrowing scheme…

Ola Fosheim Grøstad ola.fosheim.grostad at
Wed Nov 13 12:22:12 UTC 2019

Since Rust style borrowing checks lead to various complications, 
why not embrace testing as an alternative approach. Basically 
providing something like valgrind for borrowing.

You can track shared ownership by letting pointers and slices use 
ref-counting. That is well-known.

In my own attempts to model borrowing in D, I did a tiny little 
twist to it, creating borrowing pointers that will not free when 
the refcount goes to zero. Instead they fail. So you have to 
release the owner explicitly and that can only be done when the 
refcount is zero.

That allows you to track borrowing during debugging/testing, and 
turn it off in release mode. You also avoid the inconveniences 
that Rust comes with.

The downside is that the resulting code is only as safe as the 
testing environment ensures…

Anyway, this is relatively easy to implement if the code base is 

More information about the Digitalmars-d mailing list