December 10, 2013
On Tuesday, December 10, 2013 08:41:25 Joseph Rushton Wakeling wrote:
> On 10/12/13 06:33, Jonathan M Davis wrote:
> > It's still essentially a singleton - it's just that it's a single instance per thread in that case instead of per program. And you avoid all of the threading-related initialization issues with singletons if it's thread-local. Just check whether it's null, initialize it if it is (leave it alone if it isn't), and then do whatever you're going to do with it.
> 
> So for example the below code as an rndGen where Random is a class, not a struct?

Yeah. Something like that.

> I think I was misled by the "Only const or immutable ..." part of the error message: I'd assumed that any class that actually modified its internal state would be disallowed as a static instance.

It's a matter of what you can directly initialize a non-local variable with. Module-level variables, static variables, and member variables all have to be known at compile time, and you can't have a mutable class instance being constructed at compile time and then kept around until runtime.

- Jonathan M Davis
December 10, 2013
On 10/12/13 08:44, Jonathan M Davis wrote:
> Yeah. Something like that.

What I like is that it actually comes out slightly nicer than the existing code -- you don't need an extra static boolean to check if the RNG has been initialized.  This experience is proving typical of class-based RNG and RNG-dependent code so far.

>> I think I was misled by the "Only const or immutable ..." part of the error
>> message: I'd assumed that any class that actually modified its internal
>> state would be disallowed as a static instance.
>
> It's a matter of what you can directly initialize a non-local variable with.
> Module-level variables, static variables, and member variables all have to be
> known at compile time, and you can't have a mutable class instance being
> constructed at compile time and then kept around until runtime.

That's obvious in retrospect but not on the basis of the error message:

    Error: variable std.random2.generator.rndGen.result is mutable. Only const or immutable class thread local variable are allowed, not std.random2.generator.MersenneTwisterEngine!(uint, 32, 624, 397, 31, 2567483615u, 11, 4294967295u, 7, 2636928640u, 15, 4022730752u, 18, 1812433253u).MersenneTwisterEngine

Would this be better?

    Cannot initialize thread-local class variable %s with a mutable value.  Only
    const or immutable initial values are allowed (e.g. null).
December 10, 2013
On Tuesday, December 10, 2013 09:13:12 Joseph Rushton Wakeling wrote:
> On 10/12/13 08:44, Jonathan M Davis wrote:
> > It's a matter of what you can directly initialize a non-local variable with. Module-level variables, static variables, and member variables all have to be known at compile time, and you can't have a mutable class instance being constructed at compile time and then kept around until runtime.
> 
> That's obvious in retrospect but not on the basis of the error message:
> 
>      Error: variable std.random2.generator.rndGen.result is mutable. Only
> const or immutable class thread local variable are allowed, not
> std.random2.generator.MersenneTwisterEngine!(uint, 32, 624, 397, 31,
> 2567483615u, 11, 4294967295u, 7, 2636928640u, 15, 4022730752u, 18,
> 1812433253u).MersenneTwisterEngine

A lot of dmd's error messages aren't great.

> Would this be better?
> 
>      Cannot initialize thread-local class variable %s with a mutable value.
> Only const or immutable initial values are allowed (e.g. null).

That would be better.

- Jonathan M Davis
December 10, 2013
On 10/12/13 09:27, Jonathan M Davis wrote:
> A lot of dmd's error messages aren't great.
>
>> Would this be better?
>>
>>       Cannot initialize thread-local class variable %s with a mutable value.
>> Only const or immutable initial values are allowed (e.g. null).
>
> That would be better.

https://github.com/D-Programming-Language/dmd/pull/2943

I can also add a bugzilla issue if you like, but maybe seems overkill ... ?

December 10, 2013
On Tuesday, 10 December 2013 at 09:50:56 UTC, Joseph Rushton Wakeling wrote:
> On 10/12/13 09:27, Jonathan M Davis wrote:
>> A lot of dmd's error messages aren't great.
>>
>>> Would this be better?
>>>
>>>      Cannot initialize thread-local class variable %s with a mutable value.
>>> Only const or immutable initial values are allowed (e.g. null).
>>
>> That would be better.
>
> https://github.com/D-Programming-Language/dmd/pull/2943
>
> I can also add a bugzilla issue if you like, but maybe seems overkill ... ?

The changelog is partially generated from Bugzilla issues. That was the main reason to also add issues for pull request, afaik.
December 10, 2013
On Tuesday, 10 December 2013 at 09:50:56 UTC, Joseph Rushton
Wakeling wrote:
> On 10/12/13 09:27, Jonathan M Davis wrote:
>> A lot of dmd's error messages aren't great.
>>
>>> Would this be better?
>>>
>>>      Cannot initialize thread-local class variable %s with a mutable value.
>>> Only const or immutable initial values are allowed (e.g. null).
>>
>> That would be better.
>
> https://github.com/D-Programming-Language/dmd/pull/2943
>
> I can also add a bugzilla issue if you like, but maybe seems overkill ... ?

The changelog is partially generated from Bugzilla issues. That
was the main reason to also add issues for pull request, afaik.
December 10, 2013
On 10/12/13 11:31, qznc wrote:
> The changelog is partially generated from Bugzilla issues. That was the main
> reason to also add issues for pull request, afaik.

Fair enough :-)

https://d.puremagic.com/issues/show_bug.cgi?id=11714
1 2
Next ›   Last »