can we detect at compile time module ctor/dtor cycles ?

Timothee Cour thelastmammoth at gmail.com
Fri Jun 7 23:23:25 PDT 2013


Why can't we detect at compile time module ctor/dtor cycles (instead of
runtime) ?
See example below.

It should be easy to detect the chain at CT:

algo:
build graph from import dependencies a=>b if module a imports module b.
mark as red the modules that have a ctor
collapse each non-red node into its parent (and update parent's edges)
detect cycles (eg BFS)

(same with dtor)


----
a1:
import a2;
void main(){}
static this(){}


a2:
import a3;
static this(){}

a3:
import a1;
----

rdmd --force --build-only -oftest a1 #works
./test #error:
object.Exception at src/rt/minfo.d(243): Aborting: Cycle detected between
modules with ctors/dtors:
a1 -> a2 -> a3 -> a1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130607/188ea715/attachment.html>


More information about the Digitalmars-d-learn mailing list