DIP 1021--Argument Ownership and Function Calls--Final Review

Olivier FAURE couteaubleu at gmail.com
Mon Sep 23 08:34:35 UTC 2019

On Friday, 20 September 2019 at 21:51:17 UTC, Walter Bright wrote:
> D supports FP as a useful paradigm, not as a religion. It 
> allows one to easily mix&match FP with imperative code.
> I figure we can do the same for ownership/borrowing, that's why 
> it has a separate function attribute (@live) for it.

That really depends on what you mean by "mix-and-match".

If you mean as a transition path, where you try to eliminate most 
of the non- at live code as fast as you can, then yes.

If you mean, like with const, some parts of the code use it, some 
parts don't, but the latter can call the former while remaining 
@safe, then no.

Given @live as you described it, non- at live functions calling 
@live functions would have to be @system or @trusted, which isn't 
a state you want half your codebase to be in.


     @safe @live
     SmartPtr!int createPtr() {
         return SmartPtr!int();

     @safe @live
     void removePtr(ref SmartPtr!int ptr) {

     int* identity(return ref int n) { return &n; }

     void test() {
         auto ptr = createPtr;
         int* p = identity(ptr.get());
         *p = 1; 		// Memory corruption

More information about the Digitalmars-d mailing list