From b70cd796d50a8dc95d366d3e6c680d3713e8197b Mon Sep 17 00:00:00 2001 From: Ana Perez Ghiglia Date: Thu, 8 Aug 2024 19:17:53 -0300 Subject: [PATCH] remove execution_helpers auxiliary file --- tooling/nargo/src/lib.rs | 14 +++++- tooling/nargo_cli/src/cli/dap_cmd.rs | 2 +- tooling/nargo_cli/src/cli/debug_cmd.rs | 33 ++++++++++++- .../nargo_cli/src/cli/execution_helpers.rs | 49 ------------------- tooling/nargo_cli/src/cli/mod.rs | 1 - tooling/nargo_cli/src/cli/test_cmd.rs | 4 +- 6 files changed, 47 insertions(+), 56 deletions(-) delete mode 100644 tooling/nargo_cli/src/cli/execution_helpers.rs diff --git a/tooling/nargo/src/lib.rs b/tooling/nargo/src/lib.rs index c0c7602d14d..2932b4df0bb 100644 --- a/tooling/nargo/src/lib.rs +++ b/tooling/nargo/src/lib.rs @@ -14,9 +14,10 @@ pub mod package; pub mod workspace; use std::collections::BTreeMap; +use std::path::Path; use fm::{FileManager, FILE_EXTENSION}; -use noirc_driver::{add_dep, prepare_crate, prepare_dependency}; +use noirc_driver::{add_dep, file_manager_with_stdlib, prepare_crate, prepare_dependency}; use noirc_frontend::{ graph::{CrateId, CrateName}, hir::{def_map::parse_file, Context, ParsedFiles}, @@ -42,6 +43,17 @@ pub fn prepare_dependencies( } } +// TODO: find a better name +pub fn file_manager_and_files_from( + root: &Path, + workspace: &workspace::Workspace, +) -> (FileManager, ParsedFiles) { + let mut workspace_file_manager = file_manager_with_stdlib(root); + insert_all_files_for_workspace_into_file_manager(workspace, &mut workspace_file_manager); + let parsed_files = parse_all(&workspace_file_manager); + (workspace_file_manager, parsed_files) +} + pub fn insert_all_files_for_workspace_into_file_manager( workspace: &workspace::Workspace, file_manager: &mut FileManager, diff --git a/tooling/nargo_cli/src/cli/dap_cmd.rs b/tooling/nargo_cli/src/cli/dap_cmd.rs index 3aa955fe12e..3faaaae2b72 100644 --- a/tooling/nargo_cli/src/cli/dap_cmd.rs +++ b/tooling/nargo_cli/src/cli/dap_cmd.rs @@ -4,6 +4,7 @@ use acvm::FieldElement; use bn254_blackbox_solver::Bn254BlackBoxSolver; use clap::Args; use nargo::constants::PROVER_INPUT_FILE; +use nargo::file_manager_and_files_from; use nargo::package::Package; use nargo::workspace::Workspace; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; @@ -26,7 +27,6 @@ use serde_json::Value; use super::debug_cmd::{ compile_bin_package_for_debugging, compile_options_for_debugging, prepare_package_for_debug, }; -use super::execution_helpers::file_manager_and_files_from; use super::fs::inputs::read_inputs_from_file; use super::test_cmd::get_tests_in_package; use crate::errors::CliError; diff --git a/tooling/nargo_cli/src/cli/debug_cmd.rs b/tooling/nargo_cli/src/cli/debug_cmd.rs index d492c9633a4..7f859252114 100644 --- a/tooling/nargo_cli/src/cli/debug_cmd.rs +++ b/tooling/nargo_cli/src/cli/debug_cmd.rs @@ -15,7 +15,7 @@ use nargo::ops::{ }; use nargo::package::Package; use nargo::workspace::Workspace; -use nargo::{prepare_package, NargoError}; +use nargo::{file_manager_and_files_from, prepare_package, NargoError}; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_abi::input_parser::{Format, InputValue}; @@ -24,13 +24,13 @@ use noirc_driver::{ compile_no_check, link_to_debug_crate, CompileOptions, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING, }; +use noirc_frontend::debug::DebugInstrumenter; use noirc_frontend::graph::{CrateId, CrateName}; use noirc_frontend::hir::def_map::TestFunction; use noirc_frontend::hir::{Context, FunctionNameMatch, ParsedFiles}; use super::check_cmd::check_crate_and_report_errors; use super::compile_cmd::get_target_width; -use super::execution_helpers::{file_manager_and_files_from, instrument_package_files}; use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir}; use super::test_cmd::display_test_report; use super::NargoConfig; @@ -356,6 +356,35 @@ fn debug_program_and_decode( } } +/// Add debugging instrumentation to all parsed files belonging to the package +/// being compiled +pub(crate) fn instrument_package_files( + parsed_files: &mut ParsedFiles, + file_manager: &FileManager, + package: &Package, +) -> DebugInstrumenter { + // Start off at the entry path and read all files in the parent directory. + let entry_path_parent = package + .entry_path + .parent() + .unwrap_or_else(|| panic!("The entry path is expected to be a single file within a directory and so should have a parent {:?}", package.entry_path)); + + let mut debug_instrumenter = DebugInstrumenter::default(); + + for (file_id, parsed_file) in parsed_files.iter_mut() { + let file_path = + file_manager.path(*file_id).expect("Parsed file ID not found in file manager"); + for ancestor in file_path.ancestors() { + if ancestor == entry_path_parent { + // file is in package + debug_instrumenter.instrument_module(&mut parsed_file.0); + } + } + } + + debug_instrumenter +} + fn parse_initial_witness( package: &Package, prover_name: &str, diff --git a/tooling/nargo_cli/src/cli/execution_helpers.rs b/tooling/nargo_cli/src/cli/execution_helpers.rs deleted file mode 100644 index d4cb0cd231a..00000000000 --- a/tooling/nargo_cli/src/cli/execution_helpers.rs +++ /dev/null @@ -1,49 +0,0 @@ -use fm::FileManager; -use nargo::{insert_all_files_for_workspace_into_file_manager, parse_all}; -use nargo::{package::Package, workspace::Workspace}; -use noirc_driver::file_manager_with_stdlib; -use noirc_frontend::{debug::DebugInstrumenter, hir::ParsedFiles}; - -use std::path::Path; - -/// Add debugging instrumentation to all parsed files belonging to the package -/// being compiled -/// TODO: move to nargo:ops:debug? to reuse form test_cmd -pub(crate) fn instrument_package_files( - parsed_files: &mut ParsedFiles, - file_manager: &FileManager, - package: &Package, -) -> DebugInstrumenter { - // Start off at the entry path and read all files in the parent directory. - let entry_path_parent = package - .entry_path - .parent() - .unwrap_or_else(|| panic!("The entry path is expected to be a single file within a directory and so should have a parent {:?}", package.entry_path)); - - let mut debug_instrumenter = DebugInstrumenter::default(); - - for (file_id, parsed_file) in parsed_files.iter_mut() { - let file_path = - file_manager.path(*file_id).expect("Parsed file ID not found in file manager"); - for ancestor in file_path.ancestors() { - if ancestor == entry_path_parent { - // file is in package - debug_instrumenter.instrument_module(&mut parsed_file.0); - } - } - } - - debug_instrumenter -} - -// TODO: should we create a type that englobe fileManager + parsed_files? -// all functions that need file_manager needs parsed_files as well -pub(crate) fn file_manager_and_files_from( - root: &Path, - workspace: &Workspace, -) -> (FileManager, ParsedFiles) { - let mut workspace_file_manager = file_manager_with_stdlib(root); - insert_all_files_for_workspace_into_file_manager(workspace, &mut workspace_file_manager); - let parsed_files = parse_all(&workspace_file_manager); - (workspace_file_manager, parsed_files) -} diff --git a/tooling/nargo_cli/src/cli/mod.rs b/tooling/nargo_cli/src/cli/mod.rs index 2fc96bc3ead..10ec38ad1d5 100644 --- a/tooling/nargo_cli/src/cli/mod.rs +++ b/tooling/nargo_cli/src/cli/mod.rs @@ -13,7 +13,6 @@ mod compile_cmd; mod dap_cmd; mod debug_cmd; mod execute_cmd; -mod execution_helpers; mod export_cmd; mod fmt_cmd; mod info_cmd; diff --git a/tooling/nargo_cli/src/cli/test_cmd.rs b/tooling/nargo_cli/src/cli/test_cmd.rs index 9d2b7a5c7ae..49c571f95cd 100644 --- a/tooling/nargo_cli/src/cli/test_cmd.rs +++ b/tooling/nargo_cli/src/cli/test_cmd.rs @@ -4,7 +4,7 @@ use acvm::{BlackBoxFunctionSolver, FieldElement}; use bn254_blackbox_solver::Bn254BlackBoxSolver; use clap::Args; use fm::FileManager; -use nargo::{ops::TestStatus, package::Package, prepare_package}; +use nargo::{file_manager_and_files_from, ops::TestStatus, package::Package, prepare_package}; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::{check_crate, compile_no_check, CompileOptions, NOIR_ARTIFACT_VERSION_STRING}; use noirc_frontend::{ @@ -16,7 +16,7 @@ use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; use crate::{cli::check_cmd::check_crate_and_report_errors, errors::CliError}; -use super::{execution_helpers::file_manager_and_files_from, NargoConfig}; +use super::NargoConfig; /// Run the tests for this program #[derive(Debug, Clone, Args)]