[phobos] Proposed feature: print cycle when a module cyclic dependency is detected

Steve Schveighoffer schveiguy at yahoo.com
Tue Jun 22 06:57:41 PDT 2010


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:
[steves at steveslaptop testmodules]$ dmd -version=xfirst mod1.d mod2.d mod3.d -ofxfirst
[steves at steveslaptop testmodules]$ dmd mod1.d mod2.d mod3.d -ofyfirst
[steves at steveslaptop testmodules]$ ./xfirst
x = 1, y = 1
[steves at 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 <schveiguy at yahoo.com>
> To: Discuss the phobos library for D <phobos at puremagic.com>
> 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:schveiguy at yahoo.com">schveiguy at yahoo.com>
> To: Phobos 
> <
> href="mailto:phobos at puremagic.com">phobos at puremagic.com>
> 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:phobos at puremagic.com" 
> href="mailto:phobos at puremagic.com">phobos at puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos


      


More information about the phobos mailing list