summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-04-17 02:49:54 -0700
committerGitHub <noreply@github.com>2021-04-17 11:49:54 +0200
commit5c9c1988f6bb92e8cfdc639fc0f83e78cb5efbd2 (patch)
tree5e3ab9df51240dc99c4175a6c266b5c375704e26 /compiler
parent5c5f356347b15a82491c7f23e9bf2dd30a0c80f2 (diff)
downloadNim-5c9c1988f6bb92e8cfdc639fc0f83e78cb5efbd2.tar.gz
-d:nimDebug: calls doAssert false instead of quit (#17739)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ccgexprs.nim4
-rw-r--r--compiler/docgen.nim2
-rw-r--r--compiler/extccomp.nim2
-rw-r--r--compiler/ic/ic.nim3
-rw-r--r--compiler/main.nim6
-rw-r--r--compiler/msgs.nim3
-rw-r--r--compiler/options.nim10
-rw-r--r--compiler/sigmatch.nim2
-rw-r--r--compiler/syntaxes.nim2
9 files changed, 20 insertions, 14 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 0e54adf49..a42c30aae 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -2387,13 +2387,13 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
     localError(p.config, e.info, strutils.`%`(errXMustBeCompileTime, e[0].sym.name.s))
   of mSpawn:
     when defined(leanCompiler):
-      quit "compiler built without support for the 'spawn' statement"
+      p.config.quitOrRaise "compiler built without support for the 'spawn' statement"
     else:
       let n = spawn.wrapProcForSpawn(p.module.g.graph, p.module.idgen, p.module.module, e, e.typ, nil, nil)
       expr(p, n, d)
   of mParallel:
     when defined(leanCompiler):
-      quit "compiler built without support for the 'parallel' statement"
+      p.config.quitOrRaise "compiler built without support for the 'parallel' statement"
     else:
       let n = semparallel.liftParallel(p.module.g.graph, p.module.idgen, p.module.module, e)
       expr(p, n, d)
diff --git a/compiler/docgen.nim b/compiler/docgen.nim
index 2f7415241..4d9f09ca6 100644
--- a/compiler/docgen.nim
+++ b/compiler/docgen.nim
@@ -498,7 +498,7 @@ proc runAllExamples(d: PDoc) =
       "docCmd", group.docCmd,
     ]
     if os.execShellCmd(cmd) != 0:
-      quit "[runnableExamples] failed: generated file: '$1' group: '$2' cmd: $3" % [outp.string, group[].prettyString, cmd]
+      d.conf.quitOrRaise "[runnableExamples] failed: generated file: '$1' group: '$2' cmd: $3" % [outp.string, group[].prettyString, cmd]
     else:
       # keep generated source file `outp` to allow inspection.
       rawMessage(d.conf, hintSuccess, ["runnableExamples: " & outp.string])
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim
index e0fd5e206..8d1432aa8 100644
--- a/compiler/extccomp.nim
+++ b/compiler/extccomp.nim
@@ -1132,7 +1132,7 @@ proc runJsonBuildInstructions*(conf: ConfigRef; projectfile: AbsoluteFile) =
 
   except:
     let e = getCurrentException()
-    quit "\ncaught exception:\n" & e.msg & "\nstacktrace:\n" & e.getStackTrace() &
+    conf.quitOrRaise "\ncaught exception:\n" & e.msg & "\nstacktrace:\n" & e.getStackTrace() &
          "error evaluating JSON file: " & jsonFile.string
 
 proc genMappingFiles(conf: ConfigRef; list: CfileList): Rope =
diff --git a/compiler/ic/ic.nim b/compiler/ic/ic.nim
index da0af2edf..6f208a2a4 100644
--- a/compiler/ic/ic.nim
+++ b/compiler/ic/ic.nim
@@ -1149,8 +1149,7 @@ proc rodViewer*(rodfile: AbsoluteFile; config: ConfigRef, cache: IdentCache) =
   var m: PackedModule
   let err = loadRodFile(rodfile, m, config, ignoreConfig=true)
   if err != ok:
-    echo "Error: could not load: ", rodfile.string, " reason: ", err
-    quit 1
+    config.quitOrRaise "Error: could not load: " & $rodfile.string & " reason: " & $err 
 
   when true:
     echo "exports:"
diff --git a/compiler/main.nim b/compiler/main.nim
index 475ba7773..6eb830164 100644
--- a/compiler/main.nim
+++ b/compiler/main.nim
@@ -229,7 +229,7 @@ proc mainCommand*(graph: ModuleGraph) =
 
   template docLikeCmd(body) =
     when defined(leanCompiler):
-      quit "compiler wasn't built with documentation generator"
+      conf.quitOrRaise "compiler wasn't built with documentation generator"
     else:
       wantMainModule(conf)
       loadConfigs(DocConfig, cache, conf, graph.idgen)
@@ -278,7 +278,7 @@ proc mainCommand*(graph: ModuleGraph) =
       conf.setNoteDefaults(warn, true)
     conf.setNoteDefaults(warnRedefinitionOfLabel, false) # similar to issue #13218
     when defined(leanCompiler):
-      quit "compiler wasn't built with documentation generator"
+      conf.quitOrRaise "compiler wasn't built with documentation generator"
     else:
       loadConfigs(DocConfig, cache, conf, graph.idgen)
       commandRst2Html(cache, conf)
@@ -288,7 +288,7 @@ proc mainCommand*(graph: ModuleGraph) =
                  warnFieldXNotSupported, warnRstStyle]:
       conf.setNoteDefaults(warn, true)
     when defined(leanCompiler):
-      quit "compiler wasn't built with documentation generator"
+      conf.quitOrRaise "compiler wasn't built with documentation generator"
     else:
       loadConfigs(DocTexConfig, cache, conf, graph.idgen)
       commandRst2TeX(cache, conf)
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index 452b1cd89..c1e1f9e39 100644
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -398,7 +398,8 @@ proc log*(s: string) =
     close(f)
 
 proc quit(conf: ConfigRef; msg: TMsgKind) {.gcsafe.} =
-  if defined(debug) or msg == errInternal or conf.hasHint(hintStackTrace):
+  if conf.isDefined("nimDebug"): quitOrRaise(conf, $msg)
+  elif defined(debug) or msg == errInternal or conf.hasHint(hintStackTrace):
     {.gcsafe.}:
       if stackTraceAvailable() and isNil(conf.writelnHook):
         writeStackTrace()
diff --git a/compiler/options.nim b/compiler/options.nim
index 9ba4d62e4..5475410a4 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -576,6 +576,13 @@ proc isDefined*(conf: ConfigRef; symbol: string): bool =
                             osDragonfly, osMacosx}
     else: discard
 
+template quitOrRaise*(conf: ConfigRef, msg = "") =
+  # xxx in future work, consider whether to also intercept `msgQuit` calls
+  if conf.isDefined("nimDebug"):
+    doAssert false, msg
+  else:
+    quit(msg) # quits with QuitFailure
+
 proc importantComments*(conf: ConfigRef): bool {.inline.} = conf.cmd in cmdDocLike + {cmdIdeTools}
 proc usesWriteBarrier*(conf: ConfigRef): bool {.inline.} = conf.selectedGC >= gcRefc
 
@@ -732,8 +739,7 @@ proc completeGeneratedFilePath*(conf: ConfigRef; f: AbsoluteFile,
     try:
       createDir(subdir.string)
     except OSError:
-      writeLine(stdout, "cannot create directory: " & subdir.string)
-      quit(1)
+      conf.quitOrRaise "cannot create directory: " & subdir.string
   result = subdir / RelativeFile f.string.splitPath.tail
   #echo "completeGeneratedFilePath(", f, ") = ", result
 
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 2563c38e9..6a36c1381 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1011,7 +1011,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
   when declared(deallocatedRefId):
     let corrupt = deallocatedRefId(cast[pointer](f))
     if corrupt != 0:
-      quit "it's corrupt " & $corrupt
+      c.c.config.quitOrRaise "it's corrupt " & $corrupt
 
   if f.kind == tyUntyped:
     if aOrig != nil: put(c, f, aOrig)
diff --git a/compiler/syntaxes.nim b/compiler/syntaxes.nim
index e745e28ba..03a9702a3 100644
--- a/compiler/syntaxes.nim
+++ b/compiler/syntaxes.nim
@@ -50,7 +50,7 @@ proc parsePipe(filename: AbsoluteFile, inputStream: PLLStream; cache: IdentCache
     if i+1 < line.len and line[i] == '#' and line[i+1] == '?':
       when defined(nimpretty):
         # XXX this is a bit hacky, but oh well...
-        quit "can't nimpretty a source code filter"
+        config.quitOrRaise "can't nimpretty a source code filter: " & $filename
       else:
         inc(i, 2)
         while i < line.len and line[i] in Whitespace: inc(i)