- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Allow changing the bug report url for the ice hook #85640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -1151,23 +1151,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!(); | ||
|  | ||
| 
      Comment on lines
    
      -1165
     to 
      -1170
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did this need to be taken out? I guess maybe so the right  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 | ||
| let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr( | ||
| rustc_errors::ColorConfig::Auto, | ||
| None, | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes
report_iceuseless for the situations without enough control over the driver to bypass theSyncLazy::force(&DEFAULT_HOOK);. Maybe there should be areport_ice_including_default_panic_hookfunction that provides the old behavior?Though ideally the new behavior should probably use a new function name (or better, both should change names, so use sites have to pick).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set a panic hook more than once, so you can first get the default hook, then let whatever code forces
DEFAULT_HOOKrun and then set the new panic hook.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
report_ice_including_default_panic_hookfunction requires theDEFAULT_HOOKto be forced first to be able to call it without ending in an infinite loop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codegen backend is loaded after
DEFAULT_HOOKis initially forced, so it's impossible to make it work without changes torustc_driver. I'll hopefully take a look at it soon and try to come up with a better overall solution. It should be possible to e.g. capture more data into the boxed closure, and the use of astaticis somewhat incidental.Though the most direct solution is to offer a
staticthat contains the report URL (and maybe additional e.g. footer), and which can be changed independently of the panic hook.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could have something like https://github.com/bjorn3/rustc_codegen_cranelift/blob/d498e6d6971575714353f11aa4d3e63a9d2030b2/src/bin/cg_clif.rs#L20-L34 except that you call
panic::take_hook()twice and use the result of the second time as default hook. The first time you take the hook set by rustc_driver and ignore it. The second time you take the default libstd hook.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this behavior documented for
std::panic::take_hookwas what I missed, thanks!