Thread overview
[Issue 17486] lazy parameters can be used to hijack the pure system
[Issue 17486] lazy parameters cannot be used in nothrow/@nogc functions
Jun 09, 2017
Eyal
Jun 09, 2017
Eyal
Jun 09, 2017
Eyal
Jun 10, 2017
Eyal
June 09, 2017
https://issues.dlang.org/show_bug.cgi?id=17486

--- Comment #1 from Eyal <eyal@weka.io> ---
This also breaks purity type checking:

@safe:

import std.stdio:writeln;

void f(lazy int x) pure {
    x();
}

unittest {
    int g() {
        writeln("impure func called by pure func!");
        return 5;
    }
    auto xx = (() => g());
    writeln("-> f");
    f(xx());
    writeln("<- f");
}

outputs:

-> f
impure func called by pure func!
<- f

--
June 09, 2017
https://issues.dlang.org/show_bug.cgi?id=17486

--- Comment #2 from Eyal <eyal@weka.io> ---
Better bug reproduction:

@safe:

void f(ref int counter, lazy int x) pure {
    x();
    counter++;
    x();
}

void main() {
    int counter;
    int g() {
        import std.stdio:writeln;
        writeln("counter: ", counter);
        return 5;
    }
    f(counter, g);
}

// prints:
counter: 0
counter: 1

Making it clearer that we're being allowed to pass an impure delegate into a pure function that then calls it.

--
June 09, 2017
https://issues.dlang.org/show_bug.cgi?id=17486

Eyal <eyal@weka.io> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=17487

--
June 09, 2017
https://issues.dlang.org/show_bug.cgi?id=17486

greensunny12@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greensunny12@gmail.com
            Summary|lazy parameters cannot be   |lazy parameters can be used
                   |used in nothrow/@nogc       |to hijack the pure system
                   |functions                   |

--- Comment #3 from greensunny12@gmail.com ---
For @nogc and nothrow there's already an open issue:

https://issues.dlang.org/show_bug.cgi?id=12647

The other looks like a recent regression (so I am changing the title).

--
June 10, 2017
https://issues.dlang.org/show_bug.cgi?id=17486

--- Comment #4 from Eyal <eyal@weka.io> ---
The solution, clearly is to treat "lazy" is mere syntactic sugar to passing delegates - thus adding syntactic support for @nogc/etc attribute annotation on "lazy" parameters - and specifying their attributes just like is done for delegates.

The assumption that lazy parameters are all pure is wrong (thus this ticket).
The assumption that lazy parameters are all gc/throw is wrong (thus the other
ticket).

It *cannot* be inferred unless lazy parameters make everything a template, which would be unfortunate. Just like delegate parameter attributes cannot be inferred  - you have to manually specify them or templatize over the delegate type.

--
December 13
https://issues.dlang.org/show_bug.cgi?id=17486

--- Comment #5 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17797

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--