Skip to content

Commit

Permalink
Auto merge of #85640 - bjorn3:custom_ice_hook, r=jackh726
Browse files Browse the repository at this point in the history
Allow changing the bug report url for the ice hook

cc https://github.com/bjorn3/rustc_codegen_cranelift/issues/1174
  • Loading branch information
bors committed Jun 25, 2021
2 parents 079aa83 + 0bc60c0 commit 50a9081
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
25 changes: 23 additions & 2 deletions compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
#![feature(rustc_private)]
#![feature(rustc_private, once_cell)]

extern crate rustc_data_structures;
extern crate rustc_driver;
extern crate rustc_interface;
extern crate rustc_session;
extern crate rustc_target;

use std::panic;
use std::lazy::SyncLazy;

use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
use rustc_interface::interface;
use rustc_session::config::ErrorOutputType;
use rustc_session::early_error;
use rustc_target::spec::PanicStrategy;

const BUG_REPORT_URL: &str = "https://github.com/bjorn3/rustc_codegen_cranelift/issues/new";

static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
SyncLazy::new(|| {
let hook = panic::take_hook();
panic::set_hook(Box::new(|info| {
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
(*DEFAULT_HOOK)(info);

// Separate the output with an empty line
eprintln!();

// Print the ICE message
rustc_driver::report_ice(info, BUG_REPORT_URL);
}));
hook
});

#[derive(Default)]
pub struct CraneliftPassesCallbacks {
time_passes: bool,
Expand All @@ -37,7 +58,7 @@ fn main() {
let start_rss = get_resident_set_size();
rustc_driver::init_rustc_env_logger();
let mut callbacks = CraneliftPassesCallbacks::default();
rustc_driver::install_ice_hook();
SyncLazy::force(&DEFAULT_HOOK); // Install ice hook
let exit_code = rustc_driver::catch_with_exit_code(|| {
let args = std::env::args_os()
.enumerate()
Expand Down
19 changes: 11 additions & 8 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1167,23 +1167,26 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
SyncLazy::new(|| {
let hook = panic::take_hook();
panic::set_hook(Box::new(|info| report_ice(info, BUG_REPORT_URL)));
panic::set_hook(Box::new(|info| {
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
(*DEFAULT_HOOK)(info);

// Separate the output with an empty line
eprintln!();

// Print the ICE message
report_ice(info, BUG_REPORT_URL);
}));
hook
});

/// Prints the ICE message, including backtrace and query stack.
/// Prints the ICE message, including query stack, but without backtrace.
///
/// The message will point the user at `bug_report_url` to report the ICE.
///
/// When `install_ice_hook` is called, this function will be called as the panic
/// hook.
pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
(*DEFAULT_HOOK)(info);

// Separate the output with an empty line
eprintln!();

let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
rustc_errors::ColorConfig::Auto,
None,
Expand Down

0 comments on commit 50a9081

Please sign in to comment.