Skip to content
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

object copy broken in vm #16780

Closed
timotheecour opened this issue Jan 21, 2021 · 0 comments · Fixed by #19902
Closed

object copy broken in vm #16780

timotheecour opened this issue Jan 21, 2021 · 0 comments · Fixed by #19902
Labels
VM see also `const` label

Comments

@timotheecour
Copy link
Member

timotheecour commented Jan 21, 2021

I found this issue while investigating ways to fix swap double evaluation bug in vm #16779; this runs into the following issue, that object copy seems broken in vm

Example

when true:
  template swap*[T](a, b: var T) =
    var a2 = addr(a)
    var b2 = addr(b)
    var aOld = a2[]
    a2[] = b2[]
    b2[] = aOld

  proc main =
    block:
      var a = 1
      var b = 2
      swap(a, b)
      echo (a,b)

    block:
      type Foo = ref object
        x: int
      var a = Foo(x:1)
      var b = Foo(x:2)
      swap(a, b)
      echo (a.x, b.x)

    block:
      type Foo = object
        x: int
      var a = Foo(x:1)
      var b = Foo(x:2)
      swap(a, b)
      echo (a.x,b.x)

  static: main()
  main()

Current Output

nim r main:
vm:
(2, 1)
(2, 1)
(1, 2)
rt:
(2, 1)
(2, 1)
(2, 1)

nim r -b:js main:
ditto

Expected Output

nim r main:
vm:
(2, 1)
(2, 1)
(2, 1)
rt:
(2, 1)
(2, 1)
(2, 1)

nim r -b:js main:
ditto

Additional Information

  • 1.5.1 2b5841c
  • note that this issue isn't a stdlib issue nor an issue with swap, it's an issue with VM
@timotheecour timotheecour added the VM see also `const` label label Jan 21, 2021
ringabout added a commit that referenced this issue Jun 16, 2022
Araq pushed a commit that referenced this issue Jun 22, 2022
 (#19902) [backport]

* revert #12217 since the root problem seems to have been fixed; fix #15974;fix #12551; fix #19464

* fix #16020; fix #16780

* fix tests and #16613

* fix #14553

* fix #19909; skip skipRegisterAddr

* fix #18641
narimiran pushed a commit that referenced this issue Jun 23, 2022
 (#19902) [backport]

* revert #12217 since the root problem seems to have been fixed; fix #15974;fix #12551; fix #19464

* fix #16020; fix #16780

* fix tests and #16613

* fix #14553

* fix #19909; skip skipRegisterAddr

* fix #18641

(cherry picked from commit 3cb2d7a)
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VM see also `const` label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant