Re: Static constructors guaranteed to run?

2015-07-01 Thread via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 07:55:20 UTC, ketmar wrote: On Mon, 29 Jun 2015 17:22:17 +, Marc Schütz wrote: On Monday, 29 June 2015 at 11:36:42 UTC, ketmar wrote: it doesn't, afair, but it's quite natural. if user type was throwed out as unused, it would be very strange to insist on

Re: Static constructors guaranteed to run?

2015-07-01 Thread ketmar via Digitalmars-d-learn
On Wed, 01 Jul 2015 09:42:31 +, Marc Schütz wrote: The behaviour you expect makes more sense, for sure, but I was trying to guess what the current implementation might be doing without actually having to try it :-) ah, sorry. i was talking about the ideal case with ideal compiler, not

Re: Static constructors guaranteed to run?

2015-07-01 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 17:22:17 +, Marc Schütz wrote: On Monday, 29 June 2015 at 11:36:42 UTC, ketmar wrote: it doesn't, afair, but it's quite natural. if user type was throwed out as unused, it would be very strange to insist on keeping it's initialization code. Yes, but I would instead

Re: Static constructors guaranteed to run?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 29 June 2015 at 11:36:42 UTC, ketmar wrote: it doesn't, afair, but it's quite natural. if user type was throwed out as unused, it would be very strange to insist on keeping it's initialization code. Personally I would be kinda pissed if the compiler did this, I expect the static

Re: Static constructors guaranteed to run?

2015-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/26/15 6:00 PM, Tofu Ninja wrote: Also are static constructors in templated types guaranteed to run for every instantiation? I'd hazard to guess that the current compiler does run them, but that they probably aren't guaranteed to run by a sufficiently smart future compiler. Note, I

Re: Static constructors guaranteed to run?

2015-06-30 Thread via Digitalmars-d-learn
On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why? if instantiated template was not used in any code that makes into compiled binary, compiler

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 10:19:33 +, Marc Schütz wrote: On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why? if instantiated template was not

Re: Static constructors guaranteed to run?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why? if instantiated template was not used in any code that makes into compiled binary, compiler

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
p.s. also note that module can has several static ctors, i.e. this works fine: === z00.d === module z00; import std.stdio; static this () { writeln(ctor0); } static this () { writeln(ctor1); } === z01.d === module z01; import z00; void main () {} this prints: ctor0 ctor1 so you can

Re: Static constructors guaranteed to run?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 29 June 2015 at 02:31:18 UTC, ketmar wrote: yes. it doesn't do that now, afair, but i can't see any sense in running code that obviously does nothing, as it's owner is not used. module ctors was designed for such things -- i.e. to run some code on startup. if someone is doing some

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why? p.s. note that static ctors are *intended* to run in runtime, not in compile time. if compiler decides that some code is not required in runtime,

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 03:10:44 +, Tofu Ninja wrote: On Monday, 29 June 2015 at 02:31:18 UTC, ketmar wrote: yes. it doesn't do that now, afair, but i can't see any sense in running code that obviously does nothing, as it's owner is not used. module ctors was designed for such things -- i.e.

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why? if instantiated template was not used in any code that makes into compiled binary, compiler is free to remove it with all it's ctors. it may do

Re: Static constructors guaranteed to run?

2015-06-30 Thread ketmar via Digitalmars-d-learn
On Mon, 29 Jun 2015 02:19:54 +, Tofu Ninja wrote: On Monday, 29 June 2015 at 02:07:57 UTC, ketmar wrote: On Sat, 27 Jun 2015 22:49:13 +, Tofu Ninja wrote: On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why? if instantiated template was not

Re: Static constructors guaranteed to run?

2015-06-30 Thread via Digitalmars-d-learn
On Monday, 29 June 2015 at 11:36:42 UTC, ketmar wrote: it doesn't, afair, but it's quite natural. if user type was throwed out as unused, it would be very strange to insist on keeping it's initialization code. Yes, but I would instead expect that the static ctor prevents the type from

Re: Static constructors guaranteed to run?

2015-06-28 Thread via Digitalmars-d-learn
On Saturday, 27 June 2015 at 20:16:10 UTC, Timon Gehr wrote: On 06/27/2015 11:54 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: Also are static constructors in templated types guaranteed to run for every instantiation? Even if the instantiation is never actually used outside of

Re: Static constructors guaranteed to run?

2015-06-27 Thread via Digitalmars-d-learn
On Friday, 26 June 2015 at 22:00:54 UTC, Tofu Ninja wrote: Are static constructors guaranteed to run if the module is imported? AFAIK, yes. Also are static constructors in templated types guaranteed to run for every instantiation? Even if the instantiation is never actually used outside

Re: Static constructors guaranteed to run?

2015-06-27 Thread Timon Gehr via Digitalmars-d-learn
On 06/27/2015 11:54 AM, Marc =?UTF-8?B?U2Now7x0eiI=?= schue...@gmx.net wrote: Also are static constructors in templated types guaranteed to run for every instantiation? Even if the instantiation is never actually used outside of compile time code, like in an alias or in a UDA? Definitely

Re: Static constructors guaranteed to run?

2015-06-27 Thread ketmar via Digitalmars-d-learn
On Fri, 26 Jun 2015 22:00:51 +, Tofu Ninja wrote: Are static constructors guaranteed to run if the module is imported? Also are static constructors in templated types guaranteed to run for every instantiation? Even if the instantiation is never actually used outside of compile time code

Re: Static constructors guaranteed to run?

2015-06-27 Thread Tofu Ninja via Digitalmars-d-learn
On Saturday, 27 June 2015 at 22:20:40 UTC, ketmar wrote: 2. no. Hmm... any reason why?

Static constructors guaranteed to run?

2015-06-26 Thread Tofu Ninja via Digitalmars-d-learn
Are static constructors guaranteed to run if the module is imported? Also are static constructors in templated types guaranteed to run for every instantiation? Even if the instantiation is never actually used outside of compile time code, like in an alias or in a UDA?