Skip to content

system.reset is no longer magic #12937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,6 @@ when not defined(gcDestructors):
## **Note**: The `finalizer` refers to the type `T`, not to the object!
## This means that for each object of type `T` the finalizer will be called!

when defined(nimV2):
proc reset*[T](obj: var T) {.magic: "Destroy", noSideEffect.}
## Old runtime target: Resets an object `obj` to its initial (binary zero) value.
##
## New runtime target: An alias for `=destroy`.
else:
proc reset*[T](obj: var T) {.magic: "Reset", noSideEffect.}
## Old runtime target: Resets an object `obj` to its initial (binary zero) value.
##
## New runtime target: An alias for `=destroy`.

proc wasMoved*[T](obj: var T) {.magic: "WasMoved", noSideEffect.} =
## Resets an object `obj` to its initial (binary zero) value to signify
## it was "moved" and to signify its destructor should do nothing and
Expand Down Expand Up @@ -1825,6 +1814,15 @@ when defined(nimHasDefault):
proc default*(T: typedesc): T {.magic: "Default", noSideEffect.}
## returns the default value of the type ``T``.

proc reset*[T](obj: var T) {.noSideEffect.} =
## Resets an object `obj` to its default value.
obj = default(typeof(obj))
else:
when defined(nimV2):
proc reset*[T](obj: var T) {.magic: "Destroy", noSideEffect.}
else:
proc reset*[T](obj: var T) {.magic: "Reset", noSideEffect.}

proc setLen*[T](s: var seq[T], newlen: Natural) {.
magic: "SetLengthSeq", noSideEffect.}
## Sets the length of seq `s` to `newlen`. ``T`` may be any sequence type.
Expand Down