diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-08-10 20:26:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-10 14:26:40 +0200 |
commit | 7be2e2bef545e68ac3d88876fe7073a033fbb5f4 (patch) | |
tree | 377a900fa6cdde8063bc8d234de04876381a7a9c /compiler | |
parent | 8523b543d6034d8545a4db256bff83b73c927033 (diff) | |
download | Nim-7be2e2bef545e68ac3d88876fe7073a033fbb5f4.tar.gz |
replaces `doAssert false` with `raiseAssert` for unreachable branches, which works better with strictdefs (#22436)
replaces `doAssert false` with `raiseAssert`, which works better with strictdefs
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 2 | ||||
-rw-r--r-- | compiler/ccgreset.nim | 2 | ||||
-rw-r--r-- | compiler/ccgtypes.nim | 6 | ||||
-rw-r--r-- | compiler/depends.nim | 3 | ||||
-rw-r--r-- | compiler/dfa.nim | 2 | ||||
-rw-r--r-- | compiler/docgen.nim | 5 | ||||
-rw-r--r-- | compiler/jsgen.nim | 3 | ||||
-rw-r--r-- | compiler/liftdestructors.nim | 2 | ||||
-rw-r--r-- | compiler/main.nim | 6 | ||||
-rw-r--r-- | compiler/nim.nim | 2 | ||||
-rw-r--r-- | compiler/options.nim | 2 | ||||
-rw-r--r-- | compiler/pipelines.nim | 8 | ||||
-rw-r--r-- | compiler/ropes.nim | 8 | ||||
-rw-r--r-- | compiler/scriptconfig.nim | 2 | ||||
-rw-r--r-- | compiler/sem.nim | 4 | ||||
-rw-r--r-- | compiler/semfold.nim | 3 | ||||
-rw-r--r-- | compiler/tccgen.nim | 2 | ||||
-rw-r--r-- | compiler/vmconv.nim | 4 | ||||
-rw-r--r-- | compiler/vmgen.nim | 4 | ||||
-rw-r--r-- | compiler/vmhooks.nim | 4 | ||||
-rw-r--r-- | compiler/vmops.nim | 2 |
21 files changed, 34 insertions, 42 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index d62b56368..99647e293 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1499,7 +1499,7 @@ proc newIntTypeNode*(intVal: BiggestInt, typ: PType): PNode = result = newNode(nkIntLit) of tyStatic: # that's a pre-existing bug, will fix in another PR result = newNode(nkIntLit) - else: doAssert false, $kind + else: raiseAssert $kind result.intVal = intVal result.typ = typ diff --git a/compiler/ccgreset.nim b/compiler/ccgreset.nim index 0976a3356..bd0e2a58a 100644 --- a/compiler/ccgreset.nim +++ b/compiler/ccgreset.nim @@ -94,7 +94,7 @@ proc specializeResetT(p: BProc, accessor: Rope, typ: PType) = of ctInt8, ctInt16, ctInt32, ctInt64: lineCg(p, cpsStmts, "$1 = 0;$n", [accessor]) else: - doAssert false, "unexpected set type kind" + raiseAssert "unexpected set type kind" of {tyNone, tyEmpty, tyNil, tyUntyped, tyTyped, tyGenericInvocation, tyGenericParam, tyOrdinal, tyRange, tyOpenArray, tyForward, tyVarargs, tyUncheckedArray, tyProxy, tyBuiltInTypeClass, tyUserTypeClass, diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 0b8cca77e..c2c1d6318 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -477,11 +477,11 @@ proc multiFormat*(frmt: var string, chars : static openArray[char], args: openAr if i >= frmt.len or frmt[i] notin {'0'..'9'}: break num = j if j > high(arg) + 1: - doAssert false, "invalid format string: " & frmt + raiseAssert "invalid format string: " & frmt else: res.add(arg[j-1]) else: - doAssert false, "invalid format string: " & frmt + raiseAssert "invalid format string: " & frmt var start = i while i < frmt.len: if frmt[i] != c: inc(i) @@ -847,7 +847,7 @@ proc resolveStarsInCppType(typ: PType, idx, stars: int): PType = # Make sure the index refers to one of the generic params of the type. # XXX: we should catch this earlier and report it as a semantic error. if idx >= typ.len: - doAssert false, "invalid apostrophe type parameter index" + raiseAssert "invalid apostrophe type parameter index" result = typ[idx] for i in 1..stars: diff --git a/compiler/depends.nim b/compiler/depends.nim index cb462e188..84e66f780 100644 --- a/compiler/depends.nim +++ b/compiler/depends.nim @@ -42,8 +42,7 @@ proc toNimblePath(s: string, isStdlib: bool): string = let sub = "lib/" var start = s.find(sub) if start < 0: - result = "" - doAssert false + raiseAssert "unreachable" else: start += sub.len let base = s[start..^1] diff --git a/compiler/dfa.nim b/compiler/dfa.nim index 7db4c79e3..1459bde45 100644 --- a/compiler/dfa.nim +++ b/compiler/dfa.nim @@ -470,7 +470,7 @@ proc gen(c: var Con; n: PNode) = of nkConv, nkExprColonExpr, nkExprEqExpr, nkCast, PathKinds1: gen(c, n[1]) of nkVarSection, nkLetSection: genVarSection(c, n) - of nkDefer: doAssert false, "dfa construction pass requires the elimination of 'defer'" + of nkDefer: raiseAssert "dfa construction pass requires the elimination of 'defer'" else: discard when false: diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 6a78d8693..933fe57f6 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -348,7 +348,7 @@ proc newDocumentor*(filename: AbsoluteFile; cache: IdentCache; conf: ConfigRef, if conf.configVars.hasKey("doc.googleAnalytics") and conf.configVars.hasKey("doc.plausibleAnalytics"): - doAssert false, "Either use googleAnalytics or plausibleAnalytics" + raiseAssert "Either use googleAnalytics or plausibleAnalytics" if conf.configVars.hasKey("doc.googleAnalytics"): result.analytics = """ @@ -954,8 +954,7 @@ proc genDeprecationMsg(d: PDoc, n: PNode): string = else: result = "" else: - result = "" - doAssert false + raiseAssert "unreachable" type DocFlags = enum kDefault diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 8659d511b..c566a718a 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -218,8 +218,7 @@ proc mapType(typ: PType): TJSTypeKind = of tyProc: result = etyProc of tyCstring: result = etyString of tyConcept, tyIterable: - result = etyNone - doAssert false + raiseAssert "unreachable" proc mapType(p: PProc; typ: PType): TJSTypeKind = result = mapType(typ) diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index 760ee27b5..6ae417347 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -1024,7 +1024,7 @@ proc fillBody(c: var TLiftCtx; t: PType; body, x, y: PNode) = of tyOrdinal, tyRange, tyInferred, tyGenericInst, tyAlias, tySink: fillBody(c, lastSon(t), body, x, y) - of tyConcept, tyIterable: doAssert false + of tyConcept, tyIterable: raiseAssert "unreachable" proc produceSymDistinctType(g: ModuleGraph; c: PContext; typ: PType; kind: TTypeAttachedOp; info: TLineInfo; diff --git a/compiler/main.nim b/compiler/main.nim index 836f912bb..7118a253c 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -115,7 +115,7 @@ when not defined(leanCompiler): setPipeLinePass(graph, Docgen2JsonPass) of HtmlExt: setPipeLinePass(graph, Docgen2Pass) - else: doAssert false, $ext + else: raiseAssert $ext compilePipelineProject(graph) proc commandCompileToC(graph: ModuleGraph) = @@ -267,7 +267,7 @@ proc mainCommand*(graph: ModuleGraph) = # and it has added this define implictly, so we must undo that here. # A better solution might be to fix system.nim undefSymbol(conf.symbols, "useNimRtl") - of backendInvalid: doAssert false + of backendInvalid: raiseAssert "unreachable" proc compileToBackend() = customizeForBackend(conf.backend) @@ -277,7 +277,7 @@ proc mainCommand*(graph: ModuleGraph) = of backendCpp: commandCompileToC(graph) of backendObjc: commandCompileToC(graph) of backendJs: commandCompileToJS(graph) - of backendInvalid: doAssert false + of backendInvalid: raiseAssert "unreachable" template docLikeCmd(body) = when defined(leanCompiler): diff --git a/compiler/nim.nim b/compiler/nim.nim index d05f01c42..d0aa888c4 100644 --- a/compiler/nim.nim +++ b/compiler/nim.nim @@ -140,7 +140,7 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) = # tasyncjs_fail` would fail, refs https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode if cmdPrefix.len == 0: cmdPrefix = findNodeJs().quoteShell cmdPrefix.add " --unhandled-rejections=strict" - else: doAssert false, $conf.backend + else: raiseAssert $conf.backend if cmdPrefix.len > 0: cmdPrefix.add " " # without the `cmdPrefix.len > 0` check, on windows you'd get a cryptic: # `The parameter is incorrect` diff --git a/compiler/options.nim b/compiler/options.nim index d8ae29eac..bda86a598 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -663,7 +663,7 @@ proc isDefined*(conf: ConfigRef; symbol: string): bool = template quitOrRaise*(conf: ConfigRef, msg = "") = # xxx in future work, consider whether to also intercept `msgQuit` calls if conf.isDefined("nimDebug"): - doAssert false, msg + raiseAssert msg else: quit(msg) # quits with QuitFailure diff --git a/compiler/pipelines.nim b/compiler/pipelines.nim index 7bde76d5f..8517cd942 100644 --- a/compiler/pipelines.nim +++ b/compiler/pipelines.nim @@ -44,8 +44,7 @@ proc processPipeline(graph: ModuleGraph; semNode: PNode; bModule: PPassContext): of EvalPass, InterpreterPass: result = interpreterCode(bModule, semNode) of NonePass: - result = nil - doAssert false, "use setPipeLinePass to set a proper PipelinePass" + raiseAssert "use setPipeLinePass to set a proper PipelinePass" proc processImplicitImports(graph: ModuleGraph; implicits: seq[string], nodeKind: TNodeKind, m: PSym, ctx: PContext, bModule: PPassContext, idgen: IdGenerator, @@ -133,8 +132,7 @@ proc processPipelineModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator of SemPass: nil of NonePass: - doAssert false, "use setPipeLinePass to set a proper PipelinePass" - nil + raiseAssert "use setPipeLinePass to set a proper PipelinePass" if stream == nil: let filename = toFullPathConsiderDirty(graph.config, fileIdx) @@ -208,7 +206,7 @@ proc processPipelineModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator when not defined(leanCompiler): discard closeJson(graph, bModule, finalNode) of NonePass: - doAssert false, "use setPipeLinePass to set a proper PipelinePass" + raiseAssert "use setPipeLinePass to set a proper PipelinePass" if graph.config.backend notin {backendC, backendCpp, backendObjc}: # We only write rod files here if no C-like backend is active. diff --git a/compiler/ropes.nim b/compiler/ropes.nim index 7fec1a30a..e0d5aa0d3 100644 --- a/compiler/ropes.nim +++ b/compiler/ropes.nim @@ -76,7 +76,7 @@ proc runtimeFormat*(frmt: FormatStr, args: openArray[Rope]): Rope = if i >= frmt.len or frmt[i] notin {'0'..'9'}: break num = j if j > high(args) + 1: - doAssert false, "invalid format string: " & frmt + raiseAssert "invalid format string: " & frmt else: result.add(args[j-1]) of '{': @@ -88,10 +88,10 @@ proc runtimeFormat*(frmt: FormatStr, args: openArray[Rope]): Rope = num = j if frmt[i] == '}': inc(i) else: - doAssert false, "invalid format string: " & frmt + raiseAssert "invalid format string: " & frmt if j > high(args) + 1: - doAssert false, "invalid format string: " & frmt + raiseAssert "invalid format string: " & frmt else: result.add(args[j-1]) of 'n': @@ -101,7 +101,7 @@ proc runtimeFormat*(frmt: FormatStr, args: openArray[Rope]): Rope = result.add("\n") inc(i) else: - doAssert false, "invalid format string: " & frmt + raiseAssert "invalid format string: " & frmt else: result.add(frmt[i]) inc(i) diff --git a/compiler/scriptconfig.nim b/compiler/scriptconfig.nim index 46751fe4e..1a686fd20 100644 --- a/compiler/scriptconfig.nim +++ b/compiler/scriptconfig.nim @@ -240,7 +240,7 @@ proc runNimScript*(cache: IdentCache; scriptName: AbsoluteFile; of gcAtomicArc: defineSymbol(conf.symbols, "gcatomicarc") else: - doAssert false, "unreachable" + raiseAssert "unreachable" # ensure we load 'system.nim' again for the real non-config stuff! resetSystemArtifacts(graph) diff --git a/compiler/sem.nim b/compiler/sem.nim index 73422618d..42e631358 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -594,7 +594,7 @@ proc defaultFieldsForTuple(c: PContext, recNode: PNode, hasDefault: var bool, ch asgnExpr.typ = recNode.typ result.add newTree(nkExprColonExpr, recNode, asgnExpr) else: - doAssert false + raiseAssert "unreachable" proc defaultFieldsForTheUninitialized(c: PContext, recNode: PNode, checkDefault: bool): seq[PNode] = result = @[] @@ -630,7 +630,7 @@ proc defaultFieldsForTheUninitialized(c: PContext, recNode: PNode, checkDefault: asgnExpr.flags.incl nfSkipFieldChecking result.add newTree(nkExprColonExpr, recNode, asgnExpr) else: - doAssert false + raiseAssert "unreachable" proc defaultNodeField(c: PContext, a: PNode, aTyp: PType, checkDefault: bool): PNode = let aTypSkip = aTyp.skipTypes(defaultFieldsSkipTypes) diff --git a/compiler/semfold.nim b/compiler/semfold.nim index a60bfee2a..c6dec09a9 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -408,8 +408,7 @@ proc foldConv(n, a: PNode; idgen: IdGenerator; g: ModuleGraph; check = false): P result = a result.typ = n.typ else: - result = nil - doAssert false, $srcTyp.kind + raiseAssert $srcTyp.kind of tyInt..tyInt64, tyUInt..tyUInt64: case srcTyp.kind of tyFloat..tyFloat64: diff --git a/compiler/tccgen.nim b/compiler/tccgen.nim index 83c891ca8..9ee8516c4 100644 --- a/compiler/tccgen.nim +++ b/compiler/tccgen.nim @@ -14,7 +14,7 @@ const tinyPrefix = "dist/nim-tinyc-archive".unixToNativePath const nimRoot = currentSourcePath.parentDir.parentDir const tinycRoot = nimRoot / tinyPrefix when not dirExists(tinycRoot): - static: doAssert false, $(tinycRoot, "requires: ./koch installdeps tinyc") + static: raiseAssert $(tinycRoot, "requires: ./koch installdeps tinyc") {.compile: tinycRoot / "tinyc/libtcc.c".} var diff --git a/compiler/vmconv.nim b/compiler/vmconv.nim index 2353feba8..394fb838b 100644 --- a/compiler/vmconv.nim +++ b/compiler/vmconv.nim @@ -16,7 +16,7 @@ proc fromLit*(a: PNode, T: typedesc): auto = for ai in a: result.incl Ti(ai.intVal) else: - static: doAssert false, "not yet supported: " & $T # add as needed + static: raiseAssert "not yet supported: " & $T # add as needed proc toLit*[T](a: T): PNode = ## generic type => PNode @@ -43,7 +43,7 @@ proc toLit*[T](a: T): PNode = reti.add ai.toLit result.add reti else: - static: doAssert false, "not yet supported: " & $T # add as needed + static: raiseAssert "not yet supported: " & $T # add as needed proc toTimeLit*(a: Time, c: PCtx, obj: PNode, info: TLineInfo): PNode = # probably refactor it into `toLit` in the future diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 49ac7533b..8aaac6272 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -366,7 +366,7 @@ proc genBlock(c: PCtx; n: PNode; dest: var TDest) = slotTempFloat, slotTempStr, slotTempComplex}: - doAssert false, "leaking temporary " & $i & " " & $c.prc.regInfo[i].kind + raiseAssert "leaking temporary " & $i & " " & $c.prc.regInfo[i].kind c.prc.regInfo[i] = (inUse: false, kind: slotEmpty) c.clearDest(n, dest) @@ -1073,7 +1073,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) = case n[1].typ.skipTypes(abstractVarRange).kind of tyString: genUnaryABI(c, n, dest, opcLenStr) of tyCstring: genUnaryABI(c, n, dest, opcLenCstring) - else: doAssert false, $n[1].typ.kind + else: raiseAssert $n[1].typ.kind of mSlice: var d = c.genx(n[1]) diff --git a/compiler/vmhooks.nim b/compiler/vmhooks.nim index 7d9e66104..2d7ad63e7 100644 --- a/compiler/vmhooks.nim +++ b/compiler/vmhooks.nim @@ -69,9 +69,7 @@ proc getVar*(a: VmArgs; i: Natural): PNode = case p.kind of rkRegisterAddr: result = p.regAddr.node of rkNodeAddr: result = p.nodeAddr[] - else: - result = nil - doAssert false, $p.kind + else: raiseAssert $p.kind proc getNodeAddr*(a: VmArgs; i: Natural): PNode = let nodeAddr = getX(rkNodeAddr, nodeAddr) diff --git a/compiler/vmops.nim b/compiler/vmops.nim index 73d24a273..e81822ba6 100644 --- a/compiler/vmops.nim +++ b/compiler/vmops.nim @@ -243,7 +243,7 @@ proc registerAdditionalOps*(c: PCtx) = case n of 1: setResult(a, round(getFloat(a, 0))) of 2: setResult(a, round(getFloat(a, 0), getInt(a, 1).int)) - else: doAssert false, $n + else: raiseAssert $n proc `mod Wrapper`(a: VmArgs) {.nimcall.} = setResult(a, `mod`(getFloat(a, 0), getFloat(a, 1))) |