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

regression(0.20.0 => devel): var params assignment gives silently wrong results in VM #15974

Closed
timotheecour opened this issue Nov 15, 2020 · 1 comment · Fixed by #19902
Closed
Labels
Regression Severe VM see also `const` label

Comments

@timotheecour
Copy link
Member

timotheecour commented Nov 15, 2020

regression(0.20.0 => devel): in VM, a copy of a var param is affected when that param is later re-assigned.

Example

when true:
  type Foo = object
    f0: int

  proc fn(a: var Foo) =
    var s: Foo
    a = Foo(f0: 2)
    s = a
    doAssert s.f0 == 2
    a = Foo(f0: 3)
    echo s.f0

  proc main()=
    var a = Foo(f0: 1)
    fn(a)

  static: main()
  main()

Current Output

CT:
3
RT:
2

Expected Output

CT:
2
RT:
2

Additional Information

regression:

  • fails with: devel 1.5.1 c39fa0d, and 1.0.2
  • works with: nim 0.20.0
  • 1.0.0 gives: nfIsRef in regs[ra].node.flags [AssertionError]
  • likewise in other cases where you'd have a copy, eg: var s: seq[Foo] and s.add a
  • root cause for RT vs CT flyx/NimYAML#91 (nimyaml gives wrong results at CT), after a painful, painful reduction

git bisect output

162d74db91412d98a4a67b28c1e1c9c1d79a9873 is the first bad commit
commit 162d74db91412d98a4a67b28c1e1c9c1d79a9873
Author: Andreas Rumpf <[email protected]>
Date:   Thu Sep 19 14:34:56 2019 +0200

    fixes #10981; fixes #7261 (#12217)

 compiler/vmgen.nim    |  5 ++-
 tests/vm/tmisc_vm.nim | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+), 1 deletion(-)
bisect run success

=> points to #12217 /cc @Araq

@jangko
Copy link
Contributor

jangko commented Nov 21, 2020

same first bad commit with #12551 and similar symptom involving var param.

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
Regression Severe VM see also `const` label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants