diff --git a/cli-rs/src/main.rs b/cli-rs/src/main.rs index 45f09c4214..cf8fa1e230 100644 --- a/cli-rs/src/main.rs +++ b/cli-rs/src/main.rs @@ -426,7 +426,7 @@ fn execute( ) -> Result<(), Vec> { let mut pipeline = Pipeline::::default() .from_asm_file(file_name.to_path_buf()) - .with_backend(backend, None) + .with_backend_factory(backend) .with_prover_inputs(inputs) .with_output(output_dir.into(), true); diff --git a/pipeline/benches/jit_witgen_benchmark.rs b/pipeline/benches/jit_witgen_benchmark.rs index d2e578def3..eebb1cfdbc 100644 --- a/pipeline/benches/jit_witgen_benchmark.rs +++ b/pipeline/benches/jit_witgen_benchmark.rs @@ -1,5 +1,4 @@ use ::powdr_pipeline::Pipeline; -use powdr_backend::BackendType; use powdr_number::GoldilocksField; use criterion::{criterion_group, criterion_main, Criterion}; @@ -11,10 +10,8 @@ fn jit_witgen_benchmark(c: &mut Criterion) { group.sample_size(10); // Poseidon benchmark - let mut pipeline = Pipeline::::default() - .from_file("../test_data/std/poseidon_benchmark.asm".into()) - .with_backend(BackendType::Mock, None); - // this `jit_witgen_benchmark` function will also require backend type + let mut pipeline = + Pipeline::::default().from_file("../test_data/std/poseidon_benchmark.asm".into()); pipeline.compute_backend_tuned_pil().unwrap(); pipeline.compute_fixed_cols().unwrap(); diff --git a/pipeline/src/pipeline.rs b/pipeline/src/pipeline.rs index 1d589e3054..5284e53eef 100644 --- a/pipeline/src/pipeline.rs +++ b/pipeline/src/pipeline.rs @@ -97,14 +97,14 @@ impl AsIoRead for Option { } /// Optional Arguments for various stages of the pipeline. -#[derive(Default, Clone)] +#[derive(Clone)] struct Arguments { /// Externally computed witness values for witness generation. external_witness_values: Vec<(String, Vec)>, /// Callback for queries for witness generation. query_callback: Option>>, - /// Backend to use for proving. If None, proving will fail. - backend: Option, + /// Backend to use for proving. Defaults to Mock Backend. + backend: BackendType, /// Backend options backend_options: BackendOptions, /// Linker options @@ -127,6 +127,29 @@ struct Arguments { existing_proof_file: Option, } +impl Default for Arguments +where + T: FieldElement, +{ + fn default() -> Self { + Arguments { + external_witness_values: vec![], + query_callback: None, + backend: BackendType::Mock, // the only non-default value + backend_options: Default::default(), + linker_params: Default::default(), + csv_render_mode: Default::default(), + export_witness_csv: false, + export_all_columns_csv: false, + setup_file: None, + pkey_file: None, + vkey_file: None, + vkey_app_file: None, + existing_proof_file: None, + } + } +} + #[derive(Clone)] pub struct Pipeline { /// Stores all artifacts at the same time. @@ -363,19 +386,17 @@ impl Pipeline { self } - pub fn with_backend(mut self, backend: BackendType, options: Option) -> Self { - self.arguments.backend = Some(backend); - self.arguments.backend_options = options.unwrap_or_default(); + pub fn with_backend_factory(mut self, backend: BackendType) -> Self { + self.arguments.backend = backend; self.artifact.backend = None; self } - pub fn with_backend_if_none(&mut self, backend: BackendType, options: Option) { - if self.arguments.backend.is_none() { - self.arguments.backend = Some(backend); - self.arguments.backend_options = options.unwrap_or_default(); - self.artifact.backend = None; - } + pub fn with_backend(mut self, backend: BackendType, options: Option) -> Self { + self.arguments.backend = backend; + self.arguments.backend_options = options.unwrap_or_default(); + self.artifact.backend = None; + self } pub fn with_setup_file(mut self, setup_file: Option) -> Self { @@ -998,7 +1019,7 @@ impl Pipeline { self.compute_optimized_pil()?; - let backend_type = self.arguments.backend.expect("no backend selected!"); + let backend_type = self.arguments.backend; // If backend option is set, compute and cache the backend-tuned pil in artifacts and return backend-tuned pil. let optimized_pil = self.artifact.optimized_pil.clone().unwrap(); @@ -1140,7 +1161,7 @@ impl Pipeline { let pil = self.compute_backend_tuned_pil()?; // will panic if backend type is not set yet let fixed_cols = self.compute_fixed_cols()?; - let backend = self.arguments.backend.expect("no backend selected!"); + let backend = self.arguments.backend; let factory = backend.factory::(); // Opens the setup file, if set. diff --git a/pipeline/src/test_util.rs b/pipeline/src/test_util.rs index d2d637d5c1..7ab0789552 100644 --- a/pipeline/src/test_util.rs +++ b/pipeline/src/test_util.rs @@ -517,14 +517,14 @@ pub fn assert_proofs_fail_for_invalid_witnesses_pilcom( assert!(run_pilcom_with_backend_variant( pipeline .clone() - .with_backend(powdr_backend::BackendType::EStarkDump, None) + .with_backend_factory(powdr_backend::BackendType::EStarkDump) .set_witness(convert_witness(witness)), BackendVariant::Monolithic ) .is_err()); assert!(run_pilcom_with_backend_variant( pipeline - .with_backend(powdr_backend::BackendType::EStarkDumpComposite, None) + .with_backend_factory(powdr_backend::BackendType::EStarkDumpComposite) .set_witness(convert_witness(witness)), BackendVariant::Composite ) diff --git a/pipeline/tests/asm.rs b/pipeline/tests/asm.rs index 38f5a08059..beabefbc95 100644 --- a/pipeline/tests/asm.rs +++ b/pipeline/tests/asm.rs @@ -173,7 +173,7 @@ fn block_to_block_empty_submachine() { .iter() .for_each(|backend| { let mut pipeline = make_simple_prepared_pipeline::(f, LinkerMode::Bus) - .with_backend(*backend, None); + .with_backend_factory(*backend); let witness = pipeline.compute_witness().unwrap(); let arith_size = witness .iter() @@ -314,7 +314,7 @@ fn dynamic_vadcop() { // Witness generation require backend to be known for backend in [BackendType::Mock, BackendType::Plonky3].iter() { let mut pipeline = make_simple_prepared_pipeline::(f, LinkerMode::Bus) - .with_backend(*backend, None); + .with_backend_factory(*backend); let witness = pipeline.compute_witness().unwrap(); let witness_by_name = witness .iter() @@ -891,7 +891,6 @@ fn expand_fixed_jit() { let file_name = "asm/expand_fixed.asm"; let mut pipeline = Pipeline::::default() - .with_backend(BackendType::Mock, None) .with_tmp_output() .from_file(resolve_test_file(file_name)); let pil = pipeline.compute_backend_tuned_pil().unwrap(); diff --git a/pipeline/tests/executor.rs b/pipeline/tests/executor.rs index 8f0fc2dd46..12745447ec 100644 --- a/pipeline/tests/executor.rs +++ b/pipeline/tests/executor.rs @@ -6,7 +6,6 @@ use test_log::test; fn run_witgen_pil(pil: &str) -> Arc> { Pipeline::default() - .with_backend(powdr_pipeline::BackendType::Mock, None) .from_pil_string(pil.to_string()) .compute_witness() .unwrap() diff --git a/pipeline/tests/mock_backend.rs b/pipeline/tests/mock_backend.rs index 2dad3e1876..5589f65bba 100644 --- a/pipeline/tests/mock_backend.rs +++ b/pipeline/tests/mock_backend.rs @@ -16,8 +16,7 @@ fn fibonacci_wrong_initialization() { // Initializes y with 2 instead of 1 // -> fails `ISLAST * (y' - 1) = 0;` in the last row let f = "pil/fibonacci.pil"; - let pipeline = make_simple_prepared_pipeline::(f, LinkerMode::Bus) - .with_backend(powdr_backend::BackendType::Mock, None); + let pipeline = make_simple_prepared_pipeline::(f, LinkerMode::Bus); let pipeline = pipeline.set_witness(vec![ // This would be the correct witness: // col("Fibonacci::x", [1, 1, 2, 3]), @@ -36,8 +35,7 @@ fn block_to_block_wrong_connection() { // So, if we multiply all columns with a constant, the constraint // should still be satisfied, but the connection argument should fail. let f = "asm/block_to_block.asm"; - let mut pipeline = make_simple_prepared_pipeline::(f, LinkerMode::Bus) - .with_backend(powdr_backend::BackendType::Mock, None); + let mut pipeline = make_simple_prepared_pipeline::(f, LinkerMode::Bus); pipeline.compute_witness().unwrap(); diff --git a/pipeline/tests/pil.rs b/pipeline/tests/pil.rs index 0597fa83ed..8dc03f34bc 100644 --- a/pipeline/tests/pil.rs +++ b/pipeline/tests/pil.rs @@ -113,12 +113,9 @@ fn fibonacci() { fn fibonacci_with_public() { // Public references are not supported by the backends yet, but we can test witness generation. let f = "pil/fibonacci_with_public.pil"; - let pipeline: Pipeline = + let mut pipeline: Pipeline = make_prepared_pipeline(f, vec![], vec![], LinkerMode::Bus); - pipeline - .with_backend(powdr_backend::BackendType::Mock, None) - .compute_witness() - .unwrap(); + pipeline.compute_witness().unwrap(); } #[test] diff --git a/pipeline/tests/powdr_std.rs b/pipeline/tests/powdr_std.rs index 66f81c2800..51200190ba 100644 --- a/pipeline/tests/powdr_std.rs +++ b/pipeline/tests/powdr_std.rs @@ -8,9 +8,9 @@ use powdr_pipeline::{ test_runner::run_tests, test_util::{ evaluate_function, evaluate_integer_function, gen_estark_proof_with_backend_variant, - gen_halo2_proof, make_simple_prepared_pipeline, regular_test_bb, regular_test_gl, - regular_test_small_field, std_analyzed, test_halo2_with_backend_variant, test_mock_backend, - test_plonky3_pipeline, BackendVariant, + gen_halo2_proof, make_prepared_pipeline, make_simple_prepared_pipeline, regular_test_bb, + regular_test_gl, regular_test_small_field, std_analyzed, test_halo2_with_backend_variant, + test_mock_backend, test_plonky3_pipeline, BackendVariant, }, Pipeline, }; @@ -139,8 +139,15 @@ fn arith_small_test() { #[test] #[ignore = "Too slow"] fn arith_large_test() { + // We just run this test for the mock backend in bus linker mode, + // because witgen and proving should be similar to the other backends. let f = "std/arith_large_test.asm"; - regular_test_gl(f, &[]); + test_mock_backend(make_prepared_pipeline::( + f, + vec![], + vec![], + LinkerMode::Bus, + )); } #[test] @@ -153,8 +160,15 @@ fn arith256_small_test() { #[test] #[ignore = "Too slow"] fn arith256_memory_large_test() { + // We just run this test for the mock backend in bus linker mode, + // because witgen and proving should be similar to the other backends. let f = "std/arith256_memory_large_test.asm"; - regular_test_gl(f, &[]); + test_mock_backend(make_prepared_pipeline::( + f, + vec![], + vec![], + LinkerMode::Bus, + )); } #[test] diff --git a/riscv/benches/executor_benchmark.rs b/riscv/benches/executor_benchmark.rs index 6936bb05d0..f2e9100204 100644 --- a/riscv/benches/executor_benchmark.rs +++ b/riscv/benches/executor_benchmark.rs @@ -1,5 +1,4 @@ use ::powdr_pipeline::Pipeline; -use powdr_backend::BackendType; use powdr_number::GoldilocksField; use powdr_riscv::{compile_rust_crate_to_riscv, elf, CompilerOptions}; @@ -19,9 +18,7 @@ fn executor_benchmark(c: &mut Criterion) { compile_rust_crate_to_riscv("./tests/riscv_data/keccak/Cargo.toml", &tmp_dir, None); let options = CompilerOptions::new_gl(); let contents = elf::translate(&executable, options); - let mut pipeline = Pipeline::::default() - .from_asm_string(contents, None) - .with_backend(BackendType::Mock, None); + let mut pipeline = Pipeline::::default().from_asm_string(contents, None); pipeline.compute_backend_tuned_pil().unwrap(); pipeline.compute_fixed_cols().unwrap(); diff --git a/riscv/src/continuations.rs b/riscv/src/continuations.rs index 9cdbf05226..56a1411ed8 100644 --- a/riscv/src/continuations.rs +++ b/riscv/src/continuations.rs @@ -59,8 +59,6 @@ pub fn rust_continuations( where PipelineCallback: Fn(&mut Pipeline) -> Result<(), E>, { - pipeline.with_backend_if_none(powdr_pipeline::BackendType::Mock, None); - let bootloader_inputs = dry_run_result.bootloader_inputs; let num_chunks = bootloader_inputs.len(); @@ -340,8 +338,6 @@ pub fn rust_continuations_dry_run( pipeline: &mut Pipeline, profiler_opt: Option, ) -> DryRunResult { - pipeline.with_backend_if_none(powdr_pipeline::BackendType::Mock, None); - let field = F::known_field().unwrap(); // All inputs for all chunks. diff --git a/riscv/tests/common/mod.rs b/riscv/tests/common/mod.rs index 88f6f2c578..dd38ff3e43 100644 --- a/riscv/tests/common/mod.rs +++ b/riscv/tests/common/mod.rs @@ -1,5 +1,4 @@ use mktemp::Temp; -use powdr_backend::BackendType; use powdr_number::{BabyBearField, FieldElement, GoldilocksField, KnownField, KoalaBearField}; use powdr_pipeline::{ test_util::{ @@ -26,8 +25,7 @@ pub fn verify_riscv_asm_string(options: CompilerOptions) { let mut pipeline = Pipeline::::default() .from_asm_string(powdr_asm, Some(PathBuf::from(case))) - .with_backend(powdr_backend::BackendType::Mock, None) .with_prover_inputs(vec![answer.into()]) .with_prover_dict_inputs(d); @@ -615,7 +614,6 @@ fn output_syscall_with_options(options: CompilerOptions) { let inputs = vec![1u32, 2, 3].into_iter().map(T::from).collect(); let mut pipeline = Pipeline::::default() - .with_backend(powdr_backend::BackendType::Mock, None) .from_asm_string(powdr_asm, Some(PathBuf::from(case))) .with_prover_inputs(inputs);