Skip to content

Commit 786c4da

Browse files
committed
catch callback unwinding to finalize in-flight self-profiling events from queries
fatal errors currently abort the compiler process without allocating the self-profile strings: query events aren't always correctly recorded, and will show up as <unknown> in the data. catching the unwinding panic allows us to finalize the self-profiling process correctly before continuing unwinding as before.
1 parent c935696 commit 786c4da

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

compiler/rustc_interface/src/passes.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,25 @@ pub fn create_and_enter_global_ctxt<T, F: for<'tcx> FnOnce(TyCtxt<'tcx>) -> T>(
10161016
feed.crate_for_resolver(tcx.arena.alloc(Steal::new((krate, pre_configured_attrs))));
10171017
feed.output_filenames(Arc::new(outputs));
10181018

1019-
let res = f(tcx);
1020-
// FIXME maybe run finish even when a fatal error occurred? or at least
1021-
// tcx.alloc_self_profile_query_strings()?
1019+
// There are two paths out of `f`.
1020+
// - Normal exit.
1021+
// - Panic, e.g. triggered by `abort_if_errors` or a fatal error.
1022+
//
1023+
// If a panic occurs, we still need to wind down the self-profiler to correctly record
1024+
// the query events that are still in flight. Otherwise, they will be invalid, and shown
1025+
// as "<unknown>" in the profiling data.
1026+
let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f(tcx)));
1027+
let res = match res {
1028+
Ok(res) => res,
1029+
Err(err) => {
1030+
tcx.alloc_self_profile_query_strings();
1031+
1032+
// Resume unwinding if a panic happened.
1033+
std::panic::resume_unwind(err);
1034+
}
1035+
};
1036+
1037+
// FIXME maybe run finish even when a fatal error occurred?
10221038
tcx.finish();
10231039
res
10241040
},

0 commit comments

Comments
 (0)