Skip to content

Commit 9e43ea8

Browse files
committed
rename 'try' intrinsic to 'catch_unwind'
1 parent f4732dd commit 9e43ea8

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

core/src/intrinsics.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
7575
unsafe { crate::ptr::drop_in_place(to_drop) }
7676
}
7777

78+
#[cfg(bootstrap)]
79+
pub use self::r#try as catch_unwind;
80+
7881
extern "rust-intrinsic" {
7982
// N.B., these intrinsics take raw pointers because they mutate aliased
8083
// memory, which is not valid for either `&` or `&mut`.
@@ -2382,16 +2385,24 @@ extern "rust-intrinsic" {
23822385
#[rustc_nounwind]
23832386
pub fn variant_count<T>() -> usize;
23842387

2385-
/// Rust's "try catch" construct which invokes the function pointer `try_fn`
2386-
/// with the data pointer `data`.
2387-
///
2388-
/// The third argument is a function called if a panic occurs. This function
2389-
/// takes the data pointer and a pointer to the target-specific exception
2390-
/// object that was caught. For more information see the compiler's
2391-
/// source as well as std's catch implementation.
2388+
/// Rust's "try catch" construct for unwinding. Invokes the function pointer `try_fn` with the
2389+
/// data pointer `data`, and calls `catch_fn` if unwinding occurs while `try_fn` runs.
23922390
///
23932391
/// `catch_fn` must not unwind.
2392+
///
2393+
/// The third argument is a function called if an unwind occurs (both Rust unwinds and foreign
2394+
/// unwinds). This function takes the data pointer and a pointer to the target-specific
2395+
/// exception object that was caught. For more information, see the compiler's source as well as
2396+
/// std's `catch_unwind` implementation.
2397+
///
2398+
/// The stable version of this intrinsic is `std::panic::catch_unwind`.
2399+
#[rustc_nounwind]
2400+
#[cfg(not(bootstrap))]
2401+
pub fn catch_unwind(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
2402+
2403+
/// For bootstrap only, see `catch_unwind`.
23942404
#[rustc_nounwind]
2405+
#[cfg(bootstrap)]
23952406
pub fn r#try(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
23962407

23972408
/// Emits a `!nontemporal` store according to LLVM (see their docs).

std/src/panicking.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,12 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
508508
// Access to the union's fields: this is `std` and we know that the `r#try`
509509
// intrinsic fills in the `r` or `p` union field based on its return value.
510510
//
511-
// The call to `intrinsics::r#try` is made safe by:
511+
// The call to `intrinsics::catch_unwind` is made safe by:
512512
// - `do_call`, the first argument, can be called with the initial `data_ptr`.
513513
// - `do_catch`, the second argument, can be called with the `data_ptr` as well.
514514
// See their safety preconditions for more information
515515
unsafe {
516-
return if intrinsics::r#try(do_call::<F, R>, data_ptr, do_catch::<F, R>) == 0 {
516+
return if intrinsics::catch_unwind(do_call::<F, R>, data_ptr, do_catch::<F, R>) == 0 {
517517
Ok(ManuallyDrop::into_inner(data.r))
518518
} else {
519519
Err(ManuallyDrop::into_inner(data.p))
@@ -540,7 +540,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
540540
// Its must contains a valid `f` (type: F) value that can be use to fill
541541
// `data.r`.
542542
//
543-
// This function cannot be marked as `unsafe` because `intrinsics::r#try`
543+
// This function cannot be marked as `unsafe` because `intrinsics::catch_unwind`
544544
// expects normal function pointers.
545545
#[inline]
546546
fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
@@ -562,7 +562,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
562562
// Since this uses `cleanup` it also hinges on a correct implementation of
563563
// `__rustc_panic_cleanup`.
564564
//
565-
// This function cannot be marked as `unsafe` because `intrinsics::r#try`
565+
// This function cannot be marked as `unsafe` because `intrinsics::catch_unwind`
566566
// expects normal function pointers.
567567
#[inline]
568568
#[rustc_nounwind] // `intrinsic::r#try` requires catch fn to be nounwind

0 commit comments

Comments
 (0)