Skip to content

Commit

Permalink
chore: use an enum instead of Either to model the result of opcode st…
Browse files Browse the repository at this point in the history
…epping
  • Loading branch information
ggiraldez committed Oct 23, 2023
1 parent 66059e9 commit 68da2a7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion acvm-repo/acvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions acvm-repo/acvm/src/pwg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use self::{
use crate::{BlackBoxFunctionSolver, Language};

use thiserror::Error;
use either::Either;

// arithmetic
pub(crate) mod arithmetic;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -337,27 +341,27 @@ impl<'a, B: BlackBoxFunctionSolver> ACVM<'a, B> {
}
}

pub fn step_into_brillig_opcode(&mut self) -> Either<BrilligSolver<'a, B>, 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::<B>::should_skip(witness, brillig) {
Ok(true) => {
let resolution = BrilligSolver::<B>::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())
}
}

Expand Down
1 change: 0 additions & 1 deletion tooling/debugger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ noirc_printable_type.workspace = true
thiserror.workspace = true
easy-repl = "0.2.1"
owo-colors = "3"
either = "1.8.1"
7 changes: 3 additions & 4 deletions tooling/debugger/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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,
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 68da2a7

Please sign in to comment.