-
Notifications
You must be signed in to change notification settings - Fork 225
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
CFG flattening pass's reordering of store instructions breaks mem2reg #1756
Comments
Noting that if |
This fails in the same manner without brillig calls: struct Context {
read_requests: Field,
}
impl Context {
fn new() -> Context {
Context { read_requests: 0 }
}
fn push_read_request(mut self: Self, request: Field) -> Context {
self.read_requests += request;
self
}
}
struct Note {
is_real: bool,
}
fn compute_note_hash(note: Note) -> Field {
dep::std::hash::pedersen([
note.is_real as Field,
])[0]
}
fn read_2_notes(storage_slot: Field) -> (Note, Note) {
let randomness = dep::std::hash::pedersen([storage_slot])[0];
let note0_is_real = ((randomness as u32) % 2) as bool;
let note0 = Note {
is_real: note0_is_real,
};
let note1 = Note {
is_real: !note0_is_real,
};
(note0, note1)
}
fn is_real(note: Note) -> bool {
note.is_real
}
struct Set {
storage_slot: Field,
}
impl Set {
fn new(storage_slot: Field) -> Set {
Set { storage_slot }
}
fn get_2(self, mut context: Context) -> (Context, (Note, Note)) {
let storage_slot = self.storage_slot;
let notes = read_2_notes(storage_slot);
let note0_hash = compute_note_hash(notes.0);
let note1_hash = compute_note_hash(notes.1);
if is_real(notes.0) {
context = context.push_read_request(note0_hash);
};
if is_real(notes.1) {
context = context.push_read_request(note1_hash);
};
(context, notes)
}
}
#[test]
fn test_set() {
let set = Set::new(0);
let mut context = Context::new();
let result = set.get_2(context);
context = result.0;
let (note0, note1) = result.1;
assert(note0.is_real == false);
assert(note1.is_real == false);
}
fn main(x : Field, y : pub Field) {
assert(x != y);
}
|
Noting that #1761 fixes the first example but not the second |
This appears to be a problem with the flattening pass. The store that immediately following an allocate is being lost:
|
Minimal reproduction of above issue:
|
After flattening, the store instruction still exists but it has been reordered after its counterpart load, which breaks mem2reg
|
Reopening this issue as tracking the latter issue. (Was automatically closed by PR) |
Looks like this is a result of the flattening pass trying to track stores that were used across branches. It is breaking here when it tries to load the previous value of the store for reference but there was no previous value since the allocation also occurred in the branch. |
Aim
To be able to combine mutable variables with calls to unconstrained functions.
Expected Behavior
This should compile:
Bug
To Reproduce
Installation Method
Compiled from source
Nargo Version
No response
Additional Context
No response
Would you like to submit a PR for this Issue?
No
Support Needs
No response
The text was updated successfully, but these errors were encountered: