You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unwinding intrinsics use non-unwinding ABI #104451
An example demonstrating the issue. The argument passed to function f is never dropped, when assert_inhabited unwinds:
#![feature(core_intrinsics)]#![feature(never_type)]structNoisyDrop(&'staticstr);implDropforNoisyDrop{fndrop(&mutself){println!("{}",self.0);}}pubfnf<A,B>(_:A){
core::intrinsics::assert_inhabited::<B>()}fnmain(){let _a = NoisyDrop("1");f::<NoisyDrop, !>(NoisyDrop("2"));}
$ rustc a.rs && ./a
thread 'main' panicked at 'attempted to instantiate uninhabited type `!`', a.rs:13:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1
My current idea is to change assert_inhabited to is_inhabited intrinsic, and then have a wrapper that checks the value and panic if true. But making them abort sounds like an easier alternative.
It should be a nice abort via panic_str_nounwind though.
I am honestly not sure why the intrinsics are panicking rather than returning a boolean... I think I tried that and it didn't work? But yeah bool-returning intrinsics sound better (less magic) ayway.
One possible reason is that in CTFE and Miri, these intrinsics will actually abort instead of panic. Getting the if ... { panic_str_nounwind } to work in CTFE will be a bit of work (extending the existing hacks that make regular panicking work in CTFE, or using const_eval_select) and the backtrace will be slightly worse in Miri.
So given that we want something different implementations for Miri, CTFE, and runtime, maybe going with 'call panic_str_nounwind instead' is the better option. (An immediate-abort-panic just didn't exist when I added these intrinsics, otherwise this is probably what I would have done from the start.)
Yeah, I originally thought that we can remove all unwinding intrinsics, but unfortunately that's not true. I am working on a PR to change the ABI to be unwindable and stick #[rustc_nounwind] to most intrinsics.
Activity
nbdd0121 commentedon Nov 15, 2022
I'll work on this after #102906 is merged.
@rustbot claim
RalfJung commentedon Nov 15, 2022
Are these intrinsics the only ones that unwind? Maybe we should just make them abort instead by calling the (fairly recent)
panic_str_nounwind.However, AFAIK
tryis also an intrinsic and that can unwind?nbdd0121 commentedon Nov 15, 2022
trycatches unwind and it does not itself unwind.nbdd0121 commentedon Nov 15, 2022
My current idea is to change
assert_inhabitedtois_inhabitedintrinsic, and then have a wrapper that checks the value and panic if true. But making them abort sounds like an easier alternative.RalfJung commentedon Nov 15, 2022
It should be a nice abort via
panic_str_nounwindthough.I am honestly not sure why the intrinsics are panicking rather than returning a boolean... I think I tried that and it didn't work? But yeah bool-returning intrinsics sound better (less magic) ayway.
RalfJung commentedon Nov 15, 2022
One possible reason is that in CTFE and Miri, these intrinsics will actually abort instead of panic. Getting the
if ... { panic_str_nounwind }to work in CTFE will be a bit of work (extending the existing hacks that make regular panicking work in CTFE, or using const_eval_select) and the backtrace will be slightly worse in Miri.So given that we want something different implementations for Miri, CTFE, and runtime, maybe going with 'call
panic_str_nounwindinstead' is the better option. (An immediate-abort-panic just didn't exist when I added these intrinsics, otherwise this is probably what I would have done from the start.)RalfJung commentedon Apr 12, 2023
With #105997, I think
assert_inhabitedand friends do now indeed never unwind.But as determined in rust-lang/miri#2839, we still have const_eval_select, which very much can unwind.
nbdd0121 commentedon Apr 12, 2023
Yeah, I originally thought that we can remove all unwinding intrinsics, but unfortunately that's not true. I am working on a PR to change the ABI to be unwindable and stick
#[rustc_nounwind]to most intrinsics.RalfJung commentedon Apr 12, 2023
That sounds like the cleanest approach, thanks!
Rollup merge of rust-lang#110233 - nbdd0121:intrinsic, r=tmiasko