Skip to content
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

Handle panicking like rustc CTFE does #16935

Merged
merged 1 commit into from Mar 24, 2024
Merged

Conversation

Nilstrieb
Copy link
Member

Instead of using core::fmt::format to format panic messages, which may in turn panic too and cause recursive panics and other messy things, redirect panic_fmt to const_panic_fmt like CTFE, which in turn goes to panic_display and does the things normally. See the tests for the full call stack.

The tests don't work yet, I probably missed something in minicore.

fixes #16907 in my local testing, I also need to add a test for it

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 24, 2024
@@ -309,43 +334,6 @@ impl Evaluator<'_> {
let mut args = args.iter();
match it {
BeginPanic => Err(MirEvalError::Panic("<unknown-panic-payload>".to_owned())),
PanicFmt => {
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to have something like this? How const_panic_fmt can return MirEvalError::Panic on its own?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

So we need to hook panic_display in r-a as well? What is the output of rust-analyzer(debug-command) interpret function on a function that panics? It should be MirEvalError::Panic("panic message") but I guess it is now execution limit exceeded or something like that as it will try to execute panic_fmt and panic_display over and over.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hooking that function is what my rustc_const_panic_str change does.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. So we now lose the panic message? but let's track it in #16938 and merge this one.

// -> Err(ConstEvalError::Panic)
check_pass(
r#"
//- minicore: fmt, panic
Copy link
Member Author

Choose a reason for hiding this comment

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

somehow these tests don't work correctly yet, they currently fail MIR building (also, they shouldn't be check_pass but check_panic or whatever). I am currently unable to debug the build failure, so help welcome

Copy link
Member Author

Choose a reason for hiding this comment

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

I dropped this test, will do it in a follow-up PR. I added a simpler test for the hover behavior, which should be enough end-to-end.

@Nilstrieb
Copy link
Member Author

Someone else who had this problem in their project (making it unusable) confirmed that this also fixed their problem. I can drop the tests from this PR and do them in a follow up PR (I promise I won't forget about it :3) to merge this ASAP.

@Nilstrieb Nilstrieb force-pushed the dont-panic branch 2 times, most recently from ada455d to d8ef3f3 Compare March 24, 2024 14:39
Instead of using `core::fmt::format` to format panic messages, which may in turn
panic too and cause recursive panics and other messy things, redirect
`panic_fmt` to `const_panic_fmt` like CTFE, which in turn goes to
`panic_display` and does the things normally. See the tests for the full
call stack.
@Nilstrieb
Copy link
Member Author

I created #16938 to figure out the tests, so this PR should now work (and have a small hover test to ensure that end-to-end behavior doesn't regress). So this should be ready for merging now.

@Nilstrieb Nilstrieb marked this pull request as ready for review March 24, 2024 17:17
@HKalbasi
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 24, 2024

📌 Commit 2dfe7de has been approved by HKalbasi

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Mar 24, 2024

⌛ Testing commit 2dfe7de with merge 6f6b03f...

@bors
Copy link
Collaborator

bors commented Mar 24, 2024

☀️ Test successful - checks-actions
Approved by: HKalbasi
Pushing 6f6b03f to master...

@bors bors merged commit 6f6b03f into rust-lang:master Mar 24, 2024
11 checks passed
@Nilstrieb Nilstrieb deleted the dont-panic branch March 24, 2024 18:31
bors added a commit that referenced this pull request Apr 19, 2024
Implement `BeginPanic` handling in const eval

for #16935, needs some figuring out of how to write these tests correctly
bors added a commit that referenced this pull request Apr 19, 2024
Implement `BeginPanic` handling in const eval

for #16935, needs some figuring out of how to write these tests correctly
bors added a commit that referenced this pull request Apr 21, 2024
Implement `BeginPanic` handling in const eval

for #16935, needs some figuring out of how to write these tests correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hang when hovering over constant
4 participants