From 225490752a7890ff5aa2656be4e294e469a5e860 Mon Sep 17 00:00:00 2001 From: guipublic Date: Fri, 7 Jun 2024 09:53:31 +0000 Subject: [PATCH] Error for allocate instructions in acir-gen --- 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 6d7c5e570c1..84ba855ef9c 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") @@ -1306,6 +1308,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:?}"), } }