From 68da2a7803db9a97b8eab3cd893f5371ba947f98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Mon, 23 Oct 2023 12:52:24 -0400 Subject: [PATCH] chore: use an enum instead of Either to model the result of opcode stepping --- Cargo.lock | 2 -- acvm-repo/acvm/Cargo.toml | 1 - acvm-repo/acvm/src/pwg/mod.rs | 18 +++++++++++------- tooling/debugger/Cargo.toml | 1 - tooling/debugger/src/lib.rs | 7 +++---- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7e1ecae19c..5601dbae53d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,7 +42,6 @@ dependencies = [ "acvm_blackbox_solver", "acvm_stdlib", "brillig_vm", - "either", "indexmap 1.9.3", "num-bigint", "num-traits", @@ -2544,7 +2543,6 @@ version = "0.16.0" dependencies = [ "acvm", "easy-repl", - "either", "nargo", "noirc_printable_type", "owo-colors", diff --git a/acvm-repo/acvm/Cargo.toml b/acvm-repo/acvm/Cargo.toml index 0d0dadd77f8..f51bb627fd9 100644 --- a/acvm-repo/acvm/Cargo.toml +++ b/acvm-repo/acvm/Cargo.toml @@ -16,7 +16,6 @@ repository.workspace = true num-bigint.workspace = true num-traits.workspace = true thiserror.workspace = true -either = "1.8.1" acir.workspace = true stdlib.workspace = true diff --git a/acvm-repo/acvm/src/pwg/mod.rs b/acvm-repo/acvm/src/pwg/mod.rs index ee974574e72..de78e46174f 100644 --- a/acvm-repo/acvm/src/pwg/mod.rs +++ b/acvm-repo/acvm/src/pwg/mod.rs @@ -18,7 +18,6 @@ use self::{ use crate::{BlackBoxFunctionSolver, Language}; use thiserror::Error; -use either::Either; // arithmetic pub(crate) mod arithmetic; @@ -64,6 +63,11 @@ impl std::fmt::Display for ACVMStatus { } } +pub enum StepResult<'a, B: BlackBoxFunctionSolver> { + Status(ACVMStatus), + IntoBrillig(BrilligSolver<'a, B>), +} + // This enum represents the different cases in which an // opcode can be unsolvable. // The most common being that one of its input has not been @@ -337,27 +341,27 @@ impl<'a, B: BlackBoxFunctionSolver> ACVM<'a, B> { } } - pub fn step_into_brillig_opcode(&mut self) -> Either, ACVMStatus> { + pub fn step_into_brillig_opcode(&mut self) -> StepResult<'a, B> { if let Opcode::Brillig(brillig) = &self.opcodes[self.instruction_pointer] { let witness = &mut self.witness_map; match BrilligSolver::::should_skip(witness, brillig) { Ok(true) => { let resolution = BrilligSolver::::zero_out_brillig_outputs(witness, brillig); - Either::Right(self.handle_opcode_resolution(resolution)) + StepResult::Status(self.handle_opcode_resolution(resolution)) } Ok(false) => { let solver = BrilligSolver::new(witness, brillig, self.backend, self.instruction_pointer); match solver { - Ok(solver) => Either::Left(solver), - Err(..) => Either::Right(self.handle_opcode_resolution(solver.map(|_| ()))), + Ok(solver) => StepResult::IntoBrillig(solver), + Err(..) => StepResult::Status(self.handle_opcode_resolution(solver.map(|_| ()))), } } Err(err) => { - Either::Right(self.handle_opcode_resolution(Err(err))) + StepResult::Status(self.handle_opcode_resolution(Err(err))) } } } else { - Either::Right(self.solve_opcode()) + StepResult::Status(self.solve_opcode()) } } diff --git a/tooling/debugger/Cargo.toml b/tooling/debugger/Cargo.toml index 5413ef25103..7e06c549d2d 100644 --- a/tooling/debugger/Cargo.toml +++ b/tooling/debugger/Cargo.toml @@ -15,4 +15,3 @@ noirc_printable_type.workspace = true thiserror.workspace = true easy-repl = "0.2.1" owo-colors = "3" -either = "1.8.1" diff --git a/tooling/debugger/src/lib.rs b/tooling/debugger/src/lib.rs index b98cef611ec..b63b97cf2cc 100644 --- a/tooling/debugger/src/lib.rs +++ b/tooling/debugger/src/lib.rs @@ -1,5 +1,5 @@ use acvm::acir::circuit::OpcodeLocation; -use acvm::pwg::{ACVMStatus, BrilligSolver, ErrorLocation, OpcodeResolutionError, ACVM, BrilligSolverStatus}; +use acvm::pwg::{ACVMStatus, BrilligSolver, ErrorLocation, OpcodeResolutionError, ACVM, BrilligSolverStatus, StepResult}; use acvm::BlackBoxFunctionSolver; use acvm::{acir::circuit::Circuit, acir::native_types::WitnessMap}; @@ -13,7 +13,6 @@ use easy_repl::{command, CommandStatus, Critical, Repl}; use std::cell::{Cell, RefCell}; use owo_colors::OwoColorize; -use either::Either; enum SolveResult { Done, @@ -67,11 +66,11 @@ impl<'backend, B: BlackBoxFunctionSolver> DebugContext<'backend, B> { self.step_brillig_opcode() } else { match self.acvm.step_into_brillig_opcode() { - Either::Left(solver) => { + StepResult::IntoBrillig(solver) => { self.brillig_solver = Some(solver); self.step_brillig_opcode() } - Either::Right(status) => { + StepResult::Status(status) => { self.handle_acvm_status(status) } }