remove conditionals on nimHasUserErrors, nimNoNilSeqs2, nimNoNilSeqs (#16861)
* cleanup docs for type(nil) | type(nil); simplify nimHasUserErrors * simplify nimNoNilSeqs2 * simplify nimNoNilSeqs * fixup
This commit is contained in:
parent
4e1e231e29
commit
6e267d28b3
13 changed files with 29 additions and 93 deletions
|
|
@ -1127,11 +1127,7 @@ proc discardSons*(father: PNode)
|
||||||
type Indexable = PNode | PType
|
type Indexable = PNode | PType
|
||||||
|
|
||||||
proc len*(n: Indexable): int {.inline.} =
|
proc len*(n: Indexable): int {.inline.} =
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
result = n.sons.len
|
result = n.sons.len
|
||||||
else:
|
|
||||||
if isNil(n.sons): result = 0
|
|
||||||
else: result = n.sons.len
|
|
||||||
|
|
||||||
proc safeLen*(n: PNode): int {.inline.} =
|
proc safeLen*(n: PNode): int {.inline.} =
|
||||||
## works even for leaves.
|
## works even for leaves.
|
||||||
|
|
@ -1146,8 +1142,6 @@ proc safeArrLen*(n: PNode): int {.inline.} =
|
||||||
|
|
||||||
proc add*(father, son: Indexable) =
|
proc add*(father, son: Indexable) =
|
||||||
assert son != nil
|
assert son != nil
|
||||||
when not defined(nimNoNilSeqs):
|
|
||||||
if isNil(father.sons): father.sons = @[]
|
|
||||||
father.sons.add(son)
|
father.sons.add(son)
|
||||||
|
|
||||||
proc addAllowNil*(father, son: Indexable) {.inline.} =
|
proc addAllowNil*(father, son: Indexable) {.inline.} =
|
||||||
|
|
@ -1308,10 +1302,7 @@ proc copyObjectSet*(dest: var TObjectSet, src: TObjectSet) =
|
||||||
for i in 0..high(src.data): dest.data[i] = src.data[i]
|
for i in 0..high(src.data): dest.data[i] = src.data[i]
|
||||||
|
|
||||||
proc discardSons*(father: PNode) =
|
proc discardSons*(father: PNode) =
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
father.sons = @[]
|
father.sons = @[]
|
||||||
else:
|
|
||||||
father.sons = nil
|
|
||||||
|
|
||||||
proc withInfo*(n: PNode, info: TLineInfo): PNode =
|
proc withInfo*(n: PNode, info: TLineInfo): PNode =
|
||||||
n.info = info
|
n.info = info
|
||||||
|
|
@ -1436,12 +1427,6 @@ proc mergeLoc(a: var TLoc, b: TLoc) =
|
||||||
if a.r == nil: a.r = b.r
|
if a.r == nil: a.r = b.r
|
||||||
|
|
||||||
proc newSons*(father: Indexable, length: int) =
|
proc newSons*(father: Indexable, length: int) =
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
setLen(father.sons, length)
|
|
||||||
else:
|
|
||||||
if isNil(father.sons):
|
|
||||||
newSeq(father.sons, length)
|
|
||||||
else:
|
|
||||||
setLen(father.sons, length)
|
setLen(father.sons, length)
|
||||||
|
|
||||||
proc assignType*(dest, src: PType) =
|
proc assignType*(dest, src: PType) =
|
||||||
|
|
@ -1576,26 +1561,17 @@ proc propagateToOwner*(owner, elem: PType; propagateHasAsgn = true) =
|
||||||
owner.flags.incl tfHasGCedMem
|
owner.flags.incl tfHasGCedMem
|
||||||
|
|
||||||
proc rawAddSon*(father, son: PType; propagateHasAsgn = true) =
|
proc rawAddSon*(father, son: PType; propagateHasAsgn = true) =
|
||||||
when not defined(nimNoNilSeqs):
|
|
||||||
if isNil(father.sons): father.sons = @[]
|
|
||||||
father.sons.add(son)
|
father.sons.add(son)
|
||||||
if not son.isNil: propagateToOwner(father, son, propagateHasAsgn)
|
if not son.isNil: propagateToOwner(father, son, propagateHasAsgn)
|
||||||
|
|
||||||
proc rawAddSonNoPropagationOfTypeFlags*(father, son: PType) =
|
proc rawAddSonNoPropagationOfTypeFlags*(father, son: PType) =
|
||||||
when not defined(nimNoNilSeqs):
|
|
||||||
if isNil(father.sons): father.sons = @[]
|
|
||||||
father.sons.add(son)
|
father.sons.add(son)
|
||||||
|
|
||||||
proc addSonNilAllowed*(father, son: PNode) =
|
proc addSonNilAllowed*(father, son: PNode) =
|
||||||
when not defined(nimNoNilSeqs):
|
|
||||||
if isNil(father.sons): father.sons = @[]
|
|
||||||
father.sons.add(son)
|
father.sons.add(son)
|
||||||
|
|
||||||
proc delSon*(father: PNode, idx: int) =
|
proc delSon*(father: PNode, idx: int) =
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
if father.len == 0: return
|
if father.len == 0: return
|
||||||
else:
|
|
||||||
if isNil(father.sons): return
|
|
||||||
for i in idx..<father.len - 1: father[i] = father[i + 1]
|
for i in idx..<father.len - 1: father[i] = father[i + 1]
|
||||||
father.sons.setLen(father.len - 1)
|
father.sons.setLen(father.len - 1)
|
||||||
|
|
||||||
|
|
@ -1766,10 +1742,7 @@ proc getStr*(a: PNode): string =
|
||||||
of nkStrLit..nkTripleStrLit: result = a.strVal
|
of nkStrLit..nkTripleStrLit: result = a.strVal
|
||||||
of nkNilLit:
|
of nkNilLit:
|
||||||
# let's hope this fixes more problems than it creates:
|
# let's hope this fixes more problems than it creates:
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
result = ""
|
result = ""
|
||||||
else:
|
|
||||||
result = nil
|
|
||||||
else:
|
else:
|
||||||
raiseRecoverableError("cannot extract string from invalid AST node")
|
raiseRecoverableError("cannot extract string from invalid AST node")
|
||||||
#doAssert false, "getStr"
|
#doAssert false, "getStr"
|
||||||
|
|
|
||||||
|
|
@ -71,9 +71,9 @@ proc initDefines*(symbols: StringTableRef) =
|
||||||
defineSymbol("nimNewRuntime")
|
defineSymbol("nimNewRuntime")
|
||||||
defineSymbol("nimIncrSeqV3")
|
defineSymbol("nimIncrSeqV3")
|
||||||
defineSymbol("nimAshr")
|
defineSymbol("nimAshr")
|
||||||
defineSymbol("nimNoNilSeqs")
|
defineSymbol("nimNoNilSeqs") # deadcode
|
||||||
defineSymbol("nimNoNilSeqs2")
|
defineSymbol("nimNoNilSeqs2") # deadcode
|
||||||
defineSymbol("nimHasUserErrors")
|
defineSymbol("nimHasUserErrors") # deadcode
|
||||||
defineSymbol("nimUncheckedArrayTyp")
|
defineSymbol("nimUncheckedArrayTyp")
|
||||||
defineSymbol("nimHasTypeof")
|
defineSymbol("nimHasTypeof")
|
||||||
defineSymbol("nimErrorProcCanHaveBody")
|
defineSymbol("nimErrorProcCanHaveBody")
|
||||||
|
|
|
||||||
|
|
@ -329,8 +329,7 @@ proc genRecCommentAux(d: PDoc, n: PNode): Rope =
|
||||||
result = genRecCommentAux(d, n[i])
|
result = genRecCommentAux(d, n[i])
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
else:
|
else:
|
||||||
when defined(nimNoNilSeqs): n.comment = ""
|
n.comment = ""
|
||||||
else: n.comment = nil
|
|
||||||
|
|
||||||
proc genRecComment(d: PDoc, n: PNode): Rope =
|
proc genRecComment(d: PDoc, n: PNode): Rope =
|
||||||
if n == nil: return nil
|
if n == nil: return nil
|
||||||
|
|
|
||||||
|
|
@ -98,8 +98,6 @@ proc skipIntLit*(t: PType; id: IdGenerator): PType {.inline.} =
|
||||||
result = t
|
result = t
|
||||||
|
|
||||||
proc addSonSkipIntLit*(father, son: PType; id: IdGenerator) =
|
proc addSonSkipIntLit*(father, son: PType; id: IdGenerator) =
|
||||||
when not defined(nimNoNilSeqs):
|
|
||||||
if isNil(father.sons): father.sons = @[]
|
|
||||||
let s = son.skipIntLit(id)
|
let s = son.skipIntLit(id)
|
||||||
father.sons.add(s)
|
father.sons.add(s)
|
||||||
propagateToOwner(father, s)
|
propagateToOwner(father, s)
|
||||||
|
|
|
||||||
|
|
@ -164,8 +164,6 @@ proc validInd(p: var Parser): bool {.inline.} =
|
||||||
proc rawSkipComment(p: var Parser, node: PNode) =
|
proc rawSkipComment(p: var Parser, node: PNode) =
|
||||||
if p.tok.tokType == tkComment:
|
if p.tok.tokType == tkComment:
|
||||||
if node != nil:
|
if node != nil:
|
||||||
when not defined(nimNoNilSeqs):
|
|
||||||
if node.comment == nil: node.comment = ""
|
|
||||||
when defined(nimpretty):
|
when defined(nimpretty):
|
||||||
if p.tok.commentOffsetB > p.tok.commentOffsetA:
|
if p.tok.commentOffsetB > p.tok.commentOffsetA:
|
||||||
node.comment.add fileSection(p.lex.config, p.lex.fileIdx, p.tok.commentOffsetA, p.tok.commentOffsetB)
|
node.comment.add fileSection(p.lex.config, p.lex.fileIdx, p.tok.commentOffsetA, p.tok.commentOffsetB)
|
||||||
|
|
|
||||||
|
|
@ -210,11 +210,8 @@ proc matchStmtList(c: PPatternContext, p, n: PNode): PNode =
|
||||||
for j in 0..<p.len:
|
for j in 0..<p.len:
|
||||||
if not matches(c, p[j], n[i+j]):
|
if not matches(c, p[j], n[i+j]):
|
||||||
# we need to undo any bindings:
|
# we need to undo any bindings:
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
c.mapping = @[]
|
c.mapping = @[]
|
||||||
c.mappingIsFull = false
|
c.mappingIsFull = false
|
||||||
else:
|
|
||||||
if not isNil(c.mapping): c.mapping = nil
|
|
||||||
return false
|
return false
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1237,10 +1237,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||||
var body = s.typ.lastSon
|
var body = s.typ.lastSon
|
||||||
if body.kind == tyObject:
|
if body.kind == tyObject:
|
||||||
# erases all declared fields
|
# erases all declared fields
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
body.n.sons = @[]
|
body.n.sons = @[]
|
||||||
else:
|
|
||||||
body.n.sons = nil
|
|
||||||
|
|
||||||
popOwner(c)
|
popOwner(c)
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
|
|
|
||||||
|
|
@ -895,8 +895,6 @@ proc initSameTypeClosure: TSameTypeClosure =
|
||||||
proc containsOrIncl(c: var TSameTypeClosure, a, b: PType): bool =
|
proc containsOrIncl(c: var TSameTypeClosure, a, b: PType): bool =
|
||||||
result = c.s.len > 0 and c.s.contains((a.id, b.id))
|
result = c.s.len > 0 and c.s.contains((a.id, b.id))
|
||||||
if not result:
|
if not result:
|
||||||
when not defined(nimNoNilSeqs):
|
|
||||||
if isNil(c.s): c.s = @[]
|
|
||||||
c.s.add((a.id, b.id))
|
c.s.add((a.id, b.id))
|
||||||
|
|
||||||
proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool
|
proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool
|
||||||
|
|
|
||||||
|
|
@ -271,8 +271,6 @@ template getstr(a: untyped): untyped =
|
||||||
(if a.kind == rkNode: a.node.strVal else: $chr(int(a.intVal)))
|
(if a.kind == rkNode: a.node.strVal else: $chr(int(a.intVal)))
|
||||||
|
|
||||||
proc pushSafePoint(f: PStackFrame; pc: int) =
|
proc pushSafePoint(f: PStackFrame; pc: int) =
|
||||||
when not defined(nimNoNilSeqs):
|
|
||||||
if f.safePoints.isNil: f.safePoints = @[]
|
|
||||||
f.safePoints.add(pc)
|
f.safePoints.add(pc)
|
||||||
|
|
||||||
proc popSafePoint(f: PStackFrame) =
|
proc popSafePoint(f: PStackFrame) =
|
||||||
|
|
@ -2092,8 +2090,6 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
inc pc
|
inc pc
|
||||||
let typ = c.types[c.code[pc].regBx - wordExcess]
|
let typ = c.types[c.code[pc].regBx - wordExcess]
|
||||||
createStrKeepNode(regs[ra])
|
createStrKeepNode(regs[ra])
|
||||||
when not defined(nimNoNilSeqs):
|
|
||||||
if regs[ra].node.strVal.isNil: regs[ra].node.strVal = newStringOfCap(1000)
|
|
||||||
storeAny(regs[ra].node.strVal, typ, regs[rb].regToNode, c.config)
|
storeAny(regs[ra].node.strVal, typ, regs[rb].regToNode, c.config)
|
||||||
|
|
||||||
c.profiler.leave(c)
|
c.profiler.leave(c)
|
||||||
|
|
|
||||||
|
|
@ -1150,10 +1150,7 @@ when (NimMajor, NimMinor) < (1, 3) and defined(js):
|
||||||
|
|
||||||
proc ssClose(s: Stream) {.compileTime.} =
|
proc ssClose(s: Stream) {.compileTime.} =
|
||||||
var s = StringStream(s)
|
var s = StringStream(s)
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
s.data = ""
|
s.data = ""
|
||||||
else:
|
|
||||||
s.data = nil
|
|
||||||
|
|
||||||
proc newStringStream*(s: string = ""): owned StringStream {.compileTime.} =
|
proc newStringStream*(s: string = ""): owned StringStream {.compileTime.} =
|
||||||
new(result)
|
new(result)
|
||||||
|
|
@ -1253,10 +1250,7 @@ else: # after 1.3 or JS not defined
|
||||||
|
|
||||||
proc ssClose(s: Stream) =
|
proc ssClose(s: Stream) =
|
||||||
var s = StringStream(s)
|
var s = StringStream(s)
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
s.data = ""
|
s.data = ""
|
||||||
else:
|
|
||||||
s.data = nil
|
|
||||||
|
|
||||||
proc newStringStream*(s: string = ""): owned StringStream =
|
proc newStringStream*(s: string = ""): owned StringStream =
|
||||||
## Creates a new stream from the string `s`.
|
## Creates a new stream from the string `s`.
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,7 @@ proc initPackedSet*[A]: PackedSet[A] =
|
||||||
counter: 0,
|
counter: 0,
|
||||||
max: 0,
|
max: 0,
|
||||||
head: nil,
|
head: nil,
|
||||||
data: when defined(nimNoNilSeqs): @[] else: nil)
|
data: @[])
|
||||||
# a: array[0..33, int] # profiling shows that 34 elements are enough
|
# a: array[0..33, int] # profiling shows that 34 elements are enough
|
||||||
|
|
||||||
proc contains*[A](s: PackedSet[A], key: A): bool =
|
proc contains*[A](s: PackedSet[A], key: A): bool =
|
||||||
|
|
@ -392,10 +392,7 @@ proc clear*[A](result: var PackedSet[A]) =
|
||||||
# setLen(result.data, InitIntSetSize)
|
# setLen(result.data, InitIntSetSize)
|
||||||
# for i in 0..InitIntSetSize - 1: result.data[i] = nil
|
# for i in 0..InitIntSetSize - 1: result.data[i] = nil
|
||||||
# result.max = InitIntSetSize - 1
|
# result.max = InitIntSetSize - 1
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
result.data = @[]
|
result.data = @[]
|
||||||
else:
|
|
||||||
result.data = nil
|
|
||||||
result.max = 0
|
result.max = 0
|
||||||
result.counter = 0
|
result.counter = 0
|
||||||
result.head = nil
|
result.head = nil
|
||||||
|
|
@ -426,10 +423,7 @@ proc assign*[A](dest: var PackedSet[A], src: PackedSet[A]) =
|
||||||
assert len(a) == 2
|
assert len(a) == 2
|
||||||
|
|
||||||
if src.elems <= src.a.len:
|
if src.elems <= src.a.len:
|
||||||
when defined(nimNoNilSeqs):
|
|
||||||
dest.data = @[]
|
dest.data = @[]
|
||||||
else:
|
|
||||||
dest.data = nil
|
|
||||||
dest.max = 0
|
dest.max = 0
|
||||||
dest.counter = src.counter
|
dest.counter = src.counter
|
||||||
dest.head = nil
|
dest.head = nil
|
||||||
|
|
|
||||||
|
|
@ -1559,13 +1559,10 @@ proc len*[U: Ordinal; V: Ordinal](x: HSlice[U, V]): int {.noSideEffect, inline.}
|
||||||
## assert((5..2).len == 0)
|
## assert((5..2).len == 0)
|
||||||
result = max(0, ord(x.b) - ord(x.a) + 1)
|
result = max(0, ord(x.b) - ord(x.a) + 1)
|
||||||
|
|
||||||
when defined(nimNoNilSeqs2):
|
|
||||||
when not compileOption("nilseqs"):
|
when not compileOption("nilseqs"):
|
||||||
{.pragma: nilError, error.}
|
{.pragma: nilError, error.}
|
||||||
else:
|
else:
|
||||||
{.pragma: nilError.}
|
{.pragma: nilError.}
|
||||||
else:
|
|
||||||
{.pragma: nilError.}
|
|
||||||
|
|
||||||
proc isNil*[T](x: seq[T]): bool {.noSideEffect, magic: "IsNil", nilError.}
|
proc isNil*[T](x: seq[T]): bool {.noSideEffect, magic: "IsNil", nilError.}
|
||||||
## Requires `--nilseqs:on` since 0.19.
|
## Requires `--nilseqs:on` since 0.19.
|
||||||
|
|
@ -2942,19 +2939,16 @@ proc `==`*(x, y: cstring): bool {.magic: "EqCString", noSideEffect,
|
||||||
elif x.isNil or y.isNil: result = false
|
elif x.isNil or y.isNil: result = false
|
||||||
else: result = strcmp(x, y) == 0
|
else: result = strcmp(x, y) == 0
|
||||||
|
|
||||||
when defined(nimNoNilSeqs2) and not compileOption("nilseqs"):
|
when not compileOption("nilseqs"):
|
||||||
when defined(nimHasUserErrors):
|
# bug #9149; ensure that 'type(nil)' does not match *too* well by using 'type(nil) | type(nil)',
|
||||||
# bug #9149; ensure that 'type(nil)' does not match *too* well by using 'type(nil) | type(nil)'.
|
# especially for converters, see tests/overload/tconverter_to_string.nim
|
||||||
# Eventually (in 0.20?) we will be able to remove this hack completely.
|
# Eventually we will be able to remove this hack completely.
|
||||||
proc `==`*(x: string; y: type(nil) | type(nil)): bool {.
|
proc `==`*(x: string; y: type(nil) | type(nil)): bool {.
|
||||||
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
||||||
discard
|
discard
|
||||||
proc `==`*(x: type(nil) | type(nil); y: string): bool {.
|
proc `==`*(x: type(nil) | type(nil); y: string): bool {.
|
||||||
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
||||||
discard
|
discard
|
||||||
else:
|
|
||||||
proc `==`*(x: string; y: type(nil) | type(nil)): bool {.error.} = discard
|
|
||||||
proc `==`*(x: type(nil) | type(nil); y: string): bool {.error.} = discard
|
|
||||||
|
|
||||||
template closureScope*(body: untyped): untyped =
|
template closureScope*(body: untyped): untyped =
|
||||||
## Useful when creating a closure in a loop to capture local loop variables by
|
## Useful when creating a closure in a loop to capture local loop variables by
|
||||||
|
|
|
||||||
|
|
@ -477,8 +477,6 @@ proc deduplicateFiles(c: var ConfigData) =
|
||||||
let build = getOutputDir(c)
|
let build = getOutputDir(c)
|
||||||
for osA in countup(1, c.oses.len):
|
for osA in countup(1, c.oses.len):
|
||||||
for cpuA in countup(1, c.cpus.len):
|
for cpuA in countup(1, c.cpus.len):
|
||||||
when not defined(nimNoNilSeqs):
|
|
||||||
if c.cfiles[osA][cpuA].isNil: c.cfiles[osA][cpuA] = @[]
|
|
||||||
if c.explicitPlatforms and not c.platforms[osA][cpuA]: continue
|
if c.explicitPlatforms and not c.platforms[osA][cpuA]: continue
|
||||||
for dup in mitems(c.cfiles[osA][cpuA]):
|
for dup in mitems(c.cfiles[osA][cpuA]):
|
||||||
let key = $secureHashFile(build / dup)
|
let key = $secureHashFile(build / dup)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue