-
Notifications
You must be signed in to change notification settings - Fork 219
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
feat(ssa refactor): Implement first-class references #1849
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Found and fixed a bug with assignments and the mem2reg pass where we would produce incorrect code when codegening a |
This PR is passing again |
jfecher
commented
Jul 5, 2023
jfecher
commented
Jul 5, 2023
jfecher
commented
Jul 5, 2023
jfecher
commented
Jul 5, 2023
jfecher
commented
Jul 5, 2023
jfecher
commented
Jul 5, 2023
crates/nargo_cli/tests/test_data_ssa_refactor/tuples/src/main.nr
Outdated
Show resolved
Hide resolved
jfecher
commented
Jul 5, 2023
jfecher
commented
Jul 5, 2023
jfecher
commented
Jul 5, 2023
jfecher
commented
Jul 5, 2023
All of the outdated code has been removed |
vezenovm
approved these changes
Jul 5, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem*
Resolves #1702 - although I opted for first-class references instead of second-class references. These turned out to be easier/cleaner to add since adding second-class references would require some restrictions in how users are allowed to pass these around which are non-trivial to implement.
Summary*
Implements first-class references:
&mut T
is now added representing mutable references.&mut expr
*expr
*
in*foo = bar;
is now allowed on the left hand side of the=
.foo : &mut T
.&mut v
wherev
is an immutable variable or field of one.&mut v[i]
wherev[i]
is an array access. Since arrays are immutable in the ssa refactor, this is somewhat more difficult to add so I opted to leave it as an error for now. Note that this is a user-facing error rather than a panic. The error message suggests storing the array element in another variable as a work around.Documentation
This PR requires documentation updates when merged.
&mut value
wherevalue
is either an existing (mutable) variable, or a literal value.&mut T
whereT
is the element type. For example, a mutable reference to aField
will have the type&mut Field
.*my_ref
. We can think of the unary*
operation as having the typefn(&mut T) -> T
.Additional Context
PR Checklist*
cargo fmt
on default settings.