summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2016-11-12 12:39:21 +0100
committerAraq <rumpf_a@web.de>2016-11-12 12:39:21 +0100
commitb234b082b60e57ec07a380599b6b7a311026d0ed (patch)
tree3634221a1ac40dd6c5469cc88e24d18104577efc
parent860cbd310793230ef911f2eca882b2cf873c20b1 (diff)
downloadNim-b234b082b60e57ec07a380599b6b7a311026d0ed.tar.gz
bootstrapping works again
-rw-r--r--compiler/ast.nim8
-rw-r--r--compiler/ccgtrav.nim13
-rw-r--r--compiler/ccgtypes.nim10
-rw-r--r--compiler/sighashes.nim23
4 files changed, 36 insertions, 18 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 8f4acfc3b..cd94efd41 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -1209,10 +1209,10 @@ proc newType*(kind: TTypeKind, owner: PSym): PType =
   result.lockLevel = UnspecifiedLockLevel
   when debugIds:
     registerId(result)
-  #if result.id == 92231:
-  #  echo "KNID ", kind
-  #  writeStackTrace()
-  #  messageOut(typeKindToStr[kind] & ' has id: ' & toString(result.id))
+  when false:
+    if result.id == 205734:
+      echo "KNID ", kind
+      writeStackTrace()
 
 proc mergeLoc(a: var TLoc, b: TLoc) =
   if a.k == low(a.k): a.k = b.k
diff --git a/compiler/ccgtrav.nim b/compiler/ccgtrav.nim
index a8c079b35..fbba19897 100644
--- a/compiler/ccgtrav.nim
+++ b/compiler/ccgtrav.nim
@@ -58,7 +58,6 @@ proc parentObj(accessor: Rope; m: BModule): Rope {.inline.} =
 proc genTraverseProc(c: var TTraversalClosure, accessor: Rope, typ: PType) =
   if typ == nil: return
 
-  let typ = getUniqueType(typ)
   var p = c.p
   case typ.kind
   of tyGenericInst, tyGenericBody, tyTypeDesc:
@@ -99,16 +98,18 @@ proc genTraverseProcSeq(c: var TTraversalClosure, accessor: Rope, typ: PType) =
   genTraverseProc(c, "$1->data[$2]" % [accessor, i.r], typ.sons[0])
   lineF(p, cpsStmts, "}$n", [])
 
-proc genTraverseProc(m: BModule, typ: PType, reason: TTypeInfoReason): Rope =
+proc genTraverseProc(m: BModule, origTyp: PType; sig: SigHash;
+                     reason: TTypeInfoReason): Rope =
   var c: TTraversalClosure
   var p = newProc(nil, m)
-  result = getTempName(m)
+  result = "Marker_" & getTypeName(m, origTyp, sig)
+  let typ = origTyp.skipTypes(abstractInst)
 
   case reason
   of tiNew: c.visitorFrmt = "#nimGCvisit((void*)$1, op);$n"
   else: assert false
 
-  let header = "N_NIMCALL(void, $1)(void* p, NI op)" % [result]
+  let header = "static N_NIMCALL(void, $1)(void* p, NI op)" % [result]
 
   let t = getTypeDesc(m, typ)
   lineF(p, cpsLocals, "$1 a;$n", [t])
@@ -119,7 +120,7 @@ proc genTraverseProc(m: BModule, typ: PType, reason: TTypeInfoReason): Rope =
   if typ.kind == tySequence:
     genTraverseProcSeq(c, "a".rope, typ)
   else:
-    if skipTypes(typ.sons[0], typedescInst).kind in {tyArrayConstr, tyArray}:
+    if skipTypes(typ.sons[0], typedescInst).kind == tyArray:
       # C's arrays are broken beyond repair:
       genTraverseProc(c, "a".rope, typ.sons[0])
     else:
@@ -145,7 +146,7 @@ proc genTraverseProcForGlobal(m: BModule, s: PSym): Rope =
 
   c.visitorFrmt = "#nimGCvisit((void*)$1, 0);$n"
   c.p = p
-  let header = "N_NIMCALL(void, $1)(void)" % [result]
+  let header = "static N_NIMCALL(void, $1)(void)" % [result]
   genTraverseProc(c, sLoc, s.loc.t)
 
   let generatedProc = "$1 {$n$2$3$4}$n" %
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index e9adddce2..49fd14003 100644
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -111,6 +111,10 @@ proc getTypeName(m: BModule; typ: PType; sig: SigHash): Rope =
   else:
     if typ.loc.r == nil:
       typ.loc.r = typ.typeName & $sig
+    else:
+      when defined(debugSigHashes):
+        # check consistency:
+        assert($typ.loc.r == $(typ.typeName & $sig))
     result = typ.loc.r
   if result == nil: internalError("getTypeName: " & $typ.kind)
 
@@ -593,7 +597,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
   of tyEnum:
     result = cacheGetType(m.typeCache, sig)
     if result == nil:
-      result = getTypeName(m, t, sig)
+      result = getTypeName(m, origTyp, sig)
       if not (isImportedCppType(t) or
           (sfImportc in t.sym.flags and t.sym.magic == mNone)):
         m.typeCache[sig] = result
@@ -730,7 +734,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
                     else: getTupleDesc(m, t, result, check)
       if not isImportedType(t): add(m.s[cfsTypes], recdesc)
   of tySet:
-    result = getTypeName(m, t.lastSon, hashType t.lastSon) & "Set"
+    result = getTypeName(m, t.lastSon, hashType t.lastSon) & "_Set"
     m.typeCache[sig] = result
     if not isImportedType(t):
       let s = int(getSize(t))
@@ -1066,7 +1070,7 @@ proc genTypeInfo(m: BModule, t: PType): Rope =
   of tySequence, tyRef:
     genTypeInfoAux(m, t, t, result)
     if gSelectedGC >= gcMarkAndSweep:
-      let markerProc = genTraverseProc(m, t, tiNew)
+      let markerProc = genTraverseProc(m, origType, sig, tiNew)
       addf(m.s[cfsTypeInit3], "$1.marker = $2;$n", [result, markerProc])
   of tyPtr, tyRange: genTypeInfoAux(m, t, t, result)
   of tyArrayConstr, tyArray: genArrayInfo(m, t, result)
diff --git a/compiler/sighashes.nim b/compiler/sighashes.nim
index 20194a6ea..bb34ff3d2 100644
--- a/compiler/sighashes.nim
+++ b/compiler/sighashes.nim
@@ -69,6 +69,9 @@ else:
   proc `&=`(c: var MD5Context, s: string) = md5Update(c, s, s.len)
   proc `&=`(c: var MD5Context, ch: char) = md5Update(c, unsafeAddr ch, 1)
 
+  template lowlevel(v) =
+    md5Update(c, cast[cstring](unsafeAddr(v)), sizeof(v))
+
   proc `==`*(a, b: SigHash): bool =
     # {.borrow.}
     result = equalMem(unsafeAddr a, unsafeAddr b, sizeof(a))
@@ -89,9 +92,6 @@ proc hashSym(c: var MD5Context, s: PSym) =
       it = it.owner
 
 proc hashTree(c: var MD5Context, n: PNode) =
-  template lowlevel(v) =
-    md5Update(c, cast[cstring](unsafeAddr(v)), sizeof(v))
-
   if n == nil:
     c &= "\255"
     return
@@ -155,7 +155,10 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
   of tyObject, tyEnum:
     # Every cyclic type in Nim need to be constructed via some 't.sym', so this
     # is actually safe without an infinite recursion check:
-    c.hashSym(t.sym)
+    if t.sym != nil:
+      c.hashSym(t.sym)
+    else:
+      lowlevel(t.id)
   of tyRef, tyPtr, tyGenericBody:
     c.hashType t.lastSon, flags
   of tyUserTypeClass:
@@ -182,7 +185,8 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
     else:
       for i in countup(0, sonsLen(t) - 1): c.hashType t.sons[i], flags
   of tyRange:
-    if CoType notin flags: c.hashTree(t.n)
+    #if CoType notin flags:
+    c.hashTree(t.n)
     c.hashType(t.sons[0], flags)
   of tyProc:
     c &= (if tfIterator in t.flags: "iterator " else: "proc ")
@@ -205,11 +209,20 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
     for i in 0.. <t.len: c.hashType(t.sons[i], flags)
   if tfNotNil in t.flags and CoType notin flags: c &= "not nil"
 
+when defined(debugSigHashes):
+  import db_sqlite
+
+  let db = open(connection="sighashes.db", user="araq", password="",
+                database="sighashes")
+
 proc hashType*(t: PType; flags: set[ConsiderFlag] = {CoType}): SigHash =
   var c: MD5Context
   md5Init c
   hashType c, t, flags
   md5Final c, result.Md5Digest
+  when defined(debugSigHashes):
+    db.exec(sql"INSERT OR IGNORE INTO sighashes(type, hash) VALUES (?, ?)",
+            typeToString(t), $result)
 
 proc hashProc*(s: PSym): SigHash =
   var c: MD5Context