Skip to content

Commit

Permalink
chore: replace long Backend type parameters with B
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed May 9, 2023
1 parent ce423c5 commit 042925f
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 80 deletions.
6 changes: 3 additions & 3 deletions crates/nargo/src/ops/codegen_verifier.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use acvm::SmartContract;

pub fn codegen_verifier<Backend: SmartContract>(
backend: &Backend,
pub fn codegen_verifier<B: SmartContract>(
backend: B,
verification_key: &[u8],
) -> Result<String, Backend::Error> {
) -> Result<String, B::Error> {
backend.eth_contract_from_vk(verification_key)
}
12 changes: 6 additions & 6 deletions crates/nargo/src/ops/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use crate::artifacts::{
// TODO: pull this from backend.
const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg";

pub fn preprocess_program<Backend: ProofSystemCompiler>(
backend: &Backend,
pub fn preprocess_program<B: ProofSystemCompiler>(
backend: &B,
compiled_program: CompiledProgram,
) -> Result<PreprocessedProgram, Backend::Error> {
) -> Result<PreprocessedProgram, B::Error> {
// TODO: currently `compiled_program`'s bytecode is already optimized for the backend.
// In future we'll need to apply those optimizations here.
let optimized_bytecode = compiled_program.circuit;
Expand All @@ -27,10 +27,10 @@ pub fn preprocess_program<Backend: ProofSystemCompiler>(
})
}

pub fn preprocess_contract<Backend: ProofSystemCompiler>(
backend: &Backend,
pub fn preprocess_contract<B: ProofSystemCompiler>(
backend: &B,
compiled_contract: CompiledContract,
) -> Result<PreprocessedContract, Backend::Error> {
) -> Result<PreprocessedContract, B::Error> {
let mut preprocessed_contract_functions = vec![];
for func in compiled_contract.functions.into_iter() {
// TODO: currently `func`'s bytecode is already optimized for the backend.
Expand Down
6 changes: 3 additions & 3 deletions crates/nargo/src/ops/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use acvm::acir::circuit::Circuit;
use acvm::ProofSystemCompiler;
use noirc_abi::WitnessMap;

pub fn prove_execution<Backend: ProofSystemCompiler>(
backend: &Backend,
pub fn prove_execution<B: ProofSystemCompiler>(
backend: &B,
circuit: &Circuit,
solved_witness: WitnessMap,
proving_key: &[u8],
) -> Result<Vec<u8>, Backend::Error> {
) -> Result<Vec<u8>, B::Error> {
backend.prove_with_pk(circuit, solved_witness, proving_key)
}
6 changes: 3 additions & 3 deletions crates/nargo/src/ops/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use acvm::acir::circuit::Circuit;
use acvm::ProofSystemCompiler;
use noirc_abi::WitnessMap;

pub fn verify_proof<Backend: ProofSystemCompiler>(
backend: &Backend,
pub fn verify_proof<B: ProofSystemCompiler>(
backend: &B,
circuit: &Circuit,
proof: &[u8],
public_inputs: WitnessMap,
verification_key: &[u8],
) -> Result<bool, Backend::Error> {
) -> Result<bool, B::Error> {
backend.verify_with_vk(proof, public_inputs, circuit, verification_key)
}
18 changes: 9 additions & 9 deletions crates/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ pub(crate) struct CheckCommand {
compile_options: CompileOptions,
}

pub(crate) fn run<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
pub(crate) fn run<B: Backend>(
backend: &B,
args: CheckCommand,
config: NargoConfig,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
check_from_path(backend, config.program_dir, &args.compile_options)?;
println!("Constraint system successfully built!");
Ok(())
}

fn check_from_path<ConcreteBackend: Backend, P: AsRef<Path>>(
backend: &ConcreteBackend,
fn check_from_path<B: Backend, P: AsRef<Path>>(
backend: &B,
p: P,
compile_options: &CompileOptions,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
let mut driver = Resolver::resolve_root_manifest(p.as_ref(), backend.np_language())?;

driver.check_crate(compile_options).map_err(|_| CliError::CompilationError)?;
Expand Down Expand Up @@ -154,7 +154,7 @@ d2 = ["", "", ""]
let pass_dir =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("{TEST_DATA_DIR}/pass"));

let backend = crate::backends::ConcreteBackend::default();
let backend = crate::backends::B::default();
let config = CompileOptions::default();
let paths = std::fs::read_dir(pass_dir).unwrap();
for path in paths.flatten() {
Expand All @@ -173,7 +173,7 @@ d2 = ["", "", ""]
let fail_dir =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("{TEST_DATA_DIR}/fail"));

let backend = crate::backends::ConcreteBackend::default();
let backend = crate::backends::B::default();
let config = CompileOptions::default();
let paths = std::fs::read_dir(fail_dir).unwrap();
for path in paths.flatten() {
Expand All @@ -191,7 +191,7 @@ d2 = ["", "", ""]
let pass_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join(format!("{TEST_DATA_DIR}/pass_dev_mode"));

let backend = crate::backends::ConcreteBackend::default();
let backend = crate::backends::B::default();
let config = CompileOptions { allow_warnings: true, ..Default::default() };

let paths = std::fs::read_dir(pass_dir).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions crates/nargo_cli/src/cli/codegen_verifier_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ pub(crate) struct CodegenVerifierCommand {
compile_options: CompileOptions,
}

pub(crate) fn run<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
pub(crate) fn run<B: Backend>(
backend: &B,
args: CodegenVerifierCommand,
config: NargoConfig,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
// TODO(#1201): Should this be a utility function?
let circuit_build_path = args
.circuit_name
Expand Down
16 changes: 8 additions & 8 deletions crates/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ pub(crate) struct CompileCommand {
compile_options: CompileOptions,
}

pub(crate) fn run<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
pub(crate) fn run<B: Backend>(
backend: &B,
args: CompileCommand,
config: NargoConfig,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
let circuit_dir = config.program_dir.join(TARGET_DIR);

// If contracts is set we're compiling every function in a 'contract' rather than just 'main'.
Expand Down Expand Up @@ -61,18 +61,18 @@ pub(crate) fn run<ConcreteBackend: Backend>(
Ok(())
}

fn setup_driver<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
fn setup_driver<B: Backend>(
backend: &B,
program_dir: &Path,
) -> Result<Driver, DependencyResolutionError> {
Resolver::resolve_root_manifest(program_dir, backend.np_language())
}

pub(crate) fn compile_circuit<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
pub(crate) fn compile_circuit<B: Backend>(
backend: &B,
program_dir: &Path,
compile_options: &CompileOptions,
) -> Result<CompiledProgram, CliError<ConcreteBackend>> {
) -> Result<CompiledProgram, CliError<B>> {
let mut driver = setup_driver(backend, program_dir)?;
driver.compile_main(compile_options).map_err(|_| CliError::CompilationError)
}
18 changes: 9 additions & 9 deletions crates/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub(crate) struct ExecuteCommand {
compile_options: CompileOptions,
}

pub(crate) fn run<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
pub(crate) fn run<B: Backend>(
backend: &B,
args: ExecuteCommand,
config: NargoConfig,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
let (return_value, solved_witness) =
execute_with_path(backend, &config.program_dir, &args.compile_options)?;

Expand All @@ -47,11 +47,11 @@ pub(crate) fn run<ConcreteBackend: Backend>(
Ok(())
}

fn execute_with_path<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
fn execute_with_path<B: Backend>(
backend: &B,
program_dir: &Path,
compile_options: &CompileOptions,
) -> Result<(Option<InputValue>, WitnessMap), CliError<ConcreteBackend>> {
) -> Result<(Option<InputValue>, WitnessMap), CliError<B>> {
let CompiledProgram { abi, circuit } = compile_circuit(backend, program_dir, compile_options)?;

// Parse the initial witness values from Prover.toml
Expand All @@ -66,12 +66,12 @@ fn execute_with_path<ConcreteBackend: Backend>(
Ok((return_value, solved_witness))
}

pub(crate) fn execute_program<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
pub(crate) fn execute_program<B: Backend>(
backend: &B,
circuit: Circuit,
abi: &Abi,
inputs_map: &InputMap,
) -> Result<WitnessMap, CliError<ConcreteBackend>> {
) -> Result<WitnessMap, CliError<B>> {
let initial_witness = abi.encode(inputs_map, None)?;

let solved_witness = nargo::ops::execute_circuit(backend, circuit, initial_witness)?;
Expand Down
12 changes: 6 additions & 6 deletions crates/nargo_cli/src/cli/gates_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ pub(crate) struct GatesCommand {
compile_options: CompileOptions,
}

pub(crate) fn run<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
pub(crate) fn run<B: Backend>(
backend: &B,
args: GatesCommand,
config: NargoConfig,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
count_gates_with_path(backend, config.program_dir, &args.compile_options)
}

fn count_gates_with_path<ConcreteBackend: Backend, P: AsRef<Path>>(
backend: &ConcreteBackend,
fn count_gates_with_path<B: Backend, P: AsRef<Path>>(
backend: &B,
program_dir: P,
compile_options: &CompileOptions,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
let compiled_program = compile_circuit(backend, program_dir.as_ref(), compile_options)?;
let num_opcodes = compiled_program.circuit.opcodes.len();

Expand Down
6 changes: 3 additions & 3 deletions crates/nargo_cli/src/cli/new_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ fn test_main() {
}
"#;

pub(crate) fn run<ConcreteBackend: Backend>(
pub(crate) fn run<B: Backend>(
// Backend is currently unused, but we might want to use it to inform the "new" template in the future
_backend: &ConcreteBackend,
_backend: &B,
args: NewCommand,
config: NargoConfig,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
let package_dir = config.program_dir.join(args.package_name);

if package_dir.exists() {
Expand Down
12 changes: 6 additions & 6 deletions crates/nargo_cli/src/cli/print_acir_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ pub(crate) struct PrintAcirCommand {
compile_options: CompileOptions,
}

pub(crate) fn run<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
pub(crate) fn run<B: Backend>(
backend: &B,
args: PrintAcirCommand,
config: NargoConfig,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
print_acir_with_path(backend, config.program_dir, &args.compile_options)
}

fn print_acir_with_path<ConcreteBackend: Backend, P: AsRef<Path>>(
backend: &ConcreteBackend,
fn print_acir_with_path<B: Backend, P: AsRef<Path>>(
backend: &B,
program_dir: P,
compile_options: &CompileOptions,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
let compiled_program = compile_circuit(backend, program_dir.as_ref(), compile_options)?;
println!("{}", compiled_program.circuit);

Expand Down
12 changes: 6 additions & 6 deletions crates/nargo_cli/src/cli/prove_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ pub(crate) struct ProveCommand {
compile_options: CompileOptions,
}

pub(crate) fn run<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
pub(crate) fn run<B: Backend>(
backend: &B,
args: ProveCommand,
config: NargoConfig,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
let proof_dir = config.program_dir.join(PROOFS_DIR);

let circuit_build_path = args
Expand All @@ -63,15 +63,15 @@ pub(crate) fn run<ConcreteBackend: Backend>(
Ok(())
}

pub(crate) fn prove_with_path<ConcreteBackend: Backend, P: AsRef<Path>>(
backend: &ConcreteBackend,
pub(crate) fn prove_with_path<B: Backend, P: AsRef<Path>>(
backend: &B,
proof_name: Option<String>,
program_dir: P,
proof_dir: P,
circuit_build_path: Option<PathBuf>,
check_proof: bool,
compile_options: &CompileOptions,
) -> Result<Option<PathBuf>, CliError<ConcreteBackend>> {
) -> Result<Option<PathBuf>, CliError<B>> {
let preprocessed_program = match circuit_build_path {
Some(circuit_build_path) => read_program_from_file(circuit_build_path)?,
None => {
Expand Down
18 changes: 9 additions & 9 deletions crates/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ pub(crate) struct TestCommand {
compile_options: CompileOptions,
}

pub(crate) fn run<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
pub(crate) fn run<B: Backend>(
backend: &B,
args: TestCommand,
config: NargoConfig,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
let test_name: String = args.test_name.unwrap_or_else(|| "".to_owned());

run_tests(backend, &config.program_dir, &test_name, &args.compile_options)
}

fn run_tests<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
fn run_tests<B: Backend>(
backend: &B,
program_dir: &Path,
test_name: &str,
compile_options: &CompileOptions,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
let mut driver = Resolver::resolve_root_manifest(program_dir, backend.np_language())?;

driver.check_crate(compile_options).map_err(|_| CliError::CompilationError)?;
Expand Down Expand Up @@ -76,13 +76,13 @@ fn run_tests<ConcreteBackend: Backend>(
Ok(())
}

fn run_test<ConcreteBackend: Backend>(
backend: &ConcreteBackend,
fn run_test<B: Backend>(
backend: &B,
test_name: &str,
main: FuncId,
driver: &Driver,
config: &CompileOptions,
) -> Result<(), CliError<ConcreteBackend>> {
) -> Result<(), CliError<B>> {
let program = driver
.compile_no_check(config, main)
.map_err(|_| CliError::Generic(format!("Test '{test_name}' failed to compile")))?;
Expand Down
Loading

0 comments on commit 042925f

Please sign in to comment.