digitalmars.D.learn - 2.058 broke my build. Is this a bug?
- Caligo <iteronvexor gmail.com> Feb 23 2012
- Dmitry Olshansky <dmitry.olsh gmail.com> Feb 24 2012
- Caligo <iteronvexor gmail.com> Feb 24 2012
- James Miller <james aatch.net> Feb 24 2012
- Caligo <iteronvexor gmail.com> Feb 24 2012
- Caligo <iteronvexor gmail.com> Feb 24 2012
----------------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
--f46d040891eb68b08804b9c0dc3f Content-Type: text/plain; charset=UTF-8 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 shorter
----------------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
{ 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. --f46d040891eb68b08804b9c0dc3f Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <p>On Feb 25, 2012 12:16 PM, "Caligo" <<a href=3D"mailto:itero= nvexor gmail.com">iteronvexor gmail.com</a>> wrote:<br> ><br> > That was a typo, and it doesn't change anything. =C2=A0Here is a s= horter version:<br> ><br> > ----------------8<----------------8<----------------<br> > import std.datetime;<br> > import std.stdio;<br> ><br> > struct A{<br> ><br> > =C2=A0auto fun(A a){ return 0; }<br> > }<br> ><br> > void bench(alias fun)(string msg, uint n =3D 1_000_000){<br> ><br> > =C2=A0auto b =3D benchmark!fun(n);<br> > =C2=A0writefln(" %s %s ms", msg, b[0].to!("msecs",= int));<br> > }<br> ><br> > unittest{<br> ><br> > =C2=A0A a, b;<br> ><br> > =C2=A0void test1(){<br> > =C2=A0 =C2=A0auto r =3D a.fun(b);<br> > =C2=A0}<br> ><br> > =C2=A0bench!( {auto r =3D a.fun(b);} )("Does Not work");<br> > =C2=A0bench!(test1)("Works");<br> > }<br> ><br> > void main(){ }<br> > ---------------->8---------------->8----------------<br> ><br> ><br> ><br> > And here is the error:<br> ><br> > /usr/include/d/dmd/phobos/std/datetime.d(30986): Error: safe function<= br> > 'benchmark' cannot call system delegate '__lambda1'<br=
> t1.__unittest2.benchmark!(__lambda1) error instantiating<br> > t1.d(23): =C2=A0 =C2=A0 =C2=A0 =C2=A0instantiated from here: bench!(de= legate system void()<br> > {<br> > int r =3D a.fun(b);<br> > }<br> > )<br> > t1.d(23): Error: template instance t1.__unittest2.bench!(delegate sys= tem void()<br> > {<br> > int r =3D a.fun(b);<br> > }<br> > ) error instantiating</p> <p>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.</p> --f46d040891eb68b08804b9c0dc3f--
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









Dmitry Olshansky <dmitry.olsh gmail.com> 