Skip to content

Commit

Permalink
-d:nimDebug: calls doAssert false instead of quit
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Apr 16, 2021
1 parent 957478c commit 0d723ef
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion compiler/extccomp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
3 changes: 1 addition & 2 deletions compiler/ic/ic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,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:"
Expand Down
6 changes: 3 additions & 3 deletions compiler/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion compiler/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,16 @@ proc log*(s: string) =
f.writeLine(s)
close(f)

template quitOrRaise*(conf: ConfigRef, msg = "") {.gcsafe.} =
# 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 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()
Expand Down
3 changes: 1 addition & 2 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,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

Expand Down
2 changes: 1 addition & 1 deletion compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/syntaxes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0d723ef

Please sign in to comment.