Skip to content

Commit

Permalink
fix: Panic on composite types within databus (#6225)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Allows initializing databus with composite types

## Summary\*



## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
sirasistant authored Oct 7, 2024
1 parent 999071b commit 29bd125
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
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
}

0 comments on commit 29bd125

Please sign in to comment.