Re: Friends don't let friends use inout with scope and -dip1000

2018-08-22 Thread Kagamin via Digitalmars-d
On Wednesday, 22 August 2018 at 14:05:10 UTC, Steven Schveighoffer wrote: But that's not valid dip1000 code. If you call it, it should give a compiler error (r *does* escape its scope). When I complained about C++ safety to my C++ programmer colleague, he told me that the compiler just

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-22 Thread Steven Schveighoffer via Digitalmars-d
On 8/22/18 4:17 AM, Kagamin wrote: On Tuesday, 21 August 2018 at 14:04:15 UTC, Steven Schveighoffer wrote: I would guess it's no different than other inferred attributes. I would also guess that it only gets promoted to a return parameter if it's actually returned. If we can't have properly

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-22 Thread Kagamin via Digitalmars-d
On Tuesday, 21 August 2018 at 14:04:15 UTC, Steven Schveighoffer wrote: I would guess it's no different than other inferred attributes. I would also guess that it only gets promoted to a return parameter if it's actually returned. If we can't have properly typed parameters, it feels like it

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Nick Treleaven via Digitalmars-d
On Tuesday, 21 August 2018 at 13:42:31 UTC, Kagamin wrote: int[] escape(scope int[] r) { return r; //error, can't return scoped argument } ... int[] escape(T)(scope int[] r) { return r; //ok! `scope` silently promoted to `return` } You can't have strictly scoped parameter in a

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Atila Neves via Digitalmars-d
On Tuesday, 21 August 2018 at 11:28:39 UTC, Nicholas Wilson wrote: On Tuesday, 21 August 2018 at 10:57:15 UTC, Atila Neves wrote: On Tuesday, 21 August 2018 at 09:50:46 UTC, Atila Neves wrote: On Monday, 20 August 2018 at 15:55:54 UTC, Kagamin wrote: On Monday, 20 August 2018 at 13:02:23 UTC,

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Steven Schveighoffer via Digitalmars-d
On 8/21/18 9:42 AM, Kagamin wrote: except for templated functions: int[] escape(scope int[] r) {     return r; //error, can't return scoped argument } int[] escape(return int[] r) {     return r; //ok, just as planned } int[] escape(return scope int[] r) {     return r; //ok, `return

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Kagamin via Digitalmars-d
...except for templated functions: int[] escape(scope int[] r) { return r; //error, can't return scoped argument } int[] escape(return int[] r) { return r; //ok, just as planned } int[] escape(return scope int[] r) { return r; //ok, `return scope` reduced to just `return` } int[]

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Kagamin via Digitalmars-d
I mean if one method in structure is trusted, other methods need manual verification too.

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Kagamin via Digitalmars-d
On Tuesday, 21 August 2018 at 10:57:15 UTC, Atila Neves wrote: Also, if I have to remember to annotate correctly, surely this is a massive hole in @safe dip1000? In general, safety works per method and doesn't help much in building safe data structures, those are trusted as a whole. EMSI

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Kagamin via Digitalmars-d
On Tuesday, 21 August 2018 at 10:57:15 UTC, Atila Neves wrote: Never mind, I forgot to use -dip1000. Ok, cool, so _why_ does it work as intended now? Also, if I have to remember to annotate correctly, surely this is a massive hole in @safe dip1000? It thought dip1000 was impenetrable, but if

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Nicholas Wilson via Digitalmars-d
On Tuesday, 21 August 2018 at 10:57:15 UTC, Atila Neves wrote: On Tuesday, 21 August 2018 at 09:50:46 UTC, Atila Neves wrote: On Monday, 20 August 2018 at 15:55:54 UTC, Kagamin wrote: On Monday, 20 August 2018 at 13:02:23 UTC, Atila Neves wrote: On Monday, 20 August 2018 at 12:56:42 UTC,

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Atila Neves via Digitalmars-d
On Tuesday, 21 August 2018 at 09:50:46 UTC, Atila Neves wrote: On Monday, 20 August 2018 at 15:55:54 UTC, Kagamin wrote: On Monday, 20 August 2018 at 13:02:23 UTC, Atila Neves wrote: On Monday, 20 August 2018 at 12:56:42 UTC, Kagamin wrote: [...] I need `return` for what exactly? Your code

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-21 Thread Atila Neves via Digitalmars-d
On Monday, 20 August 2018 at 15:55:54 UTC, Kagamin wrote: On Monday, 20 August 2018 at 13:02:23 UTC, Atila Neves wrote: On Monday, 20 August 2018 at 12:56:42 UTC, Kagamin wrote: [...] I need `return` for what exactly? Your code still compiles, and my point is it shouldn't. It sure isn't

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-20 Thread Dgame via Digitalmars-d
On Monday, 20 August 2018 at 15:55:54 UTC, Kagamin wrote: On Monday, 20 August 2018 at 13:02:23 UTC, Atila Neves wrote: On Monday, 20 August 2018 at 12:56:42 UTC, Kagamin wrote: You need `return` attribute there, not `scope`: struct MyStruct { import core.stdc.stdlib; int* ints;

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-20 Thread Kagamin via Digitalmars-d
On Monday, 20 August 2018 at 13:02:23 UTC, Atila Neves wrote: On Monday, 20 August 2018 at 12:56:42 UTC, Kagamin wrote: You need `return` attribute there, not `scope`: struct MyStruct { import core.stdc.stdlib; int* ints; this(int size) @trusted { ints = cast(int*) malloc(size); }

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-20 Thread Steven Schveighoffer via Digitalmars-d
On 8/20/18 5:43 AM, Nicholas Wilson wrote: On Monday, 20 August 2018 at 09:31:09 UTC, Atila Neves wrote: On Friday, 17 August 2018 at 13:39:29 UTC, Steven Schveighoffer wrote: // used to be scope int* ptr() { return ints; } scope inout(int)* ptr() inout { return ints; } Does scope apply to

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-20 Thread Jonathan M Davis via Digitalmars-d
On Monday, August 20, 2018 3:43:46 AM MDT Nicholas Wilson via Digitalmars-d wrote: > On Monday, 20 August 2018 at 09:31:09 UTC, Atila Neves wrote: > > On Friday, 17 August 2018 at 13:39:29 UTC, Steven Schveighoffer > > > > wrote: > >>> // used to be scope int* ptr() { return ints; } > >>> scope

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-20 Thread Kagamin via Digitalmars-d
AIU, `return` for `scope` is what `inout` is for `const`. I proposed to extend `inout` to mean `return`, but Walter said that they are independent.

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-20 Thread Atila Neves via Digitalmars-d
On Monday, 20 August 2018 at 09:43:46 UTC, Nicholas Wilson wrote: On Monday, 20 August 2018 at 09:31:09 UTC, Atila Neves wrote: On Friday, 17 August 2018 at 13:39:29 UTC, Steven Schveighoffer wrote: [...] Does scope apply to the return value or the `this` reference? I assumed the return

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-20 Thread Atila Neves via Digitalmars-d
On Monday, 20 August 2018 at 12:56:42 UTC, Kagamin wrote: You need `return` attribute there, not `scope`: struct MyStruct { import core.stdc.stdlib; int* ints; this(int size) @trusted { ints = cast(int*) malloc(size); } ~this() @trusted { free(ints); } inout(int)* ptr()

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-20 Thread Kagamin via Digitalmars-d
You need `return` attribute there, not `scope`: struct MyStruct { import core.stdc.stdlib; int* ints; this(int size) @trusted { ints = cast(int*) malloc(size); } ~this() @trusted { free(ints); } inout(int)* ptr() return inout { return ints; } }

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-20 Thread Nicholas Wilson via Digitalmars-d
On Monday, 20 August 2018 at 09:31:09 UTC, Atila Neves wrote: On Friday, 17 August 2018 at 13:39:29 UTC, Steven Schveighoffer wrote: // used to be scope int* ptr() { return ints; } scope inout(int)* ptr() inout { return ints; } Does scope apply to the return value or the `this` reference? I

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-20 Thread Atila Neves via Digitalmars-d
On Friday, 17 August 2018 at 13:39:29 UTC, Steven Schveighoffer wrote: On 8/17/18 3:36 AM, Atila Neves wrote: Here's a struct: - struct MyStruct {     import core.stdc.stdlib;     int* ints;     this(int size) @trusted { ints = cast(int*) malloc(size); }     ~this()

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-17 Thread Dukc via Digitalmars-d
On Friday, 17 August 2018 at 13:39:29 UTC, Steven Schveighoffer wrote: On 8/17/18 3:36 AM, Atila Neves wrote: Here's a struct: - // used to be scope int* ptr() { return ints; } scope inout(int)* ptr() inout { return ints; } Does scope apply to the return value or the `this`

Re: Friends don't let friends use inout with scope and -dip1000

2018-08-17 Thread Steven Schveighoffer via Digitalmars-d
On 8/17/18 3:36 AM, Atila Neves wrote: Here's a struct: - struct MyStruct {     import core.stdc.stdlib;     int* ints;     this(int size) @trusted { ints = cast(int*) malloc(size); }     ~this() @trusted { free(ints); }     scope int* ptr() { return ints; } }