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

Array get on empty array panics at compile time #5936

Closed
michaeljklein opened this issue Sep 5, 2024 · 0 comments · Fixed by #5939
Closed

Array get on empty array panics at compile time #5936

michaeljklein opened this issue Sep 5, 2024 · 0 comments · Fixed by #5939
Assignees
Labels
bug Something isn't working

Comments

@michaeljklein
Copy link
Contributor

Aim

Attempted to compile a program where an empty array is accessed within a non-executed if statement:

fn main(x: pub bool) {
    let empty_array: [Field; 0] = [];

    if x {
        let _ = empty_array[0];
    }

    // the same error occurs when the `if` block is elided:
    // let _ = empty_array[0];

    // and when the index is dynamic (x: pub u32)
    // if x == 0 {
    //     let _ = empty_array[x];
    // }

    // and when the array is dynamic (xs: pub [Field; 0])
    // let empty_array: [Field; 0] = xs;
}

Expected Behavior

Expected the program to compile successfully

Bug

nargo compile panics during the DIE pass:

The application panicked (crashed).
Message:  attempt to divide by zero
Location: compiler/noirc_evaluator/src/ssa/opt/die.rs:386

This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.
If there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml

To Reproduce

Workaround

Yes

Workaround Description

  • Locate empty array
  • Replace with the singleton array [std::mem::zeroed()]
  • Add a new parameter to ignore the std::mem::zeroed() when needed

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 0.33.0 noirc version = 0.33.0+712468a08dd95eaed42345320e8c3e6751e88c47 (git version hash: 712468a, 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

@michaeljklein michaeljklein added the bug Something isn't working label Sep 5, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 5, 2024
@asterite asterite self-assigned this Sep 5, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 5, 2024
# Description

## Problem

Resolves #5936

## Summary


## Additional Context

I was computing an array's element size in a way that could lead to
dividing by zero, but there was already a method to get the element
size.

## Documentation

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: jfecher <jake@aztecprotocol.com>
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Sep 5, 2024
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: Done
Development

Successfully merging a pull request may close this issue.

2 participants