-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Foreign" exceptions and catch_unwind
?
#35
Comments
An idea that would accommodate my use-case would be to add something similar to pub unsafe fn new_try<R, E, F: FnOnce() -> R, FE: FnOnce(*mut u8) -> E>(f: F, fe: FE) -> Result<R, E> {
// ...
#[cold]
unsafe fn cleanup(payload: *mut u8) -> E {
fe(payload)
}
// ...
}
pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>> {
new_try(f, |payload| {
let obj = unsafe { Box::from_raw(__rust_panic_cleanup(payload)) };
panic_count::decrease();
obj
})
} |
I'm sorry to be the bearer of bad news, but One of the requirements for this group's work has always been to avoid specifying how the exception handling mechanism works. Currently, it's implemented using the "native" exception handling mechanism in LLVM, which in theory would make it possible for That said, I do see how this would be useful, and I don't know for sure that specifying it would be too restrictive for the compiler implementation. I'm not sure who has the expertise to discuss this further; @Amanieu perhaps? |
I also don't remember who on the compiler team had alternative ideas/hopes/designs for unwinding. |
|
Yeah I've followed rust-lang/rust#128321, it's excellent that it's now specified instead of UB, that solves a lot of my concerns here, so thanks a lot for that! Now I no longer feel like Rust needs to expose a way to handle custom panics, so I'm going to close this. The only real remaining issue is that, as you said, that the process just aborts, which is obviously a terrible user experience and hard to debug, but that's a "quality of implementation" issue, and the best way forwards for me here would be to integrate the Objective-C(++) exception catching mechanism in Rust's |
I think it's still desirable to be able to interact directly with foreign exceptions. Let's use this issue to keep it on radar for the WG. |
catch_unwind
?catch_unwind
?
In that case, I'm renaming the thread to be a little more general. |
I am also interested in this. I'd like to both throw and catch foreign exceptions through Rust frames, at least on a subset of platforms. I'm currently doing this in Itanium ABI EH-conformant platforms by manually invoking |
@purplesyringa Thanks for adding a use-case; could you explain a little more about why you need |
I'm working on what is effectively an alternative panic/exception implementation for Rust, with a significant focus on performance. As such, going through the default Rust machinery is counterproductive. My main problems are:
To be clear, this is not just theory, and I have seen significant performance improvements by implementing a direct Itanium interface in my usecases. I'm hoping to publish a crate soon, I can send a link here if you're interested. |
Are you calling |
I'm directly calling the |
Objective-C have exceptions similar to C++ exceptions (not very familiar with these, maybe some of this apply there as well?), and catching them require using the
objc_begin_catch
andobjc_end_catch
helper functions, similar to Rust calling the internal__rust_panic_cleanup
function as part ofcatch_unwind
.I'd like the ability to create a function similar to
catch_unwind
, but which catches Objective-C exceptions instead of Rust panics. This would be anunsafe
function intended to be used on the FFI boundary just before sending an Objective-C message (equivalent to calling an"C-unwind"
function).In the
objc
-crate's exception handling this is currently done by letting an Objective-C compiler (likeclang
) generate a helper function that uses@try
and@catch
. This adds unnecessary overhead, and is bad for cross-compilation and all that. Using the underlying intrinsiccore::intrinsics::try
we can avoid the overhead inobjc
by effectively re-implementing most ofcatch_unwind
, see an example implementation here: SSheldon/rust-objc-exception@a351a8a.But obviously
core::intrinsics::try
is an intrinsic, and not intended to be stabilized, so I'd like to discuss a way we could stabilize it, or parts of thecatch_unwind
implementation, to allow this use-case.Originally posted as an internals thread.
The text was updated successfully, but these errors were encountered: