Argh!! Cyclic dependencies!!!
Michel Fortin
michel.fortin at michelf.com
Fri Mar 18 17:03:15 PDT 2011
On 2011-03-18 19:24:41 -0400, Jason House <jason.james.house at gmail.com> said:
> Nick Sabalausky 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 module-level globals be treated like local variables to the
> static constructor for the purpose of checking purity?
>
> AKA
> static this() pure
> {
> // trivial stuff
> // calls weakly pure functions
> // writes module-level globals
> // reads module-level globals
> // etc...
> }
>
>
> That's compiler enforceable and effectively means that stati
> constructor does not count as part of a cyclic dependency...
That would work nicely, except for one thing: static constructors can
be used to build immutable global variables. And pure functions have
access to immutable global variables. This means two things:
1. purity isn't really guarantied for pure functions inside a module
constructor
2. pure functions could access immutable global variables of other
modules before their initialization
I think the pragma is a more viable solution, athough not very elegant.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list