OK, I found a bug in the cycle detection.

For some reason, the module cycle detection has a weird rule where if a module 
has no static ctors/dtors, it skips cycle detection on its immediate 
dependencies.  Here is a test case where the cycle detection fails, and the 
results:

mod1.d:

public import mod2;
public import mod3;
private import std.stdio;

void main()
{
   writefln("x = %d, y = %d", x, y);
}

mod2.d:
import mod1;

__gshared int x;

static this()
{
   version(xfirst)
      x = 1;
   else
      x = y;
}

mod3.d:
import mod1;

__gshared int y;

static this()
{
   version(xfirst)
      y = x;
   else
      y = 1;
}

the results:
[ste...@steveslaptop testmodules]$ dmd -version=xfirst mod1.d mod2.d mod3.d 
-ofxfirst
[ste...@steveslaptop testmodules]$ dmd mod1.d mod2.d mod3.d -ofyfirst
[ste...@steveslaptop testmodules]$ ./xfirst
x = 1, y = 1
[ste...@steveslaptop testmodules]$ ./yfirst
x = 0, y = 1

And yes, I did apply Don's fix to the module constructor.  What I'm trying to 
understand is the logic behind the "skip" flag that implements this "feature".  
There seems to be no explanation for it.

Also, while I have your attention on this, what triggers the compiler to set 
the MIstandalone flag?

I don't mind fixing these problems, but I want to understand the logic behind 
it first.

-Steve



----- Original Message ----
> From: Steve Schveighoffer <[email protected]>
> To: Discuss the phobos library for D <[email protected]>
> Sent: Tue, June 22, 2010 9:24:54 AM
> Subject: Re: [phobos] Proposed feature: print cycle when a module cyclic 
> dependency is detected
> 
> I just realized that this patch isn't good enough (it does not print modules 
> which have no constructors/destructors but which import other modules), I'm 
> working on a better one.

But it's definitely possible.  So assume I 
> will have a patch shortly, does the concept seem 
> worthy?

-Steve



----- Original Message ----
> From: 
> Steve Schveighoffer <
> href="mailto:[email protected]";>[email protected]>
> To: Phobos 
> <
> href="mailto:[email protected]";>[email protected]>
> Sent: 
> Tue, June 22, 2010 8:59:23 AM
> Subject: [phobos] Proposed feature: print 
> cycle when a module cyclic dependency is detected
> 
> Hi 
> all,

Recently, I had an issue when developing std.process.  I 
> 
> inadvertently caused a cyclic dependency in modules.  However, the 
> error 
> was not enough to find the problem:

object.Exception: 
> Cyclic dependency 
> in module std.stdio

The problem is, this is 
> the *end* of the cycle, not 
> the source.  I actually hadn't changed 
> the imports of std.stdio.

So 
> I improved the module constructor 
> function to automatically print all modules 
> involved in the cycle, in 
> the order they were imported.  Attached is the 
> patch.  The 
> function should not adversely affect the runtime in normal 
> operation, 
> since the changes I made only occur when a terminating exception is 
> 
> about to be thrown anyways.  Do people agree this is a worthy improvement 
> 
> to the runtime?  Anyone see any issues with the patch? If everyone 
> likes, 
> I'll commit.

-Steve


      
> 
_______________________________________________
phobos mailing list

> ymailto="mailto:[email protected]"; 
> href="mailto:[email protected]";>[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos


      
_______________________________________________
phobos mailing list
[email protected]
http://lists.puremagic.com/mailman/listinfo/phobos

Reply via email to