Skip to content

Tracking issue for RFC 2070: stable mechanism to specify the behavior of panic! in no-std applications  #44489

Closed

Description

@aturon

Update(2018-08-28)


This is a tracking issue for the RFC "stable mechanism to specify the behavior of panic! in no-std applications " (rust-lang/rfcs#2070).

Steps:

Unresolved questions:

fmt::Display

Should the Display of PanicInfo format the panic information as "panicked at 'reason', src/main.rs:27:4", as "'reason', src/main.rs:27:4", or simply as
"reason".

Unwinding in no-std

Is this design compatible, or can it be extended to work, with unwinding
implementations for no-std environments?

Issues to solve before stabilization

Activity

  1. added
    B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.
    T-libs-api[DEPRECATED; DO NOT USE]
    on Sep 11, 2017
  2. whitequark commented on Sep 12, 2017

    @whitequark
    Contributor

    Unwinding in no-std

    Is this design compatible, or can it be extended to work, with unwinding
    implementations for no-std environments?

    As someone with a working unwinding implementation in a no_std environment (not with a Rust personality function though), I can answer this if someone summarizes the feature for me. I kind of lost track and I don't have time to get into every minor detail at the moment.

  3. yodaldevoid commented on Sep 14, 2017

    @yodaldevoid
    Contributor

    As someone with a working unwinding implementation in a no_std environment (not with a Rust personality function though)...

    Sorry to bring this off topic so soon, but could you explain this? I was under the impression that unless you wanted to implement unwinding in an ad-hoc way (e.g. doing unwinding during panic by explicitly calling some function) you had to implement the eh_personality function.

  4. whitequark commented on Sep 14, 2017

    @whitequark
    Contributor

    I was under the impression that unless you wanted to implement unwinding in an ad-hoc way (e.g. doing unwinding during panic by explicitly calling some function) you had to implement the eh_personality function.

    I use unwinding in a language runtime. The language has exceptions (and so unwinding), however Rust frames are never unwound, and so there's no need for the personality function.

  5. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Sep 17, 2017
  6. Zoxc commented on Sep 19, 2017

    @Zoxc
    Contributor

    I would like the Location interface to both support the ability to pass backtraces (effectively a fn caller(&self) -> Option<Location>) and decompression of location information which requires accessing this information in a closure passed to a Location function to avoid heap allocation.

  7. Zoxc commented on Sep 19, 2017

    @Zoxc
    Contributor

    We should also support no location information at all, and abstract location information (for example just an identifying number which can be used to find the relevant information in some external source).

  8. Zoxc commented on Sep 19, 2017

    @Zoxc
    Contributor

    I did not notice that PanicInfo and Location were already stable. I guess we can just deprecate PanicInfo::location and make it return None if we want some more expressive API in the future.

  9. Zoxc commented on Sep 19, 2017

    @Zoxc
    Contributor

    I'm really not a fan of using the same API for payloads and messages. I'd rather panic! be pure message and provide some other API for payloads. So basically I want PanicInfo without location and payload. I have not seen any motivation for payloads for no_std use cases either.

  10. Zoxc commented on Sep 21, 2017

    @Zoxc
    Contributor

    I kind of prefer a PanicInfo type with no fields or methods and just an Display implementation.

    One problem with mixing the payload and the message is that we can't strip panic messages from the binary without changing the meaning of programs relying on payloads.

  11. SimonSapin commented on Jan 23, 2018

    @SimonSapin
    Contributor

    #47687 does part of the implementation. I think after that what’s needed is:

    • Change the signature of the panic_fmt lang item from (msg: fmt::Arguments, file: &'static str, line: u32, col: u32) -> ! to (&PanicInfo) -> !. This a breaking change to an unstable feature. (Maybe also rename it to begin_panic or something without fmt in the name?)
      • When creating a PanicInfo in src/libcore/panicking.rs to call the modified lang item, use the &'static str message as the payload in panic() and a value of a new private struct NoPayload; type in panic_fmt()
      • Make that core::panicking::panic function generic to accept any P: Any + Send payload instead of just &'static str.
    • Add an unstable #[panic_implementation] proc-macro attribute gated on #![feature(panic_implementation)] that checks that it is on a extern fn with the appropriate signature, and expands to #[lang = "panic_fmt"]. This expansion uses stability hygiene such that the containing crate does not need the lang_items feature gate, only the panic_implementation one (until that one is stabilized)
    • Change the error[E0152]: duplicate lang item found: `panic_fmt` error to have its own error number and a message that talks about duplicate #[panic_implementation] instead. Or maybe write new code to emit that new error when appropriate. See what the implementation of #[global_allocator] does.

    Note however that src/libcore/panicking.rs contains some comments about doing a things a certain way so that so that the linker can eliminate some of the string formatting machinery to limit code size bloat when formatting is not otherwise used. It’s possible that these changes would defeat those optimizations. I don’t know what we can do to try and preserve them while implementing RFC 2070.

    CC @japaric

  12. SimonSapin commented on Jan 27, 2018

    @SimonSapin
    Contributor

    @Zoxc We can still propose changing RFC 2070, but a Box<Any + Send + 'static> payload for panics is already part of some stable APIs:

    • In std::thread::Result, the return type of std::thread::JoinHandle and std::panic::catch_unwind
    • As a parameter of std::panic::resume_unwind
    • PanicInfo::payload and std::panic::set_hook are already stable
  13. Zoxc commented on Jan 27, 2018

    @Zoxc
    Contributor

    @SimonSapin We could just pass a NoPayload struct for panics without payloads though. Anyway we don't need to repeat mistakes in libcore.

  14. 82 remaining items

  15. added a commit that references this issue on Sep 30, 2018
  16. sanmai-NL commented on Oct 19, 2018

    @sanmai-NL
    Contributor

    @Centril: Can you please update the OP with the current status (stabilization etc.)?

  17. Centril commented on Oct 19, 2018

    @Centril
    Contributor

    @sanmai-NL I will defer this to @japaric since they are most up to date as to the status.

  18. sanmai-NL commented on Oct 19, 2018

    @sanmai-NL
    Contributor

    @Centril: I saw at the end of this thread a very clear status indication, so I considered it a management thing requiring no involvement in the effort.

  19. Centril commented on Oct 19, 2018

    @Centril
    Contributor

    @sanmai-NL ok, I ticked some boxes which seemed fulfilled; but I don't have the time to do a more in-depth review right now. :)

  20. added a commit that references this issue on Dec 17, 2018
  21. andreeaflorescu commented on Jan 11, 2019

    @andreeaflorescu

    Hey, I got to this issue because it is linked to the message method of PanicInfo which is currently available only in rust nightly according to the the docs. As this issue is closed I was wondering if there's any plan to move the message method to stable.
    Related to the following issues in Firecracker:

    Is there another recommended way to get the panic information? I was also thinking about replacing the panic_hook with catch_unwind but we might get into problems if the external crates that we are using are implementing panic with abort.

  22. curiousleo commented on Nov 15, 2019

    @curiousleo

    @bors I think this issue should be re-opened until panic_info_message is no longer an unstable feature. Currently it still is:

    #[unstable(feature = "panic_info_message", issue = "44489")]
    .

  23. yodaldevoid commented on Nov 15, 2019

    @yodaldevoid
    Contributor

    @Centril @japaric about the the above message as @bors is a bot.

  24. curiousleo commented on Nov 15, 2019

    @curiousleo

    @bors is a bot.

    Lol thanks!

  25. eddyb commented on Nov 15, 2019

    @eddyb
    Contributor

    It's not even the bot (@bors) closing the issue, this is a GitHub feature.
    When a PR with the right keywords in its description (#51366 in this case) gets merged, issues can be closed automatically by GitHub.

    @curiousleo I think the problem there is the unstable feature panic_info_message didn't get its own tracking issue, but I'm not sure.

    Also a bit surprised that @andreeaflorescu didn't get a reply in almost a year...

  26. SimonSapin commented on Nov 26, 2019

    @SimonSapin
    Contributor

    #66771 changes the tracking issue of PanicInfo::message to #66745, which also has some discussion of what to do about it.

  27. curiousleo commented on Nov 26, 2019

    @curiousleo

    #66771 changes the tracking issue of PanicInfo::message to #66745, which also has some discussion of what to do about it.

    Thanks for following up! That's massively appreciated. I'll keep an eye on those two issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCE-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libs-api[DEPRECATED; DO NOT USE]WG-embeddedWorking group: Embedded systemsdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions