make reset use the =destroy and wasMoved pair (#21821)

* make reset use the `=destroy` and `waMoved` pair

* fixes a space

* fixes `shrink` instead

* tiny fix

* fixes vm

* suppress the annotations since it breaks some important packages
This commit is contained in:
ringabout
2023-05-11 15:02:29 +08:00
committed by GitHub
parent 71439c2891
commit 055a00a6ef

View File

@@ -906,7 +906,15 @@ proc default*[T](_: typedesc[T]): T {.magic: "Default", noSideEffect.} =
proc reset*[T](obj: var T) {.noSideEffect.} =
## Resets an object `obj` to its default value.
obj = default(typeof(obj))
when nimvm:
obj = default(typeof(obj))
else:
when defined(gcDestructors):
{.cast(noSideEffect), cast(raises: []), cast(tags: []).}:
`=destroy`(obj)
wasMoved(obj)
else:
obj = default(typeof(obj))
proc setLen*[T](s: var seq[T], newlen: Natural) {.
magic: "SetLengthSeq", noSideEffect.}