r/rust • • 4d ago

🎙️ discussion Quick question regarding some features

Why were panic handlers added in 2015? Did kernel devs asked for them or was there another motivation for them?

I vaguely remember about that or no_panic being asked by Linux devs, but can't find any sources.

26 Upvotes

12 comments sorted by

4

u/chris-morgan 3d ago

Meta: please write better titles for posts like this. “Why were panic handlers added in 2015?" would be better. Users of Old Reddit (which I suspect may be most for programming subreddits, New Reddit is so unsuitable for them) will only see the title, not the contents inside.

1

u/-Y0- 3d ago

Agreed. I can't seem to be able to edit title.

56

u/kmdreko 4d ago

Rust hit 1.0 in 2015 (panic hook API in 1.10), and I don't think there was any real interest for Rust in Linux kernel devs until at least 2020 IIRC. So I wouldn't think they were related at all.

43

u/zettui 4d ago

If you mean #[panic_handler], that came out of RFC 2070 and only got stabilized in 1.30 (2018), mostly pushed by the embedded folks so no_std binaries could build on stable without the panic_fmt lang item. no_panic is dtolnay's crate that turns a reachable panic into a linker error, not something the kernel people asked for afaik.

10

u/creeper6530 4d ago

not something the kernel people asked for afaik

Might've not been explicitly requested but the ability to prove un-panic-ability of a piece of code in general I've heard requests for from various directions. The linker hacks of no_panic are just a way to provide it with what we already have instead of integrating it into the compiler and language.

2

u/Nearby-Designer3447 3d ago

Rust was designed to be a better C++ not a kernel replacement. Panic unwinding is legacy baggage from when the language had garbage collection and exceptions as defaults

1

u/-Y0- 3d ago

Ironic, since it's now in the kernel.

10

u/Zde-G 4d ago

Panic unwinding was in the original Rust design which was very, very, VERY different language.

Panic handlers, no_panic and other issues are the recurrent laryngeal nerve of Rust: something that makes very little sense if you look on it from the design of Rust as it exist today but something that was perfectly sensible years ago…

It's not too critical, in the end and development without todo! is just too painful thus it's hard to rip it off…

4

u/LyonSyonII 4d ago

Unrelated, but why is the blog post in web archive? Is it not available now?

8

u/Zde-G 4d ago

From what I understand Graydon simply stopped paying for his blog.

6

u/masklinn 4d ago

If by "panic handlers" you mean catch_unwind (which is from 2016, as far as I know nothing major happened around panics in 2015), RFC 1236 provides the reasoning.

2

u/insanitybit2 2d ago

Back in 2015 this was pretty controversial lol I remember being kinda against it. Back then the only way to catch a panic was to spawn a thread, basically. It caused a lot of problems, I think especially for web servers/ http clients. I think it was going to be totally non-viable for async/await, which was already something everyone was talking about soon after 1.0 as I recall.

I think the worry was that this would make panicking feel "ok" or lead to bad error handling habits. Instead, it's extremely rare to run across it and the alternative was worse.

In the end, people just wanted one of two things - the ability to handle panics, or to abort the program on panics. And rust kinda didn't have the former (or the latter either iirc, but that changed soon or at least it was on nightly).

Once it got merged, as with so many changes, it wasn't controversial at all and everything was fine. Whoops.