Skip to content

Commit dc5e270

Browse files
committed
Catch panics in inference in analysis-stats
1 parent 0843d06 commit dc5e270

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::{
55
env, fmt,
66
ops::AddAssign,
7+
panic::{catch_unwind, AssertUnwindSafe},
78
time::{SystemTime, UNIX_EPOCH},
89
};
910

@@ -721,6 +722,7 @@ impl flags::AnalysisStats {
721722
let mut num_pats_unknown = 0;
722723
let mut num_pats_partially_unknown = 0;
723724
let mut num_pat_type_mismatches = 0;
725+
let mut panics = 0;
724726
for &body_id in bodies {
725727
let name = body_id.name(db).unwrap_or_else(Name::missing);
726728
let module = body_id.module(db);
@@ -774,7 +776,20 @@ impl flags::AnalysisStats {
774776
}
775777
bar.set_message(msg);
776778
let body = db.body(body_id.into());
777-
let inference_result = db.infer(body_id.into());
779+
let inference_result = catch_unwind(AssertUnwindSafe(|| db.infer(body_id.into())));
780+
let inference_result = match inference_result {
781+
Ok(inference_result) => inference_result,
782+
Err(p) => {
783+
if let Some(s) = p.downcast_ref::<&str>() {
784+
eprintln!("infer panicked: {}", s);
785+
} else if let Some(s) = p.downcast_ref::<String>() {
786+
eprintln!("infer panicked: {}", s);
787+
}
788+
panics += 1;
789+
bar.inc(1);
790+
continue;
791+
}
792+
};
778793
// This query is LRU'd, so actually calling it will skew the timing results.
779794
let sm = || db.body_with_source_map(body_id.into()).1;
780795

@@ -1008,6 +1023,7 @@ impl flags::AnalysisStats {
10081023
percentage(num_pats_partially_unknown, num_pats),
10091024
num_pat_type_mismatches
10101025
);
1026+
eprintln!(" panics: {}", panics);
10111027
eprintln!("{:<20} {}", "Inference:", inference_time);
10121028
report_metric("unknown type", num_exprs_unknown, "#");
10131029
report_metric("type mismatches", num_expr_type_mismatches, "#");

0 commit comments

Comments
 (0)