From 9c2053879389af16167143eab2203c91375a249d Mon Sep 17 00:00:00 2001 From: Aztec Bot <49558828+AztecBot@users.noreply.github.com> Date: Wed, 28 Feb 2024 07:19:24 -0500 Subject: [PATCH] feat: Sync from aztec-packages (#4444) BEGIN_COMMIT_OVERRIDE chore: remove original return from aztec fns (https://github.com/AztecProtocol/aztec-packages/pull/4804) END_COMMIT_OVERRIDE --------- Co-authored-by: TomAFrench --- .aztec-sync-commit | 2 +- aztec_macros/src/lib.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.aztec-sync-commit b/.aztec-sync-commit index 9acc65d8b9c..c97738f7226 100644 --- a/.aztec-sync-commit +++ b/.aztec-sync-commit @@ -1 +1 @@ -e69b58660ff843350e1e098d8f1a84f4ce3d3c34 +9e246c1289fa40c35c4b28d2f0081dfdc2aa9d19 diff --git a/aztec_macros/src/lib.rs b/aztec_macros/src/lib.rs index 156ba1d5b08..09deb2c9712 100644 --- a/aztec_macros/src/lib.rs +++ b/aztec_macros/src/lib.rs @@ -648,6 +648,10 @@ fn transform_function( // Abstract return types such that they get added to the kernel's return_values if let Some(return_values) = abstract_return_values(func) { + // In case we are pushing return values to the context, we remove the statement that originated it + // This avoids running duplicate code, since blocks like if/else can be value returning statements + func.def.body.0.pop(); + // Add the new return statement func.def.body.0.push(return_values); } @@ -1255,13 +1259,11 @@ fn create_avm_context() -> Result { /// Any primitive type that can be cast will be casted to a field and pushed to the context. fn abstract_return_values(func: &NoirFunction) -> Option { let current_return_type = func.return_type().typ; - let len = func.def.body.len(); - let last_statement = &func.def.body.0[len - 1]; + let last_statement = func.def.body.0.last()?; // TODO: (length, type) => We can limit the size of the array returned to be limited by kernel size // Doesn't need done until we have settled on a kernel size // TODO: support tuples here and in inputs -> convert into an issue - // Check if the return type is an expression, if it is, we can handle it match last_statement { Statement { kind: StatementKind::Expression(expression), .. } => {