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: Panic on composite types within databus #6225

Merged
merged 3 commits into from
Oct 7, 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
18 changes: 10 additions & 8 deletions compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,18 @@ impl FunctionBuilder {
databus.index += 1;
}
Type::Array(typ, len) => {
assert!(typ.len() == 1, "unsupported composite type");
databus.map.insert(value, databus.index);
for i in 0..len {
// load each element of the array
let index = self
.current_function
.dfg
.make_constant(FieldElement::from(i as i128), Type::length_type());
let element = self.insert_array_get(value, index, typ[0].clone());
self.add_to_data_bus(element, databus);
for (subitem_index, subitem_typ) in typ.iter().enumerate() {
let index = i * typ.len() + subitem_index;
// load each element of the array
let index = self
.current_function
.dfg
.make_constant(FieldElement::from(index as i128), Type::length_type());
let element = self.insert_array_get(value, index, subitem_typ.clone());
self.add_to_data_bus(element, databus);
}
}
}
Type::Reference(_) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "databus_composite_calldata"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
zero = "0"
one = "1"
[[foos]]
x = "27"
y = "40"

[[foos]]
x = "28"
y = "42"
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
struct Foo {
x: u32,
y: u32,
}

fn main(foos: call_data(0) [Foo; 2], zero: u32, one: u32) -> return_data u32 {
assert_eq(foos[zero].x + 1, foos[one].x);
assert_eq(foos[zero].y + 2, foos[one].y);
foos[zero].x + foos[one].y
}

Loading