follow up #20109; remove shallow seqs/strings for ORC (#20502)

* remove `shallow` seqs/strings for ORC

* add a changelog item

* change url of DelaunayNim
This commit is contained in:
ringabout 2022-10-06 13:16:50 +08:00 • committed by GitHub
commit 723a71bd22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 45 deletions

View file

@ -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). 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. 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. `sink` for optimization purposes.
- The `nimPreviewDotLikeOps` define is going to be removed or deprecated. - The `nimPreviewDotLikeOps` define is going to be removed or deprecated.

View file

@ -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 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 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 if several different string constants are used. So code like this is reasonably
efficient: efficient:

View file

@ -2313,7 +2313,8 @@ when compileOption("rangechecks"):
else: else:
template rangeCheck*(cond) = discard template rangeCheck*(cond) = discard
proc shallow*[T](s: var seq[T]) {.noSideEffect, inline.} = 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 ## Marks a sequence `s` as `shallow`:idx:. Subsequent assignments will not
## perform deep copies of `s`. ## perform deep copies of `s`.
## ##
@ -2323,7 +2324,7 @@ proc shallow*[T](s: var seq[T]) {.noSideEffect, inline.} =
var s = cast[PGenericSeq](s) var s = cast[PGenericSeq](s)
s.reserved = s.reserved or seqShallowFlag s.reserved = s.reserved or seqShallowFlag
proc shallow*(s: var string) {.noSideEffect, inline.} = proc shallow*(s: var string) {.noSideEffect, inline.} =
## Marks a string `s` as `shallow`:idx:. Subsequent assignments will not ## Marks a string `s` as `shallow`:idx:. Subsequent assignments will not
## perform deep copies of `s`. ## perform deep copies of `s`.
## ##

View file

@ -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 "criterion", allowFailure = true # pending https://github.com/disruptek/criterion/issues/3 (wrongly closed)
pkg "datamancer" pkg "datamancer"
pkg "dashing", "nim c tests/functional.nim" pkg "dashing", "nim c tests/functional.nim"
pkg "delaunay" pkg "delaunay", url = "https://github.com/nim-lang/DelaunayNim", useHead = true
pkg "docopt" pkg "docopt"
pkg "easygl", "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl" pkg "easygl", "nim c -o:egl -r src/easygl.nim", "https://github.com/jackmott/easygl"
pkg "elvis" pkg "elvis"

View file

@ -175,11 +175,13 @@ when not defined(nimseqsv2):
var emptySeq: seq[int] = newSeq[int]() var emptySeq: seq[int] = newSeq[int]()
block: block:
var t = @[1,2,3] var t = @[1,2,3]
when defined(gcRefc):
shallow(nilSeq) shallow(nilSeq)
t = nilSeq t = nilSeq
doAssert t == @[] doAssert t == @[]
block: block:
var t = @[1,2,3] var t = @[1,2,3]
when defined(gcRefc):
shallow(emptySeq) shallow(emptySeq)
t = emptySeq t = emptySeq
doAssert t == @[] doAssert t == @[]

View file

@ -10,7 +10,7 @@ proc initBytesRange*(s: var Bytes, ibegin = 0, iend = -1): BytesRange =
let e = if iend < 0: s.len + iend + 1 let e = if iend < 0: s.len + iend + 1
else: iend else: iend
assert ibegin > 0 and e <= s.len assert ibegin > 0 and e <= s.len
when defined(gcRefc):
shallow(s) shallow(s)
result.bytes = s result.bytes = s
result.ibegin = ibegin result.ibegin = ibegin

View file

@ -14,7 +14,7 @@ proc initBytesRange*(s: var Bytes, ibegin = 0, iend = -1): BytesRange =
let e = if iend < 0: s.len + iend + 1 let e = if iend < 0: s.len + iend + 1
else: iend else: iend
assert ibegin >= 0 and e <= s.len assert ibegin >= 0 and e <= s.len
when defined(gcRefc):
shallow(s) shallow(s)
result.bytes = s result.bytes = s
result.ibegin = ibegin result.ibegin = ibegin

View file

@ -18,6 +18,7 @@ block: # setLen
block: # forceCopy block: # forceCopy
var a: string var a: string
a = "foo" a = "foo"
when defined(gcRefc):
shallow(a) shallow(a)
var b: string var b: string
b = a b = a

View file

@ -26,6 +26,7 @@ when true:
# casting an empty string as sequence with shallow() should not segfault # casting an empty string as sequence with shallow() should not segfault
var s2: string var s2: string
when defined(gcRefc):
shallow(s2) shallow(s2)
s2 &= "foo" s2 &= "foo"
doAssert s2 == "foo" doAssert s2 == "foo"