Skip to content

Commit 6e4e088

Browse files
authored
Merge pull request #20278 from lnicola/analysis-stats-mir-lowering-only
internal: Support filtering in analysis-stats MIR lowering
2 parents bdfc770 + c9b0776 commit 6e4e088

File tree

1 file changed

+66
-62
lines changed

1 file changed

+66
-62
lines changed

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

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -656,22 +656,26 @@ impl flags::AnalysisStats {
656656
let mut sw = self.stop_watch();
657657
let mut all = 0;
658658
let mut fail = 0;
659-
for &body in bodies {
660-
if matches!(body, DefWithBody::Variant(_)) {
659+
for &body_id in bodies {
660+
if matches!(body_id, DefWithBody::Variant(_)) {
661+
continue;
662+
}
663+
let module = body_id.module(db);
664+
if !self.should_process(db, body_id, module) {
661665
continue;
662666
}
667+
663668
all += 1;
664-
let Err(e) = db.mir_body(body.into()) else {
669+
let Err(e) = db.mir_body(body_id.into()) else {
665670
continue;
666671
};
667672
if verbosity.is_spammy() {
668-
let full_name = body
669-
.module(db)
673+
let full_name = module
670674
.path_to_root(db)
671675
.into_iter()
672676
.rev()
673677
.filter_map(|it| it.name(db))
674-
.chain(Some(body.name(db).unwrap_or_else(Name::missing)))
678+
.chain(Some(body_id.name(db).unwrap_or_else(Name::missing)))
675679
.map(|it| it.display(db, Edition::LATEST).to_string())
676680
.join("::");
677681
bar.println(format!("Mir body for {full_name} failed due {e:?}"));
@@ -727,26 +731,9 @@ impl flags::AnalysisStats {
727731
let name = body_id.name(db).unwrap_or_else(Name::missing);
728732
let module = body_id.module(db);
729733
let display_target = module.krate().to_display_target(db);
730-
let full_name = move || {
731-
module
732-
.krate()
733-
.display_name(db)
734-
.map(|it| it.canonical_name().as_str().to_owned())
735-
.into_iter()
736-
.chain(
737-
module
738-
.path_to_root(db)
739-
.into_iter()
740-
.filter_map(|it| it.name(db))
741-
.rev()
742-
.chain(Some(body_id.name(db).unwrap_or_else(Name::missing)))
743-
.map(|it| it.display(db, Edition::LATEST).to_string()),
744-
)
745-
.join("::")
746-
};
747734
if let Some(only_name) = self.only.as_deref() {
748735
if name.display(db, Edition::LATEST).to_string() != only_name
749-
&& full_name() != only_name
736+
&& full_name(db, body_id, module) != only_name
750737
{
751738
continue;
752739
}
@@ -763,12 +750,17 @@ impl flags::AnalysisStats {
763750
let original_file = src.file_id.original_file(db);
764751
let path = vfs.file_path(original_file.file_id(db));
765752
let syntax_range = src.text_range();
766-
format!("processing: {} ({} {:?})", full_name(), path, syntax_range)
753+
format!(
754+
"processing: {} ({} {:?})",
755+
full_name(db, body_id, module),
756+
path,
757+
syntax_range
758+
)
767759
} else {
768-
format!("processing: {}", full_name())
760+
format!("processing: {}", full_name(db, body_id, module))
769761
}
770762
} else {
771-
format!("processing: {}", full_name())
763+
format!("processing: {}", full_name(db, body_id, module))
772764
}
773765
};
774766
if verbosity.is_spammy() {
@@ -781,9 +773,11 @@ impl flags::AnalysisStats {
781773
Ok(inference_result) => inference_result,
782774
Err(p) => {
783775
if let Some(s) = p.downcast_ref::<&str>() {
784-
eprintln!("infer panicked for {}: {}", full_name(), s);
776+
eprintln!("infer panicked for {}: {}", full_name(db, body_id, module), s);
785777
} else if let Some(s) = p.downcast_ref::<String>() {
786-
eprintln!("infer panicked for {}: {}", full_name(), s);
778+
eprintln!("infer panicked for {}: {}", full_name(db, body_id, module), s);
779+
} else {
780+
eprintln!("infer panicked for {}", full_name(db, body_id, module));
787781
}
788782
panics += 1;
789783
bar.inc(1);
@@ -890,7 +884,7 @@ impl flags::AnalysisStats {
890884
if verbosity.is_spammy() {
891885
bar.println(format!(
892886
"In {}: {} exprs, {} unknown, {} partial",
893-
full_name(),
887+
full_name(db, body_id, module),
894888
num_exprs - previous_exprs,
895889
num_exprs_unknown - previous_unknown,
896890
num_exprs_partially_unknown - previous_partially_unknown
@@ -993,7 +987,7 @@ impl flags::AnalysisStats {
993987
if verbosity.is_spammy() {
994988
bar.println(format!(
995989
"In {}: {} pats, {} unknown, {} partial",
996-
full_name(),
990+
full_name(db, body_id, module),
997991
num_pats - previous_pats,
998992
num_pats_unknown - previous_unknown,
999993
num_pats_partially_unknown - previous_partially_unknown
@@ -1049,34 +1043,8 @@ impl flags::AnalysisStats {
10491043
bar.tick();
10501044
for &body_id in bodies {
10511045
let module = body_id.module(db);
1052-
let full_name = move || {
1053-
module
1054-
.krate()
1055-
.display_name(db)
1056-
.map(|it| it.canonical_name().as_str().to_owned())
1057-
.into_iter()
1058-
.chain(
1059-
module
1060-
.path_to_root(db)
1061-
.into_iter()
1062-
.filter_map(|it| it.name(db))
1063-
.rev()
1064-
.chain(Some(body_id.name(db).unwrap_or_else(Name::missing)))
1065-
.map(|it| it.display(db, Edition::LATEST).to_string()),
1066-
)
1067-
.join("::")
1068-
};
1069-
if let Some(only_name) = self.only.as_deref() {
1070-
if body_id
1071-
.name(db)
1072-
.unwrap_or_else(Name::missing)
1073-
.display(db, Edition::LATEST)
1074-
.to_string()
1075-
!= only_name
1076-
&& full_name() != only_name
1077-
{
1078-
continue;
1079-
}
1046+
if !self.should_process(db, body_id, module) {
1047+
continue;
10801048
}
10811049
let msg = move || {
10821050
if verbosity.is_verbose() {
@@ -1090,12 +1058,17 @@ impl flags::AnalysisStats {
10901058
let original_file = src.file_id.original_file(db);
10911059
let path = vfs.file_path(original_file.file_id(db));
10921060
let syntax_range = src.text_range();
1093-
format!("processing: {} ({} {:?})", full_name(), path, syntax_range)
1061+
format!(
1062+
"processing: {} ({} {:?})",
1063+
full_name(db, body_id, module),
1064+
path,
1065+
syntax_range
1066+
)
10941067
} else {
1095-
format!("processing: {}", full_name())
1068+
format!("processing: {}", full_name(db, body_id, module))
10961069
}
10971070
} else {
1098-
format!("processing: {}", full_name())
1071+
format!("processing: {}", full_name(db, body_id, module))
10991072
}
11001073
};
11011074
if verbosity.is_spammy() {
@@ -1205,11 +1178,42 @@ impl flags::AnalysisStats {
12051178
eprintln!("{:<20} {} ({} files)", "IDE:", ide_time, file_ids.len());
12061179
}
12071180

1181+
fn should_process(&self, db: &RootDatabase, body_id: DefWithBody, module: hir::Module) -> bool {
1182+
if let Some(only_name) = self.only.as_deref() {
1183+
let name = body_id.name(db).unwrap_or_else(Name::missing);
1184+
1185+
if name.display(db, Edition::LATEST).to_string() != only_name
1186+
&& full_name(db, body_id, module) != only_name
1187+
{
1188+
return false;
1189+
}
1190+
}
1191+
true
1192+
}
1193+
12081194
fn stop_watch(&self) -> StopWatch {
12091195
StopWatch::start()
12101196
}
12111197
}
12121198

1199+
fn full_name(db: &RootDatabase, body_id: DefWithBody, module: hir::Module) -> String {
1200+
module
1201+
.krate()
1202+
.display_name(db)
1203+
.map(|it| it.canonical_name().as_str().to_owned())
1204+
.into_iter()
1205+
.chain(
1206+
module
1207+
.path_to_root(db)
1208+
.into_iter()
1209+
.filter_map(|it| it.name(db))
1210+
.rev()
1211+
.chain(Some(body_id.name(db).unwrap_or_else(Name::missing)))
1212+
.map(|it| it.display(db, Edition::LATEST).to_string()),
1213+
)
1214+
.join("::")
1215+
}
1216+
12131217
fn location_csv_expr(db: &RootDatabase, vfs: &Vfs, sm: &BodySourceMap, expr_id: ExprId) -> String {
12141218
let src = match sm.expr_syntax(expr_id) {
12151219
Ok(s) => s,

0 commit comments

Comments
 (0)