changeset 1309:0c03ba6f7c24

Fixed deal breaker bug for more-at-once compilation when any module contained aggregates. Fixes ticket #272 .
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Thu, 07 May 2009 02:10:29 +0200
parents 316e9ecfeb7d
children 09c79cae1b86
files dmd/declaration.c dmd/declaration.h gen/classes.cpp gen/structs.cpp ir/irtypeclass.cpp ir/irtypestruct.cpp ir/irvar.cpp ir/irvar.h
diffstat 8 files changed, 54 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/declaration.c	Wed May 06 20:29:27 2009 +0200
+++ b/dmd/declaration.c	Thu May 07 02:10:29 2009 +0200
@@ -624,10 +624,15 @@
     canassign = 0;
     value = NULL;
 
+#if IN_LLVM
+    aggrIndex = 0;
+
     // LDC
     anonDecl = NULL;
     offset2 = 0;
+
     nakedUse = false;
+#endif
 }
 
 Dsymbol *VarDeclaration::syntaxCopy(Dsymbol *s)
--- a/dmd/declaration.h	Wed May 06 20:29:27 2009 +0200
+++ b/dmd/declaration.h	Thu May 07 02:10:29 2009 +0200
@@ -290,9 +290,15 @@
     /// Codegen traversal
     virtual void codegen(Ir* ir);
 
-    // LDC
+    /// Index into parent aggregate.
+    /// Set during type generation.
+    unsigned aggrIndex;
+
+    // FIXME: we're not using these anymore!
     AnonDeclaration* anonDecl;
     unsigned offset2;
+
+    /// This var is used by a naked function.
     bool nakedUse;
 #endif
 };
--- a/gen/classes.cpp	Wed May 06 20:29:27 2009 +0200
+++ b/gen/classes.cpp	Thu May 07 02:10:29 2009 +0200
@@ -53,6 +53,18 @@
     IrStruct* irstruct = new IrStruct(cd);
     cd->ir.irStruct = irstruct;
 
+    // make sure all fields really get their ir field
+    ArrayIter<VarDeclaration> it(cd->fields);
+    for (; !it.done(); it.next())
+    {
+        VarDeclaration* vd = it.get();
+        if (vd->ir.irField == NULL) {
+            new IrField(vd);
+        } else {
+            IF_LOG Logger::println("class field already exists!!!");
+        }
+    }
+
     bool needs_def = mustDefineSymbol(cd);
 
     // emit the ClassZ symbol
--- a/gen/structs.cpp	Wed May 06 20:29:27 2009 +0200
+++ b/gen/structs.cpp	Thu May 07 02:10:29 2009 +0200
@@ -44,6 +44,18 @@
     IrStruct* irstruct = new IrStruct(sd);
     sd->ir.irStruct = irstruct;
 
+    // make sure all fields really get their ir field
+    ArrayIter<VarDeclaration> it(sd->fields);
+    for (; !it.done(); it.next())
+    {
+        VarDeclaration* vd = it.get();
+        if (vd->ir.irField == NULL) {
+            new IrField(vd);
+        } else {
+            IF_LOG Logger::println("struct field already exists!!!");
+        }
+    }
+
     // perform definition
     bool needs_def = mustDefineSymbol(sd);
     if (needs_def)
--- a/ir/irtypeclass.cpp	Wed May 06 20:29:27 2009 +0200
+++ b/ir/irtypeclass.cpp	Thu May 07 02:10:29 2009 +0200
@@ -159,22 +159,8 @@
         offset = vd->offset + vd->type->size();
 
         // create ir field
-        if (vd->ir.irField == NULL)
-            new IrField(vd, field_index);
-        else
-            assert(vd->ir.irField->index == field_index &&
-                vd->ir.irField->unionOffset == 0 &&
-                "inconsistent field data");
-        field_index++;
-    }
-
-    // make sure all fields really get their ir field
-    ArrayIter<VarDeclaration> it(base->fields);
-    for (; !it.done(); it.next())
-    {
-        VarDeclaration* vd = it.get();
-        if (vd->ir.irField == NULL)
-            new IrField(vd, 0, vd->offset);
+        vd->aggrIndex = (unsigned)field_index;
+        ++field_index;
     }
 
     // any interface implementations?
--- a/ir/irtypestruct.cpp	Wed May 06 20:29:27 2009 +0200
+++ b/ir/irtypestruct.cpp	Thu May 07 02:10:29 2009 +0200
@@ -208,14 +208,8 @@
         // advance offset to right past this field
         offset = vd->offset + vd->type->size();
 
-        // create ir field
-        if (vd->ir.irField == NULL)
-            new IrField(vd, field_index);
-        else
-            assert(vd->ir.irField->index == field_index &&
-                vd->ir.irField->unionOffset == 0 &&
-                "inconsistent field data");
-        field_index++;
+        // set the field index
+        vd->aggrIndex = (unsigned)field_index++;
     }
 
     // tail padding?
@@ -224,15 +218,6 @@
         add_zeros(defaultTypes, sd->structsize - offset);
     }
 
-    // make sure all fields really get their ir field
-    ArrayIter<VarDeclaration> it(sd->fields);
-    for (; !it.done(); it.next())
-    {
-        VarDeclaration* vd = it.get();
-        if (vd->ir.irField == NULL)
-            new IrField(vd, 0, vd->offset);
-    }
-
     // build the llvm type
     const llvm::Type* st = llvm::StructType::get(defaultTypes, packed);
 
--- a/ir/irvar.cpp	Wed May 06 20:29:27 2009 +0200
+++ b/ir/irvar.cpp	Thu May 07 02:10:29 2009 +0200
@@ -36,14 +36,22 @@
 //////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////
 
-IrField::IrField(VarDeclaration* v, size_t idx, size_t offset) : IrVar(v)
+IrField::IrField(VarDeclaration* v) : IrVar(v)
 {
-    index = idx;
-    unionOffset = offset;
-    constInit = NULL;
-
     assert(V->ir.irField == NULL && "field for this variable already exists");
     V->ir.irField = this;
+
+    if (v->aggrIndex)
+    {
+        index = v->aggrIndex;
+        unionOffset = 0;
+    }
+    else
+    {
+        index = 0;
+        unionOffset = v->offset;
+    }
+    constInit = NULL;
 }
 
 extern LLConstant* get_default_initializer(
--- a/ir/irvar.h	Wed May 06 20:29:27 2009 +0200
+++ b/ir/irvar.h	Thu May 07 02:10:29 2009 +0200
@@ -34,7 +34,7 @@
 // represents an aggregate field variable
 struct IrField : IrVar
 {
-    IrField(VarDeclaration* v, size_t idx, size_t offset = 0);
+    IrField(VarDeclaration* v);
 
     unsigned index;
     unsigned unionOffset;