--nilseqs is now a deprecated noop (#17211)
* --nilseqs is now a deprecated noop * fix tests; fix: future => sugar
This commit is contained in:
parent
bb0c19f42c
commit
6c5872c169
15 changed files with 37 additions and 53 deletions
|
|
@ -214,6 +214,8 @@ provided by the operating system.
|
||||||
|
|
||||||
- Deprecated `TaintedString` and `--taintmode`.
|
- Deprecated `TaintedString` and `--taintmode`.
|
||||||
|
|
||||||
|
- Deprecated `--nilseqs` which is now a noop.
|
||||||
|
|
||||||
- Source+Edit links now appear on top of every docgen'd page when
|
- Source+Edit links now appear on top of every docgen'd page when
|
||||||
`nim doc --git.url:url ...` is given.
|
`nim doc --git.url:url ...` is given.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -85,10 +85,9 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
|
||||||
of tyNil:
|
of tyNil:
|
||||||
result = genNilStringLiteral(p.module, n.info)
|
result = genNilStringLiteral(p.module, n.info)
|
||||||
of tyString:
|
of tyString:
|
||||||
# with the new semantics for 'nil' strings, we can map "" to nil and
|
# with the new semantics for not 'nil' strings, we can map "" to nil and
|
||||||
# save tons of allocations:
|
# save tons of allocations:
|
||||||
if n.strVal.len == 0 and optNilSeqs notin p.options and
|
if n.strVal.len == 0 and optSeqDestructors notin p.config.globalOptions:
|
||||||
optSeqDestructors notin p.config.globalOptions:
|
|
||||||
result = genNilStringLiteral(p.module, n.info)
|
result = genNilStringLiteral(p.module, n.info)
|
||||||
else:
|
else:
|
||||||
result = genStringLiteral(p.module, n)
|
result = genStringLiteral(p.module, n)
|
||||||
|
|
@ -176,8 +175,7 @@ proc canMove(p: BProc, n: PNode; dest: TLoc): bool =
|
||||||
if not isDeepConstExpr(n) or n.len == 0:
|
if not isDeepConstExpr(n) or n.len == 0:
|
||||||
if skipTypes(n.typ, abstractVarRange).kind == tySequence:
|
if skipTypes(n.typ, abstractVarRange).kind == tySequence:
|
||||||
return true
|
return true
|
||||||
elif optNilSeqs notin p.options and
|
elif n.kind in nkStrKinds and n.strVal.len == 0:
|
||||||
n.kind in nkStrKinds and n.strVal.len == 0:
|
|
||||||
# Empty strings are codegen'd as NIM_NIL so it's just a pointer copy
|
# Empty strings are codegen'd as NIM_NIL so it's just a pointer copy
|
||||||
return true
|
return true
|
||||||
result = n.kind in nkCallKinds
|
result = n.kind in nkCallKinds
|
||||||
|
|
@ -1371,8 +1369,7 @@ proc genNewSeq(p: BProc, e: PNode) =
|
||||||
getTypeDesc(p.module, seqtype.lastSon),
|
getTypeDesc(p.module, seqtype.lastSon),
|
||||||
getSeqPayloadType(p.module, seqtype)])
|
getSeqPayloadType(p.module, seqtype)])
|
||||||
else:
|
else:
|
||||||
let lenIsZero = optNilSeqs notin p.options and
|
let lenIsZero = e[2].kind == nkIntLit and e[2].intVal == 0
|
||||||
e[2].kind == nkIntLit and e[2].intVal == 0
|
|
||||||
genNewSeqAux(p, a, b.rdLoc, lenIsZero)
|
genNewSeqAux(p, a, b.rdLoc, lenIsZero)
|
||||||
gcUsage(p.config, e)
|
gcUsage(p.config, e)
|
||||||
|
|
||||||
|
|
@ -1497,8 +1494,7 @@ proc genSeqConstr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
getSeqPayloadType(p.module, seqtype)])
|
getSeqPayloadType(p.module, seqtype)])
|
||||||
else:
|
else:
|
||||||
# generate call to newSeq before adding the elements per hand:
|
# generate call to newSeq before adding the elements per hand:
|
||||||
genNewSeqAux(p, dest[], l,
|
genNewSeqAux(p, dest[], l, n.len == 0)
|
||||||
optNilSeqs notin p.options and n.len == 0)
|
|
||||||
for i in 0..<n.len:
|
for i in 0..<n.len:
|
||||||
initLoc(arr, locExpr, n[i], OnHeap)
|
initLoc(arr, locExpr, n[i], OnHeap)
|
||||||
arr.r = ropecg(p.module, "$1$3[$2]", [rdLoc(dest[]), intLiteral(i), dataField(p)])
|
arr.r = ropecg(p.module, "$1$3[$2]", [rdLoc(dest[]), intLiteral(i), dataField(p)])
|
||||||
|
|
@ -1527,7 +1523,7 @@ proc genArrToSeq(p: BProc, n: PNode, d: var TLoc) =
|
||||||
[rdLoc d, L, getTypeDesc(p.module, seqtype.lastSon),
|
[rdLoc d, L, getTypeDesc(p.module, seqtype.lastSon),
|
||||||
getSeqPayloadType(p.module, seqtype)])
|
getSeqPayloadType(p.module, seqtype)])
|
||||||
else:
|
else:
|
||||||
genNewSeqAux(p, d, intLiteral(L), optNilSeqs notin p.options and L == 0)
|
genNewSeqAux(p, d, intLiteral(L), L == 0)
|
||||||
initLocExpr(p, n[1], a)
|
initLocExpr(p, n[1], a)
|
||||||
# bug #5007; do not produce excessive C source code:
|
# bug #5007; do not produce excessive C source code:
|
||||||
if L < 10:
|
if L < 10:
|
||||||
|
|
|
||||||
|
|
@ -318,7 +318,9 @@ proc testCompileOption*(conf: ConfigRef; switch: string, info: TLineInfo): bool
|
||||||
of "implicitstatic": result = contains(conf.options, optImplicitStatic)
|
of "implicitstatic": result = contains(conf.options, optImplicitStatic)
|
||||||
of "patterns", "trmacros": result = contains(conf.options, optTrMacros)
|
of "patterns", "trmacros": result = contains(conf.options, optTrMacros)
|
||||||
of "excessivestacktrace": result = contains(conf.globalOptions, optExcessiveStackTrace)
|
of "excessivestacktrace": result = contains(conf.globalOptions, optExcessiveStackTrace)
|
||||||
of "nilseqs": result = contains(conf.options, optNilSeqs)
|
of "nilseqs":
|
||||||
|
warningDeprecated(conf, info, "nilseqs is a deprecated noop")
|
||||||
|
result = false
|
||||||
else: invalidCmdLineOption(conf, passCmd1, switch, info)
|
else: invalidCmdLineOption(conf, passCmd1, switch, info)
|
||||||
|
|
||||||
proc processPath(conf: ConfigRef; path: string, info: TLineInfo,
|
proc processPath(conf: ConfigRef; path: string, info: TLineInfo,
|
||||||
|
|
@ -650,7 +652,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
else:
|
else:
|
||||||
undefSymbol(conf.symbols, "hotcodereloading")
|
undefSymbol(conf.symbols, "hotcodereloading")
|
||||||
undefSymbol(conf.symbols, "useNimRtl")
|
undefSymbol(conf.symbols, "useNimRtl")
|
||||||
of "nilseqs": processOnOffSwitch(conf, {optNilSeqs}, arg, pass, info)
|
of "nilseqs": warningDeprecated(conf, info, "nilseqs is a deprecated noop")
|
||||||
of "checks", "x": processOnOffSwitch(conf, ChecksOptions, arg, pass, info)
|
of "checks", "x": processOnOffSwitch(conf, ChecksOptions, arg, pass, info)
|
||||||
of "floatchecks":
|
of "floatchecks":
|
||||||
processOnOffSwitch(conf, {optNaNCheck, optInfCheck}, arg, pass, info)
|
processOnOffSwitch(conf, {optNaNCheck, optInfCheck}, arg, pass, info)
|
||||||
|
|
|
||||||
|
|
@ -590,6 +590,9 @@ template localError*(conf: ConfigRef; info: TLineInfo, format: string, params: o
|
||||||
template message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
template message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
|
||||||
liMessage(conf, info, msg, arg, doNothing, instLoc())
|
liMessage(conf, info, msg, arg, doNothing, instLoc())
|
||||||
|
|
||||||
|
proc warningDeprecated*(conf: ConfigRef, info: TLineInfo = gCmdLineInfo, msg = "") {.inline.} =
|
||||||
|
message(conf, info, warnDeprecated, msg)
|
||||||
|
|
||||||
proc internalErrorImpl(conf: ConfigRef; info: TLineInfo, errMsg: string, info2: InstantiationInfo) =
|
proc internalErrorImpl(conf: ConfigRef; info: TLineInfo, errMsg: string, info2: InstantiationInfo) =
|
||||||
if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return
|
if conf.cmd == cmdIdeTools and conf.structuredErrorHook.isNil: return
|
||||||
writeContext(conf, info)
|
writeContext(conf, info)
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ type # please make sure we have under 32 options
|
||||||
# evaluation
|
# evaluation
|
||||||
optTrMacros, # en/disable pattern matching
|
optTrMacros, # en/disable pattern matching
|
||||||
optMemTracker,
|
optMemTracker,
|
||||||
optNilSeqs,
|
|
||||||
optSinkInference # 'sink T' inference
|
optSinkInference # 'sink T' inference
|
||||||
optCursorInference
|
optCursorInference
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -556,12 +556,6 @@ proc recordRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||||
proc allowsNil(f: PType): TTypeRelation {.inline.} =
|
proc allowsNil(f: PType): TTypeRelation {.inline.} =
|
||||||
result = if tfNotNil notin f.flags: isSubtype else: isNone
|
result = if tfNotNil notin f.flags: isSubtype else: isNone
|
||||||
|
|
||||||
proc allowsNilDeprecated(c: TCandidate, f: PType): TTypeRelation =
|
|
||||||
if optNilSeqs in c.c.config.options:
|
|
||||||
result = allowsNil(f)
|
|
||||||
else:
|
|
||||||
result = isNone
|
|
||||||
|
|
||||||
proc inconsistentVarTypes(f, a: PType): bool {.inline.} =
|
proc inconsistentVarTypes(f, a: PType): bool {.inline.} =
|
||||||
result = f.kind != a.kind and
|
result = f.kind != a.kind and
|
||||||
(f.kind in {tyVar, tyLent, tySink} or a.kind in {tyVar, tyLent, tySink})
|
(f.kind in {tyVar, tyLent, tySink} or a.kind in {tyVar, tyLent, tySink})
|
||||||
|
|
@ -1300,7 +1294,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
|
||||||
result = isNone
|
result = isNone
|
||||||
elif tfNotNil in f.flags and tfNotNil notin a.flags:
|
elif tfNotNil in f.flags and tfNotNil notin a.flags:
|
||||||
result = isNilConversion
|
result = isNilConversion
|
||||||
of tyNil: result = allowsNilDeprecated(c, f)
|
of tyNil: result = isNone
|
||||||
else: discard
|
else: discard
|
||||||
of tyOrdinal:
|
of tyOrdinal:
|
||||||
if isOrdinalType(a, allowEnumWithHoles = optNimV1Emulation in c.c.config.globalOptions):
|
if isOrdinalType(a, allowEnumWithHoles = optNimV1Emulation in c.c.config.globalOptions):
|
||||||
|
|
@ -1396,7 +1390,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
|
||||||
result = isNilConversion
|
result = isNilConversion
|
||||||
else:
|
else:
|
||||||
result = isEqual
|
result = isEqual
|
||||||
of tyNil: result = allowsNilDeprecated(c, f)
|
of tyNil: result = isNone
|
||||||
else: discard
|
else: discard
|
||||||
of tyCString:
|
of tyCString:
|
||||||
# conversion from string to cstring is automatic:
|
# conversion from string to cstring is automatic:
|
||||||
|
|
|
||||||
|
|
@ -102,8 +102,6 @@ Advanced options:
|
||||||
--excessiveStackTrace:on|off
|
--excessiveStackTrace:on|off
|
||||||
stack traces use full file paths
|
stack traces use full file paths
|
||||||
--stackTraceMsgs:on|off enable user defined stack frame msgs via `setFrameMsg`
|
--stackTraceMsgs:on|off enable user defined stack frame msgs via `setFrameMsg`
|
||||||
--nilseqs:on|off allow 'nil' for strings/seqs for
|
|
||||||
backwards compatibility
|
|
||||||
--seqsv2:on|off use the new string/seq implementation based on
|
--seqsv2:on|off use the new string/seq implementation based on
|
||||||
destructors
|
destructors
|
||||||
--skipCfg:on|off do not read the nim installation's configuration file
|
--skipCfg:on|off do not read the nim installation's configuration file
|
||||||
|
|
|
||||||
|
|
@ -1600,26 +1600,19 @@ 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 not compileOption("nilseqs"):
|
when true: # PRTEMP: remove?
|
||||||
{.pragma: nilError, error.}
|
proc isNil*[T](x: seq[T]): bool {.noSideEffect, magic: "IsNil", error.}
|
||||||
else:
|
## Seqs are no longer nil by default, but set and empty.
|
||||||
{.pragma: nilError.}
|
## Check for zero length instead.
|
||||||
|
##
|
||||||
|
## See also:
|
||||||
|
## * `isNil(string) <#isNil,string>`_
|
||||||
|
|
||||||
proc isNil*[T](x: seq[T]): bool {.noSideEffect, magic: "IsNil", nilError.}
|
proc isNil*(x: string): bool {.noSideEffect, magic: "IsNil", error.}
|
||||||
## Requires `--nilseqs:on` since 0.19.
|
## See also:
|
||||||
##
|
## * `isNil(seq[T]) <#isNil,seq[T]>`_
|
||||||
## Seqs are no longer nil by default, but set and empty.
|
|
||||||
## Check for zero length instead.
|
|
||||||
##
|
|
||||||
## See also:
|
|
||||||
## * `isNil(string) <#isNil,string>`_
|
|
||||||
|
|
||||||
proc isNil*[T](x: ref T): bool {.noSideEffect, magic: "IsNil".}
|
proc isNil*[T](x: ref T): bool {.noSideEffect, magic: "IsNil".}
|
||||||
proc isNil*(x: string): bool {.noSideEffect, magic: "IsNil", nilError.}
|
|
||||||
## Requires `--nilseqs:on`.
|
|
||||||
##
|
|
||||||
## See also:
|
|
||||||
## * `isNil(seq[T]) <#isNil,seq[T]>`_
|
|
||||||
|
|
||||||
proc isNil*[T](x: ptr T): bool {.noSideEffect, magic: "IsNil".}
|
proc isNil*[T](x: ptr T): bool {.noSideEffect, magic: "IsNil".}
|
||||||
proc isNil*(x: pointer): bool {.noSideEffect, magic: "IsNil".}
|
proc isNil*(x: pointer): bool {.noSideEffect, magic: "IsNil".}
|
||||||
|
|
@ -2985,15 +2978,15 @@ 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 not compileOption("nilseqs"):
|
when true: # xxx PRTEMP remove
|
||||||
# bug #9149; ensure that 'typeof(nil)' does not match *too* well by using 'typeof(nil) | typeof(nil)',
|
# bug #9149; ensure that 'typeof(nil)' does not match *too* well by using 'typeof(nil) | typeof(nil)',
|
||||||
# especially for converters, see tests/overload/tconverter_to_string.nim
|
# especially for converters, see tests/overload/tconverter_to_string.nim
|
||||||
# Eventually we will be able to remove this hack completely.
|
# Eventually we will be able to remove this hack completely.
|
||||||
proc `==`*(x: string; y: typeof(nil) | typeof(nil)): bool {.
|
proc `==`*(x: string; y: typeof(nil) | typeof(nil)): bool {.
|
||||||
error: "'nil' is now invalid for 'string'; compile with --nilseqs:on for a migration period".} =
|
error: "'nil' is now invalid for 'string'".} =
|
||||||
discard
|
discard
|
||||||
proc `==`*(x: typeof(nil) | typeof(nil); y: string): bool {.
|
proc `==`*(x: typeof(nil) | typeof(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'".} =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
template closureScope*(body: untyped): untyped =
|
template closureScope*(body: untyped): untyped =
|
||||||
|
|
|
||||||
|
|
@ -250,8 +250,6 @@ proc jsTests(r: var TResults, cat: Category, options: string) =
|
||||||
# ------------------------- nim in action -----------
|
# ------------------------- nim in action -----------
|
||||||
|
|
||||||
proc testNimInAction(r: var TResults, cat: Category, options: string) =
|
proc testNimInAction(r: var TResults, cat: Category, options: string) =
|
||||||
let options = options & " --nilseqs:on"
|
|
||||||
|
|
||||||
template test(filename: untyped) =
|
template test(filename: untyped) =
|
||||||
testSpec r, makeTest(filename, options, cat)
|
testSpec r, makeTest(filename, options, cat)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: "nim $target --nilseqs:off $options $file"
|
cmd: "nim $target $options $file"
|
||||||
output: "Hello"
|
output: "Hello"
|
||||||
ccodecheck: "\\i@'a = ((NimStringDesc*) NIM_NIL)'"
|
ccodecheck: "\\i@'a = ((NimStringDesc*) NIM_NIL)'"
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
targets: "cpp"
|
targets: "cpp"
|
||||||
output: "hello"
|
output: "hello"
|
||||||
cmd: "nim cpp --nilseqs:on --clearNimblePath --nimblePath:build/deps/pkgs $file"
|
cmd: "nim cpp --clearNimblePath --nimblePath:build/deps/pkgs $file"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# bug #3299
|
# bug #3299
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@ path = "dependencies/genpacket"
|
||||||
path = "enet_server"
|
path = "enet_server"
|
||||||
debugger = off
|
debugger = off
|
||||||
warning[SmallLshouldNotBeUsed] = off
|
warning[SmallLshouldNotBeUsed] = off
|
||||||
nilseqs = on
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ block: # Block added due to clash.
|
||||||
let dog = Dog()
|
let dog = Dog()
|
||||||
dog.bark() #<2>
|
dog.bark() #<2>
|
||||||
|
|
||||||
import sequtils, future, strutils
|
import sequtils, sugar, strutils
|
||||||
let list = @["Dominik Picheta", "Andreas Rumpf", "Desmond Hume"]
|
let list = @["Dominik Picheta", "Andreas Rumpf", "Desmond Hume"]
|
||||||
list.map(
|
list.map(
|
||||||
(x: string) -> (string, string) => (x.split[0], x.split[1])
|
(x: string) -> (string, string) => (x.split[0], x.split[1])
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ proc resultVar2: string =
|
||||||
result.add("returned")
|
result.add("returned")
|
||||||
|
|
||||||
doAssert implicit() == "I will be returned"
|
doAssert implicit() == "I will be returned"
|
||||||
doAssert discarded() == nil
|
doAssert discarded().len == 0
|
||||||
doAssert explicit() == "I will be returned"
|
doAssert explicit() == "I will be returned"
|
||||||
doAssert resultVar() == "I will be returned"
|
doAssert resultVar() == "I will be returned"
|
||||||
doAssert resultVar2() == "I will be returned"
|
doAssert resultVar2() == "I will be returned"
|
||||||
|
|
@ -140,7 +140,7 @@ let numbers = @[1, 2, 3, 4, 5, 6]
|
||||||
let odd = filter(numbers, proc (x: int): bool = x mod 2 != 0)
|
let odd = filter(numbers, proc (x: int): bool = x mod 2 != 0)
|
||||||
doAssert odd == @[1, 3, 5]
|
doAssert odd == @[1, 3, 5]
|
||||||
|
|
||||||
import sequtils, future
|
import sequtils, sugar
|
||||||
let numbers1 = @[1, 2, 3, 4, 5, 6]
|
let numbers1 = @[1, 2, 3, 4, 5, 6]
|
||||||
let odd1 = filter(numbers1, (x: int) -> bool => x mod 2 != 0)
|
let odd1 = filter(numbers1, (x: int) -> bool => x mod 2 != 0)
|
||||||
assert odd1 == @[1, 3, 5]
|
assert odd1 == @[1, 3, 5]
|
||||||
|
|
@ -149,7 +149,7 @@ proc isValid(x: int, validator: proc (x: int): bool) =
|
||||||
if validator(x): echo(x, " is valid")
|
if validator(x): echo(x, " is valid")
|
||||||
else: echo(x, " is NOT valid")
|
else: echo(x, " is NOT valid")
|
||||||
|
|
||||||
import future
|
import sugar
|
||||||
proc isValid2(x: int, validator: (x: int) -> bool) =
|
proc isValid2(x: int, validator: (x: int) -> bool) =
|
||||||
if validator(x): echo(x, " is valid")
|
if validator(x): echo(x, " is valid")
|
||||||
else: echo(x, " is NOT valid")
|
else: echo(x, " is NOT valid")
|
||||||
|
|
@ -193,7 +193,7 @@ doAssertRaises(IndexDefect):
|
||||||
|
|
||||||
block:
|
block:
|
||||||
var list = newSeq[string](3)
|
var list = newSeq[string](3)
|
||||||
assert list[0] == nil
|
assert list[0].len == 0
|
||||||
list[0] = "Foo"
|
list[0] = "Foo"
|
||||||
list[1] = "Bar"
|
list[1] = "Bar"
|
||||||
list[2] = "Baz"
|
list[2] = "Baz"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue