Skip to content

Commit

Permalink
fix: Restrict fill_internal_slices pass to acir functions (#3634)
Browse files Browse the repository at this point in the history
* restrict fill_internal_slices pass to acir functions

* rename test
  • Loading branch information
vezenovm authored Nov 29, 2023
1 parent 23f1182 commit 0cad9aa
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
12 changes: 9 additions & 3 deletions compiler/noirc_evaluator/src/ssa/opt/fill_internal_slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::ssa::{
ir::{
basic_block::BasicBlockId,
dfg::CallStack,
function::Function,
function::{Function, RuntimeType},
function_inserter::FunctionInserter,
instruction::{Instruction, InstructionId, Intrinsic},
post_order::PostOrder,
Expand All @@ -62,8 +62,14 @@ use fxhash::FxHashMap as HashMap;
impl Ssa {
pub(crate) fn fill_internal_slices(mut self) -> Ssa {
for function in self.functions.values_mut() {
let mut context = Context::new(function);
context.process_blocks();
// This pass is only necessary for generating ACIR and thus we should not
// process Brillig functions.
// The pass is also currently only setup to handle a function with a single flattened block.
// For complex Brillig functions we can expect this pass to panic.
if function.runtime() == RuntimeType::Acir {
let mut context = Context::new(function);
context.process_blocks();
}
}
self
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "brillig_set_slice_of_slice"
type = "bin"
authors = [""]
compiler_version = ">=0.19.4"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
struct Property
{
key : [u8],
value : [u8],
}

struct JSON
{
doc : [Property]
}

unconstrained fn slice_eq(self: [u8], other: [u8]) -> bool {
let mut equal = true;
for i in 0..self.len() {
if self[i] != other[i] {
equal = false;
}
}
equal
}

// This test acts a regression for issue #3476
unconstrained fn main() {
let mut json = JSON { doc: [] };
let mut prop = Property { key: [], value:[] };

let other_prop = Property { key: [0, 1, 2], value:[10] };
json.doc = json.doc.push_back(other_prop);

for i in 0..3 {
prop.key = prop.key.push_back(i as u8);
}
prop.value = prop.value.push_back(5);

// add property to json or replace existing
let len : Field = json.doc.len();
let mut found = false;
for i in 0..len
{
if (!found)
{
if (slice_eq(prop.key, json.doc[i].key))
{
json.doc[i].value = prop.value;
found = true;
}
}
}
assert(found == true);
assert(json.doc[0].value[0] == 5);
}

0 comments on commit 0cad9aa

Please sign in to comment.