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

a11e99z black80 at bk.ru
Mon Sep 16 10:46:41 UTC 2019


On Monday, 16 September 2019 at 09:13:48 UTC, Mike Parker wrote:
> DIP 1021, "Argument Ownership and Function Calls", is now ready 
> for Final Review. This is the last chance for community 
> feedback before the DIP is handed off to Walter (the author in 
> this case) and Átila for the Formal Assessment.
>

does help this DIP with next situation or another option already 
exists in D?
https://run.dlang.io/is/LQJ79M

dmd -dip1000 ....
---------------------------
import std;

struct Data {
     private void[10] buf;
     private void* ptr; // some data

     //TODO. OT
     // should it be possible to initialize pointers to internals 
in the default constructor for structs? does DIP-xxxx(idr) solve 
it? whether its necessary?
     // this() { ptr = buf.ptr; }

     // I want that data can be used only at block { that 
requested it }
    	void[] data() @trusted return scope {
        	return ptr[0..10]; // returns some internals
     }
}

// user func that work with Data internals that shouldn't run away
// user can forget to use "scope"
void[] userFunc( ref Data d ) @safe {
     auto tmp = d.data;
     // FIXME
     // tmp shouldn't run away.
     // "scope" in user hands is not solution. (scope ref Data d)
     // lib should control access to lib internals not the user.
     return tmp;
}

void main() {
     Data d;
     userFunc( d );
     "data runs away. and dip1000 is enabled.".writeln;
}



More information about the Digitalmars-d mailing list