Skip to content

Commit

Permalink
fix: save the data bus to the current function before generating others
Browse files Browse the repository at this point in the history
Otherwise the databus will be saved to the last generated function instead of
the main function.
  • Loading branch information
ggiraldez committed Jan 15, 2024
1 parent c631e1b commit 40d72ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ pub(crate) fn generate_ssa(program: Program) -> Result<Ssa, RuntimeError> {
_ => unreachable!("ICE - expect return on the last block"),
}
}
// we save the data bus inside the dfg
function_context.builder.current_function.dfg.data_bus =
DataBus::get_data_bus(call_data, return_data);

// Main has now been compiled and any other functions referenced within have been added to the
// function queue as they were found in codegen_ident. This queueing will happen each time a
Expand All @@ -106,9 +109,6 @@ pub(crate) fn generate_ssa(program: Program) -> Result<Ssa, RuntimeError> {
function_context.new_function(dest_id, function);
function_context.codegen_function_body(&function.body)?;
}
// we save the data bus inside the dfg
function_context.builder.current_function.dfg.data_bus =
DataBus::get_data_bus(call_data, return_data);

Ok(function_context.builder.finish())
}
Expand Down
14 changes: 8 additions & 6 deletions test_programs/execution_success/databus/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Test unsafe integer multiplication with overflow: 12^8 = 429 981 696
// The circuit should handle properly the growth of the bit size
use dep::std;

fn main(mut x: u32, y: call_data u32, z: call_data [u32;4] ) -> return_data u32 {

let a = z[x];
a+y
fn main(mut x: u32, y: call_data u32, z: call_data [u32;4]) -> return_data u32 {
let a = z[x];
a+foo(y)
}

// Use an unconstrained function to force the compiler to avoid inlining
unconstrained fn foo(x: u32) -> u32 {
x+1
}

0 comments on commit 40d72ce

Please sign in to comment.