Skip to content
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

C-unwind and Rust 1.71.0 #539

Closed
herabit opened this issue Dec 10, 2023 · 9 comments
Closed

C-unwind and Rust 1.71.0 #539

herabit opened this issue Dec 10, 2023 · 9 comments
Labels
A-block2 Affects the `block2` crate A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates bug Something isn't working I-unsound A soundness hole

Comments

@herabit
Copy link

herabit commented Dec 10, 2023

Rust 1.71.0 stabilizes (at least partially) C-unwinding. However, due to issues with the feature attribute's usage on stable, one is unable to utilize C-unwind on Rust 1.71.0+, despite it being available, when on stable.

There should be some kind of additional conditional compilation code to handle these versions, while still maintaining the current MSRV of 0.60.0. I'm trying to figure out how myself rn, hence my fork.

@madsmtm madsmtm added A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates A-block2 Affects the `block2` crate I-unsound A soundness hole bug Something isn't working and removed I-unsound A soundness hole labels Dec 10, 2023
@madsmtm
Copy link
Owner

madsmtm commented Dec 10, 2023

If we just remove the #![feature(c_unwind)], then it should compile on stable, no?

@madsmtm madsmtm added the I-unsound A soundness hole label Dec 10, 2023
@madsmtm
Copy link
Owner

madsmtm commented Dec 10, 2023

Though actually making extern "C-unwind" sound will take more effort, since Rust panics and Objective-C exceptions are not compatible.

@herabit
Copy link
Author

herabit commented Dec 10, 2023

Yeah this is kind of annoying when I'm trying to make Rust cocoa wrappers that, are Rusty, and, safe. I wonder if there's any way to bridge this incompatibility...

@madsmtm
Copy link
Owner

madsmtm commented Mar 14, 2024

Given that rust-lang/rust#115285 is FCP, this is now becoming a bit more important.

Unfortunately, I can't really raise the MSRV for objc2 to 1.71.0 yet, as Winit's MSRV is still at 1.70.0 :/

@herabit
Copy link
Author

herabit commented Mar 14, 2024

It could, at least in the short term be an opt-in feature, or perhaps enabled only on newer rust versions with a crate such as rustversion, which, well allows conditional compilation based upon whatever version of rustc you're compiling for. It may be worth taking a look at, though, in the short term it may complicate maintainability, and anger some folk due to the additional dependency. A build script may be able to provide similar functionality, though, again with potential issues pertaining to maintainability, as managing a lot of conditional compilation can, really be a pain in the ass.

@madsmtm
Copy link
Owner

madsmtm commented Mar 14, 2024

Yeah. I think the easier solution might be to allow a bump to Winit's Rust version on macOS only.

@madsmtm madsmtm added this to the objc2 v0.6 milestone May 20, 2024
madsmtm added a commit that referenced this issue Jun 2, 2024
Improves the situation in #539.
madsmtm added a commit that referenced this issue Jun 2, 2024
Improves the situation in #539.
@madsmtm
Copy link
Owner

madsmtm commented Jun 2, 2024

In bbf81ac and fc7e6e2 I've improved upon this by making the (still unstable) feature available in block2, and by removing #![feature(c_unwind)].

@madsmtm
Copy link
Owner

madsmtm commented Sep 5, 2024

Rust is deciding to let catching foreign unwinding (like Objective-C exceptions) in "C-unwind" be defined behaviour, see rust-lang/rust#128321 and rust-lang/reference#1226. With that, things are trivial to make safe, so I'll probably be bumping MSRV to 1.71 soon, and justify it as a soundness fix if anyone complains ;) .

madsmtm added a commit that referenced this issue Sep 12, 2024
C-unwind was added in Rust 1.71, and allows panicking/unwinding
/exceptions across foreign function interfaces.

Additionally, Rust decided to let handling of foreign unwinds be
implementation defined behavior (instead of undefined), so we can now
mark `throw` as safe, see rust-lang/rust#128321.

This has a cost in that we now have landing pads on every message send;
this is strictly the correct choice, though, so we will have to bear
with it.

Fixes #539.
madsmtm added a commit that referenced this issue Sep 12, 2024
C-unwind was added in Rust 1.71, and allows panicking/unwinding
/exceptions across foreign function interfaces.

Additionally, Rust decided to let handling of foreign unwinds be
implementation defined behavior (instead of undefined), so we can now
mark `throw` as safe, see rust-lang/rust#128321.

This has a cost in that we now have landing pads on every message send;
this is strictly the correct choice, though, so we will have to bear
with it.

Fixes #539.
madsmtm added a commit that referenced this issue Sep 12, 2024
C-unwind was added in Rust 1.71, and allows panicking/unwinding
/exceptions across foreign function interfaces.

Additionally, Rust decided to let handling of foreign unwinds be
implementation defined behavior (instead of undefined), so we can now
mark `throw` as safe, see rust-lang/rust#128321.

This has a cost in that we now have landing pads on every message send;
this is strictly the correct choice, though, so we will have to bear
with it.

Fixes #539.
@madsmtm
Copy link
Owner

madsmtm commented Sep 16, 2024

I have bumped MSRV to 1.71, and used C-unwind when it makes sense, will be released in the next version of objc2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-block2 Affects the `block2` crate A-objc2 Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates bug Something isn't working I-unsound A soundness hole
Projects
None yet
Development

No branches or pull requests

2 participants