order of static constructor execution

Don nospam at nospam.com
Fri Mar 12 04:17:18 PST 2010


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(nodep)" or "@nodep" for instance)? That has the same end 
>>> effect but for only a little more work, removes any non-determinism 
>>> and allows for easy control of how things are resolved.
>>
>> I agree. Seems to me that if a circular import exists, it's really 
>> something that the programmer needs to think about, and so it's 
>> reasonable for it to be explicit.
>>
>> A really harsh solution would be:
>>
>> pragma(nodependency, somepackage.somemodule);
>>
>> The compiler could check that somepackage.somemodule actually defines 
>> a static constructor. And it could even check that a circular import 
>> situation actually exists. This would force the pragma to be 
>> maintained correctly.
> 
> I think that the main problem comes from static initializers that are 
> mixed in and by themselves have no circular dependency. 

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.



More information about the Digitalmars-d mailing list