www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 668] New: Use of *.di files breaks the order of static module construction

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

           Summary: Use of *.di files breaks the order of static module
                    construction
           Product: D
           Version: 0.176
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: kinaba is.s.u-tokyo.ac.jp


The spec says that "each module is assumed to depend on any
imported modules being statically constructed first" in module.html.
But when I use *.di interface files, the order seems broken.
Here is an example:

//credit goes to http://pc8.2ch.net/test/read.cgi/tech/1158013550/987
------- lib.d -------
bool initialized;
static this(){ initialized = true; } 
------- main.d -------
import lib;
import std.stdio;
void main(){ } 
static this(){ writefln("lib.initialized? ", lib.initialized); } 

 dmd -c -H lib.d   // generating lib.di
 dmd main.d lib.obj
 main
lib.initialized? false // wrong
 del lib.di        // deleteing b.di
 dmd main.d lib.obj
 main
lib.initialized? true // correct --
Dec 09 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668


fvbommel wxs.nl changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|Windows                     |All
            Version|0.176                       |0.177





The likely cause:
-----
urxae localhost:~/tmp$ cat lib.d
bool initialized;
static this(){ initialized = true; } 
urxae localhost:~/tmp$ dmd -H -c lib.d
urxae localhost:~/tmp$ cat lib.di
// D import file generated from 'lib.d'
bool initialized;
-----
The static constructor isn't present in the .di so the compiler doesn't see it
when compiling main.d.

Confirmed on dmd-0.177/Linux.


-- 
Dec 10 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668


kamm incasoftware.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kamm incasoftware.de





Indeed, when you change lib.di to show the existance of a static constructor:

lib.di
---
// D import file generated from 'lib.d'
bool initialized;
static this();
---

Then it'll work as expected. Confirmed on dmd 1.013.


-- 
Apr 25 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668


sean f4.ca changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sean f4.ca





*** Bug 1278 has been marked as a duplicate of this bug. ***


-- 
Jun 18 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668


clayasaurus gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clayasaurus gmail.com





This bug is blocking the Arc v.2 release. 


-- 
Jul 03 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668


deewiant gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |blocker





Raising severity in accordance with clayasaurus's comment.


-- 
Jul 03 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668






Strictly speaking, since there's a work around, it's not a blocker.  But it's
fairly serious so I'll leave it as is.


-- 
Jul 03 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668






I'm using a work-around for now and I am going to release Arc v.2, but I still
want this bug fixed! :)

Plus, this bug is high-severity for any DSSS installable software, because any
DSSS library that uses static ctors will be broken. 


-- 
Jul 16 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668


kamm incasoftware.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed in DMD 1.019 and 2.003. Thanks Walter!


-- 
Jul 23 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668


sean f4.ca changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |





I don't think this issue is completely resolved.  The compiler now generates a
"static this() {}" in the .di file whenever it seems a static ctor in the
module.  However, the presence of a complete but empty static ctor seems to
convince the compiler that they are available, inlinable and empty.  In some
instances, this causes errors like:

"filename.di(0): variable SOME_VARIABLE missing initializer in static
constructor for const variable"

This is preventing the Tango user library from compiling properly on 1.019 and
above for Linux/MacOS.

The solution seems to be generating "static this();" rather than the complete
"static this() {}".


-- 
Aug 06 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668






Please provide a test case.


-- 
Aug 06 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668






----
// Header.di

class Thread
{
    final char[] name();
    static const int PRIORITY_MIN;
    static const int PRIORITY_MAX;
    static Thread getThis();
    static this(){}
}

----

// Main.d

private import Header;

class Main
{
    void go()
    {
        char[] threadName = Thread.getThis.name;
    }
}

----

C:\> dmd -c -inline -release Main.d


The crucial bit is to have -inline and -release set.  Clearing either of these
eliminated the problem.


-- 
Aug 06 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=668


braddr puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED





Fixed in 1.022/2.005


-- 
Oct 20 2007