Skip to content

Commit 723a71b

Browse files
authored
follow up #20109; remove shallow seqs/strings for ORC (#20502)
* remove `shallow` seqs/strings for ORC * add a changelog item * change url of DelaunayNim
1 parent 964afd3 commit 723a71b

File tree

9 files changed

+36
-45
lines changed

9 files changed

+36
-45
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
or define your own `Math.trunc` polyfill using the [`emit` pragma](https://nim-lang.org/docs/manual.html#implementation-specific-pragmas-emit-pragma).
5454
Nim uses `Math.trunc` for the division and modulo operators for integers.
5555

56-
- `shallowCopy` is removed for ARC/ORC. Use `move` when possible or combine assignment and
56+
- `shallowCopy` and `shallow` are removed for ARC/ORC. Use `move` when possible or combine assignment and
5757
`sink` for optimization purposes.
5858

5959
- The `nimPreviewDotLikeOps` define is going to be removed or deprecated.

doc/nimc.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -778,20 +778,6 @@ For `let` symbols a copy is not always necessary:
778778
let s = varA # may only copy a pointer if it safe to do so
779779
```
780780

781-
782-
If you know what you're doing, you can also mark single-string (or sequence)
783-
objects as `shallow`:idx:\:
784-
785-
```Nim
786-
var s = "abc"
787-
shallow(s) # mark 's' as a shallow string
788-
var x = s # now might not copy the string!
789-
```
790-
791-
Usage of `shallow` is always safe once you know the string won't be modified
792-
anymore, similar to Ruby's `freeze`:idx:.
793-
794-
795781
The compiler optimizes string case statements: A hashing scheme is used for them
796782
if several different string constants are used. So code like this is reasonably
797783
efficient:

lib/system.nim

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,29 +2313,30 @@ when compileOption("rangechecks"):
23132313
else:
23142314
template rangeCheck*(cond) = discard
23152315

2316-
proc shallow*[T](s: var seq[T]) {.noSideEffect, inline.} =
2317-
## Marks a sequence `s` as `shallow`:idx:. Subsequent assignments will not
2318-
## perform deep copies of `s`.
2319-
##
2320-
## This is only useful for optimization purposes.
2321-
if s.len == 0: return
2322-
when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
2323-
var s = cast[PGenericSeq](s)
2324-
s.reserved = s.reserved or seqShallowFlag
2325-
2326-
proc shallow*(s: var string) {.noSideEffect, inline.} =
2327-
## Marks a string `s` as `shallow`:idx:. Subsequent assignments will not
2328-
## perform deep copies of `s`.
2329-
##
2330-
## This is only useful for optimization purposes.
2331-
when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
2332-
var s = cast[PGenericSeq](s)
2333-
if s == nil:
2334-
s = cast[PGenericSeq](newString(0))
2335-
# string literals cannot become 'shallow':
2336-
if (s.reserved and strlitFlag) == 0:
2316+
when not defined(gcArc) and not defined(gcOrc):
2317+
proc shallow*[T](s: var seq[T]) {.noSideEffect, inline.} =
2318+
## Marks a sequence `s` as `shallow`:idx:. Subsequent assignments will not
2319+
## perform deep copies of `s`.
2320+
##
2321+
## This is only useful for optimization purposes.
2322+
if s.len == 0: return
2323+
when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
2324+
var s = cast[PGenericSeq](s)
23372325
s.reserved = s.reserved or seqShallowFlag
23382326
2327+
proc shallow*(s: var string) {.noSideEffect, inline.} =
2328+
## Marks a string `s` as `shallow`:idx:. Subsequent assignments will not
2329+
## perform deep copies of `s`.
2330+
##
2331+
## This is only useful for optimization purposes.
2332+
when not defined(js) and not defined(nimscript) and not defined(nimSeqsV2):
2333+
var s = cast[PGenericSeq](s)
2334+
if s == nil:
2335+
s = cast[PGenericSeq](newString(0))
2336+
# string literals cannot become 'shallow':
2337+
if (s.reserved and strlitFlag) == 0:
2338+
s.reserved = s.reserved or seqShallowFlag
2339+
23392340
type
23402341
NimNodeObj = object
23412342

testament/important_packages.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pkg "comprehension", "nimble test", "https://github.com/alehander92/comprehensio
5959
pkg "criterion", allowFailure = true # pending https://github.com/disruptek/criterion/issues/3 (wrongly closed)
6060
pkg "datamancer"
6161
pkg "dashing", "nim c tests/functional.nim"
62-
pkg "delaunay"
62+
pkg "delaunay", url = "https://github.com/nim-lang/DelaunayNim", useHead = true
6363
pkg "docopt"
6464
pkg "easygl", "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl"
6565
pkg "elvis"

tests/collections/tseq.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,14 @@ when not defined(nimseqsv2):
175175
var emptySeq: seq[int] = newSeq[int]()
176176
block:
177177
var t = @[1,2,3]
178-
shallow(nilSeq)
178+
when defined(gcRefc):
179+
shallow(nilSeq)
179180
t = nilSeq
180181
doAssert t == @[]
181182
block:
182183
var t = @[1,2,3]
183-
shallow(emptySeq)
184+
when defined(gcRefc):
185+
shallow(emptySeq)
184186
t = emptySeq
185187
doAssert t == @[]
186188
block:

tests/converter/t7097.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ proc initBytesRange*(s: var Bytes, ibegin = 0, iend = -1): BytesRange =
1010
let e = if iend < 0: s.len + iend + 1
1111
else: iend
1212
assert ibegin > 0 and e <= s.len
13-
14-
shallow(s)
13+
when defined(gcRefc):
14+
shallow(s)
1515
result.bytes = s
1616
result.ibegin = ibegin
1717
result.iend = e

tests/converter/t7098.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ proc initBytesRange*(s: var Bytes, ibegin = 0, iend = -1): BytesRange =
1414
let e = if iend < 0: s.len + iend + 1
1515
else: iend
1616
assert ibegin >= 0 and e <= s.len
17-
18-
shallow(s)
17+
when defined(gcRefc):
18+
shallow(s)
1919
result.bytes = s
2020
result.ibegin = ibegin
2121
result.iend = e

tests/stdlib/tstrutils2.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ block: # setLen
1818
block: # forceCopy
1919
var a: string
2020
a = "foo"
21-
shallow(a)
21+
when defined(gcRefc):
22+
shallow(a)
2223
var b: string
2324
b = a
2425
doAssert b[0].addr == a[0].addr

tests/system/tnilconcats.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ when true:
2626

2727
# casting an empty string as sequence with shallow() should not segfault
2828
var s2: string
29-
shallow(s2)
29+
when defined(gcRefc):
30+
shallow(s2)
3031
s2 &= "foo"
3132
doAssert s2 == "foo"
3233

0 commit comments

Comments
 (0)