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

Tracking Issue for abort_unwind #130338

Open
2 of 7 tasks
CAD97 opened this issue Sep 14, 2024 · 5 comments
Open
2 of 7 tasks

Tracking Issue for abort_unwind #130338

CAD97 opened this issue Sep 14, 2024 · 5 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@CAD97
Copy link
Contributor

CAD97 commented Sep 14, 2024

Feature gate: #![feature(abort_unwind)]

This is a tracking issue for core::panic::abort_unwind.

abort_unwind is similar to catch_unwind, except that it aborts the process if it unwinds instead of catching the unwind. Prior to the abort, the panic hook is called in the same way that it is for other functions that cannot unwind (e.g. extern "C" fn).

Public API

// in core::panic (and std::panic)

fn abort_unwind<F: FnOnce() -> R, R>(f: F) -> R;

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@CAD97 CAD97 added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 14, 2024
@ChrisDenton
Copy link
Member

Does this not imply we should have abort in core?

@CAD97
Copy link
Contributor Author

CAD97 commented Sep 15, 2024

As was mentioned on the ACP, it would indeed be unfortunate if abort_unwind(|| panic!()) became the pseudo canonical way to abort without std. (I do think exposing a way to create non-unwinding panics would be a good idea.) However, note that this API doesn't enable anything that wasn't already possible in user code without std—while the implementation is written using #[rustc_nounwind], extern "C" stably has that same effect now, as of 1.81.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 15, 2024
Add `core::panic::abort_unwind`

`abort_unwind` is like `catch_unwind` except that it aborts the process if it unwinds, using the `#[rustc_nounwind]` mechanism also used by `extern "C" fn` to abort unwinding. The docs attempt to make it clear when to (rarely) and when not to (usually) use the function.

Although usage of the function is discouraged, having it available will help to normalize the experience when abort_unwind shims are hit, as opposed to the current ecosystem where there exist multiple common patterns for converting unwinding into a process abort.

For further information and justification, see the linked ACP.

- Tracking issue: rust-lang#130338
- ACP: rust-lang/libs-team#441
@the8472
Copy link
Member

the8472 commented Sep 15, 2024

Bikeshed: I think abort_on_unwind would be a better name. Otherwise it sounds like some somewhat nonsense operation that first unwinds and then aborts.

@CAD97
Copy link
Contributor Author

CAD97 commented Sep 15, 2024

abort_unwind is named like catch_unwind, but it's also named like resume_unwind, so I can see expecting abort_unwind to instead be

fn abort_unwind(payload: Box<dyn Any + Send>) {
    abort_on_unwind(|| drop(payload))
    // or aborts with "unwind in cleanup"
}

for handling the catch_unwind footgun where dropping the panic payload can itself unwind. Or some magic to abort an in-progress unwind.

I'm mostly ambivalent on this matter and the implementation PR is approved already, so I'll leave the name to let libs-api stew on it for now.

rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 15, 2024
Rollup merge of rust-lang#130339 - CAD97:unwind-choice, r=dtolnay

Add `core::panic::abort_unwind`

`abort_unwind` is like `catch_unwind` except that it aborts the process if it unwinds, using the `#[rustc_nounwind]` mechanism also used by `extern "C" fn` to abort unwinding. The docs attempt to make it clear when to (rarely) and when not to (usually) use the function.

Although usage of the function is discouraged, having it available will help to normalize the experience when abort_unwind shims are hit, as opposed to the current ecosystem where there exist multiple common patterns for converting unwinding into a process abort.

For further information and justification, see the linked ACP.

- Tracking issue: rust-lang#130338
- ACP: rust-lang/libs-team#441
@RalfJung
Copy link
Member

I agree the name is confusing, I first thought this would abort unwinding (e.g., being in the same category as resume_unwind) -- whatever that means.

bors added a commit to rust-lang/miri that referenced this issue Sep 23, 2024
add test for new abort_unwind function

Seems like a good thing to have an explicit test for.

Cc rust-lang/rust#130338
RalfJung pushed a commit to RalfJung/rust that referenced this issue Sep 29, 2024
add test for new abort_unwind function

Seems like a good thing to have an explicit test for.

Cc rust-lang#130338
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants