From 58c7532da8dd86ee02b20d7e7809f5437f667845 Mon Sep 17 00:00:00 2001 From: guipublic <47281315+guipublic@users.noreply.github.com> Date: Mon, 10 Jun 2024 12:14:12 +0200 Subject: [PATCH] fix: error for allocate instructions in acir-gen (#5200) # Description ## Problem\* Resolves #5175 ## Summary\* When we cannot resolve some references to an array, its allocate is not simplified and we get a panic. I changed this to an error message saying that we could not resolve all references from the array. I believe an error message is better than the panic, however I am not sure whether having remaining allocates only happens because of this case. ## Additional Context ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [ ] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --- compiler/noirc_evaluator/src/errors.rs | 5 ++++- compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/noirc_evaluator/src/errors.rs b/compiler/noirc_evaluator/src/errors.rs index 1e922060100..dd63a254a18 100644 --- a/compiler/noirc_evaluator/src/errors.rs +++ b/compiler/noirc_evaluator/src/errors.rs @@ -43,6 +43,8 @@ pub enum RuntimeError { UnconstrainedSliceReturnToConstrained { call_stack: CallStack }, #[error("All `oracle` methods should be wrapped in an unconstrained fn")] UnconstrainedOracleReturnToConstrained { call_stack: CallStack }, + #[error("Could not resolve some references to the array. All references must be resolved at compile time")] + UnknownReference { call_stack: CallStack }, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -123,7 +125,8 @@ impl RuntimeError { | RuntimeError::NestedSlice { call_stack, .. } | RuntimeError::BigIntModulus { call_stack, .. } | RuntimeError::UnconstrainedSliceReturnToConstrained { call_stack } - | RuntimeError::UnconstrainedOracleReturnToConstrained { call_stack } => call_stack, + | RuntimeError::UnconstrainedOracleReturnToConstrained { call_stack } + | RuntimeError::UnknownReference { call_stack } => call_stack, } } } diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs index 2aac083d727..40170e58a30 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -682,7 +682,9 @@ impl<'a> Context<'a> { self.handle_array_operation(instruction_id, dfg)?; } Instruction::Allocate => { - unreachable!("Expected all allocate instructions to be removed before acir_gen") + return Err(RuntimeError::UnknownReference { + call_stack: self.acir_context.get_call_stack().clone(), + }); } Instruction::Store { .. } => { unreachable!("Expected all store instructions to be removed before acir_gen") @@ -1307,6 +1309,9 @@ impl<'a> Context<'a> { } Ok(AcirValue::Array(values)) } + Type::Reference(reference_type) => { + self.array_get_value(reference_type.as_ref(), block_id, var_index) + } _ => unreachable!("ICE: Expected an array or numeric but got {ssa_type:?}"), } }