Skip to content

Commit

Permalink
remove execution_helpers auxiliary file
Browse files Browse the repository at this point in the history
  • Loading branch information
anaPerezGhiglia committed Aug 8, 2024
1 parent 2dc687c commit b70cd79
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 56 deletions.
14 changes: 13 additions & 1 deletion tooling/nargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_cli/src/cli/dap_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down
33 changes: 31 additions & 2 deletions tooling/nargo_cli/src/cli/debug_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
49 changes: 0 additions & 49 deletions tooling/nargo_cli/src/cli/execution_helpers.rs

This file was deleted.

1 change: 0 additions & 1 deletion tooling/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tooling/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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)]
Expand Down

0 comments on commit b70cd79

Please sign in to comment.