Skip to content

Stabilise abort_immediate - #160766

Open
nia-e wants to merge 1 commit into
rust-lang:mainfrom
nia-e:stable-abort-immediate
Open

Stabilise abort_immediate#160766
nia-e wants to merge 1 commit into
rust-lang:mainfrom
nia-e:stable-abort-immediate

Conversation

@nia-e

@nia-e nia-e commented Aug 8, 2026

Copy link
Copy Markdown
Member
  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

Closes #154601 by stabilising the feature. Explicitly do not promise any particular behaviour beyond aborting in some nonspecific violent fashion.

The ACP for the relevant feature was accepted 2 years ago and the feature has been on nightly for 5 months with the only apparent concerns being related to naming and the possibility of having a version of abort in core that guarantees calling the system abort if available, but such an implementation is blocked on EIIs and there is merit to offering this in parallel as well. Additionally, the nonspecific semantics of abort_immediate let us change its behaviour to opportunistically call abort in the future if so desired.

@nia-e nia-e added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. I-libs-nominated Nominated for discussion during a libs team meeting. labels Aug 8, 2026
@rustbot

rustbot commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 8, 2026
@rustbot

rustbot commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

r? @clarfonthey

rustbot has assigned @clarfonthey.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey

@ChrisDenton

Copy link
Copy Markdown
Member

It would probably be good to replace uses of intrinsics::abort in core/alloc with abort_immediate before stabilization.

@clarfonthey

Copy link
Copy Markdown
Contributor

Only potential confusion is panic=immediate-abort which does not relate to this at all. (#147286)

@nia-e

nia-e commented Aug 8, 2026

Copy link
Copy Markdown
Member Author

It would probably be good to replace uses of intrinsics::abort in core/alloc with abort_immediate before stabilization.

happy to roll that into this pr, since this just wraps the intrinsic

Only potential confusion is panic=immediate-abort which does not relate to this at all. (#147286)

hmm, fair. in that case still i'd let the team rule on the preferred naming here

@clarfonthey

Copy link
Copy Markdown
Contributor

Yeah, fine with the team deciding on the naming, but I think immediate-abort and abort_immediate are close enough and distinct enough that one of them should change, and I'm inclined to say it's this one that should change.

Bad suggestion: abort_by_any_means_necessary

@maxdexh

maxdexh commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

abort_immediate has the nice property of telling you in the name that you should be using abort instead if you can. Even if it's a little questionable to call it an abort (though it could be implemented as one), I think abort_* is a very practical name (compared to the suggestion of crash)

@ChrisDenton

Copy link
Copy Markdown
Member

I can't really think of anything much better. The most important property is that it tries to terminate the process without doing anything else (if possible) or at least a minimal amount of other things.

The only thing I can think of is something like abort_critical. Which I feel has a sense urgency about it. But I'm fine with abort_immediate to be quite honest.

@clarfonthey

Copy link
Copy Markdown
Contributor

I guess that it doesn't technically matter if the two names don't have the same exact semantics because the idea of immediately aborting is the same in both cases.

And the rearranged words helps to indicate that they might be different.

@hanna-kruppe

Copy link
Copy Markdown
Contributor

Additionally, the nonspecific semantics of abort_immediate let us change its behaviour to opportunistically call abort in the future if so desired.

I think it would be better if we could get consensus to not do that, i.e., keep abort_immediate as it was originally conceived and plan to call the "maybe calls std::process::abort()" version something different if/when it's added. There are places where you want to exit immediately with as little chance of other code running for safety, and/or want to minimize code size overhead. So there's a need for a function that promises to do just that.

For example, glibc abort() until 2.26 did stdio buffer flushing, risking deadlocks (we still support glibc 2.17 last I checked). And on all POSIX platforms, abort() raises SIGABRT and thus can run a signal handler, which you can readily install and do silly things in. Technically some abort_immediate impls like x86 ud2 can also be caught as SIGILL, but I think the risk for that is significantly lower (e.g., signal-hook-registry refuses to install SIGILL handlers in its main API, and I hope people writing SIGILL handlers are more careful about not doing anything on the canonical "crash ASAP" operation).

@RalfJung

RalfJung commented Aug 8, 2026

Copy link
Copy Markdown
Member

IMO it is UB to install signal handlers that do anything "weird", so the SIGABRT argument is not very convincing to me. But I agree with the rest.

@xtqqczze

xtqqczze commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

The naming could be confusing since std::process::abort is already documented to "immediately terminate the current process".

@hanna-kruppe

hanna-kruppe commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

IMO it is UB to install signal handlers that do anything "weird", so the SIGABRT argument is not very convincing to me. But I agree with the rest.

It's certainly ill-advised to do anything non-trivial, and in practice almost every signal handler I've ever seen is not quite async-signal-safe and thus UB anyway. But having a SIGABRT handler at all isn't too weird if you e.g. want to make sure you restore terminal state on exit.

And more generally: async-signal-safe code has to be able to abort somehow (panic isn't AS-safe). While abort() is AS-safe, the reentrance via another signal handler still seems like a huge footgun.

@RalfJung

RalfJung commented Aug 8, 2026

Copy link
Copy Markdown
Member

async-signal-safety is a necessary condition for code in such a signal handler, but not a sufficient one. The rest of the program generally gets to assume that signal handlers don't interfere with the normal program execution.

Comment on lines 28 to 32

@clarfonthey clarfonthey Aug 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This paragraph feels a bit weird to me since it tries to define what an interrupt is to people operating on bare-metal targets as if they've only worked with OS targets before.

Not exactly sure what a better version would look like, but this feels very strange.

View changes since the review

Comment on lines 33 to 37
@@ -34,7 +35,7 @@
/// corresponds to `SIGILL` or equivalent, *unless* this signal is handled.
/// Other signals such as `SIGABRT`, `SIGTRAP`, `SIGSEGV`, and `SIGBUS` may be
/// produced instead, depending on specifics. This is not an exhaustive list.

@clarfonthey clarfonthey Aug 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As mentioned in the signal handling discussion, we probably should just put our foot down somewhat on this and say that you generally should not try and intercept whatever signal gets raised by this, and instead rely on the regular abort if you want predictable mechanics.

View changes since the review

@PoignardAzur

Copy link
Copy Markdown
Contributor

How about abort_raw or abort_minimal?

@maxdexh

maxdexh commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

abort_yesterday

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

Labels

I-libs-nominated Nominated for discussion during a libs team meeting. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking Issue for abort_immediate (abort in core)

9 participants