summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2021-03-05 09:58:55 +0100
committerGitHub <noreply@github.com>2021-03-05 09:58:55 +0100
commit8f1fa3e5b014c4301477f2f1872afde0640906b3 (patch)
tree4d320551a698d16849fbbd8149db3c4f34819c09
parentf8cfe330b3c23bd538ec50a674b2b578bd431d21 (diff)
downloadNim-8f1fa3e5b014c4301477f2f1872afde0640906b3.tar.gz
IC: further progress (#17150)
* IC: respect the -f switch

* IC: better rod file inspection

* progress
-rw-r--r--compiler/ic/dce.nim10
-rw-r--r--compiler/ic/to_packed_ast.nim18
-rw-r--r--lib/system/excpt.nim3
3 files changed, 19 insertions, 12 deletions
diff --git a/compiler/ic/dce.nim b/compiler/ic/dce.nim
index eb36e0302..d60c707aa 100644
--- a/compiler/ic/dce.nim
+++ b/compiler/ic/dce.nim
@@ -33,7 +33,7 @@ proc isExportedToC(c: var AliveContext; g: PackedModuleGraph; symId: int32): boo
   # are not transformed correctly; issue (#411). However, the whole purpose here
   # is to eliminate unused procs. So there is no special logic required for this case.
   if sfCompileTime notin flags:
-    if ({sfExportc, sfCompilerProc} * flags == {sfExportc}) or
+    if ({sfExportc, sfCompilerProc} * flags != {}) or
         (symPtr.kind == skMethod):
       result = true
       # XXX: This used to be a condition to:
@@ -52,6 +52,10 @@ proc followLater(c: var AliveContext; g: PackedModuleGraph; module: int; item: i
       let opt = g[module].fromDisk.sh.syms[item].options
       c.stack.add((module, opt, NodePos(body)))
 
+    when false:
+      let name = g[module].fromDisk.sh.strings[g[module].fromDisk.sh.syms[item].name]
+      echo "I was called! ", name, " body exists: ", body != emptyNodeId
+
 proc requestCompilerProc(c: var AliveContext; g: PackedModuleGraph; name: string) =
   let (module, item) = c.compilerProcs[name]
   followLater(c, g, module, item)
@@ -107,7 +111,9 @@ proc aliveCode(c: var AliveContext; g: PackedModuleGraph; tree: PackedTree; n: N
      nkFromStmt, nkStaticStmt:
     discard
   of nkVarSection, nkLetSection, nkConstSection:
-    discard
+    # XXX ignore the defining local variable name?
+    for son in sonsReadonly(tree, n):
+      aliveCode(c, g, tree, son)
   of nkChckRangeF, nkChckRange64, nkChckRange:
     rangeCheckAnalysis(c, g, tree, n)
   of nkProcDef, nkConverterDef, nkMethodDef, nkLambda, nkDo, nkFuncDef:
diff --git a/compiler/ic/to_packed_ast.nim b/compiler/ic/to_packed_ast.nim
index 4a0deede4..58b71e3a4 100644
--- a/compiler/ic/to_packed_ast.nim
+++ b/compiler/ic/to_packed_ast.nim
@@ -453,7 +453,8 @@ proc toPackedNodeTopLevel*(n: PNode, encoder: var PackedEncoder; m: var PackedMo
 proc loadError(err: RodFileError; filename: AbsoluteFile) =
   echo "Error: ", $err, " loading file: ", filename.string
 
-proc loadRodFile*(filename: AbsoluteFile; m: var PackedModule; config: ConfigRef): RodFileError =
+proc loadRodFile*(filename: AbsoluteFile; m: var PackedModule; config: ConfigRef;
+                  ignoreConfig = false): RodFileError =
   m.sh = Shared()
   var f = rodfiles.open(filename.string)
   f.loadHeader()
@@ -462,7 +463,7 @@ proc loadRodFile*(filename: AbsoluteFile; m: var PackedModule; config: ConfigRef
   f.loadPrim m.definedSymbols
   f.loadPrim m.cfg
 
-  if f.err == ok and not configIdentical(m, config):
+  if f.err == ok and not configIdentical(m, config) and not ignoreConfig:
     f.err = configMismatch
 
   template loadSeqSection(section, data) {.dirty.} =
@@ -875,7 +876,7 @@ proc needsRecompile(g: var PackedModuleGraph; conf: ConfigRef; cache: IdentCache
     let rod = toRodFile(conf, AbsoluteFile fullpath)
     let err = loadRodFile(rod, g[m].fromDisk, conf)
     if err == ok:
-      result = false
+      result = optForceFullMake in conf.globalOptions
       # check its dependencies:
       for dep in g[m].fromDisk.imports:
         let fid = toFileIndex(dep, g[m].fromDisk, conf)
@@ -887,7 +888,9 @@ proc needsRecompile(g: var PackedModuleGraph; conf: ConfigRef; cache: IdentCache
       if not result:
         setupLookupTables(g, conf, cache, fileIdx, g[m])
         cachedModules.add fileIdx
-      g[m].status = if result: outdated else: loaded
+        g[m].status = loaded
+      else:
+        g[m] = LoadedModule(status: outdated, module: g[m].module)
     else:
       loadError(err, rod)
       g[m].status = outdated
@@ -1062,14 +1065,15 @@ proc idgenFromLoadedModule*(m: LoadedModule): IdGenerator =
 
 proc rodViewer*(rodfile: AbsoluteFile; config: ConfigRef, cache: IdentCache) =
   var m: PackedModule
-  if loadRodFile(rodfile, m, config) != ok:
-    echo "Error: could not load: ", rodfile.string
+  let err = loadRodFile(rodfile, m, config, ignoreConfig=true)
+  if err != ok:
+    echo "Error: could not load: ", rodfile.string, " reason: ", err
     quit 1
 
   when true:
     echo "exports:"
     for ex in m.exports:
-      echo "  ", m.sh.strings[ex[0]]
+      echo "  ", m.sh.strings[ex[0]], " local ID: ", ex[1]
       assert ex[0] == m.sh.syms[ex[1]].name
       # ex[1] int32
 
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index c3f8255b1..8f7e2cbc7 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -378,7 +378,6 @@ proc reportUnhandledErrorAux(e: ref Exception) {.nodestroy.} =
     # ugly, but avoids heap allocations :-)
     template xadd(buf, s, slen) =
       if L + slen < high(buf):
-
         copyMem(addr(buf[L]), (when s is cstring: s else: cstring(s)), slen)
         inc L, slen
     template add(buf, s) =
@@ -404,8 +403,6 @@ proc reportUnhandledError(e: ref Exception) {.nodestroy.} =
     unhandledExceptionHook(e)
   when hostOS != "any":
     reportUnhandledErrorAux(e)
-  else:
-    discard ()
 
 proc nimLeaveFinally() {.compilerRtl.} =
   when defined(cpp) and not defined(noCppExceptions) and not gotoBasedExceptions: