digitalmars.D.learn - 2.058 broke my build. Is this a bug?
- Caligo (34/34) Feb 23 2012 ----------------8<----------------8<----------------
- Dmitry Olshansky (8/42) Feb 24 2012 I guess that should be
- Caligo (36/36) Feb 24 2012 That was a typo, and it doesn't change anything. Here is a shorter vers...
- James Miller (5/41) Feb 24 2012 void()
- Caligo (3/5) Feb 24 2012 Is there another workaround than the one I've posted?
- Caligo (1/1) Feb 24 2012 I found another workaround: mark the module as trusted.
----------------8<----------------8<---------------- 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(){ } ---------------->8---------------->8---------------- 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
Feb 23 2012
On 24.02.2012 10:28, Caligo wrote:----------------8<----------------8<---------------- 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(){ } ---------------->8---------------->8---------------- 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
Feb 24 2012
That was a typo, and it doesn't change anything. Here is a shorter version: ----------------8<----------------8<---------------- 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(){ } ---------------->8---------------->8---------------- 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
Feb 24 2012
On Feb 25, 2012 12:16 PM, "Caligo" <iteronvexor gmail.com> wrote:That was a typo, and it doesn't change anything. Here is a shorterversion:----------------8<----------------8<---------------- 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(){ } ---------------->8---------------->8---------------- 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 systemvoid(){ int r = a.fun(b); } ) error instantiatingHmm 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.
Feb 24 2012
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 <james 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.
Feb 24 2012
I found another workaround: mark the module as trusted.
Feb 24 2012