From 34406e7af17f41be4fe6ca6ab60f736f23944568 Mon Sep 17 00:00:00 2001 From: shak58 <150069539+shak58@users.noreply.github.com> Date: Sun, 18 Aug 2024 00:54:59 +0100 Subject: [PATCH 1/6] Switch Acir function Ids from raw integers to a struct type --- acvm-repo/acir/src/circuit/brillig.rs | 2 ++ acvm-repo/acir/src/circuit/mod.rs | 2 ++ acvm-repo/acir/src/circuit/opcodes.rs | 7 ++++++- .../acir/src/circuit/opcodes/function_id.rs | 20 +++++++++++++++++++ acvm-repo/acvm/src/pwg/mod.rs | 6 +++--- .../src/ssa/acir_gen/acir_ir/acir_variable.rs | 4 ++-- tooling/debugger/src/context.rs | 6 +++--- tooling/nargo/src/ops/execute.rs | 6 +++--- 8 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 acvm-repo/acir/src/circuit/opcodes/function_id.rs diff --git a/acvm-repo/acir/src/circuit/brillig.rs b/acvm-repo/acir/src/circuit/brillig.rs index a9714ce29b2..8b1231e2707 100644 --- a/acvm-repo/acir/src/circuit/brillig.rs +++ b/acvm-repo/acir/src/circuit/brillig.rs @@ -46,3 +46,5 @@ impl std::fmt::Display for BrilligFunctionId { write!(f, "{}", self.0) } } + + diff --git a/acvm-repo/acir/src/circuit/mod.rs b/acvm-repo/acir/src/circuit/mod.rs index 43984e4a922..c301e76f153 100644 --- a/acvm-repo/acir/src/circuit/mod.rs +++ b/acvm-repo/acir/src/circuit/mod.rs @@ -3,6 +3,7 @@ pub mod brillig; pub mod directives; pub mod opcodes; + use crate::native_types::{Expression, Witness}; use acir_field::AcirField; pub use opcodes::Opcode; @@ -18,6 +19,7 @@ use std::collections::BTreeSet; use self::{brillig::BrilligBytecode, opcodes::BlockId}; + /// Specifies the maximum width of the expressions which will be constrained. /// /// Unbounded Expressions are useful if you are eventually going to pass the ACIR diff --git a/acvm-repo/acir/src/circuit/opcodes.rs b/acvm-repo/acir/src/circuit/opcodes.rs index b1fdc5e0080..efa110c11f4 100644 --- a/acvm-repo/acir/src/circuit/opcodes.rs +++ b/acvm-repo/acir/src/circuit/opcodes.rs @@ -2,6 +2,11 @@ use super::{ brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs}, directives::Directive, }; + + +pub mod function_id; +pub use function_id::AcirFunctionId; + use crate::native_types::{Expression, Witness}; use acir_field::AcirField; use serde::{Deserialize, Serialize}; @@ -125,7 +130,7 @@ pub enum Opcode { Call { /// Id for the function being called. It is the responsibility of the executor /// to fetch the appropriate circuit from this id. - id: u32, + id: AcirFunctionId, /// Inputs to the function call inputs: Vec, /// Outputs of the function call diff --git a/acvm-repo/acir/src/circuit/opcodes/function_id.rs b/acvm-repo/acir/src/circuit/opcodes/function_id.rs new file mode 100644 index 00000000000..3a23a8df7bd --- /dev/null +++ b/acvm-repo/acir/src/circuit/opcodes/function_id.rs @@ -0,0 +1,20 @@ +use serde::{Serialize, Deserialize}; + +#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Hash)] +#[serde(transparent)] +pub struct AcirFunctionId(pub u32); + +impl AcirFunctionId { + pub fn as_usize(&self) -> usize { + self.0 as usize + } +} + +impl std::fmt::Display for AcirFunctionId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } +} + + + diff --git a/acvm-repo/acvm/src/pwg/mod.rs b/acvm-repo/acvm/src/pwg/mod.rs index 83c5aeb6296..7492b9fb85a 100644 --- a/acvm-repo/acvm/src/pwg/mod.rs +++ b/acvm-repo/acvm/src/pwg/mod.rs @@ -6,7 +6,7 @@ use acir::{ brillig::ForeignCallResult, circuit::{ brillig::{BrilligBytecode, BrilligFunctionId}, - opcodes::{BlockId, ConstantOrWitnessEnum, FunctionInput}, + opcodes::{BlockId, ConstantOrWitnessEnum, FunctionInput, function_id::AcirFunctionId}, AssertionPayload, ErrorSelector, ExpressionOrMemory, Opcode, OpcodeLocation, RawAssertionPayload, ResolvedAssertionPayload, STRING_ERROR_SELECTOR, }, @@ -575,7 +575,7 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver> ACVM<'a, F, B> { else { unreachable!("Not executing a Call opcode"); }; - if *id == 0 { + if *id == AcirFunctionId(0) { return Err(OpcodeResolutionError::AcirMainCallAttempted { opcode_location: ErrorLocation::Resolved(OpcodeLocation::Acir( self.instruction_pointer(), @@ -716,7 +716,7 @@ pub(crate) fn is_predicate_false( #[derive(Debug, Clone, PartialEq)] pub struct AcirCallWaitInfo { /// Index in the list of ACIR function's that should be called - pub id: u32, + pub id: AcirFunctionId, /// Initial witness for the given circuit to be called pub initial_witness: WitnessMap, } diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index 24b30b22ec4..77cb9c53487 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -8,7 +8,7 @@ use crate::ssa::ir::dfg::CallStack; use crate::ssa::ir::types::Type as SsaType; use crate::ssa::ir::{instruction::Endian, types::NumericType}; use acvm::acir::circuit::brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs}; -use acvm::acir::circuit::opcodes::{BlockId, BlockType, MemOp}; +use acvm::acir::circuit::opcodes::{BlockId, BlockType, MemOp, AcirFunctionId}; use acvm::acir::circuit::{AssertionPayload, ExpressionOrMemory, ExpressionWidth, Opcode}; use acvm::blackbox_solver; use acvm::brillig_vm::{MemoryValue, VMStatus, VM}; @@ -1979,7 +1979,7 @@ impl AcirContext { vecmap(&outputs, |witness_index| self.add_data(AcirVarData::Witness(*witness_index))); let predicate = Some(self.var_to_expression(predicate)?); - self.acir_ir.push_opcode(Opcode::Call { id, inputs, outputs, predicate }); + self.acir_ir.push_opcode(Opcode::Call { id: AcirFunctionId(id), inputs, outputs, predicate }); Ok(results) } } diff --git a/tooling/debugger/src/context.rs b/tooling/debugger/src/context.rs index 6ec1aff8325..aefa435a087 100644 --- a/tooling/debugger/src/context.rs +++ b/tooling/debugger/src/context.rs @@ -566,7 +566,7 @@ impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { &mut self, call_info: AcirCallWaitInfo, ) -> DebugCommandResult { - let callee_circuit = &self.circuits[call_info.id as usize]; + let callee_circuit = &self.circuits[call_info.id.as_usize()]; let callee_witness_map = call_info.initial_witness; let callee_acvm = ACVM::new( self.backend, @@ -578,7 +578,7 @@ impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { let caller_acvm = std::mem::replace(&mut self.acvm, callee_acvm); self.acvm_stack .push(ExecutionFrame { circuit_id: self.current_circuit_id, acvm: caller_acvm }); - self.current_circuit_id = call_info.id; + self.current_circuit_id = call_info.id.0; // Explicitly handling the new ACVM status here handles two edge cases: // 1. there is a breakpoint set at the beginning of a circuit @@ -596,7 +596,7 @@ impl<'a, B: BlackBoxFunctionSolver> DebugContext<'a, B> { let ACVMStatus::RequiresAcirCall(call_info) = self.acvm.get_status() else { unreachable!("Resolving an ACIR call, the caller is in an invalid state"); }; - let acir_to_call = &self.circuits[call_info.id as usize]; + let acir_to_call = &self.circuits[call_info.id.as_usize()]; let mut call_resolved_outputs = Vec::new(); for return_witness_index in acir_to_call.return_values.indices() { diff --git a/tooling/nargo/src/ops/execute.rs b/tooling/nargo/src/ops/execute.rs index c9cc60d03d9..2e214c4e425 100644 --- a/tooling/nargo/src/ops/execute.rs +++ b/tooling/nargo/src/ops/execute.rs @@ -139,9 +139,9 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver, E: ForeignCallExecutor> }); // Set current function to the circuit we are about to execute - self.current_function_index = call_info.id as usize; + self.current_function_index = call_info.id.as_usize(); // Execute the ACIR call - let acir_to_call = &self.functions[call_info.id as usize]; + let acir_to_call = &self.functions[call_info.id.as_usize()]; let initial_witness = call_info.initial_witness; let call_solved_witness = self.execute_circuit(initial_witness)?; @@ -163,7 +163,7 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver, E: ForeignCallExecutor> } } acvm.resolve_pending_acir_call(call_resolved_outputs); - self.witness_stack.push(call_info.id, call_solved_witness); + self.witness_stack.push(call_info.id.0, call_solved_witness); } } } From 8a6fe259bef3bcec9f07a833acda0bb58212b0c2 Mon Sep 17 00:00:00 2001 From: shak58 <150069539+shak58@users.noreply.github.com> Date: Sun, 18 Aug 2024 00:57:10 +0100 Subject: [PATCH 2/6] cargo fmt --- acvm-repo/acir/src/circuit/brillig.rs | 2 -- acvm-repo/acir/src/circuit/mod.rs | 2 -- acvm-repo/acir/src/circuit/opcodes.rs | 1 - acvm-repo/acir/src/circuit/opcodes/function_id.rs | 5 +---- acvm-repo/acvm/src/pwg/mod.rs | 2 +- .../src/ssa/acir_gen/acir_ir/acir_variable.rs | 9 +++++++-- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/acvm-repo/acir/src/circuit/brillig.rs b/acvm-repo/acir/src/circuit/brillig.rs index 8b1231e2707..a9714ce29b2 100644 --- a/acvm-repo/acir/src/circuit/brillig.rs +++ b/acvm-repo/acir/src/circuit/brillig.rs @@ -46,5 +46,3 @@ impl std::fmt::Display for BrilligFunctionId { write!(f, "{}", self.0) } } - - diff --git a/acvm-repo/acir/src/circuit/mod.rs b/acvm-repo/acir/src/circuit/mod.rs index c301e76f153..43984e4a922 100644 --- a/acvm-repo/acir/src/circuit/mod.rs +++ b/acvm-repo/acir/src/circuit/mod.rs @@ -3,7 +3,6 @@ pub mod brillig; pub mod directives; pub mod opcodes; - use crate::native_types::{Expression, Witness}; use acir_field::AcirField; pub use opcodes::Opcode; @@ -19,7 +18,6 @@ use std::collections::BTreeSet; use self::{brillig::BrilligBytecode, opcodes::BlockId}; - /// Specifies the maximum width of the expressions which will be constrained. /// /// Unbounded Expressions are useful if you are eventually going to pass the ACIR diff --git a/acvm-repo/acir/src/circuit/opcodes.rs b/acvm-repo/acir/src/circuit/opcodes.rs index efa110c11f4..d7f0f5f6f1f 100644 --- a/acvm-repo/acir/src/circuit/opcodes.rs +++ b/acvm-repo/acir/src/circuit/opcodes.rs @@ -3,7 +3,6 @@ use super::{ directives::Directive, }; - pub mod function_id; pub use function_id::AcirFunctionId; diff --git a/acvm-repo/acir/src/circuit/opcodes/function_id.rs b/acvm-repo/acir/src/circuit/opcodes/function_id.rs index 3a23a8df7bd..b5abb1b3942 100644 --- a/acvm-repo/acir/src/circuit/opcodes/function_id.rs +++ b/acvm-repo/acir/src/circuit/opcodes/function_id.rs @@ -1,4 +1,4 @@ -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Hash)] #[serde(transparent)] @@ -15,6 +15,3 @@ impl std::fmt::Display for AcirFunctionId { write!(f, "{}", self.0) } } - - - diff --git a/acvm-repo/acvm/src/pwg/mod.rs b/acvm-repo/acvm/src/pwg/mod.rs index 7492b9fb85a..b31efda25dc 100644 --- a/acvm-repo/acvm/src/pwg/mod.rs +++ b/acvm-repo/acvm/src/pwg/mod.rs @@ -6,7 +6,7 @@ use acir::{ brillig::ForeignCallResult, circuit::{ brillig::{BrilligBytecode, BrilligFunctionId}, - opcodes::{BlockId, ConstantOrWitnessEnum, FunctionInput, function_id::AcirFunctionId}, + opcodes::{function_id::AcirFunctionId, BlockId, ConstantOrWitnessEnum, FunctionInput}, AssertionPayload, ErrorSelector, ExpressionOrMemory, Opcode, OpcodeLocation, RawAssertionPayload, ResolvedAssertionPayload, STRING_ERROR_SELECTOR, }, diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index 77cb9c53487..40239374bbf 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -8,7 +8,7 @@ use crate::ssa::ir::dfg::CallStack; use crate::ssa::ir::types::Type as SsaType; use crate::ssa::ir::{instruction::Endian, types::NumericType}; use acvm::acir::circuit::brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs}; -use acvm::acir::circuit::opcodes::{BlockId, BlockType, MemOp, AcirFunctionId}; +use acvm::acir::circuit::opcodes::{AcirFunctionId, BlockId, BlockType, MemOp}; use acvm::acir::circuit::{AssertionPayload, ExpressionOrMemory, ExpressionWidth, Opcode}; use acvm::blackbox_solver; use acvm::brillig_vm::{MemoryValue, VMStatus, VM}; @@ -1979,7 +1979,12 @@ impl AcirContext { vecmap(&outputs, |witness_index| self.add_data(AcirVarData::Witness(*witness_index))); let predicate = Some(self.var_to_expression(predicate)?); - self.acir_ir.push_opcode(Opcode::Call { id: AcirFunctionId(id), inputs, outputs, predicate }); + self.acir_ir.push_opcode(Opcode::Call { + id: AcirFunctionId(id), + inputs, + outputs, + predicate, + }); Ok(results) } } From 05bced3b115185a7a01a866d25f5ce1964b9e087 Mon Sep 17 00:00:00 2001 From: shak58 <150069539+shak58@users.noreply.github.com> Date: Sun, 18 Aug 2024 17:05:56 +0100 Subject: [PATCH 3/6] update --- .../noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs | 4 ++-- compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index 40239374bbf..27606564ee8 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -1959,7 +1959,7 @@ impl AcirContext { pub(crate) fn call_acir_function( &mut self, - id: u32, + id: AcirFunctionId, inputs: Vec, output_count: usize, predicate: AcirVar, @@ -1980,7 +1980,7 @@ impl AcirContext { let predicate = Some(self.var_to_expression(predicate)?); self.acir_ir.push_opcode(Opcode::Call { - id: AcirFunctionId(id), + id: id, inputs, outputs, predicate, diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs index e7465f62ece..64748d3f350 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -33,6 +33,7 @@ use acvm::acir::circuit::opcodes::BlockType; use noirc_frontend::monomorphization::ast::InlineType; use acvm::acir::circuit::brillig::{BrilligBytecode, BrilligFunctionId}; +use acvm::acir::circuit::opcodes::function_id::AcirFunctionId; use acvm::acir::circuit::{AssertionPayload, ErrorSelector, ExpressionWidth, OpcodeLocation}; use acvm::acir::native_types::Witness; use acvm::acir::BlackBoxFunc; @@ -775,7 +776,7 @@ impl<'a> Context<'a> { .get(id) .expect("ICE: should have an associated final index"); let output_vars = self.acir_context.call_acir_function( - *acir_function_id, + AcirFunctionId(*acir_function_id), inputs, output_count, self.current_side_effects_enabled_var, From c74494ae4d9b2b339487e35695846013fe9e5a6c Mon Sep 17 00:00:00 2001 From: shak58 <150069539+shak58@users.noreply.github.com> Date: Sun, 18 Aug 2024 17:10:54 +0100 Subject: [PATCH 4/6] cargo fmt --- .../src/ssa/acir_gen/acir_ir/acir_variable.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index 27606564ee8..18e9f30c1da 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -1979,12 +1979,7 @@ impl AcirContext { vecmap(&outputs, |witness_index| self.add_data(AcirVarData::Witness(*witness_index))); let predicate = Some(self.var_to_expression(predicate)?); - self.acir_ir.push_opcode(Opcode::Call { - id: id, - inputs, - outputs, - predicate, - }); + self.acir_ir.push_opcode(Opcode::Call { id: id, inputs, outputs, predicate }); Ok(results) } } From 7e8e053cb7ddf2492496466fc3cbf63754988c4a Mon Sep 17 00:00:00 2001 From: shak58 <150069539+shak58@users.noreply.github.com> Date: Sun, 18 Aug 2024 17:18:31 +0100 Subject: [PATCH 5/6] reformat --- .../noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index 18e9f30c1da..a8324c11592 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -1979,7 +1979,7 @@ impl AcirContext { vecmap(&outputs, |witness_index| self.add_data(AcirVarData::Witness(*witness_index))); let predicate = Some(self.var_to_expression(predicate)?); - self.acir_ir.push_opcode(Opcode::Call { id: id, inputs, outputs, predicate }); + self.acir_ir.push_opcode(Opcode::Call { id, inputs, outputs, predicate }); Ok(results) } } From 0586062413c5c0ea1a0373faa82189ef97fc6e17 Mon Sep 17 00:00:00 2001 From: shak58 <150069539+shak58@users.noreply.github.com> Date: Sun, 18 Aug 2024 18:23:01 +0100 Subject: [PATCH 6/6] fmt --- .../acir/tests/test_program_serialization.rs | 8 +-- acvm-repo/acvm/src/pwg/mod.rs | 2 +- acvm-repo/acvm_js/src/execute.rs | 4 +- .../noirc_evaluator/src/ssa/acir_gen/mod.rs | 55 +++++++++++++++---- tooling/debugger/src/context.rs | 9 ++- 5 files changed, 58 insertions(+), 20 deletions(-) diff --git a/acvm-repo/acir/tests/test_program_serialization.rs b/acvm-repo/acir/tests/test_program_serialization.rs index 1a634eeea9c..ce28d47021c 100644 --- a/acvm-repo/acir/tests/test_program_serialization.rs +++ b/acvm-repo/acir/tests/test_program_serialization.rs @@ -14,7 +14,7 @@ use std::collections::BTreeSet; use acir::{ circuit::{ brillig::{BrilligBytecode, BrilligFunctionId, BrilligInputs, BrilligOutputs}, - opcodes::{BlackBoxFuncCall, BlockId, FunctionInput, MemOp}, + opcodes::{AcirFunctionId, BlackBoxFuncCall, BlockId, FunctionInput, MemOp}, Circuit, Opcode, Program, PublicInputs, }, native_types::{Expression, Witness}, @@ -381,13 +381,13 @@ fn nested_acir_call_circuit() { // x // } let nested_call = Opcode::Call { - id: 1, + id: AcirFunctionId(1), inputs: vec![Witness(0), Witness(1)], outputs: vec![Witness(2)], predicate: None, }; let nested_call_two = Opcode::Call { - id: 1, + id: AcirFunctionId(1), inputs: vec![Witness(0), Witness(1)], outputs: vec![Witness(3)], predicate: None, @@ -419,7 +419,7 @@ fn nested_acir_call_circuit() { q_c: FieldElement::one() + FieldElement::one(), }); let call = Opcode::Call { - id: 2, + id: AcirFunctionId(2), inputs: vec![Witness(2), Witness(1)], outputs: vec![Witness(3)], predicate: None, diff --git a/acvm-repo/acvm/src/pwg/mod.rs b/acvm-repo/acvm/src/pwg/mod.rs index b31efda25dc..647c11bd3c3 100644 --- a/acvm-repo/acvm/src/pwg/mod.rs +++ b/acvm-repo/acvm/src/pwg/mod.rs @@ -6,7 +6,7 @@ use acir::{ brillig::ForeignCallResult, circuit::{ brillig::{BrilligBytecode, BrilligFunctionId}, - opcodes::{function_id::AcirFunctionId, BlockId, ConstantOrWitnessEnum, FunctionInput}, + opcodes::{AcirFunctionId, BlockId, ConstantOrWitnessEnum, FunctionInput}, AssertionPayload, ErrorSelector, ExpressionOrMemory, Opcode, OpcodeLocation, RawAssertionPayload, ResolvedAssertionPayload, STRING_ERROR_SELECTOR, }, diff --git a/acvm-repo/acvm_js/src/execute.rs b/acvm-repo/acvm_js/src/execute.rs index c596dcf9614..98a0c4c3abe 100644 --- a/acvm-repo/acvm_js/src/execute.rs +++ b/acvm-repo/acvm_js/src/execute.rs @@ -250,7 +250,7 @@ impl<'a, B: BlackBoxFunctionSolver> ProgramExecutor<'a, B> { acvm.resolve_pending_foreign_call(result); } ACVMStatus::RequiresAcirCall(call_info) => { - let acir_to_call = &self.functions[call_info.id as usize]; + let acir_to_call = &self.functions[call_info.id.as_usize()]; let initial_witness = call_info.initial_witness; let call_solved_witness = self .execute_circuit(acir_to_call, initial_witness, witness_stack) @@ -267,7 +267,7 @@ impl<'a, B: BlackBoxFunctionSolver> ProgramExecutor<'a, B> { } } acvm.resolve_pending_acir_call(call_resolved_outputs); - witness_stack.push(call_info.id, call_solved_witness.clone()); + witness_stack.push(call_info.id.0, call_solved_witness.clone()); } } } diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs index 64748d3f350..3e36459a0d6 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -29,11 +29,10 @@ use crate::brillig::brillig_ir::BrilligContext; use crate::brillig::{brillig_gen::brillig_fn::FunctionContext as BrilligFunctionContext, Brillig}; use crate::errors::{InternalError, InternalWarning, RuntimeError, SsaReport}; pub(crate) use acir_ir::generated_acir::GeneratedAcir; -use acvm::acir::circuit::opcodes::BlockType; +use acvm::acir::circuit::opcodes::{AcirFunctionId, BlockType}; use noirc_frontend::monomorphization::ast::InlineType; use acvm::acir::circuit::brillig::{BrilligBytecode, BrilligFunctionId}; -use acvm::acir::circuit::opcodes::function_id::AcirFunctionId; use acvm::acir::circuit::{AssertionPayload, ErrorSelector, ExpressionWidth, OpcodeLocation}; use acvm::acir::native_types::Witness; use acvm::acir::BlackBoxFunc; @@ -2868,9 +2867,13 @@ fn can_omit_element_sizes_array(array_typ: &Type) -> bool { #[cfg(test)] mod test { + use acvm::{ acir::{ - circuit::{brillig::BrilligFunctionId, ExpressionWidth, Opcode, OpcodeLocation}, + circuit::{ + brillig::BrilligFunctionId, opcodes::AcirFunctionId, ExpressionWidth, Opcode, + OpcodeLocation, + }, native_types::Witness, }, FieldElement, @@ -3021,8 +3024,18 @@ mod test { let main_opcodes = main_acir.opcodes(); assert_eq!(main_opcodes.len(), 3, "Should have two calls to `foo`"); - check_call_opcode(&main_opcodes[0], 1, vec![Witness(0), Witness(1)], vec![Witness(2)]); - check_call_opcode(&main_opcodes[1], 1, vec![Witness(0), Witness(1)], vec![Witness(3)]); + check_call_opcode( + &main_opcodes[0], + AcirFunctionId(1), + vec![Witness(0), Witness(1)], + vec![Witness(2)], + ); + check_call_opcode( + &main_opcodes[1], + AcirFunctionId(1), + vec![Witness(0), Witness(1)], + vec![Witness(3)], + ); if let Opcode::AssertZero(expr) = &main_opcodes[2] { assert_eq!(expr.linear_combinations[0].0, FieldElement::from(1u128)); @@ -3077,9 +3090,19 @@ mod test { let main_opcodes = main_acir.opcodes(); assert_eq!(main_opcodes.len(), 3, "Should have two calls to `foo` and an assert"); - check_call_opcode(&main_opcodes[0], 1, vec![Witness(0), Witness(1)], vec![Witness(2)]); + check_call_opcode( + &main_opcodes[0], + AcirFunctionId(1), + vec![Witness(0), Witness(1)], + vec![Witness(2)], + ); // The output of the first call should be the input of the second call - check_call_opcode(&main_opcodes[1], 1, vec![Witness(2), Witness(1)], vec![Witness(3)]); + check_call_opcode( + &main_opcodes[1], + AcirFunctionId(1), + vec![Witness(2), Witness(1)], + vec![Witness(3)], + ); } fn basic_nested_call(inline_type: InlineType) { @@ -3168,9 +3191,19 @@ mod test { assert_eq!(main_opcodes.len(), 3, "Should have two calls to `foo` and an assert"); // Both of these should call func_with_nested_foo_call f1 - check_call_opcode(&main_opcodes[0], 1, vec![Witness(0), Witness(1)], vec![Witness(2)]); + check_call_opcode( + &main_opcodes[0], + AcirFunctionId(1), + vec![Witness(0), Witness(1)], + vec![Witness(2)], + ); // The output of the first call should be the input of the second call - check_call_opcode(&main_opcodes[1], 1, vec![Witness(0), Witness(1)], vec![Witness(3)]); + check_call_opcode( + &main_opcodes[1], + AcirFunctionId(1), + vec![Witness(0), Witness(1)], + vec![Witness(3)], + ); let func_with_nested_call_acir = &acir_functions[1]; let func_with_nested_call_opcodes = func_with_nested_call_acir.opcodes(); @@ -3183,7 +3216,7 @@ mod test { // Should call foo f2 check_call_opcode( &func_with_nested_call_opcodes[1], - 2, + AcirFunctionId(2), vec![Witness(3), Witness(1)], vec![Witness(4)], ); @@ -3191,7 +3224,7 @@ mod test { fn check_call_opcode( opcode: &Opcode, - expected_id: u32, + expected_id: AcirFunctionId, expected_inputs: Vec, expected_outputs: Vec, ) { diff --git a/tooling/debugger/src/context.rs b/tooling/debugger/src/context.rs index aefa435a087..890732b579c 100644 --- a/tooling/debugger/src/context.rs +++ b/tooling/debugger/src/context.rs @@ -946,7 +946,7 @@ mod tests { brillig::IntegerBitSize, circuit::{ brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs}, - opcodes::{BlockId, BlockType}, + opcodes::{AcirFunctionId, BlockId, BlockType}, }, native_types::Expression, AcirField, @@ -1210,7 +1210,12 @@ mod tests { outputs: vec![], predicate: None, }, - Opcode::Call { id: 1, inputs: vec![], outputs: vec![], predicate: None }, + Opcode::Call { + id: AcirFunctionId(1), + inputs: vec![], + outputs: vec![], + predicate: None, + }, Opcode::AssertZero(Expression::default()), ], ..Circuit::default()