On Fri, 18 Mar 2011 17:42:58 -0400, Nick Sabalausky <[email protected]> wrote:

These module constructor "Cyclic dependencies" errors are really starting to
piss me off. I feel like I'm back in the days when you'd sneeze and DMD
would vomit out 100 forward reference errors just because you didn't write
your whole damn app in one giant ultra-module. (/me takes a breather to
chill out...Ok...)

I don't suppose there's any chance we could get a quick little:

import foo;

pragma(staticCtorsAvoid, foo);
// Or
pragma(staticCtorsRunBefore, foo);
// Or
pragma(staticCtorsRunAfter, foo);

static this()
{
    // do trivial shit that doesn't touch foo
}

Could we? I don't care which it is. I don't care if it doesn't enforce any safety at all. I don't care if it gets depricated in favor of an alternate
solution in a later version. I just need a way to say "this'll work, dmd,
just do it and quit yer damn whinin'!!" Doesn't need to be perfect, just
needs to work. At the very least, if I manage to be able to hack something
like that it in, would there be any chance of it getting accepted?

If you are interested, the code that runs the static ctors is in druntime, not the compiler. So you can turn off the errors if you want in your local copy of druntime.

FWIW, there is a "standalone" flag which allows you to skip cycle detection on that module. I'm not quite sure why the compiler sets that flag, but it has something to do with little modules created by the compiler itself. When I rewrote the cycle detection code, I used to have an idea of why, but it's faded from my memory.

In any case, I think you could do something repulsive like naming your module nodeps_x instead of x, and have the cycle detection skip over that module when detecting cycles. Bottom line is, there is no valid static data before static ctors run, so you must figure out how to get the info to the cycle detection routine without static data.

If we are changing the compiler, I'd like this:

@standalone module foo;

which would tell the compiler to set the standalone flag, no proof required. I don't think it's really possible to verify that a static ctor does not depend on outside data without full analysis which isn't currently possible.

-Steve

Reply via email to