Skip to content

Commit 19e09a4

Browse files
Merge #8333
8333: analysis-stats: allow skipping type inference r=jonas-schievink a=jonas-schievink This removes "noise" from memory profiles since it avoids lowering function bodies and types bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents 4be4d29 + ab49f76 commit 19e09a4

File tree

3 files changed

+42
-22
lines changed

3 files changed

+42
-22
lines changed

crates/rust-analyzer/src/bin/flags.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ xflags::xflags! {
7171
optional --load-output-dirs
7272
/// Use proc-macro-srv for proc-macro expanding.
7373
optional --with-proc-macro
74+
/// Only resolve names, don't run type inference.
75+
optional --skip-inference
7476
}
7577

7678
cmd diagnostics
@@ -158,6 +160,7 @@ pub struct AnalysisStats {
158160
pub no_sysroot: bool,
159161
pub load_output_dirs: bool,
160162
pub with_proc_macro: bool,
163+
pub skip_inference: bool,
161164
}
162165

163166
#[derive(Debug)]

crates/rust-analyzer/src/bin/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ fn try_main() -> Result<()> {
7878
path: cmd.path,
7979
load_output_dirs: cmd.load_output_dirs,
8080
with_proc_macro: cmd.with_proc_macro,
81+
skip_inference: cmd.skip_inference,
8182
}
8283
.run(verbosity)?,
8384

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ use std::{
99

1010
use hir::{
1111
db::{AstDatabase, DefDatabase, HirDatabase},
12-
AssocItem, Crate, HasSource, HirDisplay, ModuleDef,
12+
AssocItem, Crate, Function, HasSource, HirDisplay, ModuleDef,
1313
};
1414
use hir_def::FunctionId;
1515
use hir_ty::TypeWalk;
16+
use ide::{AnalysisHost, RootDatabase};
1617
use ide_db::base_db::{
1718
salsa::{self, ParallelDatabase},
1819
SourceDatabaseExt,
@@ -24,6 +25,7 @@ use rayon::prelude::*;
2425
use rustc_hash::FxHashSet;
2526
use stdx::format_to;
2627
use syntax::AstNode;
28+
use vfs::Vfs;
2729

2830
use crate::cli::{
2931
load_cargo::{load_workspace_at, LoadCargoConfig},
@@ -51,6 +53,7 @@ pub struct AnalysisStatsCmd {
5153
pub path: PathBuf,
5254
pub load_output_dirs: bool,
5355
pub with_proc_macro: bool,
56+
pub skip_inference: bool,
5457
}
5558

5659
impl AnalysisStatsCmd {
@@ -128,6 +131,39 @@ impl AnalysisStatsCmd {
128131
shuffle(&mut rng, &mut funcs);
129132
}
130133

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+
) {
131167
let mut bar = match verbosity {
132168
Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(),
133169
_ if self.parallel => ProgressReport::hidden(),
@@ -154,7 +190,7 @@ impl AnalysisStatsCmd {
154190
let mut num_exprs_unknown = 0;
155191
let mut num_exprs_partially_unknown = 0;
156192
let mut num_type_mismatches = 0;
157-
for f in funcs {
193+
for f in funcs.iter().copied() {
158194
let name = f.name(db);
159195
let full_name = f
160196
.module(db)
@@ -296,26 +332,6 @@ impl AnalysisStatsCmd {
296332
report_metric("type mismatches", num_type_mismatches, "#");
297333

298334
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(())
319335
}
320336

321337
fn stop_watch(&self) -> StopWatch {

0 commit comments

Comments
 (0)