summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-02-21 11:42:58 +0100
committerAraq <rumpf_a@web.de>2018-02-21 11:42:58 +0100
commit67380f71d606f5e4c31cdf0a591ad5e882e93fe4 (patch)
tree9a530930bbbc8a6d51961c4bdc87ad9119adf87a
parent046ed4ed22095d9381d7317beaf215cf67ea4996 (diff)
downloadNim-67380f71d606f5e4c31cdf0a591ad5e882e93fe4.tar.gz
symbol files: delay the emission of forwarded procs
-rw-r--r--compiler/rod.nim2
-rw-r--r--compiler/rodimpl.nim26
-rw-r--r--compiler/sem.nim1
3 files changed, 20 insertions, 9 deletions
diff --git a/compiler/rod.nim b/compiler/rod.nim
index bb9beff54..bc2f3931e 100644
--- a/compiler/rod.nim
+++ b/compiler/rod.nim
@@ -20,6 +20,8 @@ when not defined(nimSymbolfiles):
 
   template addModuleDep*(module, fileIdx: int32; isIncludeFile: bool) = discard
 
+  template storeRemaining*(module: PSym) = discard
+
 else:
   include rodimpl
 
diff --git a/compiler/rodimpl.nim b/compiler/rodimpl.nim
index 767929aa5..ceed166b4 100644
--- a/compiler/rodimpl.nim
+++ b/compiler/rodimpl.nim
@@ -15,6 +15,8 @@ import strutils, os, intsets, tables, ropes, db_sqlite, msgs, options, types,
 ## Todo:
 ## - Implement the 'import' replay logic so that the codegen runs over
 ##   dependent modules.
+## - Make conditional symbols and the configuration part of a module's
+##   dependencies.
 ## - Test multi methods.
 ## - Implement the limited VM support based on sets.
 ## - Depencency computation should use signature hashes in order to
@@ -49,7 +51,7 @@ proc getModuleId*(fileIdx: int32; fullpath: string): int =
   if gSymbolFiles != v2Sf: return getID()
   let module = db.getRow(
     sql"select id, fullHash from modules where fullpath = ?", fullpath)
-  let currentFullhash = $secureHashFile(fullpath)
+  let currentFullhash = hashFileCached(fileIdx, fullpath)
   if module[0].len == 0:
     result = int db.insertID(sql"insert into modules(fullpath, interfHash, fullHash) values (?, ?, ?)",
       fullpath, "", currentFullhash)
@@ -75,12 +77,13 @@ type
     sstack: seq[PSym]          # a stack of symbols to process
     tstack: seq[PType]         # a stack of types to process
     tmarks, smarks: IntSet
+    forwardedSyms: seq[PSym]
 
   PRodWriter = var TRodWriter
 
 proc initRodWriter(module: PSym): TRodWriter =
   result = TRodWriter(module: module, sstack: @[], tstack: @[],
-    tmarks: initIntSet(), smarks: initIntSet())
+    tmarks: initIntSet(), smarks: initIntSet(), forwardedSyms: @[])
 
 when false:
   proc getDefines(): string =
@@ -89,13 +92,6 @@ when false:
       if result.len != 0: add(result, " ")
       add(result, d)
 
-  proc addInclDep(w: PRodWriter, dep: string; info: TLineInfo) =
-    let resolved = dep.findModule(info.toFullPath)
-    encodeVInt(fileIdx(w, resolved), w.inclDeps)
-    add(w.inclDeps, " ")
-    encodeStr($secureHashFile(resolved), w.inclDeps)
-    add(w.inclDeps, rodNL)
-
 const
   rodNL = "\L"
 
@@ -381,6 +377,9 @@ proc encodeSym(w: PRodWriter, s: PSym, result: var string) =
     encodeNode(w, s.info, s.ast, result)
 
 proc storeSym(w: PRodWriter; s: PSym) =
+  if sfForward in s.flags and s.kind != skModule:
+    w.forwardedSyms.add s
+    return
   var buf = newStringOfCap(160)
   encodeSym(w, s, buf)
   # XXX only store the name for exported symbols in order to speed up lookup
@@ -421,6 +420,14 @@ proc storeNode*(module: PSym; n: PNode) =
       break
     inc i
 
+proc storeRemaining*(module: PSym) =
+  if gSymbolFiles != v2Sf: return
+  w.module = module
+  for s in w.forwardedSyms:
+    assert sfForward notin s.flags
+    storeSym(w, s)
+  w.forwardedSyms.setLen 0
+
 # ---------------- decoder -----------------------------------
 type
   TRodReader = object
@@ -781,6 +788,7 @@ proc loadSymFromBlob(r; b; info: TLineInfo): PSym =
     result.ast = decodeNode(r, b, result.info)
   if sfCompilerProc in result.flags:
     registerCompilerProc(result)
+    #echo "loading ", result.name.s
 
 proc loadSym(r; id: int; info: TLineInfo): PSym =
   result = r.syms.getOrDefault(id)
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 12e77affc..937f1637a 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -619,6 +619,7 @@ proc myClose(graph: ModuleGraph; context: PPassContext, n: PNode): PNode =
     replayMethodDefs(graph, c.rd)
   popOwner(c)
   popProcCon(c)
+  storeRemaining(c.module)
   if c.runnableExamples != nil: testExamples(c)
 
 const semPass* = makePass(myOpen, myOpenCached, myProcess, myClose,