diff --git a/acvm/src/compiler.rs b/acvm/src/compiler.rs index bb4db27cc..07d103346 100644 --- a/acvm/src/compiler.rs +++ b/acvm/src/compiler.rs @@ -11,7 +11,7 @@ use acir::{ use indexmap::IndexMap; use optimizers::GeneralOptimizer; use thiserror::Error; -use transformers::{CSatTransformer, FallbackTransformer, IsOpcodeSupported, R1CSTransformer}; +use transformers::{CSatTransformer, FallbackTransformer, R1CSTransformer}; use self::optimizers::RangeOptimizer; use self::optimizers::Simplifier; @@ -25,7 +25,7 @@ pub enum CompileError { pub fn compile( acir: Circuit, np_language: Language, - is_opcode_supported: IsOpcodeSupported, + is_opcode_supported: impl Fn(&Opcode) -> bool, simplifier: &Simplifier, ) -> Result { // Instantiate the optimizer. diff --git a/acvm/src/compiler/optimizers/simplify.rs b/acvm/src/compiler/optimizers/simplify.rs index 5373d128f..3737d1e0c 100644 --- a/acvm/src/compiler/optimizers/simplify.rs +++ b/acvm/src/compiler/optimizers/simplify.rs @@ -439,10 +439,7 @@ mod test { FieldElement, }; - use crate::compiler::{ - optimizers::Simplifier, - transformers::{FallbackTransformer, IsOpcodeSupported}, - }; + use crate::compiler::{optimizers::Simplifier, transformers::FallbackTransformer}; #[test] fn simplify_test() { @@ -479,7 +476,7 @@ mod test { simplifier.simplify(&mut circuit); assert_eq!(circuit.len(), 3); assert_eq!(simplifier.solved_gates.len(), 1); - let support_all: IsOpcodeSupported = |_| true; + let support_all = |_opcode: &Opcode| true; let mut acir = Circuit::default(); acir.opcodes = circuit; let acir = FallbackTransformer::transform(acir, support_all, &simplifier).unwrap(); diff --git a/acvm/src/compiler/transformers/fallback.rs b/acvm/src/compiler/transformers/fallback.rs index b9bc8834e..ca68e9aed 100644 --- a/acvm/src/compiler/transformers/fallback.rs +++ b/acvm/src/compiler/transformers/fallback.rs @@ -7,16 +7,13 @@ use acir::{ BlackBoxFunc, }; -// A predicate that returns true if the black box function is supported -pub type IsOpcodeSupported = fn(&Opcode) -> bool; - pub struct FallbackTransformer; impl FallbackTransformer { //ACIR pass which replace unsupported opcodes using arithmetic fallback pub fn transform( acir: Circuit, - is_supported: IsOpcodeSupported, + is_supported: impl Fn(&Opcode) -> bool, simplifier: &Simplifier, ) -> Result { let mut acir_supported_opcodes = Vec::with_capacity(acir.opcodes.len()); diff --git a/acvm/src/compiler/transformers/mod.rs b/acvm/src/compiler/transformers/mod.rs index ddc0e3419..e0d690188 100644 --- a/acvm/src/compiler/transformers/mod.rs +++ b/acvm/src/compiler/transformers/mod.rs @@ -4,5 +4,4 @@ mod r1cs; pub use csat::CSatTransformer; pub use fallback::FallbackTransformer; -pub use fallback::IsOpcodeSupported; pub use r1cs::R1CSTransformer; diff --git a/acvm/src/lib.rs b/acvm/src/lib.rs index d28b6d21f..4e8b0485e 100644 --- a/acvm/src/lib.rs +++ b/acvm/src/lib.rs @@ -159,8 +159,8 @@ pub trait ProofSystemCompiler { /// if the language and proof system does not line up. fn np_language(&self) -> Language; - // Returns true if the backend supports the selected black box function - fn black_box_function_supported(&self, opcode: &BlackBoxFunc) -> bool; + // Returns true if the backend supports the selected opcode + fn supports_opcode(&self, opcode: &Opcode) -> bool; /// Returns the number of gates in a circuit fn get_exact_circuit_size(&self, circuit: &Circuit) -> Result; @@ -222,14 +222,12 @@ pub fn checksum_constraint_system(cs: &Circuit) -> u32 { } #[deprecated( - note = "For backwards compatibility, this method allows you to derive _sensible_ defaults for black box function support based on the np language. \n Backends should simply specify what they support." + note = "For backwards compatibility, this method allows you to derive _sensible_ defaults for opcode support based on the np language. \n Backends should simply specify what they support." )] // This is set to match the previous functionality that we had // Where we could deduce what opcodes were supported // by knowing the np complete language -pub fn default_is_opcode_supported( - language: Language, -) -> compiler::transformers::IsOpcodeSupported { +pub fn default_is_opcode_supported(language: Language) -> fn(&Opcode) -> bool { // R1CS does not support any of the opcode except Arithmetic by default. // The compiler will replace those that it can -- ie range, xor, and fn r1cs_is_supported(opcode: &Opcode) -> bool {