diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/rust-analyzer/src/bin/flags.rs | 3 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 1 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/analysis_stats.rs | 60 |
3 files changed, 42 insertions, 22 deletions
diff --git a/crates/rust-analyzer/src/bin/flags.rs b/crates/rust-analyzer/src/bin/flags.rs index b05fc00b9..63953098a 100644 --- a/crates/rust-analyzer/src/bin/flags.rs +++ b/crates/rust-analyzer/src/bin/flags.rs | |||
@@ -71,6 +71,8 @@ xflags::xflags! { | |||
71 | optional --load-output-dirs | 71 | optional --load-output-dirs |
72 | /// Use proc-macro-srv for proc-macro expanding. | 72 | /// Use proc-macro-srv for proc-macro expanding. |
73 | optional --with-proc-macro | 73 | optional --with-proc-macro |
74 | /// Only resolve names, don't run type inference. | ||
75 | optional --skip-inference | ||
74 | } | 76 | } |
75 | 77 | ||
76 | cmd diagnostics | 78 | cmd diagnostics |
@@ -158,6 +160,7 @@ pub struct AnalysisStats { | |||
158 | pub no_sysroot: bool, | 160 | pub no_sysroot: bool, |
159 | pub load_output_dirs: bool, | 161 | pub load_output_dirs: bool, |
160 | pub with_proc_macro: bool, | 162 | pub with_proc_macro: bool, |
163 | pub skip_inference: bool, | ||
161 | } | 164 | } |
162 | 165 | ||
163 | #[derive(Debug)] | 166 | #[derive(Debug)] |
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 3b9b9e8b4..873e82c7b 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs | |||
@@ -78,6 +78,7 @@ fn try_main() -> Result<()> { | |||
78 | path: cmd.path, | 78 | path: cmd.path, |
79 | load_output_dirs: cmd.load_output_dirs, | 79 | load_output_dirs: cmd.load_output_dirs, |
80 | with_proc_macro: cmd.with_proc_macro, | 80 | with_proc_macro: cmd.with_proc_macro, |
81 | skip_inference: cmd.skip_inference, | ||
81 | } | 82 | } |
82 | .run(verbosity)?, | 83 | .run(verbosity)?, |
83 | 84 | ||
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 9c59e7ee4..18fd7ea74 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -9,10 +9,11 @@ use std::{ | |||
9 | 9 | ||
10 | use hir::{ | 10 | use hir::{ |
11 | db::{AstDatabase, DefDatabase, HirDatabase}, | 11 | db::{AstDatabase, DefDatabase, HirDatabase}, |
12 | AssocItem, Crate, HasSource, HirDisplay, ModuleDef, | 12 | AssocItem, Crate, Function, HasSource, HirDisplay, ModuleDef, |
13 | }; | 13 | }; |
14 | use hir_def::FunctionId; | 14 | use hir_def::FunctionId; |
15 | use hir_ty::TypeWalk; | 15 | use hir_ty::TypeWalk; |
16 | use ide::{AnalysisHost, RootDatabase}; | ||
16 | use ide_db::base_db::{ | 17 | use ide_db::base_db::{ |
17 | salsa::{self, ParallelDatabase}, | 18 | salsa::{self, ParallelDatabase}, |
18 | SourceDatabaseExt, | 19 | SourceDatabaseExt, |
@@ -24,6 +25,7 @@ use rayon::prelude::*; | |||
24 | use rustc_hash::FxHashSet; | 25 | use rustc_hash::FxHashSet; |
25 | use stdx::format_to; | 26 | use stdx::format_to; |
26 | use syntax::AstNode; | 27 | use syntax::AstNode; |
28 | use vfs::Vfs; | ||
27 | 29 | ||
28 | use crate::cli::{ | 30 | use crate::cli::{ |
29 | load_cargo::{load_workspace_at, LoadCargoConfig}, | 31 | load_cargo::{load_workspace_at, LoadCargoConfig}, |
@@ -51,6 +53,7 @@ pub struct AnalysisStatsCmd { | |||
51 | pub path: PathBuf, | 53 | pub path: PathBuf, |
52 | pub load_output_dirs: bool, | 54 | pub load_output_dirs: bool, |
53 | pub with_proc_macro: bool, | 55 | pub with_proc_macro: bool, |
56 | pub skip_inference: bool, | ||
54 | } | 57 | } |
55 | 58 | ||
56 | impl AnalysisStatsCmd { | 59 | impl AnalysisStatsCmd { |
@@ -128,6 +131,39 @@ impl AnalysisStatsCmd { | |||
128 | shuffle(&mut rng, &mut funcs); | 131 | shuffle(&mut rng, &mut funcs); |
129 | } | 132 | } |
130 | 133 | ||
134 | if !self.skip_inference { | ||
135 | self.run_inference(&host, db, &vfs, &funcs, verbosity); | ||
136 | } | ||
137 | |||
138 | let total_span = analysis_sw.elapsed(); | ||
139 | eprintln!("{:<20} {}", "Total:", total_span); | ||
140 | report_metric("total time", total_span.time.as_millis() as u64, "ms"); | ||
141 | if let Some(instructions) = total_span.instructions { | ||
142 | report_metric("total instructions", instructions, "#instr"); | ||
143 | } | ||
144 | if let Some(memory) = total_span.memory { | ||
145 | report_metric("total memory", memory.allocated.megabytes() as u64, "MB"); | ||
146 | } | ||
147 | |||
148 | if env::var("RA_COUNT").is_ok() { | ||
149 | eprintln!("{}", profile::countme::get_all()); | ||
150 | } | ||
151 | |||
152 | if self.memory_usage && verbosity.is_verbose() { | ||
153 | print_memory_usage(host, vfs); | ||
154 | } | ||
155 | |||
156 | Ok(()) | ||
157 | } | ||
158 | |||
159 | fn run_inference( | ||
160 | &self, | ||
161 | host: &AnalysisHost, | ||
162 | db: &RootDatabase, | ||
163 | vfs: &Vfs, | ||
164 | funcs: &[Function], | ||
165 | verbosity: Verbosity, | ||
166 | ) { | ||
131 | let mut bar = match verbosity { | 167 | let mut bar = match verbosity { |
132 | Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(), | 168 | Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(), |
133 | _ if self.parallel => ProgressReport::hidden(), | 169 | _ if self.parallel => ProgressReport::hidden(), |
@@ -154,7 +190,7 @@ impl AnalysisStatsCmd { | |||
154 | let mut num_exprs_unknown = 0; | 190 | let mut num_exprs_unknown = 0; |
155 | let mut num_exprs_partially_unknown = 0; | 191 | let mut num_exprs_partially_unknown = 0; |
156 | let mut num_type_mismatches = 0; | 192 | let mut num_type_mismatches = 0; |
157 | for f in funcs { | 193 | for f in funcs.iter().copied() { |
158 | let name = f.name(db); | 194 | let name = f.name(db); |
159 | let full_name = f | 195 | let full_name = f |
160 | .module(db) | 196 | .module(db) |
@@ -296,26 +332,6 @@ impl AnalysisStatsCmd { | |||
296 | report_metric("type mismatches", num_type_mismatches, "#"); | 332 | report_metric("type mismatches", num_type_mismatches, "#"); |
297 | 333 | ||
298 | eprintln!("{:<20} {}", "Inference:", inference_sw.elapsed()); | 334 | eprintln!("{:<20} {}", "Inference:", inference_sw.elapsed()); |
299 | |||
300 | let total_span = analysis_sw.elapsed(); | ||
301 | eprintln!("{:<20} {}", "Total:", total_span); | ||
302 | report_metric("total time", total_span.time.as_millis() as u64, "ms"); | ||
303 | if let Some(instructions) = total_span.instructions { | ||
304 | report_metric("total instructions", instructions, "#instr"); | ||
305 | } | ||
306 | if let Some(memory) = total_span.memory { | ||
307 | report_metric("total memory", memory.allocated.megabytes() as u64, "MB"); | ||
308 | } | ||
309 | |||
310 | if env::var("RA_COUNT").is_ok() { | ||
311 | eprintln!("{}", profile::countme::get_all()); | ||
312 | } | ||
313 | |||
314 | if self.memory_usage && verbosity.is_verbose() { | ||
315 | print_memory_usage(host, vfs); | ||
316 | } | ||
317 | |||
318 | Ok(()) | ||
319 | } | 335 | } |
320 | 336 | ||
321 | fn stop_watch(&self) -> StopWatch { | 337 | fn stop_watch(&self) -> StopWatch { |