Thread overview
Compiling phobos with -cov
Jun 26, 2006
Don Clugston
Jun 26, 2006
BCS
Jun 26, 2006
kris
Jun 26, 2006
Deewiant
June 26, 2006
Has anyone had any success in compiling phobos with -cov -unittest?
Using DMD 0.161 - Windows, it compiles without warnings, but running the executable just prints:

C:\dmd\src\phobos>dmd -cov -unittest unittest
c:\dmd\bin\..\..\dm\bin\link.exe unittest,,,user32+kernel32/noi;

C:\dmd\src\phobos>unittest
Error: circular initialization dependency with module object


Am I doing something wrong?
(I copied my phobos.lib into dmd\lib to overwrite the existing one).
June 26, 2006
Don Clugston wrote:
> Has anyone had any success in compiling phobos with -cov -unittest?
> Using DMD 0.161 - Windows, it compiles without warnings, but running the executable just prints:
> 
> C:\dmd\src\phobos>dmd -cov -unittest unittest
> c:\dmd\bin\..\..\dm\bin\link.exe unittest,,,user32+kernel32/noi;
> 
> C:\dmd\src\phobos>unittest
> Error: circular initialization dependency with module object
> 
> 
> Am I doing something wrong?
> (I copied my phobos.lib into dmd\lib to overwrite the existing one).

this is (I think) a known issue with dmd and circular imports. -cov adds a static constructor that somehow gets interpreted by the runtime as a link in a circular dependency. Until Walter fixes this (please oh please do this soon!!) the best thing I have considered is building with -cov on one or more modules (but not all) at a time.
June 26, 2006
BCS wrote:
> Don Clugston wrote:
> 
>> Has anyone had any success in compiling phobos with -cov -unittest?
>> Using DMD 0.161 - Windows, it compiles without warnings, but running the executable just prints:
>>
>> C:\dmd\src\phobos>dmd -cov -unittest unittest
>> c:\dmd\bin\..\..\dm\bin\link.exe unittest,,,user32+kernel32/noi;
>>
>> C:\dmd\src\phobos>unittest
>> Error: circular initialization dependency with module object
>>
>>
>> Am I doing something wrong?
>> (I copied my phobos.lib into dmd\lib to overwrite the existing one).
> 
> 
> this is (I think) a known issue with dmd and circular imports. -cov adds a static constructor that somehow gets interpreted by the runtime as a link in a circular dependency. Until Walter fixes this (please oh please do this soon!!) the best thing I have considered is building with -cov on one or more modules (but not all) at a time.

-cov adds a static-ctor to each module compiled in that manner (IIRC), and thus exposes a runtime issue where any of the relevant modules have circular imports.

Probably the only realistic way to fix this is to break the circle.

Don ~ I noticed that the new Win32 headers have a similar dilemma. Where large numbers of modules are concerned (e.g. Win32) I've found Dimple to be a real help in figuring out where the cycles are.
June 26, 2006
kris wrote:
> -cov adds a static-ctor to each module compiled in that manner (IIRC), and thus exposes a runtime issue where any of the relevant modules have circular imports.
> 
> Probably the only realistic way to fix this is to break the circle.
> 

I don't see why this is such a problem. Circular construction might be, yes --- each static constructor wanting to initialise something which needs the other module. Then, the compiler cannot know which should be initialised first.

However, usually, couldn't the compiler just pick one module and run its constructors first? If not, perhaps a feature could be added: the constructors could have a parameter corresponding to their priority --- highest priority is run first. The brackets in "static this()" are redundant as is, since there's never anything to put in them, so might as well put a number there and have it do something useful.

Or is there a deeper issue I'm ignorant of?