www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Cyclic dependency between module A and B

reply kdevel <kdevel vogtner.de> writes:
Recently (before refactoring) my application complained right 
after invocation:

    object.Error src/rt/minfo.d(371): Cyclic dependency between 
module Filebrowser and App
    Filebrowser* ->
    App* ->
    Filebrowser*

Is it possible to detect this dependency before the program is 
started?
Perhaps during linking?
Apr 10 2019
parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 4/10/19 2:52 PM, kdevel wrote:
 Recently (before refactoring) my application complained right after 
 invocation:
 
     object.Error src/rt/minfo.d(371): Cyclic dependency between module 
 Filebrowser and App
     Filebrowser* ->
     App* ->
     Filebrowser*
 
 Is it possible to detect this dependency before the program is started?
 Perhaps during linking?
Unfortunately not, because D supports separate compilation, and interface files (.di files). So the compiler can't necessarily know at compile time that there is a cycle. The suckiest part is that once it's compiled, and doesn't detect a cycle, it's never going to have a cycle -- yet we run the algorithm to detect it on every start up (we actually have to in order to properly sort the static ctors). I'd love to get rid of that penalty. -Steve
Apr 11 2019