Feedback Thread: DIP 1035-- at system Variables--Final Review

Dukc ajieskola at gmail.com
Fri Feb 25 21:46:25 UTC 2022


On Saturday, 19 February 2022 at 12:26:26 UTC, Mike Parker wrote:
> This is the feedback thread for the Final Review of DIP 1035, 
> "@system Variables".
----------

> A workaround could be to put the handle in a `union` with a 
> pointer, but that would unnecessarily increase the size of the 
> struct to `size_t.sizeof`.

Wouldn't putting the handle in union with `void[1]` work?

----------

This part concerns me:

> Further operations disallowed in @safe code on a @system 
> variable or field are:
> 
> - creating a mutable pointer to it by using &
> - passing it as an argument to a function parameter marked ref 
> without const
> - returning it by ref without const

Doesn't that mean that this is allowed:
```D
ref const identity(T)(return ref const T var){return var;}

@safe void main()
{ auto x = someContainer.internalRepresentation.identity;
}
```
? It defeats the purpose of disallowing reading `@system` 
variables in `@safe` code.

---------------

> ```D
> struct T
> {
>     @system int y;
>     @system int z = 3; // allowed
>     this(int y, int z) @safe
>     {
>         this.y = y; // allowed, this is initialization
>         this.y = y; // second time disallowed, this is 
> assignment to a `@system` variable
>         this.z = z; // disallowed, this is assignment
>     }
> }
> ```

The third comment is wrong according to my test:

```D
import std.stdio;

struct Int
{ int quantity;
   this(int q, string unused){quantity = q;}
   this(int q)
   { quantity = q;
     writeln("constructed");
   }
   void opAssign(int q)
   { quantity = q;
     writeln("assigned");
   }
}

struct T
{ Int y;
   Int z = Int(3, ""); // allowed
   this(int y, int z)
   { writeln(1);
     this.y = y; // allowed, this is initialization
     writeln(2);
     this.y = y; // second time disallowed, this is assignment to 
a `@system` variable
     writeln(3);
     this.z = z; // disallowed, this is assignment
   }
}

void main(){auto x = T(5, 10);}
```
outputs
```
1
constructed
2
assigned
3
constructed
```



More information about the Digitalmars-d mailing list