Skip to content

Commit b4ca582

Browse files
committed
rename 'try' intrinsic to 'catch_unwind'
1 parent e9f9594 commit b4ca582

File tree

16 files changed

+42
-30
lines changed

16 files changed

+42
-30
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_middle::ty::layout::{HasParamEnv, ValidityRequirement};
2323
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
2424
use rustc_middle::ty::GenericArgsRef;
2525
use rustc_span::source_map::Spanned;
26-
use rustc_span::symbol::{kw, sym, Symbol};
26+
use rustc_span::symbol::{sym, Symbol};
2727

2828
pub(crate) use self::llvm::codegen_llvm_intrinsic_call;
2929
use crate::prelude::*;
@@ -1132,7 +1132,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
11321132
ret.write_cvalue(fx, val);
11331133
}
11341134

1135-
kw::Try => {
1135+
sym::catch_unwind => {
11361136
intrinsic_args!(fx, args => (f, data, catch_fn); intrinsic);
11371137
let f = f.load_scalar(fx);
11381138
let data = data.load_scalar(fx);

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::ty::{self, Instance, Ty};
2121
use rustc_middle::ty::layout::LayoutOf;
2222
#[cfg(feature="master")]
2323
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt};
24-
use rustc_span::{Span, Symbol, symbol::kw, sym};
24+
use rustc_span::{Span, Symbol, sym};
2525
use rustc_target::abi::HasDataLayout;
2626
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode};
2727
use rustc_target::spec::PanicStrategy;
@@ -129,7 +129,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
129129
let res = self.context.new_call(None, builtin, &[a]);
130130
self.icmp(IntPredicate::IntEQ, res, self.const_i32(0))
131131
}
132-
kw::Try => {
132+
sym::catch_unwind => {
133133
try_intrinsic(
134134
self,
135135
args[0].immediate(),

compiler/rustc_codegen_llvm/src/intrinsic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_hir as hir;
1717
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, LayoutOf};
1818
use rustc_middle::ty::{self, GenericArgsRef, Ty};
1919
use rustc_middle::{bug, span_bug};
20-
use rustc_span::{sym, symbol::kw, Span, Symbol};
20+
use rustc_span::{sym, Span, Symbol};
2121
use rustc_target::abi::{self, Align, HasDataLayout, Primitive};
2222
use rustc_target::spec::{HasTargetSpec, PanicStrategy};
2323

@@ -133,8 +133,8 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
133133
}
134134
sym::unlikely => self
135135
.call_intrinsic("llvm.expect.i1", &[args[0].immediate(), self.const_bool(false)]),
136-
kw::Try => {
137-
try_intrinsic(
136+
sym::catch_unwind => {
137+
catch_unwind_intrinsic(
138138
self,
139139
args[0].immediate(),
140140
args[1].immediate(),
@@ -457,7 +457,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
457457
}
458458
}
459459

460-
fn try_intrinsic<'ll>(
460+
fn catch_unwind_intrinsic<'ll>(
461461
bx: &mut Builder<'_, 'll, '_>,
462462
try_func: &'ll Value,
463463
data: &'ll Value,

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir as hir;
1212
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
1313
use rustc_middle::ty::{self, Ty, TyCtxt};
1414
use rustc_span::def_id::LocalDefId;
15-
use rustc_span::symbol::{kw, sym};
15+
use rustc_span::symbol::sym;
1616
use rustc_span::{Span, Symbol};
1717
use rustc_target::spec::abi::Abi;
1818

@@ -445,7 +445,7 @@ pub fn check_intrinsic_type(
445445
)
446446
}
447447

448-
kw::Try => {
448+
sym::catch_unwind => {
449449
let mut_u8 = Ty::new_mut_ptr(tcx, tcx.types.u8);
450450
let try_fn_ty = ty::Binder::dummy(tcx.mk_fn_sig(
451451
[mut_u8],

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ symbols! {
487487
call_once,
488488
caller_location,
489489
capture_disjoint_fields,
490+
catch_unwind,
490491
cause,
491492
cdylib,
492493
ceilf32,

library/core/src/intrinsics.rs

+18-7
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).

library/std/src/panicking.rs

+4-4
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

src/tools/miri/src/shims/intrinsics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
5454

5555
// Some intrinsics are special and need the "ret".
5656
match intrinsic_name {
57-
"try" => return this.handle_try(args, dest, ret),
57+
"catch_unwind" => return this.handle_catch_unwind(args, dest, ret),
5858
_ => {}
5959
}
6060

src/tools/miri/src/shims/panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
6969
}
7070

7171
/// Handles the `try` intrinsic, the underlying implementation of `std::panicking::try`.
72-
fn handle_try(
72+
fn handle_catch_unwind(
7373
&mut self,
7474
args: &[OpTy<'tcx, Provenance>],
7575
dest: &PlaceTy<'tcx, Provenance>,

src/tools/miri/tests/fail/function_calls/check_callback_abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() {
88
unsafe {
99
// Make sure we check the ABI when Miri itself invokes a function
1010
// as part of a shim implementation.
11-
std::intrinsics::r#try(
11+
std::intrinsics::catch_unwind(
1212
//~^ ERROR: calling a function with ABI C using caller ABI Rust
1313
std::mem::transmute::<extern "C" fn(*mut u8), _>(try_fn),
1414
std::ptr::null_mut(),

src/tools/miri/tests/fail/function_calls/check_callback_abi.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error: Undefined Behavior: calling a function with ABI C using caller ABI Rust
22
--> $DIR/check_callback_abi.rs:LL:CC
33
|
4-
LL | / std::intrinsics::r#try(
4+
LL | / std::intrinsics::catch_unwind(
55
LL | |
66
LL | | std::mem::transmute::<extern "C" fn(*mut u8), _>(try_fn),
77
LL | | std::ptr::null_mut(),

src/tools/miri/tests/pass/function_calls/disable_abi_check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
unsafe {
1616
let _ = malloc(0);
1717
std::mem::transmute::<fn(), extern "C" fn()>(foo)();
18-
std::intrinsics::r#try(
18+
std::intrinsics::catch_unwind(
1919
std::mem::transmute::<extern "C" fn(*mut u8), _>(try_fn),
2020
std::ptr::null_mut(),
2121
|_, _| unreachable!(),

tests/assembly/wasm_exceptions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn test_cleanup() {
4141
#[no_mangle]
4242
pub fn test_rtry() {
4343
unsafe {
44-
core::intrinsics::r#try(|_| {
44+
core::intrinsics::catch_unwind(|_| {
4545
may_panic();
4646
}, core::ptr::null_mut(), |data, exception| {
4747
log_number(data as usize);

tests/codegen/wasm_exceptions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn test_cleanup() {
3535
#[no_mangle]
3636
pub fn test_rtry() {
3737
unsafe {
38-
core::intrinsics::r#try(|_| {
38+
core::intrinsics::catch_unwind(|_| {
3939
may_panic();
4040
}, core::ptr::null_mut(), |data, exception| {
4141
log_number(data as usize);

tests/run-make/wasm-exceptions-nostd/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub extern "C" fn start() -> usize {
3939
let data = 0x1234usize as *mut u8; // Something to recognize
4040

4141
unsafe {
42-
core::intrinsics::r#try(|data: *mut u8| {
42+
core::intrinsics::catch_unwind(|data: *mut u8| {
4343
let _log_on_drop = LogOnDrop;
4444

4545
logging::log_str(&alloc::format!("`r#try` called with ptr {:?}", data));

tests/ui/interior-mutability/interior-mutability.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ note: required because it's used within this closure
1515
|
1616
LL | catch_unwind(|| { x.set(23); });
1717
| ^^
18-
note: required by a bound in `catch_unwind`
18+
note: required by a bound in `std::panic::catch_unwind`
1919
--> $SRC_DIR/std/src/panic.rs:LL:COL
2020

2121
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)