Re: 2.058 broke my build. Is this a bug?
On 24.02.2012 10:28, Caligo wrote: 88 import std.datetime : benchmark; import std.stdio : writefln; struct A(int r, int c){ public: alias float[r * c] Data; Data _data; auto opBinary(A a){ float t; foreach(i; 0..r*c) foreach(j; 0..r*c) t += this[i,j]; I guess that should be foreach(i; 0..r) foreach(j; 0..c) t += this[i,j]; since you do row/col multiplication in opIndex? return a; } pure float opIndex(size_t rr, size_t cc = 0) const{ return _data[cc + rr * c]; } pure ref float opIndex(size_t rr, size_t cc = 0){ return _data[cc + rr * c]; } } void bench(alias fun)(string msg, uint n = 1_000_000){ auto b = benchmark!fun(n); writefln( %s %s ms, msg, b[0].to!(msecs, int)); } unittest{ alias A!(3, 3) AA; AA a; bench!( {auto r = a * a;})(broken); } void main(){ } 88 Other parts of my code using bench() works fine, except in rare cases. So I'm guessing this is a bug? I can't tell if it's in DMD or std.datetime. Can anyone help? I will bug report myself tomorrow if it turns out to be a bug for sure. DMD 2.058, 64-bit GNU/Linux -- Dmitry Olshansky
Re: 2.058 broke my build. Is this a bug?
That was a typo, and it doesn't change anything. Here is a shorter version: 88 import std.datetime; import std.stdio; struct A{ auto fun(A a){ return 0; } } void bench(alias fun)(string msg, uint n = 1_000_000){ auto b = benchmark!fun(n); writefln( %s %s ms, msg, b[0].to!(msecs, int)); } unittest{ A a, b; void test1(){ auto r = a.fun(b); } bench!( {auto r = a.fun(b);} )(Does Not work); bench!(test1)(Works); } void main(){ } 88 And here is the error: /usr/include/d/dmd/phobos/std/datetime.d(30986): Error: safe function 'benchmark' cannot call system delegate '__lambda1' t1.d(11): Error: template instance t1.__unittest2.benchmark!(__lambda1) error instantiating t1.d(23):instantiated from here: bench!(delegate @system void() { int r = a.fun(b); } ) t1.d(23): Error: template instance t1.__unittest2.bench!(delegate @system void() { int r = a.fun(b); } ) error instantiating
Re: 2.058 broke my build. Is this a bug?
On Feb 25, 2012 12:16 PM, Caligo iteronve...@gmail.com wrote: That was a typo, and it doesn't change anything. Here is a shorter version: 88 import std.datetime; import std.stdio; struct A{ auto fun(A a){ return 0; } } void bench(alias fun)(string msg, uint n = 1_000_000){ auto b = benchmark!fun(n); writefln( %s %s ms, msg, b[0].to!(msecs, int)); } unittest{ A a, b; void test1(){ auto r = a.fun(b); } bench!( {auto r = a.fun(b);} )(Does Not work); bench!(test1)(Works); } void main(){ } 88 And here is the error: /usr/include/d/dmd/phobos/std/datetime.d(30986): Error: safe function 'benchmark' cannot call system delegate '__lambda1' t1.d(11): Error: template instance t1.__unittest2.benchmark!(__lambda1) error instantiating t1.d(23):instantiated from here: bench!(delegate @system void() { int r = a.fun(b); } ) t1.d(23): Error: template instance t1.__unittest2.bench!(delegate @system void() { int r = a.fun(b); } ) error instantiating Hmm it seems that the delegate is being implicitly marked as system, and im not sure why benchmark is @safe. I'd say file a bug report.
Re: 2.058 broke my build. Is this a bug?
Is there another workaround than the one I've posted? http://d.puremagic.com/issues/show_bug.cgi?id=7577 On Fri, Feb 24, 2012 at 8:44 PM, James Miller ja...@aatch.net wrote: Hmm it seems that the delegate is being implicitly marked as system, and im not sure why benchmark is @safe. I'd say file a bug report.
Re: 2.058 broke my build. Is this a bug?
I found another workaround: mark the module as trusted.
2.058 broke my build. Is this a bug?
88 import std.datetime : benchmark; import std.stdio : writefln; struct A(int r, int c){ public: alias float[r * c] Data; Data _data; auto opBinary(A a){ float t; foreach(i; 0..r*c) foreach(j; 0..r*c) t += this[i,j]; return a; } pure float opIndex(size_t rr, size_t cc = 0) const{ return _data[cc + rr * c]; } pure ref float opIndex(size_t rr, size_t cc = 0){ return _data[cc + rr * c]; } } void bench(alias fun)(string msg, uint n = 1_000_000){ auto b = benchmark!fun(n); writefln( %s %s ms, msg, b[0].to!(msecs, int)); } unittest{ alias A!(3, 3) AA; AA a; bench!( {auto r = a * a;})(broken); } void main(){ } 88 Other parts of my code using bench() works fine, except in rare cases. So I'm guessing this is a bug? I can't tell if it's in DMD or std.datetime. Can anyone help? I will bug report myself tomorrow if it turns out to be a bug for sure. DMD 2.058, 64-bit GNU/Linux