diff --git a/Cargo.lock b/Cargo.lock index 3add28d3939..bf51fcefe34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2743,14 +2743,12 @@ dependencies = [ "nargo", "nargo_fmt", "nargo_toml", - "noirc_artifacts", "noirc_driver", "noirc_errors", "noirc_frontend", "rayon", "serde", "serde_json", - "serde_with", "strum", "thiserror", "tokio", diff --git a/compiler/noirc_errors/src/debug_info.rs b/compiler/noirc_errors/src/debug_info.rs index b480d20fde4..af4f7c0f2a7 100644 --- a/compiler/noirc_errors/src/debug_info.rs +++ b/compiler/noirc_errors/src/debug_info.rs @@ -12,7 +12,6 @@ use serde::Serializer; use serde_with::serde_as; use serde_with::DisplayFromStr; use std::collections::BTreeMap; -use std::collections::HashMap; use std::io::Read; use std::io::Write; use std::mem; @@ -106,14 +105,6 @@ pub struct DebugInfo { pub types: DebugTypes, } -/// Holds OpCodes Counts for Acir and Brillig Opcodes -/// To be printed with `nargo info --profile-info` -#[derive(Default, Debug, Serialize, Deserialize, Clone)] -pub struct OpCodesCount { - pub acir_size: usize, - pub brillig_size: usize, -} - impl DebugInfo { pub fn new( locations: BTreeMap>, @@ -147,38 +138,4 @@ impl DebugInfo { pub fn opcode_location(&self, loc: &OpcodeLocation) -> Option> { self.locations.get(loc).cloned() } - - pub fn count_span_opcodes(&self) -> HashMap { - let mut accumulator: HashMap> = HashMap::new(); - - for (opcode_location, locations) in self.locations.iter() { - for location in locations.iter() { - let opcodes = accumulator.entry(*location).or_default(); - opcodes.push(opcode_location); - } - } - - let counted_opcodes = accumulator - .iter() - .map(|(location, opcodes)| { - let acir_opcodes: Vec<_> = opcodes - .iter() - .filter(|opcode_location| matches!(opcode_location, OpcodeLocation::Acir(_))) - .collect(); - let brillig_opcodes: Vec<_> = opcodes - .iter() - .filter(|opcode_location| { - matches!(opcode_location, OpcodeLocation::Brillig { .. }) - }) - .collect(); - let opcodes_count = OpCodesCount { - acir_size: acir_opcodes.len(), - brillig_size: brillig_opcodes.len(), - }; - (*location, opcodes_count) - }) - .collect(); - - counted_opcodes - } } diff --git a/tooling/lsp/Cargo.toml b/tooling/lsp/Cargo.toml index c15895d801f..04c8edf7ea9 100644 --- a/tooling/lsp/Cargo.toml +++ b/tooling/lsp/Cargo.toml @@ -22,13 +22,11 @@ nargo_toml.workspace = true noirc_driver.workspace = true noirc_errors.workspace = true noirc_frontend.workspace = true -noirc_artifacts.workspace = true serde.workspace = true serde_json.workspace = true strum = "0.24" tower.workspace = true async-lsp = { workspace = true, features = ["omni-trait"] } -serde_with = "3.2.0" thiserror.workspace = true fm.workspace = true rayon.workspace = true diff --git a/tooling/lsp/src/lib.rs b/tooling/lsp/src/lib.rs index a85b9d043b9..aa93b5215d0 100644 --- a/tooling/lsp/src/lib.rs +++ b/tooling/lsp/src/lib.rs @@ -54,9 +54,9 @@ use requests::{ on_code_action_request, on_code_lens_request, on_completion_request, on_document_symbol_request, on_formatting, on_goto_declaration_request, on_goto_definition_request, on_goto_type_definition_request, on_hover_request, on_initialize, - on_inlay_hint_request, on_prepare_rename_request, on_profile_run_request, - on_references_request, on_rename_request, on_shutdown, on_signature_help_request, - on_test_run_request, on_tests_request, LspInitializationOptions, + on_inlay_hint_request, on_prepare_rename_request, on_references_request, on_rename_request, + on_shutdown, on_signature_help_request, on_test_run_request, on_tests_request, + LspInitializationOptions, }; use serde_json::Value as JsonValue; use thiserror::Error; @@ -154,7 +154,6 @@ impl NargoLspService { .request::(on_code_lens_request) .request::(on_tests_request) .request::(on_test_run_request) - .request::(on_profile_run_request) .request::(on_goto_definition_request) .request::(on_goto_declaration_request) .request::(on_goto_type_definition_request) diff --git a/tooling/lsp/src/requests/code_lens_request.rs b/tooling/lsp/src/requests/code_lens_request.rs index 42f2af3a7bf..0c1877c156d 100644 --- a/tooling/lsp/src/requests/code_lens_request.rs +++ b/tooling/lsp/src/requests/code_lens_request.rs @@ -24,9 +24,6 @@ const EXECUTE_CODELENS_TITLE: &str = "Execute"; const DEBUG_COMMAND: &str = "nargo.debug.dap"; const DEBUG_CODELENS_TITLE: &str = "Debug"; -const PROFILE_COMMAND: &str = "nargo.profile"; -const PROFILE_CODELENS_TITLE: &str = "Profile"; - fn with_arrow(title: &str) -> String { format!("{ARROW} {title}") } @@ -162,7 +159,6 @@ pub(crate) fn collect_lenses_for_package( let internal_command_lenses = [ (INFO_CODELENS_TITLE, INFO_COMMAND), (EXECUTE_CODELENS_TITLE, EXECUTE_COMMAND), - (PROFILE_CODELENS_TITLE, PROFILE_COMMAND), (DEBUG_CODELENS_TITLE, DEBUG_COMMAND), ] .map(|(title, command)| { @@ -214,16 +210,6 @@ pub(crate) fn collect_lenses_for_package( let info_lens = CodeLens { range, command: Some(info_command), data: None }; lenses.push(info_lens); - - let profile_command = Command { - title: PROFILE_CODELENS_TITLE.to_string(), - command: PROFILE_COMMAND.into(), - arguments: Some(package_selection_args(workspace, package)), - }; - - let profile_lens = CodeLens { range, command: Some(profile_command), data: None }; - - lenses.push(profile_lens); } } diff --git a/tooling/lsp/src/requests/mod.rs b/tooling/lsp/src/requests/mod.rs index 0ee66f1f618..d32a69c25a3 100644 --- a/tooling/lsp/src/requests/mod.rs +++ b/tooling/lsp/src/requests/mod.rs @@ -44,7 +44,6 @@ mod goto_declaration; mod goto_definition; mod hover; mod inlay_hint; -mod profile_run; mod references; mod rename; mod signature_help; @@ -56,8 +55,7 @@ pub(crate) use { code_lens_request::on_code_lens_request, completion::on_completion_request, document_symbol::on_document_symbol_request, goto_declaration::on_goto_declaration_request, goto_definition::on_goto_definition_request, goto_definition::on_goto_type_definition_request, - hover::on_hover_request, inlay_hint::on_inlay_hint_request, - profile_run::on_profile_run_request, references::on_references_request, + hover::on_hover_request, inlay_hint::on_inlay_hint_request, references::on_references_request, rename::on_prepare_rename_request, rename::on_rename_request, signature_help::on_signature_help_request, test_run::on_test_run_request, tests::on_tests_request, diff --git a/tooling/lsp/src/requests/profile_run.rs b/tooling/lsp/src/requests/profile_run.rs deleted file mode 100644 index a7362300adc..00000000000 --- a/tooling/lsp/src/requests/profile_run.rs +++ /dev/null @@ -1,122 +0,0 @@ -use std::{ - collections::{BTreeMap, HashMap}, - future::{self, Future}, -}; - -use crate::insert_all_files_for_workspace_into_file_manager; -use acvm::acir::circuit::ExpressionWidth; -use async_lsp::{ErrorCode, ResponseError}; -use nargo::ops::report_errors; -use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; -use noirc_artifacts::debug::DebugArtifact; -use noirc_driver::{CompileOptions, DebugFile, NOIR_ARTIFACT_VERSION_STRING}; -use noirc_errors::{debug_info::OpCodesCount, Location}; - -use crate::{ - parse_diff, - types::{NargoProfileRunParams, NargoProfileRunResult}, - LspState, -}; -use fm::FileId; - -pub(crate) fn on_profile_run_request( - state: &mut LspState, - params: NargoProfileRunParams, -) -> impl Future> { - future::ready(on_profile_run_request_inner(state, params)) -} - -fn on_profile_run_request_inner( - state: &mut LspState, - params: NargoProfileRunParams, -) -> Result { - let root_path = state.root_path.as_deref().ok_or_else(|| { - ResponseError::new(ErrorCode::REQUEST_FAILED, "Could not find project root") - })?; - - let toml_path = find_package_manifest(root_path, root_path).map_err(|err| { - // If we cannot find a manifest, we can't run the test - ResponseError::new(ErrorCode::REQUEST_FAILED, err) - })?; - - let crate_name = params.package; - - let workspace = resolve_workspace_from_toml( - &toml_path, - PackageSelection::DefaultOrAll, - Some(NOIR_ARTIFACT_VERSION_STRING.to_string()), - ) - .map_err(|err| { - // If we found a manifest, but the workspace is invalid, we raise an error about it - ResponseError::new(ErrorCode::REQUEST_FAILED, err) - })?; - - let mut workspace_file_manager = workspace.new_file_manager(); - insert_all_files_for_workspace_into_file_manager( - state, - &workspace, - &mut workspace_file_manager, - ); - let parsed_files = parse_diff(&workspace_file_manager, state); - - // Since we filtered on crate name, this should be the only item in the iterator - match workspace.into_iter().next() { - Some(_package) => { - let expression_width = ExpressionWidth::Bounded { width: 3 }; - - let compiled_workspace = nargo::ops::compile_workspace( - &workspace_file_manager, - &parsed_files, - &workspace, - &CompileOptions::default(), - ); - - let (compiled_programs, compiled_contracts) = report_errors( - compiled_workspace, - &workspace_file_manager, - CompileOptions::default().deny_warnings, - CompileOptions::default().silence_warnings, - ) - .map_err(|err| ResponseError::new(ErrorCode::REQUEST_FAILED, err))?; - - let mut opcodes_counts: HashMap = HashMap::new(); - let mut file_map: BTreeMap = BTreeMap::new(); - for compiled_program in compiled_programs { - let compiled_program = - nargo::ops::transform_program(compiled_program, expression_width); - - for function_debug in compiled_program.debug.iter() { - let span_opcodes = function_debug.count_span_opcodes(); - opcodes_counts.extend(span_opcodes); - } - let debug_artifact: DebugArtifact = compiled_program.into(); - file_map.extend(debug_artifact.file_map); - } - - for compiled_contract in compiled_contracts { - let compiled_contract = - nargo::ops::transform_contract(compiled_contract, expression_width); - - let function_debug_info = compiled_contract - .functions - .iter() - .flat_map(|func| &func.debug) - .collect::>(); - for contract_function_debug in function_debug_info { - let span_opcodes = contract_function_debug.count_span_opcodes(); - opcodes_counts.extend(span_opcodes); - } - let debug_artifact: DebugArtifact = compiled_contract.into(); - file_map.extend(debug_artifact.file_map); - } - - let result = NargoProfileRunResult { file_map, opcodes_counts }; - - Ok(result) - } - None => Err(ResponseError::new( - ErrorCode::REQUEST_FAILED, - format!("Could not locate package named: {crate_name}"), - )), - } -} diff --git a/tooling/lsp/src/types.rs b/tooling/lsp/src/types.rs index 043c50a87fd..b49377787e8 100644 --- a/tooling/lsp/src/types.rs +++ b/tooling/lsp/src/types.rs @@ -1,15 +1,10 @@ -use fm::FileId; use lsp_types::{ CodeActionOptions, CompletionOptions, DeclarationCapability, DefinitionOptions, DocumentSymbolOptions, HoverOptions, InlayHintOptions, OneOf, ReferencesOptions, RenameOptions, SignatureHelpOptions, TypeDefinitionProviderCapability, }; -use noirc_driver::DebugFile; -use noirc_errors::{debug_info::OpCodesCount, Location}; use noirc_frontend::graph::CrateName; use serde::{Deserialize, Serialize}; -use serde_with::serde_as; -use std::collections::{BTreeMap, HashMap}; // Re-providing lsp_types that we don't need to override pub(crate) use lsp_types::{ @@ -23,8 +18,8 @@ pub(crate) mod request { use lsp_types::{request::Request, InitializeParams}; use super::{ - InitializeResult, NargoProfileRunParams, NargoProfileRunResult, NargoTestRunParams, - NargoTestRunResult, NargoTestsParams, NargoTestsResult, + InitializeResult, NargoTestRunParams, NargoTestRunResult, NargoTestsParams, + NargoTestsResult, }; // Re-providing lsp_types that we don't need to override @@ -56,14 +51,6 @@ pub(crate) mod request { type Result = NargoTestsResult; const METHOD: &'static str = "nargo/tests"; } - - #[derive(Debug)] - pub(crate) struct NargoProfileRun; - impl Request for NargoProfileRun { - type Params = NargoProfileRunParams; - type Result = NargoProfileRunResult; - const METHOD: &'static str = "nargo/profile/run"; - } } pub(crate) mod notification { @@ -253,17 +240,6 @@ pub(crate) struct NargoTestRunResult { pub(crate) result: String, pub(crate) message: Option, } -#[derive(Debug, Serialize, Deserialize)] -pub(crate) struct NargoProfileRunParams { - pub(crate) package: CrateName, -} -#[serde_as] -#[derive(Debug, Serialize, Deserialize)] -pub(crate) struct NargoProfileRunResult { - pub(crate) file_map: BTreeMap, - #[serde_as(as = "Vec<(_, _)>")] - pub(crate) opcodes_counts: HashMap, -} pub(crate) type CodeLensResult = Option>; pub(crate) type GotoDefinitionResult = Option;