order of static constructor execution

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Mar 11 20:25:35 PST 2010


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 behavior on detecting a loop is to quit with an error message.
>
> The problems are:
>
> 1. The cycles are not easily gotten rid of when they are the result of
> template mixins.
>
> 2. Trying to analyze the static constructors to see what the
> dependencies actually are is fraught with unsolvable problems.
>
>
> 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.
>
>
> The mitigating rationale is that modules that import each other are
> presumably written by the same person or team, and so that person is in
> the best place to explicitly control dependencies themselves.
>
>
> I'm not happy with this solution, but it seems to be the best compromise
> I can come up with.
>
> What do you think?

It looks like a step backwards to me.

Andrei



More information about the Digitalmars-d mailing list