|
4 | 4 | use std::{
|
5 | 5 | env, fmt,
|
6 | 6 | ops::AddAssign,
|
| 7 | + panic::{catch_unwind, AssertUnwindSafe}, |
7 | 8 | time::{SystemTime, UNIX_EPOCH},
|
8 | 9 | };
|
9 | 10 |
|
@@ -721,6 +722,7 @@ impl flags::AnalysisStats {
|
721 | 722 | let mut num_pats_unknown = 0;
|
722 | 723 | let mut num_pats_partially_unknown = 0;
|
723 | 724 | let mut num_pat_type_mismatches = 0;
|
| 725 | + let mut panics = 0; |
724 | 726 | for &body_id in bodies {
|
725 | 727 | let name = body_id.name(db).unwrap_or_else(Name::missing);
|
726 | 728 | let module = body_id.module(db);
|
@@ -774,7 +776,20 @@ impl flags::AnalysisStats {
|
774 | 776 | }
|
775 | 777 | bar.set_message(msg);
|
776 | 778 | 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 | + }; |
778 | 793 | // This query is LRU'd, so actually calling it will skew the timing results.
|
779 | 794 | let sm = || db.body_with_source_map(body_id.into()).1;
|
780 | 795 |
|
@@ -1008,6 +1023,7 @@ impl flags::AnalysisStats {
|
1008 | 1023 | percentage(num_pats_partially_unknown, num_pats),
|
1009 | 1024 | num_pat_type_mismatches
|
1010 | 1025 | );
|
| 1026 | + eprintln!(" panics: {}", panics); |
1011 | 1027 | eprintln!("{:<20} {}", "Inference:", inference_time);
|
1012 | 1028 | report_metric("unknown type", num_exprs_unknown, "#");
|
1013 | 1029 | report_metric("type mismatches", num_expr_type_mismatches, "#");
|
|
0 commit comments