Skip to content

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

Merged
merged 2 commits into from
Jun 25, 2021

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented May 24, 2021

@bjorn3 bjorn3 added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 24, 2021
@rust-highfive
Copy link
Contributor

Some changes occured to rustc_codegen_cranelift

cc @bjorn3

@rust-highfive
Copy link
Contributor

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 24, 2021
@jackh726
Copy link
Member

r? @bjorn3

@rust-highfive rust-highfive assigned bjorn3 and unassigned jackh726 May 24, 2021
@bjorn3
Copy link
Member Author

bjorn3 commented May 24, 2021

I opened this PR, so I probably shouldn't review it myself. :)

r? @jackh726

@rust-highfive rust-highfive assigned jackh726 and unassigned bjorn3 May 24, 2021
@jackh726
Copy link
Member

🤦‍♀️ whoops

Copy link
Member

@jackh726 jackh726 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I'm not sure how I feel about this. I feel like most ICEs happen in the frontend, not backend. So usually reporting to rust-lang/rust is a better idea. So maybe instead it's better to just include some extra information in the ICE report?

I'm probably not the best person to review this, since I'm not really in the loop here.

Comment on lines -1165 to -1170
// 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!();

Copy link
Member

Choose a reason for hiding this comment

The 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 DEFAULT_HOOK gets registered?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFAULT_HOOK both gets the default hook and registers the new ice hook with the default bug report url. This means that if you register a custom ice hook that calls report_ice, the ice hook with the default bug report url will be registered again. It is also easy to get into a cycle where the default ice hook and the custom ice hook recursively call each other on panics.

@bjorn3
Copy link
Member Author

bjorn3 commented May 24, 2021

I feel like most ICEs happen in the frontend, not backend. So usually reporting to rust-lang/rust is a better idea.

While this is true for the mature cg_llvm backend, this is not true for cg_clif. I do still sometimes get an ice caused by cg_clif. If the ice is in the frontend, I can redirect the issue to rust-lang/rust. In addition when using cg_clif, it is reasonable for someone to assume that cg_clif caused the issue if it doesn't reproduce with cg_llvm.

@jackh726
Copy link
Member

jackh726 commented Jun 1, 2021

I don't feel comfortable approving this myself (not necessarily because these changes are technically hard, but because this is really a decision that potentially impacts e.g. future codegen backends). Maybe if someone from @rust-lang/compiler wants to weigh in or an MCP, that might be better.

@nikomatsakis
Copy link
Contributor

I think an MCP would be a good idea here, but I approve the general concept.

@bjorn3
Copy link
Member Author

bjorn3 commented Jun 3, 2021

I think an MCP would be a good idea here

Opened rust-lang/compiler-team#436

@oli-obk
Copy link
Contributor

oli-obk commented Jun 3, 2021

cc @rust-lang/clippy we may want this, too

@flip1995
Copy link
Member

flip1995 commented Jun 3, 2021

Clippy already has this since 2019 👍

static ICE_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> = SyncLazy::new(|| {
let hook = panic::take_hook();
panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
hook
});

@jackh726
Copy link
Member

MCP is finished

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jun 24, 2021

📌 Commit 0bc60c0 has been approved by jackh726

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 24, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Jun 24, 2021
@bors
Copy link
Collaborator

bors commented Jun 25, 2021

⌛ Testing commit 0bc60c0 with merge 50a9081...

@bors
Copy link
Collaborator

bors commented Jun 25, 2021

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing 50a9081 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 25, 2021
@bors bors merged commit 50a9081 into rust-lang:master Jun 25, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jun 25, 2021
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Jul 7, 2021
Comment on lines -1154 to +1163
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);
}));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes report_ice useless for the situations without enough control over the driver to bypass the SyncLazy::force(&DEFAULT_HOOK);. Maybe there should be a report_ice_including_default_panic_hook function 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).

Copy link
Member Author

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_HOOK run and then set the new panic hook.

Copy link
Member Author

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_hook function requires the DEFAULT_HOOK to be forced first to be able to call it without ending in an infinite loop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you can first get the default hook

The codegen backend is loaded after DEFAULT_HOOK is initially forced, so it's impossible to make it work without changes to rustc_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 a static is somewhat incidental.

Though the most direct solution is to offer a static that contains the report URL (and maybe additional e.g. footer), and which can be changed independently of the panic hook.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no custom hook is registered, the default hook will be returned.

Ah, this behavior documented for std::panic::take_hook was what I missed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants