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

nargo debug does not follow natural order of program statements #7410

Open
smanilov opened this issue Feb 17, 2025 · 0 comments
Open

nargo debug does not follow natural order of program statements #7410

smanilov opened this issue Feb 17, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@smanilov
Copy link

Aim

Consider the following program (lines indexed from 1):

fn main() {
    for i in 0..2 {
        println("---Test");
    }
}

Running nargo debug on this program, and stepping through it with next yields the following behavior:

  1. cursor is pointing to line 1;
  2. cursor is pointing to line 2, and highlighting i;
  3. cursor is pointing to line 3, and highlighting the whole println expression;
  4. cursor jumps back to line 2, highlighting 2, which is the boundary check of the loop;
  5. cursor is pointing to line 2, and highlighting i;
  6. cursor is pointing to line 3, and highlighting the whole println expression;
  7. cursor is pointing to line 3, and highlighting the whole println expression;
  8. cursor jumps back to line 4, highlighting nothing, which is the closing bracket of the loop body;
  9. cursor jumps back to line 2, highlighting 2, which is the boundary check of the loop;
  10. cursor is pointing to line 2, and highlighting i;
  11. cursor is pointing to line 3, and highlighting the whole println expression;
  12. cursor is pointing to line 3, and highlighting the whole println expression;
  13. cursor jumps back to line 4, highlighting nothing, which is the closing bracket of the loop body;
  14. cursor jumps back to line 2, highlighting 2, which is the boundary check of the loop;
  15. cursor jumps back to line 5, highlighting nothing, which is the closing bracket of the function body; and
  16. finished execution.

Expected Behavior

  1. cursor is pointing to line 1;
    cursor is pointing to line 2, and highlighting i;
    cursor is pointing to line 3, and highlighting the whole println expression;
  2. cursor is pointing to line 2, highlighting 2, which is the boundary check of the loop;
  3. cursor is pointing to line 2, and highlighting i;
  4. cursor is pointing to line 3, and highlighting the whole println expression;
  5. cursor is pointing to line 3, and highlighting the whole println expression;
  6. cursor jumps back to line 4, highlighting nothing, which is the closing bracket of the loop body;
  7. cursor jumps back to line 2, highlighting 2, which is the boundary check of the loop;
  8. cursor is pointing to line 2, and highlighting i;
  9. cursor is pointing to line 3, and highlighting the whole println expression;
  10. cursor is pointing to line 3, and highlighting the whole println expression;
  11. cursor jumps back to line 4, highlighting nothing, which is the closing bracket of the loop body;
  12. cursor jumps back to line 2, highlighting 2, which is the boundary check of the loop;
  13. cursor jumps back to line 5, highlighting nothing, which is the closing bracket of the function body; and
  14. finished execution.

Bug

In the observed behavior, the loop seems to be entered before the first boundary check is made.

To Reproduce

  1. nargo new bug_example && cd bug_example
  2. copy the source mentioned earlier in src/main.nr
  3. run nargo debug and step through the program using next

Workaround

Yes

Workaround Description

Commenting out Ssa::loop_invariant_code_motion and Ssa::fold_constants from the list of performed optimizations and recompiling nargo leads to the expected behavior of nargo debug.

P.S., disabling just Ssa::loop_invariant_code_motion leads to a different behavior of nargo debug, but it is still not the naturally expected one. Let me know and we can file a separate issue.

Additional Context

No response

Project Impact

Blocker

Blocker Context

Our project (a debugger GUI) depends on the natural behavior of nargo debug.

Nargo Version

nargo version = 1.0.0-beta.2 noirc version = 1.0.0-beta.2+b7ace682af1ab8a43308457302f08b151af342db (git version hash: b7ace68, is dirty: false)

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@smanilov smanilov added the bug Something isn't working label Feb 17, 2025
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant