Skip to content
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
6 changes: 6 additions & 0 deletions compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ impl FunctionBuilder {
let index_var = FieldElement::from(index as i128);
let index_var =
self.current_function.dfg.make_constant(index_var, length_type);
// If we do not check for an empty array we will have an unused array get
// as an array of length zero will not be actually added to the databus' values.
if let Type::Array(_, 0) = subitem_typ {
continue;
}
let element = self.insert_array_get(value, index_var, subitem_typ.clone());
index += match subitem_typ {
Type::Array(_, _) | Type::Slice(_) => subitem_typ.element_size(),
Expand Down Expand Up @@ -230,6 +235,7 @@ impl FunctionBuilder {
}
}
}

// create the call-data-bus from the filtered lists
let mut result = Vec::new();
for id in databus_param.keys() {
Expand Down
37 changes: 37 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,40 @@ fn basic_loop() {

assert_normalized_ssa_equals(ssa, expected);
}

#[named]
#[test]
fn databus_no_dead_param_on_empty_array() {
let src = "
fn main(a: (i8, u32, i8), b: call_data(0) [(i8, i8, bool, bool, str<0>); 2]) -> pub [(bool, str<3>, str<0>, u32); 0] {
[]
}
";

let ssa = get_initial_ssa(src, function_path!()).unwrap();

// We expect that there to be no `array_get` attempting to fetch from v3
// the empty nested array `[u8; 0]`.
// The databus is only going to be initialized with actual numeric values so keeping
// an empty array in the databus is pointless.
// The databus is not mutated after initialization as well. So if we have instructions
// on the data bus (such as an `array_get` on an empty array) that go unused, it becomes
// more difficult to eliminate those unused instructions. Thus, we just do not generate them.
let expected = "
acir(inline) fn main f0 {
b0(v0: i8, v1: u32, v2: i8, v3: [(i8, i8, u1, u1, [u8; 0]); 2]):
v5 = array_get v3, index u32 0 -> i8
v7 = array_get v3, index u32 1 -> i8
v9 = array_get v3, index u32 2 -> u1
v11 = array_get v3, index u32 3 -> u1
v13 = array_get v3, index u32 4 -> i8
v15 = array_get v3, index u32 5 -> i8
v17 = array_get v3, index u32 6 -> u1
v19 = array_get v3, index u32 7 -> u1
v20 = make_array [v5, v7, v9, v11, v13, v15, v17, v19] : [Field; 8]
v21 = make_array [] : [(u1, [u8; 3], [u8; 0], u32); 0]
return v21
}
";
assert_normalized_ssa_equals(ssa, expected);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

[package]
name = "noirc_evaluator_ssa_ssa_gen_tests_databus_no_dead_param_on_empty_array"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

fn main(a: (i8, u32, i8), b: call_data(0) [(i8, i8, bool, bool, str<0>); 2]) -> pub [(bool, str<3>, str<0>, u32); 0] {
[]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8959072883599795205
6 changes: 6 additions & 0 deletions test_programs/execution_success/databus_dead_param/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "databus_dead_param"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a = ["1", "2", "3"]
b = [["0", "0", true, true, ""], ["0", "0", true, true, ""]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Regression for issue #8398 (https://github.com/noir-lang/noir/issues/8398)
fn main(
a: (i8, u32, i8),
b: call_data(0) [(i8, i8, bool, bool, str<0>); 2],
) -> pub [(bool, str<3>, str<0>, u32); 0] {
[]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[databus_dead_param] Circuit output: Vec([])

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading