From 96ea988bf1f3e2be6f8a5dc020bd7f720c81edc8 Mon Sep 17 00:00:00 2001 From: Tom French Date: Fri, 13 Oct 2023 17:18:56 +0100 Subject: [PATCH] chore: make `acvm` a non-optional field on `DebugContext` --- tooling/debugger/src/lib.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/tooling/debugger/src/lib.rs b/tooling/debugger/src/lib.rs index ed9fe08ca97..6d541f836ab 100644 --- a/tooling/debugger/src/lib.rs +++ b/tooling/debugger/src/lib.rs @@ -18,7 +18,7 @@ enum SolveResult { } struct DebugContext<'backend, B: BlackBoxFunctionSolver> { - acvm: Option>, + acvm: ACVM<'backend, B>, debug_artifact: DebugArtifact, foreign_call_executor: ForeignCallExecutor, circuit: Circuit, @@ -27,7 +27,7 @@ struct DebugContext<'backend, B: BlackBoxFunctionSolver> { impl<'backend, B: BlackBoxFunctionSolver> DebugContext<'backend, B> { fn step_opcode(&mut self) -> Result { - let solver_status = self.acvm.as_mut().unwrap().solve_opcode(); + let solver_status = self.acvm.solve_opcode(); match solver_status { ACVMStatus::Solved => Ok(SolveResult::Done), @@ -59,16 +59,15 @@ impl<'backend, B: BlackBoxFunctionSolver> DebugContext<'backend, B> { ACVMStatus::RequiresForeignCall(foreign_call) => { let foreign_call_result = self.foreign_call_executor.execute(&foreign_call, self.show_output)?; - self.acvm.as_mut().unwrap().resolve_pending_foreign_call(foreign_call_result); + self.acvm.resolve_pending_foreign_call(foreign_call_result); Ok(SolveResult::Ok) } } } fn show_current_vm_status(&self) { - let acvm = self.acvm.as_ref().unwrap(); - let ip = acvm.instruction_pointer(); - let opcodes = acvm.opcodes(); + let ip = self.acvm.instruction_pointer(); + let opcodes = self.acvm.opcodes(); if ip >= opcodes.len() { println!("Finished execution"); } else { @@ -101,8 +100,8 @@ impl<'backend, B: BlackBoxFunctionSolver> DebugContext<'backend, B> { Ok(SolveResult::Done) } - fn finalize(&mut self) -> WitnessMap { - self.acvm.take().unwrap().finalize() + fn finalize(self) -> WitnessMap { + self.acvm.finalize() } } @@ -123,7 +122,7 @@ pub fn debug_circuit( let opcodes = circuit.opcodes.clone(); let context = RefCell::new(DebugContext { - acvm: Some(ACVM::new(blackbox_solver, &opcodes, initial_witness)), + acvm: ACVM::new(blackbox_solver, &opcodes, initial_witness), foreign_call_executor: ForeignCallExecutor::default(), circuit, debug_artifact, @@ -169,8 +168,12 @@ pub fn debug_circuit( repl.run().expect("Debugger error"); + // REPL execution has finished. + // Drop it so that we can move fields out from `context` again. + drop(repl); + if solved.get() { - let solved_witness = context.borrow_mut().finalize(); + let solved_witness = context.into_inner().finalize(); Ok(Some(solved_witness)) } else { Ok(None)