summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-10-06 13:16:50 +0800
committerGitHub <noreply@github.com>2022-10-06 07:16:50 +0200
commit723a71bd229cad3498f01c3095a10cf9f6c3255d (patch)
tree02e51620ef031633f8a78a153eef8351a2e19f60
parent964afd30508c40f2a415d96d7bcdcabfeb26ae52 (diff)
downloadNim-723a71bd229cad3498f01c3095a10cf9f6c3255d.tar.gz
follow up #20109; remove `shallow` seqs/strings for ORC (#20502)
* remove `shallow` seqs/strings for ORC

* add a changelog item

* change url of DelaunayNim
-rw-r--r--changelog.md2
-rw-r--r--doc/nimc.md14
-rw-r--r--lib/system.nim43
-rw-r--r--testament/important_packages.nim2
-rw-r--r--tests/collections/tseq.nim6
-rw-r--r--tests/converter/t7097.nim4
-rw-r--r--tests/converter/t7098.nim4
-rw-r--r--tests/stdlib/tstrutils2.nim3
-rw-r--r--tests/system/tnilconcats.nim3
9 files changed, 36 insertions, 45 deletions
diff --git a/changelog.md b/changelog.md
index 840a19b51..6b31121e6 100644
--- a/changelog.md
+++ b/changelog.md
@@ -53,7 +53,7 @@
   or define your own `Math.trunc` polyfill using the [`emit` pragma](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-emit-pragma).
   Nim uses `Math.trunc` for the division and modulo operators for integers.
 
-- `shallowCopy` is removed for ARC/ORC. Use `move` when possible or combine assignment and
+- `shallowCopy` and `shallow` are removed for ARC/ORC. Use `move` when possible or combine assignment and
 `sink` for optimization purposes.
 
 - The `nimPreviewDotLikeOps` define is going to be removed or deprecated.
diff --git a/doc/nimc.md b/doc/nimc.md
index 0590c42a6..8671e0832 100644
--- a/doc/nimc.md
+++ b/doc/nimc.md
@@ -778,20 +778,6 @@ For `let` symbols a copy is not always necessary:
   let s = varA    # may only copy a pointer if it safe to do so
   ```
 
-
-If you know what you're doing, you can also mark single-string (or sequence)
-objects as `shallow`:idx:\:
-
-  ```Nim
-  var s = "abc"
-  shallow(s) # mark 's' as a shallow string
-  var x = s  # now might not copy the string!
-  ```
-
-Usage of `shallow` is always safe once you know the string won't be modified
-anymore, similar to Ruby's `freeze`:idx:.
-
-
 The compiler optimizes string case statements: A hashing scheme is used for them
 if several different string constants are used. So code like this is reasonably
 efficient:
diff --git a/lib/system.nim b/lib/system.nim
index dd4670577..e7712836b 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -2313,29 +2313,30 @@ when compileOption("rangechecks"):
 else:
   template rangeCheck*(cond) = discard
 
-proc shallow*[T](s: var seq[T]) {.noSideEffect, inline.} =
-  ## Marks a sequence `s` as `shallow`:idx:. Subsequent assignments will not
-  ## perform deep copies of `s`.
-  ##
-  ## This is only useful for optimization purposes.
-  if s.len == 0: return
-  when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
-    var s = cast[PGenericSeq](s)
-    s.reserved = s.reserved or seqShallowFlag
-
-proc shallow*(s: var string) {.noSideEffect, inline.} =
-  ## Marks a string `s` as `shallow`:idx:. Subsequent assignments will not
-  ## perform deep copies of `s`.
-  ##
-  ## This is only useful for optimization purposes.
-  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))
-    # string literals cannot become 'shallow':
-    if (s.reserved and strlitFlag) == 0:
+when not defined(gcArc) and not defined(gcOrc):
+  proc shallow*[T](s: var seq[T]) {.noSideEffect, inline.} =
+    ## Marks a sequence `s` as `shallow`:idx:. Subsequent assignments will not
+    ## perform deep copies of `s`.
+    ##
+    ## This is only useful for optimization purposes.
+    if s.len == 0: return
+    when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
+      var s = cast[PGenericSeq](s)
       s.reserved = s.reserved or seqShallowFlag
 
+  proc shallow*(s: var string) {.noSideEffect, inline.} =
+    ## Marks a string `s` as `shallow`:idx:. Subsequent assignments will not
+    ## perform deep copies of `s`.
+    ##
+    ## This is only useful for optimization purposes.
+    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))
+      # string literals cannot become 'shallow':
+      if (s.reserved and strlitFlag) == 0:
+        s.reserved = s.reserved or seqShallowFlag
+
 type
   NimNodeObj = object
 
diff --git a/testament/important_packages.nim b/testament/important_packages.nim
index 10e50306b..d16ba6926 100644
--- a/testament/important_packages.nim
+++ b/testament/important_packages.nim
@@ -59,7 +59,7 @@ pkg "comprehension", "nimble test", "https://github.com/alehander92/comprehensio
 pkg "criterion", allowFailure = true # pending https://github.com/disruptek/criterion/issues/3 (wrongly closed)
 pkg "datamancer"
 pkg "dashing", "nim c tests/functional.nim"
-pkg "delaunay"
+pkg "delaunay", url = "https://github.com/nim-lang/DelaunayNim", useHead = true
 pkg "docopt"
 pkg "easygl", "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl"
 pkg "elvis"
diff --git a/tests/collections/tseq.nim b/tests/collections/tseq.nim
index c4dd40052..39f066f4c 100644
--- a/tests/collections/tseq.nim
+++ b/tests/collections/tseq.nim
@@ -175,12 +175,14 @@ when not defined(nimseqsv2):
       var emptySeq: seq[int] = newSeq[int]()
       block:
         var t = @[1,2,3]
-        shallow(nilSeq)
+        when defined(gcRefc):
+          shallow(nilSeq)
         t = nilSeq
         doAssert t == @[]
       block:
         var t = @[1,2,3]
-        shallow(emptySeq)
+        when defined(gcRefc):
+          shallow(emptySeq)
         t = emptySeq
         doAssert t == @[]
       block:
diff --git a/tests/converter/t7097.nim b/tests/converter/t7097.nim
index fdb573588..d8e953080 100644
--- a/tests/converter/t7097.nim
+++ b/tests/converter/t7097.nim
@@ -10,8 +10,8 @@ proc initBytesRange*(s: var Bytes, ibegin = 0, iend = -1): BytesRange =
   let e = if iend < 0: s.len + iend + 1
           else: iend
   assert ibegin > 0 and e <= s.len
-  
-  shallow(s)
+  when defined(gcRefc):
+    shallow(s)
   result.bytes = s
   result.ibegin = ibegin
   result.iend = e
diff --git a/tests/converter/t7098.nim b/tests/converter/t7098.nim
index 8e7634882..30c9c1e25 100644
--- a/tests/converter/t7098.nim
+++ b/tests/converter/t7098.nim
@@ -14,8 +14,8 @@ proc initBytesRange*(s: var Bytes, ibegin = 0, iend = -1): BytesRange =
   let e = if iend < 0: s.len + iend + 1
           else: iend
   assert ibegin >= 0 and e <= s.len
-
-  shallow(s)
+  when defined(gcRefc):
+    shallow(s)
   result.bytes = s
   result.ibegin = ibegin
   result.iend = e
diff --git a/tests/stdlib/tstrutils2.nim b/tests/stdlib/tstrutils2.nim
index 22a935ab8..2cb5b8ec4 100644
--- a/tests/stdlib/tstrutils2.nim
+++ b/tests/stdlib/tstrutils2.nim
@@ -18,7 +18,8 @@ block: # setLen
 block: # forceCopy
   var a: string
   a = "foo"
-  shallow(a)
+  when defined(gcRefc):
+    shallow(a)
   var b: string
   b = a
   doAssert b[0].addr == a[0].addr
diff --git a/tests/system/tnilconcats.nim b/tests/system/tnilconcats.nim
index c1126405c..69fc3913c 100644
--- a/tests/system/tnilconcats.nim
+++ b/tests/system/tnilconcats.nim
@@ -26,7 +26,8 @@ when true:
 
   # casting an empty string as sequence with shallow() should not segfault
   var s2: string
-  shallow(s2)
+  when defined(gcRefc):
+    shallow(s2)
   s2 &= "foo"
   doAssert s2 == "foo"