summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-10-19 19:30:48 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-10-20 08:11:07 +0200
commit0eae2217b69541ea8ce1cf6509732928fb0869ee (patch)
tree36a4b4cfdc732f96eec13bf1d36605e79d0138a1
parented2fb36bc61bd5272734899783ede5e6f285da0e (diff)
downloadNim-0eae2217b69541ea8ce1cf6509732928fb0869ee.tar.gz
first implementation of the new --seqsv2 switch
-rw-r--r--compiler/commands.nim5
-rw-r--r--doc/advopt.txt2
-rw-r--r--lib/system.nim20
-rw-r--r--lib/system/excpt.nim2
-rw-r--r--lib/system/gc_ms.nim4
-rw-r--r--lib/system/mmdisp.nim2
-rw-r--r--lib/system/repr.nim2
7 files changed, 22 insertions, 15 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 05626a9c3..a3ab6e522 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -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}
diff --git a/doc/advopt.txt b/doc/advopt.txt
index 96db6a9c2..351815ade 100644
--- a/doc/advopt.txt
+++ b/doc/advopt.txt
@@ -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
diff --git a/lib/system.nim b/lib/system.nim
index a7d8e8f05..5e1bcd309 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -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))
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index 1eb4cedc8..e3448ff4c 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -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)
diff --git a/lib/system/gc_ms.nim b/lib/system/gc_ms.nim
index 3ce428930..271543445 100644
--- a/lib/system/gc_ms.nim
+++ b/lib/system/gc_ms.nim
@@ -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)
diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim
index cba88104d..de89acd33 100644
--- a/lib/system/mmdisp.nim
+++ b/lib/system/mmdisp.nim
@@ -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
diff --git a/lib/system/repr.nim b/lib/system/repr.nim
index 97975277b..0c7848c75 100644
--- a/lib/system/repr.nim
+++ b/lib/system/repr.nim
@@ -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