digitalmars.D - Bug 20868 and dip1000
- RazvanN (47/47) Jan 11 2021 Hello everyone,
- 12345swordy (4/52) Jan 11 2021 You need to email Walter on this as he is the one spearheading
- Meta (4/52) Jan 11 2021 I've run into a similar problem. I never got a satisfactory
- Meta (3/6) Jan 11 2021 Whoops, forgot the link:
- Walter Bright (2/5) Jan 14 2021 Replied in bugzilla.
Hello everyone, Bug 20868 [3] reports the following code: void scoped (scope void delegate() dg) { static void delegate()[] dgs; // dgs ~= dg; // error nonScoped(dg); // not an error??? } void nonScoped (void delegate() dg) { static void delegate()[] dgs; dgs ~= dg; } void main () { int x; scoped({x = 100;}); } The above code, compiled with -dip1000, compiles succesfully. If the scoped and nonScoped functions are annotated with safe, the nonScoped call will be reported as an error (as it should). Spec [1] says: "scope escape analysis is only done for safe functions. For other functions scope semantics must be manually enforced.". Dip1000 [2] says: "Errors for scope violations are only reported in safe code.". My understanding is that scope checks are performed only when dip1000 is enabled and in safe code. However, that is not entirely the case. For example: int* scoped(scope int* p) { return p; } void main() { int i; int* p = &i; scoped(p); } Compiled with dip1000, yields: "onlineapp.d(2): Error: scope variable `p` may not be returned". I want to fix the issue, but I don't know what the official specification is. Should we disable any dip1000 checks in system functions or is there any other piece of spec that I am missing? Cheers, RazvanN [1] https://dlang.org/spec/function.html#scope-parameters [2] https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md [3] https://issues.dlang.org/show_bug.cgi?id=20868
Jan 11 2021
On Monday, 11 January 2021 at 13:20:12 UTC, RazvanN wrote:Hello everyone, Bug 20868 [3] reports the following code: void scoped (scope void delegate() dg) { static void delegate()[] dgs; // dgs ~= dg; // error nonScoped(dg); // not an error??? } void nonScoped (void delegate() dg) { static void delegate()[] dgs; dgs ~= dg; } void main () { int x; scoped({x = 100;}); } The above code, compiled with -dip1000, compiles succesfully. If the scoped and nonScoped functions are annotated with safe, the nonScoped call will be reported as an error (as it should). Spec [1] says: "scope escape analysis is only done for safe functions. For other functions scope semantics must be manually enforced.". Dip1000 [2] says: "Errors for scope violations are only reported in safe code.". My understanding is that scope checks are performed only when dip1000 is enabled and in safe code. However, that is not entirely the case. For example: int* scoped(scope int* p) { return p; } void main() { int i; int* p = &i; scoped(p); } Compiled with dip1000, yields: "onlineapp.d(2): Error: scope variable `p` may not be returned". I want to fix the issue, but I don't know what the official specification is. Should we disable any dip1000 checks in system functions or is there any other piece of spec that I am missing? Cheers, RazvanN [1] https://dlang.org/spec/function.html#scope-parameters [2] https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md [3] https://issues.dlang.org/show_bug.cgi?id=20868You need to email Walter on this as he is the one spearheading the dip1000. -Alex
Jan 11 2021
On Monday, 11 January 2021 at 13:20:12 UTC, RazvanN wrote:Hello everyone, Bug 20868 [3] reports the following code: void scoped (scope void delegate() dg) { static void delegate()[] dgs; // dgs ~= dg; // error nonScoped(dg); // not an error??? } void nonScoped (void delegate() dg) { static void delegate()[] dgs; dgs ~= dg; } void main () { int x; scoped({x = 100;}); } The above code, compiled with -dip1000, compiles succesfully. If the scoped and nonScoped functions are annotated with safe, the nonScoped call will be reported as an error (as it should). Spec [1] says: "scope escape analysis is only done for safe functions. For other functions scope semantics must be manually enforced.". Dip1000 [2] says: "Errors for scope violations are only reported in safe code.". My understanding is that scope checks are performed only when dip1000 is enabled and in safe code. However, that is not entirely the case. For example: int* scoped(scope int* p) { return p; } void main() { int i; int* p = &i; scoped(p); } Compiled with dip1000, yields: "onlineapp.d(2): Error: scope variable `p` may not be returned". I want to fix the issue, but I don't know what the official specification is. Should we disable any dip1000 checks in system functions or is there any other piece of spec that I am missing? Cheers, RazvanN [1] https://dlang.org/spec/function.html#scope-parameters [2] https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md [3] https://issues.dlang.org/show_bug.cgi?id=20868I've run into a similar problem. I never got a satisfactory answer from Walter, and the only solution I could come up with other than rewriting the code was to reach for trusted.
Jan 11 2021
On Monday, 11 January 2021 at 15:19:07 UTC, Meta wrote:I've run into a similar problem. I never got a satisfactory answer from Walter, and the only solution I could come up with other than rewriting the code was to reach for trusted.Whoops, forgot the link: https://forum.dlang.org/post/laqjadtwrsdhdrqokryx forum.dlang.org
Jan 11 2021
On Monday, 11 January 2021 at 15:19:44 UTC, Meta wrote:On Monday, 11 January 2021 at 15:19:07 UTC, Meta wrote:I suspect Walter would complain about a lack of bug report.I've run into a similar problem. I never got a satisfactory answer from Walter, and the only solution I could come up with other than rewriting the code was to reach for trusted.Whoops, forgot the link: https://forum.dlang.org/post/laqjadtwrsdhdrqokryx forum.dlang.org
Jan 11 2021
On Monday, 11 January 2021 at 15:27:50 UTC, jmh530 wrote:On Monday, 11 January 2021 at 15:19:44 UTC, Meta wrote:I am not sure if it's a bug or working as intended (though I suspect the latter). I couldn't get an answer for that, either.On Monday, 11 January 2021 at 15:19:07 UTC, Meta wrote:I suspect Walter would complain about a lack of bug report.I've run into a similar problem. I never got a satisfactory answer from Walter, and the only solution I could come up with other than rewriting the code was to reach for trusted.Whoops, forgot the link: https://forum.dlang.org/post/laqjadtwrsdhdrqokryx forum.dlang.org
Jan 11 2021
On Monday, 11 January 2021 at 16:09:29 UTC, Meta wrote:[snip]I'd say report it and if it's working as intended, then he can close himself.I suspect Walter would complain about a lack of bug report.I am not sure if it's a bug or working as intended (though I suspect the latter). I couldn't get an answer for that, either.
Jan 11 2021
On 1/11/2021 5:20 AM, RazvanN wrote:[1] https://dlang.org/spec/function.html#scope-parameters [2] https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP1000.md [3] https://issues.dlang.org/show_bug.cgi?id=20868Replied in bugzilla.
Jan 14 2021