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

Add second-class references to Noir #1702

Closed
jfecher opened this issue Jun 14, 2023 · 0 comments · Fixed by #1849
Closed

Add second-class references to Noir #1702

jfecher opened this issue Jun 14, 2023 · 0 comments · Fixed by #1849
Labels
enhancement New feature or request

Comments

@jfecher
Copy link
Contributor

jfecher commented Jun 14, 2023

Problem

Noir has mutable variables, but they are strictly local: no mutation can be observed across function boundaries. This leads to code like the following:

fn foo() {
    let mut ctx = Context::new();
    ctx.foo.bar.my_vec = ctx.foo.bar.my_vec.push(4);
}

Happy Case

If references were added, BoundedVec::push could take a mutable reference to the vector and the code could be simplified to the more natural:

fn foo() {
    let mut ctx = Context::new();
    ctx.foo.bar.my_vec.push(4);
}

However, adding first-class references comes with a host of problems. Namely, tracking the references as they are passed around everywhere, stored in structs, arrays, or returned from functions can become trouble-some. To alleviate this, we should only add second-class references to Noir. Second-class references will not be allowed to be stored within structs or arrays, and can only be used essentially as a parameter-passing mode. This way our existing analysis for references will suffice while still gaining us some increased ergonomics.

Alternatives Considered

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant