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

The type [u32] cannot be represented in ACIR #2535

Closed
Tracked by #3363
0xrishabh opened this issue Sep 2, 2023 · 1 comment · Fixed by #4280
Closed
Tracked by #3363

The type [u32] cannot be represented in ACIR #2535

0xrishabh opened this issue Sep 2, 2023 · 1 comment · Fixed by #4280
Assignees
Labels
bug Something isn't working
Milestone

Comments

@0xrishabh
Copy link

0xrishabh commented Sep 2, 2023

Aim

Given an array, the program tries to get another of length y.

use dep::std;
use dep::std::collections::vec::Vec;

global DEPTH: Field = 40000;
fn main(x: [u32; DEPTH], y: u32) {
    let mut new_x = Vec::new();
    new_x = clear(x, y);
}

unconstrained fn clear(x: [u32; DEPTH], y: u32) -> Vec<u32> { 
  let mut a = Vec::new();
  for i in 0..y{
    a.push(x[i]);
  }
  a
}

Expected Behavior

Should have run successfully, to populate new_x with values

Bug

But when running it gives an error:
internal error: entered unreachable code: The type [u32] cannot be represented in ACIR

To Reproduce

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

Yes

Support Needs

No response

@0xrishabh 0xrishabh added the bug Something isn't working label Sep 2, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 2, 2023
@jfecher
Copy link
Contributor

jfecher commented Sep 5, 2023

Unfortunately, Vec<T> cannot be passed between unconstrained and non-unconstrained functions because it contains a slice internally. Slices and references are both prohibited to cross this boundary, although for different reasons. For slices it is because we'd need to know their exact length at that point - so you'd need to convert them to an array. For references, it is because any mutations to the reference inside the unconstrained function will not be observed outside.

I'll work on a better user-facing compiler error to explain this.

@kevaundray kevaundray removed the beta label Jan 15, 2024
@kevaundray kevaundray added this to the 0.25 milestone Jan 15, 2024
@vezenovm vezenovm self-assigned this Feb 6, 2024
github-merge-queue bot pushed a commit that referenced this issue Feb 6, 2024
#4280)

# Description

## Problem\*

Resolves #2535 

## Summary\*

We currently panic when attempting to return a slice from an
unconstrained runtime to an ACIR runtime. In some cases such as in the
linked issue the panic is not very clear at all.

New error:
<img width="811" alt="Screenshot 2024-02-06 at 1 33 39 PM"
src="https://github.com/noir-lang/noir/assets/43554004/e37e7b3b-13ef-4222-a359-2f14084478da">


## Additional Context



## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

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

---------

Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Feb 6, 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
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants