Re: order of static constructor execution

2010-03-17 Thread Russell Lewis
Walter Bright wrote: So, I propose the following: 1. Attempt the depth-first traversal of the static constructors. 2. If a loop is detected, rather than issuing an error message, simply arbitrarily pick one order and continue constructing. I'm of the camp that "if it's broken, the programmer

Re: order of static constructor execution

2010-03-17 Thread Regan Heath
Walter Bright wrote: Regan Heath wrote: So, this needs to work when compiling modules seperately and then linking, likewise libraries, right? Is that the problem you're referring to? Yes. Couldn't you store a list of dependencies in usage order in the output of the compile (the .o[bj] file

Re: order of static constructor execution

2010-03-16 Thread Walter Bright
Regan Heath wrote: So, this needs to work when compiling modules seperately and then linking, likewise libraries, right? Is that the problem you're referring to? Yes. Couldn't you store a list of dependencies in usage order in the output of the compile (the .o[bj] file) and use these lists

Re: order of static constructor execution

2010-03-16 Thread Regan Heath
Walter Bright wrote: Regan Heath wrote: Walter Bright wrote: Regan Heath wrote: Walter Bright wrote: Regan Heath wrote: I expect this either isn't possible or falls into the 'possible up to a point' category. It's possible up to a point, that point being the parts of the program the comp

Re: order of static constructor execution

2010-03-15 Thread Walter Bright
Regan Heath wrote: Walter Bright wrote: Regan Heath wrote: Walter Bright wrote: Regan Heath wrote: I expect this either isn't possible or falls into the 'possible up to a point' category. It's possible up to a point, that point being the parts of the program the compiler does not see. S

Re: order of static constructor execution

2010-03-15 Thread Regan Heath
Walter Bright wrote: Regan Heath wrote: Walter Bright wrote: Regan Heath wrote: I expect this either isn't possible or falls into the 'possible up to a point' category. It's possible up to a point, that point being the parts of the program the compiler does not see. So.. isn't that the s

Re: order of static constructor execution

2010-03-15 Thread Walter Bright
Regan Heath wrote: Walter Bright wrote: Regan Heath wrote: I expect this either isn't possible or falls into the 'possible up to a point' category. It's possible up to a point, that point being the parts of the program the compiler does not see. So.. isn't that the same point the current

Re: order of static constructor execution

2010-03-15 Thread Regan Heath
Walter Bright wrote: Regan Heath wrote: I expect this either isn't possible or falls into the 'possible up to a point' category. It's possible up to a point, that point being the parts of the program the compiler does not see. So.. isn't that the same point the current import dependency me

Re: order of static constructor execution

2010-03-15 Thread Walter Bright
Regan Heath wrote: I expect this either isn't possible or falls into the 'possible up to a point' category. It's possible up to a point, that point being the parts of the program the compiler does not see.

Re: order of static constructor execution

2010-03-15 Thread Regan Heath
Walter Bright wrote: Doing lazy initialization certainly works, but it would require all static member access to go through a check for initialization, first. The cost of this check persists for a statically compiled language; for a JITted language like C# the access can be rewritten to remove

Re: order of static constructor execution

2010-03-14 Thread Leandro Lucarella
BCS, el 12 de marzo a las 04:43 me escribiste: > Hello Walter, > > >2. If a loop is detected, rather than issuing an error message, simply > >arbitrarily pick one order and continue constructing. > > How about a way to explicitly cut edges in the graph (tagging > imports with "pragma(nodep)" or "

Re: order of static constructor execution

2010-03-13 Thread Max Samukha
On 13.03.2010 2:27, Michel Fortin wrote: On 2010-03-12 19:10:10 -0500, Max Samukha said: If static constructors in templates ran during the initialization of the module where they are defined, the problem with mixed-in code could be solved like this: But templates can take function and types

Re: order of static constructor execution

2010-03-12 Thread Michel Fortin
On 2010-03-12 19:10:10 -0500, Max Samukha said: If static constructors in templates ran during the initialization of the module where they are defined, the problem with mixed-in code could be solved like this: But templates can take function and types as argument. If the 'static this' of a

Re: order of static constructor execution

2010-03-12 Thread Max Samukha
On 12.03.2010 23:03, Walter Bright wrote: BCS wrote: Random thought: Aside from making a new corner case, why not make static constructors in mixins only depend on imports from where they are defined rather than where they are used? Template mixins are intended to behave like macros - they ar

Re: order of static constructor execution

2010-03-12 Thread Walter Bright
BCS wrote: Hello Walter, Don wrote: If that's true, then perhaps a more restricted solution is better. Eg, use Walter's proposal ONLY if the static initializer is mixed in. I should note that all static constructors in a module are combined into one function. So, the mixin static initialize

Re: order of static constructor execution

2010-03-12 Thread Fawzi Mohamed
On 12-mar-10, at 19:17, Walter Bright wrote: Doing lazy initialization certainly works, but it would require all static member access to go through a check for initialization, first. The cost of this check persists for a statically compiled language; for a JITted language like C# the acces

Re: order of static constructor execution

2010-03-12 Thread BCS
Hello Walter, Don wrote: If that's true, then perhaps a more restricted solution is better. Eg, use Walter's proposal ONLY if the static initializer is mixed in. I should note that all static constructors in a module are combined into one function. So, the mixin static initializers are combi

Re: order of static constructor execution

2010-03-12 Thread Walter Bright
Don wrote: If that's true, then perhaps a more restricted solution is better. Eg, use Walter's proposal ONLY if the static initializer is mixed in. I should note that all static constructors in a module are combined into one function. So, the mixin static initializers are combined with any ot

Re: order of static constructor execution

2010-03-12 Thread Walter Bright
BCS wrote: Random thought: Aside from making a new corner case, why not make static constructors in mixins only depend on imports from where they are defined rather than where they are used? Template mixins are intended to behave like macros - they are instantiated in the context of where th

Re: order of static constructor execution

2010-03-12 Thread BCS
Hello Walter, Doing lazy initialization certainly works, but it would require all static member access to go through a check for initialization, first. The cost of this check persists for a statically compiled language; for a JITted language like C# the access can be rewritten to remove the chec

Re: order of static constructor execution

2010-03-12 Thread BCS
Hello Don, If that's true, then perhaps a more restricted solution is better. Eg, use Walter's proposal ONLY if the static initializer is mixed in. Random thought: Aside from making a new corner case, why not make static constructors in mixins only depend on imports from where they are define

Re: order of static constructor execution

2010-03-12 Thread Walter Bright
Doing lazy initialization certainly works, but it would require all static member access to go through a check for initialization, first. The cost of this check persists for a statically compiled language; for a JITted language like C# the access can be rewritten to remove the check.

Re: order of static constructor execution

2010-03-12 Thread Robert Clipsham
On 12/03/10 16:44, Robert Clipsham wrote: I don't know the full situation, or even if this will help, but maybe something like the following could help? a.d: module a; import b; Foo fooA; static this() { fooA = bar(); } b.d: module b; import a; class Foo { } Foo bar() { return

Re: order of static constructor execution

2010-03-12 Thread Robert Clipsham
On 12/03/10 02:42, Walter Bright wrote: Currently, it is performed as a strictly "depth-first" traversal of the graph defined by the import statements. As we've been discussing here, this works great until one has circular imports, meaning the depth-first graph has a loop in it. The current beha

Re: order of static constructor execution

2010-03-12 Thread Fawzi Mohamed
On 2010-03-12 15:05:25 +0100, Michel Fortin said: [...] Most mixins static constructors will probably have to be @cyclehead. Here is an example of a reasonable use case to clarify why I think that my proposal, or something like it is the correct solution. Often the static initializers like t

Re: order of static constructor execution

2010-03-12 Thread Michel Fortin
On 2010-03-11 21:42:47 -0500, Walter Bright said: Currently, it is performed as a strictly "depth-first" traversal of the graph defined by the import statements. As we've been discussing here, this works great until one has circular imports, meaning the depth-first graph has a loop in it. T

Re: order of static constructor execution

2010-03-12 Thread Don
Fawzi Mohamed wrote: On 12-mar-10, at 09:59, Don wrote: BCS wrote: Hello Walter, 2. If a loop is detected, rather than issuing an error message, simply arbitrarily pick one order and continue constructing. How about a way to explicitly cut edges in the graph (tagging imports with "pragma(no

Re: order of static constructor execution

2010-03-12 Thread Regan Heath
Walter Bright Wrote: > I'm not happy with this solution, but it seems to be the best compromise > I can come up with. > > What do you think? The first thought that occurred to me was "how this was handled in other languages". As C# is one of the more recent languages, and has some static cons

Re: order of static constructor execution

2010-03-12 Thread Jacob Carlborg
On 3/12/10 03:42, Walter Bright wrote: Currently, it is performed as a strictly "depth-first" traversal of the graph defined by the import statements. As we've been discussing here, this works great until one has circular imports, meaning the depth-first graph has a loop in it. The current behav

Re: order of static constructor execution

2010-03-12 Thread Fawzi Mohamed
On 12-mar-10, at 09:59, Don wrote: BCS wrote: Hello Walter, 2. If a loop is detected, rather than issuing an error message, simply arbitrarily pick one order and continue constructing. How about a way to explicitly cut edges in the graph (tagging imports with "pragma(nodep)" or "@nodep" f

Re: order of static constructor execution

2010-03-12 Thread Don
BCS wrote: Hello Walter, 2. If a loop is detected, rather than issuing an error message, simply arbitrarily pick one order and continue constructing. How about a way to explicitly cut edges in the graph (tagging imports with "pragma(nodep)" or "@nodep" for instance)? That has the same end e

Re: order of static constructor execution

2010-03-12 Thread Max Samukha
Andrei Alexandrescu wrote: It looks like a step backwards to me. Andrei What solution do you propose for problem 1?

Re: order of static constructor execution

2010-03-11 Thread Bob Jones
"Walter Bright" wrote in message news:hnc9n2$2tk...@digitalmars.com... > Currently, it is performed as a strictly "depth-first" traversal of the > graph defined by the import statements. As we've been discussing here, > this works great until one has circular imports, meaning the depth-first

Re: order of static constructor execution

2010-03-11 Thread Ellery Newcomer
On 03/11/2010 10:15 PM, Walter Bright wrote: Ellery Newcomer wrote: On 03/11/2010 08:42 PM, Walter Bright wrote: 2. Trying to analyze the static constructors to see what the dependencies actually are is fraught with unsolvable problems. could you elucidate on this point? Is it definitely im

Re: order of static constructor execution

2010-03-11 Thread BCS
Hello Walter, 2. If a loop is detected, rather than issuing an error message, simply arbitrarily pick one order and continue constructing. How about a way to explicitly cut edges in the graph (tagging imports with "pragma(nodep)" or "@nodep" for instance)? That has the same end effect but fo

Re: order of static constructor execution

2010-03-11 Thread Andrei Alexandrescu
On 03/11/2010 08:42 PM, Walter Bright wrote: Currently, it is performed as a strictly "depth-first" traversal of the graph defined by the import statements. As we've been discussing here, this works great until one has circular imports, meaning the depth-first graph has a loop in it. The current

Re: order of static constructor execution

2010-03-11 Thread Walter Bright
Ellery Newcomer wrote: On 03/11/2010 08:42 PM, Walter Bright wrote: 2. Trying to analyze the static constructors to see what the dependencies actually are is fraught with unsolvable problems. could you elucidate on this point? Is it definitely impossible to get a hold of a complete dag, eve

Re: order of static constructor execution

2010-03-11 Thread Ellery Newcomer
On 03/11/2010 08:42 PM, Walter Bright wrote: 2. Trying to analyze the static constructors to see what the dependencies actually are is fraught with unsolvable problems. could you elucidate on this point? Is it definitely impossible to get a hold of a complete dag, even if at runtime?

Re: order of static constructor execution

2010-03-11 Thread bearophile
Walter Bright: > 1. Attempt the depth-first traversal of the static constructors. > 2. If a loop is detected, rather than issuing an error message, simply > arbitrarily pick one order and continue constructing. Some alternative possibilities: - Issue a warning too? - Or allow that only if the cod

order of static constructor execution

2010-03-11 Thread Walter Bright
Currently, it is performed as a strictly "depth-first" traversal of the graph defined by the import statements. As we've been discussing here, this works great until one has circular imports, meaning the depth-first graph has a loop in it. The current behavior on detecting a loop is to quit wi