DIP 1021--Argument Ownership and Function Calls--Community Review Round 1

Walter Bright newshound2 at digitalmars.com
Fri Aug 2 08:07:57 UTC 2019


On 7/15/2019 8:55 AM, Paul Backus wrote:
> On Monday, 15 July 2019 at 15:23:32 UTC, Mike Parker wrote:
>> This is the feedback thread for the first round of Community Review for DIP 
>> 1021, "Argument Ownership and Function Calls":
>>
>> https://github.com/dlang/DIPs/blob/793f83911fdc8c88c6ef34e6a36b5e11e3e574e5/DIPs/DIP1021.md 
>>
> 
> Do these new checks also handle the case where one of the references is passed 
> implicitly to a delegate or nested function via their context?

Yes. Access to such variables is treated "as if" they were passed by reference 
as arguments to the function. Of course, in reality they actually are passed by ref!


> In other words, 
> if we re-write the example from the DIP to use a nested function, like so:
> 
> struct S {
>      byte* ptr;
>      ref byte get() { return *ptr; }
> }
> 
> void test() {
>      S s;
>      s.ptr = cast(byte*) malloc(1);
> 
>      void foo(ref byte b) {
>          free(s.ptr);
>          b = 4;
>      }
> 
>      foo(s.ptr);
> }
> 
> Will the call to `foo` here be correctly flagged as taking multiple mutable 
> references to `s`?

Yes, the parameter list will be treated as:

     void foo(ref byte b, ref S s);

and the call:

     foo(s.ptr, s);



More information about the Digitalmars-d mailing list