Fixing cyclic import static construction problems

Walter Bright newshound2 at digitalmars.com
Thu Nov 29 14:39:48 PST 2012


On 11/29/2012 11:58 PM, Manfred Nowak wrote:
> This is sufficient only for a simple cycle without any branches
> or a trivial clique like the one shown. Please recall, that in a
> clique every member is connected to every other member---in this
> case by an import statement.
>
> It is already not sufficient for a simple clique consisting of
> three modules, because now orderinh would be given for the
> remaining two modules.

If you have:

    a imports b,c
    b imports a,c
    c imports a,b

then two of those will need the pragma, that is correct. I don't see an 
issue with that, because there are two cycles.

> And it is ambiguous if both of the modules in the example given
> are marked with that pragma.

If:

    a imports b
    b imports a

and a has the pragma, then the order of construction is a,b. If both 
have the pragma, then the order is a,b or b,a, yes, it is ambiguous, but 
it is not an error. One gets picked arbitrarily.


> In general a topological sorting has to be specified for all
> strongly connected components of the graph of imports.

I believe that the pragma does that.

> This cannot be done within the module, because this would bind
> the module to that special strongly connected component in that
> special set of  modules. Which in turn would destroy reusability
> of the module for other programming tasks.

I just don't see the problem.



More information about the Digitalmars-d mailing list