Skip to content

Reference correction - Panic Implementation - core definition of panic #140970

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

Closed
KalyanKadiyala opened this issue May 13, 2025 · 4 comments
Closed
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@KalyanKadiyala
Copy link

KalyanKadiyala commented May 13, 2025

Reference to weak lang item mapping for panic_impl isn't found at the specified location, as referenced in point number 1 in the current doc. Via search, I could see here.

Here's a sample of expected flow, that invokes the panic_impl (printed as rust_begin_unwind):
Image

Have a follow-up question about the mapping itself to rust_begin_unwind, the suffix part - unwind. At hand-off to std code paths, couldn't find any explicit unwind call that invokes the drop impls. I see that the once the backtrace is printed in the default hook, a call to intrinsics::abort is made. Like to understand if there's a relation from this code path to the support for destructors? Or are these independent, in the sense the runtime completes the panic flow, then independently invokes the destructors as the code that called the panic goes out of scope (assuming so for now)? Reason to seek clarification came from the mention of destructors in the commented lines here - call to destructors!

Like to bring this to the forum's attention with an intent to seek clarification or an update to the current doc!

Thanks,
Kalyan

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 13, 2025
@lolbinarycat lolbinarycat added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 13, 2025
@lolbinarycat
Copy link
Contributor

I couldn't find the exact commit or version where it was removed, but weak_lang_items.rs has not existed for a loooong time.

@KalyanKadiyala
Copy link
Author

I couldn't find the exact commit or version where it was removed, but weak_lang_items.rs has not existed for a loooong time.

Hi @lolbinarycat - thanks for the update. So, does it make sense to update the doc with the reference that I've shared earlier? Also, does it make sense to also clarify any connection with how destructors are invoked when a thread panics? I didn't see explicit references for other than traversing the backtrace, format it and print it out.

@KalyanKadiyala
Copy link
Author

KalyanKadiyala commented May 13, 2025

A little patience takes a long way :). I am able to connect the dots to implicit drop of all associated value references on the call-trace in the context i.e., that which raised a panic. As shown in the following call trace sample, the default handler performs two actions - drop over a print result.

Image

First, the trace is collected and printed to some inferred stderr, where the result of the print is passed into the drop fn. Considering the stack trace references are moved into the drop function, they go out of scope on completion of the drop, leading to an implicit drop of all references associated with the panic's call-trace.

The following is a visual attempt that I've put together to describe the flow based on 2021 and later editions, about what happens from when a panic of a certain kind is raised:

Image

@lolbinarycat - I reviewed your linked weak_lang_item.rs contents. Quick clarification - did you mean weak_lang_item.rs existed for a very long time? I'm assuming it so.

With latest attempt, I think I'm able to connect the dots here!

Thank you,
Kalyan

@KalyanKadiyala
Copy link
Author

For the purpose that I've been putting some effort, I got my clarifications answered. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants