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

swap has double evaluation bug in vm and js #16779

Open
timotheecour opened this issue Jan 21, 2021 · 0 comments
Open

swap has double evaluation bug in vm and js #16779

timotheecour opened this issue Jan 21, 2021 · 0 comments
Labels
Javascript VM see also `const` label

Comments

@timotheecour
Copy link
Member

timotheecour commented Jan 21, 2021

Example

when true:
  proc identity[T](a: var T): var T =
    echo (a, )
    a
  proc main() =
    var a = 1
    var b = 2
    swap(identity(a), identity(b))
  static: main()
  main()

Current Output

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

rt:
(1,)
(2,)

nim r -b:js main
vm:
(1,)
(1,)
(2,)
(2,)

rt:
(1,)
(1,)
(2,)
(2,)

Expected Output

vm:
(1,)
(2,)

rt:
(1,)
(2,)

Additional Information

1.5.1 2b5841c
after #16778:
nim r -b:js main
vm:
(1,)
(1,)
(2,)
(2,)

rt:
(1,)
(1,)

so js+vm and c+vm are still broken after that PR

note that attempts to fix this in VM via addr runs into #16780

@timotheecour timotheecour added the VM see also `const` label label Jan 21, 2021
Araq pushed a commit that referenced this issue Apr 3, 2024
fixes #16771

follow up #16536

Ideally it should be handled in the IR part in the future

I have also checked the double evaluation of `swap` in the JS runtime
#16779, that might be solved by a
copy flag or something. Well, it should be best solved in the IR so that
it doesn't bother backends anymore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Javascript VM see also `const` label
Projects
None yet
Development

No branches or pull requests

2 participants