Skip to content

Commit 37048a0

Browse files
authored
Merge pull request rust-lang#20560 from ChayimFriedman2/analysis-stats-improve
fix: Add progress bars to more places in analysis-stats
2 parents 85d383f + 0a55022 commit 37048a0

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

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

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl flags::AnalysisStats {
333333
}
334334

335335
if self.run_all_ide_things {
336-
self.run_ide_things(host.analysis(), file_ids.clone());
336+
self.run_ide_things(host.analysis(), file_ids.clone(), db, &vfs, verbosity);
337337
}
338338

339339
if self.run_term_search {
@@ -393,26 +393,39 @@ impl flags::AnalysisStats {
393393
}
394394

395395
fn run_const_eval(&self, db: &RootDatabase, bodies: &[DefWithBody], verbosity: Verbosity) {
396+
let len = bodies
397+
.iter()
398+
.filter(|body| matches!(body, DefWithBody::Const(_) | DefWithBody::Static(_)))
399+
.count();
400+
let mut bar = match verbosity {
401+
Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(),
402+
_ if self.parallel || self.output.is_some() => ProgressReport::hidden(),
403+
_ => ProgressReport::new(len),
404+
};
405+
396406
let mut sw = self.stop_watch();
397407
let mut all = 0;
398408
let mut fail = 0;
399409
for &b in bodies {
410+
bar.set_message(move || format!("const eval: {}", full_name(db, b, b.module(db))));
400411
let res = match b {
401412
DefWithBody::Const(c) => c.eval(db),
402413
DefWithBody::Static(s) => s.eval(db),
403414
_ => continue,
404415
};
416+
bar.inc(1);
405417
all += 1;
406418
let Err(error) = res else {
407419
continue;
408420
};
409421
if verbosity.is_spammy() {
410422
let full_name =
411423
full_name_of_item(db, b.module(db), b.name(db).unwrap_or(Name::missing()));
412-
println!("Const eval for {full_name} failed due {error:?}");
424+
bar.println(format!("Const eval for {full_name} failed due {error:?}"));
413425
}
414426
fail += 1;
415427
}
428+
bar.finish_and_clear();
416429
let const_eval_time = sw.elapsed();
417430
eprintln!("{:<20} {}", "Const evaluation:", const_eval_time);
418431
eprintln!("Failed const evals: {fail} ({}%)", percentage(fail, all));
@@ -662,6 +675,10 @@ impl flags::AnalysisStats {
662675
let mut all = 0;
663676
let mut fail = 0;
664677
for &body_id in bodies {
678+
bar.set_message(move || {
679+
format!("mir lowering: {}", full_name(db, body_id, body_id.module(db)))
680+
});
681+
bar.inc(1);
665682
if matches!(body_id, DefWithBody::Variant(_)) {
666683
continue;
667684
}
@@ -1089,12 +1106,29 @@ impl flags::AnalysisStats {
10891106
report_metric("body lowering time", body_lowering_time.time.as_millis() as u64, "ms");
10901107
}
10911108

1092-
fn run_ide_things(&self, analysis: Analysis, mut file_ids: Vec<EditionedFileId>) {
1109+
fn run_ide_things(
1110+
&self,
1111+
analysis: Analysis,
1112+
mut file_ids: Vec<EditionedFileId>,
1113+
db: &RootDatabase,
1114+
vfs: &Vfs,
1115+
verbosity: Verbosity,
1116+
) {
1117+
let len = file_ids.len();
1118+
let create_bar = || match verbosity {
1119+
Verbosity::Quiet | Verbosity::Spammy => ProgressReport::hidden(),
1120+
_ if self.parallel || self.output.is_some() => ProgressReport::hidden(),
1121+
_ => ProgressReport::new(len),
1122+
};
1123+
10931124
file_ids.sort();
10941125
file_ids.dedup();
10951126
let mut sw = self.stop_watch();
10961127

1128+
let mut bar = create_bar();
10971129
for &file_id in &file_ids {
1130+
let msg = format!("diagnostics: {}", vfs.file_path(file_id.file_id(db)));
1131+
bar.set_message(move || msg.clone());
10981132
_ = analysis.full_diagnostics(
10991133
&DiagnosticsConfig {
11001134
enabled: true,
@@ -1121,8 +1155,14 @@ impl flags::AnalysisStats {
11211155
ide::AssistResolveStrategy::All,
11221156
analysis.editioned_file_id_to_vfs(file_id),
11231157
);
1158+
bar.inc(1);
11241159
}
1160+
bar.finish_and_clear();
1161+
1162+
let mut bar = create_bar();
11251163
for &file_id in &file_ids {
1164+
let msg = format!("inlay hints: {}", vfs.file_path(file_id.file_id(db)));
1165+
bar.set_message(move || msg.clone());
11261166
_ = analysis.inlay_hints(
11271167
&InlayHintsConfig {
11281168
render_colons: false,
@@ -1158,8 +1198,14 @@ impl flags::AnalysisStats {
11581198
analysis.editioned_file_id_to_vfs(file_id),
11591199
None,
11601200
);
1201+
bar.inc(1);
11611202
}
1203+
bar.finish_and_clear();
1204+
1205+
let mut bar = create_bar();
11621206
for &file_id in &file_ids {
1207+
let msg = format!("annotations: {}", vfs.file_path(file_id.file_id(db)));
1208+
bar.set_message(move || msg.clone());
11631209
analysis
11641210
.annotations(
11651211
&AnnotationConfig {
@@ -1178,7 +1224,10 @@ impl flags::AnalysisStats {
11781224
.for_each(|annotation| {
11791225
_ = analysis.resolve_annotation(annotation);
11801226
});
1227+
bar.inc(1);
11811228
}
1229+
bar.finish_and_clear();
1230+
11821231
let ide_time = sw.elapsed();
11831232
eprintln!("{:<20} {} ({} files)", "IDE:", ide_time, file_ids.len());
11841233
}

0 commit comments

Comments
 (0)