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
parent ed2fb36bc6
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")
conf.selectedGC = 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":
case arg.normalize
of "off": conf.globalOptions = conf.globalOptions - {optStyleHint, optStyleError}

View File

@@ -89,6 +89,8 @@ Advanced options:
strings is allowed; only for backwards compatibility
--nilseqs:on|off allow 'nil' for strings/seqs for
backwards compatibility
--seqsv2:on|off use the new string/seq implementation based on
destructors
--oldast:on|off use old AST for backwards compatibility
--skipCfg:on|off do not read the nim installation'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 \
## "fake variables" like `var EBADF {.importc.}: cint`.
when not defined(JS) and not defined(gcDestructors):
when not defined(JS) and not defined(nimSeqsV2):
type
TGenericSeq {.compilerproc, pure, inheritable.} = object
len, reserved: int
@@ -684,7 +684,7 @@ when not defined(JS) and not defined(gcDestructors):
NimString = ptr NimStringDesc
when not defined(JS) and not defined(nimscript):
when not defined(gcDestructors):
when not defined(nimSeqsV2):
template space(s: PGenericSeq): int {.dirty.} =
s.reserved and not (seqShallowFlag or strlitFlag)
when not defined(nimV2):
@@ -1020,7 +1020,7 @@ when not defined(JS):
## assert len(x) == 3
## x[0] = 10
result = newSeqOfCap[T](len)
when defined(gcDestructors):
when defined(nimSeqsV2):
cast[ptr int](addr result)[] = len
else:
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":
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.}
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.}
## 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)
for i in 0..high(y): x[xl+i] = y[i]
when defined(gcDestructors):
when defined(nimSeqsV2):
template movingCopy(a, b) =
a = move(b)
else:
@@ -3039,7 +3039,7 @@ proc `==`*[T](x, y: seq[T]): bool {.noSideEffect.} =
else:
when not defined(JS):
proc seqToPtr[T](x: seq[T]): pointer {.inline, noSideEffect.} =
when defined(gcDestructors):
when defined(nimSeqsV2):
result = cast[NimSeqV2[T]](x).p
else:
result = cast[pointer](x)
@@ -3135,7 +3135,7 @@ when not defined(js):
name: cstring
PNimType = ptr TNimType
when defined(gcDestructors) and not defined(nimscript):
when defined(nimSeqsV2) and not defined(nimscript):
include "core/strs"
include "core/seqs"
@@ -3784,7 +3784,7 @@ when not defined(JS): #and not defined(nimscript):
{.pop.}
{.push stack_trace: off, profiler:off.}
when hasAlloc:
when not defined(gcDestructors):
when not defined(nimSeqsV2):
include "system/sysstr"
{.pop.}
when hasAlloc: include "system/strmantle"
@@ -4199,7 +4199,7 @@ proc shallow*(s: var string) {.noSideEffect, inline.} =
## perform deep copies of `s`.
##
## 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)
if s == nil:
s = cast[PGenericSeq](newString(0))

View File

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

View File

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

View File

@@ -518,7 +518,7 @@ else:
else:
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.} =
when defined(gcRegions):
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)
add result, "]"
when defined(gcDestructors):
when defined(nimSeqsV2):
type
GenericSeq = object
len: int