first implementation of the new --seqsv2 switch

This commit is contained in:
Araq 2019-10-19 19:30:48 +02:00 • committed by Andreas Rumpf
commit 0eae2217b6
7 changed files with 22 additions and 15 deletions

View file

@ -765,6 +765,11 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
defineSymbol(conf.symbols, "nimV2") defineSymbol(conf.symbols, "nimV2")
conf.selectedGC = gcDestructors conf.selectedGC = gcDestructors
defineSymbol(conf.symbols, "gcdestructors") defineSymbol(conf.symbols, "gcdestructors")
defineSymbol(conf.symbols, "nimSeqsV2")
of "seqsv2":
processOnOffSwitchG(conf, {optSeqDestructors}, arg, pass, info)
if pass in {passCmd2, passPP}:
defineSymbol(conf.symbols, "nimSeqsV2")
of "stylecheck": of "stylecheck":
case arg.normalize case arg.normalize
of "off": conf.globalOptions = conf.globalOptions - {optStyleHint, optStyleError} of "off": conf.globalOptions = conf.globalOptions - {optStyleHint, optStyleError}

View file

@ -89,6 +89,8 @@ Advanced options:
strings is allowed; only for backwards compatibility strings is allowed; only for backwards compatibility
--nilseqs:on|off allow 'nil' for strings/seqs for --nilseqs:on|off allow 'nil' for strings/seqs for
backwards compatibility backwards compatibility
--seqsv2:on|off use the new string/seq implementation based on
destructors
--oldast:on|off use old AST for backwards compatibility --oldast:on|off use old AST for backwards compatibility
--skipCfg:on|off do not read the nim installation's configuration file --skipCfg:on|off do not read the nim installation's configuration file
--skipUserCfg:on|off do not read the user's configuration file --skipUserCfg:on|off do not read the user's configuration file

View file

@ -671,7 +671,7 @@ include "system/inclrtl"
const NoFakeVars* = defined(nimscript) ## `true` if the backend doesn't support \ const NoFakeVars* = defined(nimscript) ## `true` if the backend doesn't support \
## "fake variables" like `var EBADF {.importc.}: cint`. ## "fake variables" like `var EBADF {.importc.}: cint`.
when not defined(JS) and not defined(gcDestructors): when not defined(JS) and not defined(nimSeqsV2):
type type
TGenericSeq {.compilerproc, pure, inheritable.} = object TGenericSeq {.compilerproc, pure, inheritable.} = object
len, reserved: int len, reserved: int
@ -684,7 +684,7 @@ when not defined(JS) and not defined(gcDestructors):
NimString = ptr NimStringDesc NimString = ptr NimStringDesc
when not defined(JS) and not defined(nimscript): when not defined(JS) and not defined(nimscript):
when not defined(gcDestructors): when not defined(nimSeqsV2):
template space(s: PGenericSeq): int {.dirty.} = template space(s: PGenericSeq): int {.dirty.} =
s.reserved and not (seqShallowFlag or strlitFlag) s.reserved and not (seqShallowFlag or strlitFlag)
when not defined(nimV2): when not defined(nimV2):
@ -1020,7 +1020,7 @@ when not defined(JS):
## assert len(x) == 3 ## assert len(x) == 3
## x[0] = 10 ## x[0] = 10
result = newSeqOfCap[T](len) result = newSeqOfCap[T](len)
when defined(gcDestructors): when defined(nimSeqsV2):
cast[ptr int](addr result)[] = len cast[ptr int](addr result)[] = len
else: else:
var s = cast[PGenericSeq](result) var s = cast[PGenericSeq](result)
@ -2111,10 +2111,10 @@ const hasAlloc = (hostOS != "standalone" or not defined(nogc)) and not defined(n
when not defined(JS) and not defined(nimscript) and hostOS != "standalone": when not defined(JS) and not defined(nimscript) and hostOS != "standalone":
include "system/cgprocs" include "system/cgprocs"
when not defined(JS) and not defined(nimscript) and hasAlloc and not defined(gcDestructors): when not defined(JS) and not defined(nimscript) and hasAlloc and not defined(nimSeqsV2):
proc addChar(s: NimString, c: char): NimString {.compilerproc, benign.} proc addChar(s: NimString, c: char): NimString {.compilerproc, benign.}
when not defined(gcDestructors) or defined(nimscript): when not defined(nimSeqsV2) or defined(nimscript):
proc add*[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.} proc add*[T](x: var seq[T], y: T) {.magic: "AppendSeqElem", noSideEffect.}
## Generic proc for adding a data item `y` to a container `x`. ## Generic proc for adding a data item `y` to a container `x`.
## ##
@ -2141,7 +2141,7 @@ proc add*[T](x: var seq[T], y: openArray[T]) {.noSideEffect.} =
setLen(x, xl + y.len) setLen(x, xl + y.len)
for i in 0..high(y): x[xl+i] = y[i] for i in 0..high(y): x[xl+i] = y[i]
when defined(gcDestructors): when defined(nimSeqsV2):
template movingCopy(a, b) = template movingCopy(a, b) =
a = move(b) a = move(b)
else: else:
@ -3039,7 +3039,7 @@ proc `==`*[T](x, y: seq[T]): bool {.noSideEffect.} =
else: else:
when not defined(JS): when not defined(JS):
proc seqToPtr[T](x: seq[T]): pointer {.inline, noSideEffect.} = proc seqToPtr[T](x: seq[T]): pointer {.inline, noSideEffect.} =
when defined(gcDestructors): when defined(nimSeqsV2):
result = cast[NimSeqV2[T]](x).p result = cast[NimSeqV2[T]](x).p
else: else:
result = cast[pointer](x) result = cast[pointer](x)
@ -3135,7 +3135,7 @@ when not defined(js):
name: cstring name: cstring
PNimType = ptr TNimType PNimType = ptr TNimType
when defined(gcDestructors) and not defined(nimscript): when defined(nimSeqsV2) and not defined(nimscript):
include "core/strs" include "core/strs"
include "core/seqs" include "core/seqs"
@ -3784,7 +3784,7 @@ when not defined(JS): #and not defined(nimscript):
{.pop.} {.pop.}
{.push stack_trace: off, profiler:off.} {.push stack_trace: off, profiler:off.}
when hasAlloc: when hasAlloc:
when not defined(gcDestructors): when not defined(nimSeqsV2):
include "system/sysstr" include "system/sysstr"
{.pop.} {.pop.}
when hasAlloc: include "system/strmantle" when hasAlloc: include "system/strmantle"
@ -4199,7 +4199,7 @@ proc shallow*(s: var string) {.noSideEffect, inline.} =
## perform deep copies of `s`. ## perform deep copies of `s`.
## ##
## This is only useful for optimization purposes. ## This is only useful for optimization purposes.
when not defined(JS) and not defined(nimscript) and not defined(gcDestructors): when not defined(JS) and not defined(nimscript) and not defined(nimSeqsV2):
var s = cast[PGenericSeq](s) var s = cast[PGenericSeq](s)
if s == nil: if s == nil:
s = cast[PGenericSeq](newString(0)) s = cast[PGenericSeq](newString(0))

View file

@ -439,7 +439,7 @@ proc getStackTrace(e: ref Exception): string =
proc getStackTraceEntries*(e: ref Exception): seq[StackTraceEntry] = proc getStackTraceEntries*(e: ref Exception): seq[StackTraceEntry] =
## Returns the attached stack trace to the exception ``e`` as ## Returns the attached stack trace to the exception ``e`` as
## a ``seq``. This is not yet available for the JS backend. ## a ``seq``. This is not yet available for the JS backend.
when not defined(gcDestructors): when not defined(nimSeqsV2):
shallowCopy(result, e.trace) shallowCopy(result, e.trace)
else: else:
result = move(e.trace) result = move(e.trace)

View file

@ -254,7 +254,7 @@ proc forAllChildren(cell: PCell, op: WalkOp) =
of tyRef: # common case of tyRef: # common case
forAllChildrenAux(cellToUsr(cell), cell.typ.base, op) forAllChildrenAux(cellToUsr(cell), cell.typ.base, op)
of tySequence: of tySequence:
when not defined(gcDestructors): when not defined(nimSeqsV2):
var d = cast[ByteAddress](cellToUsr(cell)) var d = cast[ByteAddress](cellToUsr(cell))
var s = cast[PGenericSeq](d) var s = cast[PGenericSeq](d)
if s != nil: if s != nil:
@ -304,7 +304,7 @@ proc newObjRC1(typ: PNimType, size: int): pointer {.compilerRtl.} =
zeroMem(result, size) zeroMem(result, size)
when defined(memProfiler): nimProfile(size) when defined(memProfiler): nimProfile(size)
when not defined(gcDestructors): when not defined(nimSeqsV2):
proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.} = proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.} =
# `newObj` already uses locks, so no need for them here. # `newObj` already uses locks, so no need for them here.
let size = addInt(mulInt(len, typ.base.size), GenericSeqSize) let size = addInt(mulInt(len, typ.base.size), GenericSeqSize)

View file

@ -518,7 +518,7 @@ else:
else: else:
include "system/gc" include "system/gc"
when not declared(nimNewSeqOfCap) and not defined(gcDestructors): when not declared(nimNewSeqOfCap) and not defined(nimSeqsV2):
proc nimNewSeqOfCap(typ: PNimType, cap: int): pointer {.compilerproc.} = proc nimNewSeqOfCap(typ: PNimType, cap: int): pointer {.compilerproc.} =
when defined(gcRegions): when defined(gcRegions):
let s = mulInt(cap, typ.base.size) # newStr already adds GenericSeqSize let s = mulInt(cap, typ.base.size) # newStr already adds GenericSeqSize

View file

@ -160,7 +160,7 @@ when not defined(useNimRtl):
reprAux(result, cast[pointer](cast[ByteAddress](p) + i*bs), typ.base, cl) reprAux(result, cast[pointer](cast[ByteAddress](p) + i*bs), typ.base, cl)
add result, "]" add result, "]"
when defined(gcDestructors): when defined(nimSeqsV2):
type type
GenericSeq = object GenericSeq = object
len: int len: int