Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
anaPerezGhiglia committed Aug 7, 2024
1 parent c36f131 commit c8f8b40
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
22 changes: 8 additions & 14 deletions tooling/debugger/src/dap.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::collections::BTreeMap;
use std::io::{Read, Write};

use acvm::acir::circuit::brillig::BrilligBytecode;
use acvm::acir::circuit::Circuit;
use acvm::acir::native_types::WitnessMap;
use acvm::{BlackBoxFunctionSolver, FieldElement};
use nargo::errors::try_to_diagnose_runtime_error;
Expand Down Expand Up @@ -67,20 +65,18 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver<FieldElement>> DapSession<
pub fn new(
server: Server<R, W>,
solver: &'a B,
circuits: &'a [Circuit<FieldElement>],
program: &'a CompiledProgram,
debug_artifact: &'a DebugArtifact,
initial_witness: WitnessMap<FieldElement>,
unconstrained_functions: &'a [BrilligBytecode<FieldElement>],
test_function: Option<TestFunction>,
abi: &'a Abi,
) -> Self {
let context = DebugContext::new(
solver,
circuits,
&program.program.functions,
debug_artifact,
initial_witness,
Box::new(DefaultDebugForeignCallExecutor::from_artifact(true, debug_artifact)),
unconstrained_functions,
&program.program.unconstrained_functions,
);
Self {
server,
Expand All @@ -91,7 +87,7 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver<FieldElement>> DapSession<
instruction_breakpoints: vec![],
source_breakpoints: BTreeMap::new(),
test_function,
abi,
abi: &program.abi,
}
}

Expand Down Expand Up @@ -400,15 +396,15 @@ impl<'a, R: Read, W: Write, B: BlackBoxFunctionSolver<FieldElement>> DapSession<
// Since the test shouldn't have failed, so that user can
// - see the error on the exception panel
// - restart the debug session
let message = format!("x Text failed: {}", err.to_string());
let message = format!("x Text failed: {}", err);
self.send_debug_output_message(message)?;
} else {
// Finish the execution of the debugger since the test reached
// the expected state (failed)
self.running = false;
let diagnostic = try_to_diagnose_runtime_error(
&err,
&self.abi,
self.abi,
&self.debug_artifact.debug_symbols,
);
let message = match check_expected_failure_message(
Expand Down Expand Up @@ -674,16 +670,14 @@ pub fn run_session<R: Read, W: Write, B: BlackBoxFunctionSolver<FieldElement>>(
initial_witness: WitnessMap<FieldElement>,
test_function: Option<TestFunction>,
) -> Result<(), ServerError> {
let debug_artifact = DebugArtifact { debug_symbols: program.debug, file_map: program.file_map };
let debug_artifact = DebugArtifact { debug_symbols: program.debug.clone(), file_map: program.file_map.clone() };
let mut session = DapSession::new(
server,
solver,
&program.program.functions,
&program,
&debug_artifact,
initial_witness,
&program.program.unconstrained_functions,
test_function,
&program.abi,
);

session.run_loop()
Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ pub fn try_to_diagnose_runtime_error(

pub fn map_execution_error<F: AcirField>(
error: OpcodeResolutionError<F>,
call_stack: &Vec<ResolvedOpcodeLocation>,
call_stack: &[ResolvedOpcodeLocation],
) -> ExecutionError<F> {
let call_stack = match &error {
OpcodeResolutionError::UnsatisfiedConstrain { .. }
| OpcodeResolutionError::IndexOutOfBounds { .. }
| OpcodeResolutionError::BrilligFunctionFailed { .. } => Some(call_stack.clone()),
| OpcodeResolutionError::BrilligFunctionFailed { .. } => Some(call_stack.to_vec()),
_ => None,
};

Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo_cli/src/cli/dap_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ fn load_and_compile_test_function(

let test_functions = context
.get_all_test_functions_in_crate_matching(&crate_id, FunctionNameMatch::Exact(test_name));
let (_, test_function) = test_functions.into_iter().nth(0).expect("Test function should exist");
let (_, test_function) = test_functions.into_iter().next().expect("Test function should exist");

let compiled = compile_no_check_for_debug(&mut context, &test_function, &compile_options)
let compiled = compile_no_check_for_debug(&mut context, &test_function, compile_options)
.map_err(|_| LoadError::Generic("Failed to compile project".into()))?;
Ok((compiled, Some(test_function)))
}
Expand Down
8 changes: 3 additions & 5 deletions tooling/nargo_cli/src/cli/debug_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub(crate) fn compile_bin_package_for_debugging(
&parsed_files,
workspace,
package,
&compile_options,
compile_options,
None,
)
};
Expand Down Expand Up @@ -184,17 +184,15 @@ fn run_async(
}

type DebugResult = Result<WitnessStack<FieldElement>, NargoError<FieldElement>>;
type ExecutionResult = Result<(Option<InputValue>, WitnessStack<FieldElement>), NargoError<FieldElement>>;

// FIXME: We have nested results to differentiate between the execution result (the inner one - Nargo)
// and setting up the debugger errors (outer one - CliErrors)
fn debug_program_and_decode(
program: CompiledProgram,
package: &Package,
prover_name: &str,
) -> Result<
Result<(Option<InputValue>, WitnessStack<FieldElement>), NargoError<FieldElement>>,
CliError,
> {
) -> Result<ExecutionResult, CliError> {
let program_abi = program.abi.clone();

let initial_witness = parse_initial_witness(package, prover_name, &program.abi)?;
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/src/cli/execution_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) fn prepare_package_for_debug<'a>(
parsed_files: &'a mut ParsedFiles,
package: &'a Package,
) -> (Context<'a, 'a>, CrateId) {
let debug_instrumenter = instrument_package_files(parsed_files, &file_manager, package);
let debug_instrumenter = instrument_package_files(parsed_files, file_manager, package);

// -- This :down: is from nargo::ops(compile).compile_program_with_debug_instrumenter
let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package);
Expand Down

0 comments on commit c8f8b40

Please sign in to comment.