make move use =wasMoved internally (#22032)

* make `move` use `=wasMoved` internally

* fixes tests

* fixes spawn finally

* fixes views

* rename to internalMove

* add a test case
This commit is contained in:
ringabout
2023-06-09 21:53:12 +08:00
committed by GitHub
parent 49e11d9dcc
commit 64b27edd3a
5 changed files with 50 additions and 11 deletions

View File

@@ -147,10 +147,26 @@ proc wasMoved*[T](obj: var T) {.inline, noSideEffect.} =
{.cast(raises: []), cast(tags: []).}:
`=wasMoved`(obj)
proc move*[T](x: var T): T {.magic: "Move", noSideEffect.} =
result = x
{.cast(raises: []), cast(tags: []).}:
`=wasMoved`(x)
const notJSnotNims = not defined(js) and not defined(nimscript)
const arcLikeMem = defined(gcArc) or defined(gcAtomicArc) or defined(gcOrc)
when notJSnotNims and arcLikeMem:
proc internalMove[T](x: var T): T {.magic: "Move", noSideEffect, compilerproc.} =
result = x
proc move*[T](x: var T): T {.noSideEffect, nodestroy.} =
{.cast(noSideEffect).}:
when nimvm:
result = internalMove(x)
else:
result = internalMove(x)
{.cast(raises: []), cast(tags: []).}:
`=wasMoved`(x)
else:
proc move*[T](x: var T): T {.magic: "Move", noSideEffect.} =
result = x
{.cast(raises: []), cast(tags: []).}:
`=wasMoved`(x)
type
range*[T]{.magic: "Range".} ## Generic type to construct range types.
@@ -415,7 +431,6 @@ include "system/inclrtl"
const NoFakeVars = defined(nimscript) ## `true` if the backend doesn't support \
## "fake variables" like `var EBADF {.importc.}: cint`.
const notJSnotNims = not defined(js) and not defined(nimscript)
when not defined(js) and not defined(nimSeqsV2):
type