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: Restrict fill_internal_slices pass to acir functions #3634

Merged
merged 2 commits into from
Nov 29, 2023
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
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);
}
Loading