www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2457] New: Detecting circular module dependencies at compile time

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2457

           Summary: Detecting circular module dependencies at compile time
           Product: D
           Version: 1.036
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: dhasenan gmail.com


I've been getting a lot of runtime errors about circular module dependencies.
It'd save me some time if the compiler could detect at least some of these. The
runtime doesn't have a chance of giving a reasonable error message, but the
compiler could. At the very least, it'd save some time.


-- 
Nov 15 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2457






Without example code it is unlikely that this will get fixed. Add the code
which is failing and include the compilation options you are using. Extra
points will be awarded for making the failing code as short as possible.


-- 
Nov 16 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2457






====[a.d]====
module a;
import b;
static this(){}
void main(){}

====[b.d]====
module b;
import a;
static this(){}

====[Command line]====
$ rebuild a
$ ./a
object.Exception: Cyclic dependency in module a
$

Pretty short.

It makes no sense that the compiler would output an executable that will always
cause a runtime error.  The compiler knows that there is a circular module
dependency, and should be able to issue an error at compile time.

Note, however, that in this case there _is_ no circular dependency.  Even
though the modules are circularly imported and both have static constructors,
the static constructors do not depend on the other module.  This _should_ be
legal, at least semantically.  That the program issues an error means that the
compiler and runtime aren't doing a whole lot of analysis to determine that
there is a cyclic dependency.  It's a false positive.


-- 
Nov 16 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2457


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com





An interesting concept.  The only reason I can see for this being a runtime
failure is that the module dependencies are analysed at runtime to determine
the order in which to run static constructors.  But why?

This process should be in the compile time.  Then not only can it report any
circular dependency problems during compilation, but it can also attempt to
resolve any apparent circularity by examining what the static constructor
itself depends on (directly or indirectly).


-- 
Nov 16 2008