From 40d72cedd9fc63c4700a5ac4697202e31032006c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Mon, 8 Jan 2024 13:08:07 -0500 Subject: [PATCH] fix: save the data bus to the current function before generating others Otherwise the databus will be saved to the last generated function instead of the main function. --- compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs | 6 +++--- .../execution_success/databus/src/main.nr | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs index 0b8c3a37ef9..8ad0bce7b48 100644 --- a/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs @@ -96,6 +96,9 @@ pub(crate) fn generate_ssa(program: Program) -> Result { _ => 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 @@ -106,9 +109,6 @@ pub(crate) fn generate_ssa(program: Program) -> Result { 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()) } diff --git a/test_programs/execution_success/databus/src/main.nr b/test_programs/execution_success/databus/src/main.nr index 631331ef2d7..61a9637f5fe 100644 --- a/test_programs/execution_success/databus/src/main.nr +++ b/test_programs/execution_success/databus/src/main.nr @@ -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 } +