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

fix(ssa): RC correctness issue #6134

Merged
merged 7 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ impl<'a> FunctionContext<'a> {
let element_types = Self::convert_type(element_type);
values.map_both(element_types, |value, element_type| {
let reference = value.eval_reference();
// Reference counting in brillig relies on us incrementing reference
// counts when arrays/slices are constructed or indexed.
// Thus, if we dereference an lvalue which happens to be array/slice we should increment its reference counter.
self.builder.increment_array_reference_count(reference);
self.builder.insert_load(reference, element_type).into()
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "brillig_rc_regression_6123"
type = "bin"
authors = [""]
compiler_version = ">=0.34.0"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
struct Builder {
note_hashes: BoundedVec<Field, 2>,
nullifiers: BoundedVec<Field, 2>,
}

impl Builder {
fn append_note_hashes_with_logs(&mut self, num_note_hashes: u32) {
let index_offset = self.note_hashes.len();
for i in 0..self.note_hashes.max_len() {
if i < num_note_hashes {
self.add_new_note_hash((index_offset + i) as Field);
}
}
}

fn add_new_note_hash(&mut self, value: Field) {
self.note_hashes.push(value);
}
}

fn swap_items<T, let N: u32>(vec: &mut BoundedVec<T, N>, from_index: u32, to_index: u32) {
let tmp = vec.storage[from_index];
vec.storage[from_index] = vec.storage[to_index];
vec.storage[to_index] = tmp;
}

unconstrained fn main() {
let mut builder = Builder { note_hashes: BoundedVec::new(), nullifiers: BoundedVec::new() };

builder.append_note_hashes_with_logs(2);
builder.nullifiers.storage[1] = 27;
// Get ordered items before shuffling.
let note_hashes = builder.note_hashes.storage;
let original_first_note_hash = note_hashes[0];
// Shuffle.
swap_items(&mut builder.note_hashes, 1, 0);

for i in 0..1 {
assert_eq(note_hashes[i], original_first_note_hash);
}
}
3 changes: 2 additions & 1 deletion tooling/debugger/ignored-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ is_unconstrained
macros
references
regression_4709
reference_only_used_as_alias
reference_only_used_as_alias
brillig_rc_regression_6123
Loading