aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/Cargo.toml1
-rw-r--r--crates/rust-analyzer/src/bin/args.rs13
-rw-r--r--crates/rust-analyzer/src/bin/main.rs2
-rw-r--r--crates/rust-analyzer/src/cli/analysis_stats.rs31
4 files changed, 42 insertions, 5 deletions
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml
index 803755106..837b6714d 100644
--- a/crates/rust-analyzer/Cargo.toml
+++ b/crates/rust-analyzer/Cargo.toml
@@ -28,6 +28,7 @@ rustc-hash = "1.1.0"
28serde = { version = "1.0.106", features = ["derive"] } 28serde = { version = "1.0.106", features = ["derive"] }
29serde_json = "1.0.48" 29serde_json = "1.0.48"
30threadpool = "1.7.1" 30threadpool = "1.7.1"
31rayon = "1.3.1"
31 32
32stdx = { path = "../stdx" } 33stdx = { path = "../stdx" }
33 34
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs
index cf1108e12..8a0b10117 100644
--- a/crates/rust-analyzer/src/bin/args.rs
+++ b/crates/rust-analyzer/src/bin/args.rs
@@ -25,6 +25,7 @@ pub(crate) enum Command {
25 }, 25 },
26 Stats { 26 Stats {
27 randomize: bool, 27 randomize: bool,
28 parallel: bool,
28 memory_usage: bool, 29 memory_usage: bool,
29 only: Option<String>, 30 only: Option<String>,
30 with_deps: bool, 31 with_deps: bool,
@@ -157,10 +158,14 @@ USAGE:
157 rust-analyzer analysis-stats [FLAGS] [OPTIONS] [PATH] 158 rust-analyzer analysis-stats [FLAGS] [OPTIONS] [PATH]
158 159
159FLAGS: 160FLAGS:
161 -o, --only Only analyze items matching this path
160 -h, --help Prints help information 162 -h, --help Prints help information
161 --memory-usage 163 --memory-usage Collect memory usage statistics (requires `--feature jemalloc`)
164 --randomize Randomize order in which crates, modules, and items are processed
165 --parallel Run type inference in parallel
162 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis 166 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
163 --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding 167 --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
168 --with-deps Also analyze all dependencies
164 -v, --verbose 169 -v, --verbose
165 -q, --quiet 170 -q, --quiet
166 171
@@ -174,6 +179,7 @@ ARGS:
174 } 179 }
175 180
176 let randomize = matches.contains("--randomize"); 181 let randomize = matches.contains("--randomize");
182 let parallel = matches.contains("--parallel");
177 let memory_usage = matches.contains("--memory-usage"); 183 let memory_usage = matches.contains("--memory-usage");
178 let only: Option<String> = matches.opt_value_from_str(["-o", "--only"])?; 184 let only: Option<String> = matches.opt_value_from_str(["-o", "--only"])?;
179 let with_deps: bool = matches.contains("--with-deps"); 185 let with_deps: bool = matches.contains("--with-deps");
@@ -189,6 +195,7 @@ ARGS:
189 195
190 Command::Stats { 196 Command::Stats {
191 randomize, 197 randomize,
198 parallel,
192 memory_usage, 199 memory_usage,
193 only, 200 only,
194 with_deps, 201 with_deps,
@@ -209,7 +216,7 @@ USAGE:
209FLAGS: 216FLAGS:
210 -h, --help Prints help information 217 -h, --help Prints help information
211 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis 218 --load-output-dirs Load OUT_DIR values by running `cargo check` before analysis
212 --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding 219 --with-proc-macro Use ra-proc-macro-srv for proc-macro expanding
213 -v, --verbose 220 -v, --verbose
214 221
215OPTIONS: 222OPTIONS:
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index 16882fc13..0f55c3ee2 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -32,6 +32,7 @@ fn main() -> Result<()> {
32 args::Command::Highlight { rainbow } => cli::highlight(rainbow)?, 32 args::Command::Highlight { rainbow } => cli::highlight(rainbow)?,
33 args::Command::Stats { 33 args::Command::Stats {
34 randomize, 34 randomize,
35 parallel,
35 memory_usage, 36 memory_usage,
36 only, 37 only,
37 with_deps, 38 with_deps,
@@ -45,6 +46,7 @@ fn main() -> Result<()> {
45 only.as_ref().map(String::as_ref), 46 only.as_ref().map(String::as_ref),
46 with_deps, 47 with_deps,
47 randomize, 48 randomize,
49 parallel,
48 load_output_dirs, 50 load_output_dirs,
49 with_proc_macro, 51 with_proc_macro,
50 )?, 52 )?,
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs
index 9d09501cd..14982919d 100644
--- a/crates/rust-analyzer/src/cli/analysis_stats.rs
+++ b/crates/rust-analyzer/src/cli/analysis_stats.rs
@@ -5,6 +5,7 @@ use std::{path::Path, time::Instant};
5 5
6use itertools::Itertools; 6use itertools::Itertools;
7use rand::{seq::SliceRandom, thread_rng}; 7use rand::{seq::SliceRandom, thread_rng};
8use rayon::prelude::*;
8use rustc_hash::FxHashSet; 9use rustc_hash::FxHashSet;
9 10
10use hir::{ 11use hir::{
@@ -13,12 +14,23 @@ use hir::{
13}; 14};
14use hir_def::FunctionId; 15use hir_def::FunctionId;
15use hir_ty::{Ty, TypeWalk}; 16use hir_ty::{Ty, TypeWalk};
16use ra_db::SourceDatabaseExt; 17use ra_db::{
18 salsa::{self, ParallelDatabase},
19 SourceDatabaseExt,
20};
17use ra_syntax::AstNode; 21use ra_syntax::AstNode;
18use stdx::format_to; 22use stdx::format_to;
19 23
20use crate::cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity}; 24use crate::cli::{load_cargo::load_cargo, progress_report::ProgressReport, Result, Verbosity};
21 25
26/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
27struct Snap<DB>(DB);
28impl<DB: ParallelDatabase> Clone for Snap<salsa::Snapshot<DB>> {
29 fn clone(&self) -> Snap<salsa::Snapshot<DB>> {
30 Snap(self.0.snapshot())
31 }
32}
33
22pub fn analysis_stats( 34pub fn analysis_stats(
23 verbosity: Verbosity, 35 verbosity: Verbosity,
24 memory_usage: bool, 36 memory_usage: bool,
@@ -26,6 +38,7 @@ pub fn analysis_stats(
26 only: Option<&str>, 38 only: Option<&str>,
27 with_deps: bool, 39 with_deps: bool,
28 randomize: bool, 40 randomize: bool,
41 parallel: bool,
29 load_output_dirs: bool, 42 load_output_dirs: bool,
30 with_proc_macro: bool, 43 with_proc_macro: bool,
31) -> Result<()> { 44) -> Result<()> {
@@ -91,12 +104,26 @@ pub fn analysis_stats(
91 funcs.shuffle(&mut thread_rng()); 104 funcs.shuffle(&mut thread_rng());
92 } 105 }
93 106
94 let inference_time = Instant::now();
95 let mut bar = match verbosity { 107 let mut bar = match verbosity {
96 Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(), 108 Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(),
97 _ => ProgressReport::new(funcs.len() as u64), 109 _ => ProgressReport::new(funcs.len() as u64),
98 }; 110 };
99 111
112 if parallel {
113 let inference_time = Instant::now();
114 let snap = Snap(db.snapshot());
115 funcs
116 .par_iter()
117 .map_with(snap, |snap, &f| {
118 let f_id = FunctionId::from(f);
119 snap.0.body(f_id.into());
120 snap.0.infer(f_id.into());
121 })
122 .count();
123 println!("Parallel Inference: {:?}, {}", inference_time.elapsed(), ra_prof::memory_usage());
124 }
125
126 let inference_time = Instant::now();
100 bar.tick(); 127 bar.tick();
101 let mut num_exprs = 0; 128 let mut num_exprs = 0;
102 let mut num_exprs_unknown = 0; 129 let mut num_exprs_unknown = 0;