From d7c283083b5852bee44898b0f588fdfba9894a14 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 09:20:59 +0100 Subject: [PATCH 01/12] Bump objc-sys version 0.3.1 -> 0.3.2 --- Cargo.lock | 2 +- crates/block-sys/Cargo.toml | 2 +- crates/objc-sys/CHANGELOG.md | 3 +++ crates/objc-sys/Cargo.toml | 2 +- crates/objc-sys/src/lib.rs | 2 +- crates/objc2/Cargo.toml | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c935d3617..441f7646c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -306,7 +306,7 @@ dependencies = [ [[package]] name = "objc-sys" -version = "0.3.1" +version = "0.3.2" dependencies = [ "cc", ] diff --git a/crates/block-sys/Cargo.toml b/crates/block-sys/Cargo.toml index 58d5b11f6..4fc64b4fd 100644 --- a/crates/block-sys/Cargo.toml +++ b/crates/block-sys/Cargo.toml @@ -60,7 +60,7 @@ unstable-objfw = [] unstable-docsrs = ["objc-sys", "objc-sys/unstable-docsrs"] [dependencies] -objc-sys = { path = "../objc-sys", version = "0.3.1", default-features = false, optional = true } +objc-sys = { path = "../objc-sys", version = "0.3.2", default-features = false, optional = true } [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/crates/objc-sys/CHANGELOG.md b/crates/objc-sys/CHANGELOG.md index 427a43f64..34ea08416 100644 --- a/crates/objc-sys/CHANGELOG.md +++ b/crates/objc-sys/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased - YYYY-MM-DD + +## 0.3.2 - 2023-12-03 + ### Added * Added `objc_terminate`, `object_isClass`, `objc_alloc` and `objc_allocWithZone` now that Rust's macOS deployment target is 10.12. diff --git a/crates/objc-sys/Cargo.toml b/crates/objc-sys/Cargo.toml index 244401aa5..a7893475f 100644 --- a/crates/objc-sys/Cargo.toml +++ b/crates/objc-sys/Cargo.toml @@ -5,7 +5,7 @@ name = "objc-sys" # # Also, beware of using pre-release versions here, since because of the # `links` key, two pre-releases requested with `=...` are incompatible. -version = "0.3.1" +version = "0.3.2" authors = ["Mads Marquart "] edition = "2021" rust-version = "1.60" diff --git a/crates/objc-sys/src/lib.rs b/crates/objc-sys/src/lib.rs index 68b0b1087..c1f758d69 100644 --- a/crates/objc-sys/src/lib.rs +++ b/crates/objc-sys/src/lib.rs @@ -29,7 +29,7 @@ #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] #![allow(non_snake_case)] -#![doc(html_root_url = "https://docs.rs/objc-sys/0.3.1")] +#![doc(html_root_url = "https://docs.rs/objc-sys/0.3.2")] #![cfg_attr(feature = "unstable-c-unwind", feature(c_unwind))] #![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg, doc_cfg_hide))] #![cfg_attr(feature = "unstable-docsrs", doc(cfg_hide(doc)))] diff --git a/crates/objc2/Cargo.toml b/crates/objc2/Cargo.toml index 05df438de..a38112b4e 100644 --- a/crates/objc2/Cargo.toml +++ b/crates/objc2/Cargo.toml @@ -101,7 +101,7 @@ unstable-compiler-rt = ["apple"] [dependencies] malloc_buf = { version = "1.0", optional = true } -objc-sys = { path = "../objc-sys", version = "0.3.1", default-features = false } +objc-sys = { path = "../objc-sys", version = "0.3.2", default-features = false } objc2-encode = { path = "../objc2-encode", version = "3.0.0", default-features = false } objc2-proc-macros = { path = "../objc2-proc-macros", version = "0.1.1", optional = true } From c4594d9c7633aa86a747ad0a7dd4c95daa000ffb Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 09:25:57 +0100 Subject: [PATCH 02/12] Bump objc2-encode version 3.0.0 -> 4.0.0 --- Cargo.lock | 2 +- crates/objc2-encode/CHANGELOG.md | 3 +++ crates/objc2-encode/Cargo.toml | 2 +- crates/objc2-encode/src/lib.rs | 2 +- crates/objc2/CHANGELOG.md | 1 + crates/objc2/Cargo.toml | 2 +- 6 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 441f7646c..3f6799b3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -326,7 +326,7 @@ dependencies = [ [[package]] name = "objc2-encode" -version = "3.0.0" +version = "4.0.0" [[package]] name = "objc2-proc-macros" diff --git a/crates/objc2-encode/CHANGELOG.md b/crates/objc2-encode/CHANGELOG.md index 5a581d73a..2aa99379c 100644 --- a/crates/objc2-encode/CHANGELOG.md +++ b/crates/objc2-encode/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased - YYYY-MM-DD + +## 4.0.0 - 2023-12-03 + ### Changed * **BREAKING**: Changed the type of `EncodingBox::Struct` and `EncodingBox::Union` to no longer contain an `Option`. diff --git a/crates/objc2-encode/Cargo.toml b/crates/objc2-encode/Cargo.toml index 557fd45d2..84d188684 100644 --- a/crates/objc2-encode/Cargo.toml +++ b/crates/objc2-encode/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "objc2-encode" # Remember to update html_root_url in lib.rs -version = "3.0.0" +version = "4.0.0" authors = ["Steven Sheldon", "Mads Marquart "] edition = "2021" rust-version = "1.60" diff --git a/crates/objc2-encode/src/lib.rs b/crates/objc2-encode/src/lib.rs index 1bb1f564e..584f79e67 100644 --- a/crates/objc2-encode/src/lib.rs +++ b/crates/objc2-encode/src/lib.rs @@ -48,7 +48,7 @@ #![warn(clippy::missing_errors_doc)] #![warn(clippy::missing_panics_doc)] // Update in Cargo.toml as well. -#![doc(html_root_url = "https://docs.rs/objc2-encode/3.0.0")] +#![doc(html_root_url = "https://docs.rs/objc2-encode/4.0.0")] #![cfg_attr(feature = "unstable-c-unwind", feature(c_unwind))] #[cfg(doctest)] diff --git a/crates/objc2/CHANGELOG.md b/crates/objc2/CHANGELOG.md index 931643621..36de8a4de 100644 --- a/crates/objc2/CHANGELOG.md +++ b/crates/objc2/CHANGELOG.md @@ -154,6 +154,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). that uses of `Option>` is now simply `Allocated`. * `AnyObject::class` now returns a `'static` reference to the class. * Relaxed `ProtocolType` requirement on `ProtocolObject`. +* **BREAKING**: Updated `encode` types to those from `objc2-encode v4.0.0`. ### Deprecated * Soft deprecated using `msg_send!` without a comma between arguments (i.e. diff --git a/crates/objc2/Cargo.toml b/crates/objc2/Cargo.toml index a38112b4e..9ea63ec6c 100644 --- a/crates/objc2/Cargo.toml +++ b/crates/objc2/Cargo.toml @@ -102,7 +102,7 @@ unstable-compiler-rt = ["apple"] [dependencies] malloc_buf = { version = "1.0", optional = true } objc-sys = { path = "../objc-sys", version = "0.3.2", default-features = false } -objc2-encode = { path = "../objc2-encode", version = "3.0.0", default-features = false } +objc2-encode = { path = "../objc2-encode", version = "4.0.0", default-features = false } objc2-proc-macros = { path = "../objc2-proc-macros", version = "0.1.1", optional = true } [dev-dependencies] From 0303d73e0d022db9b7d586cc931f37a5934f2583 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 09:27:52 +0100 Subject: [PATCH 03/12] Bump objc2 version 0.4.1 -> 0.5.0 --- Cargo.lock | 2 +- crates/block2/CHANGELOG.md | 3 +++ crates/block2/Cargo.toml | 2 +- crates/icrate/CHANGELOG.md | 7 ++++--- crates/icrate/Cargo.toml | 2 +- crates/objc2/CHANGELOG.md | 3 +++ crates/objc2/Cargo.toml | 2 +- crates/objc2/src/lib.rs | 2 +- 8 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3f6799b3b..852798432 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -313,7 +313,7 @@ dependencies = [ [[package]] name = "objc2" -version = "0.4.1" +version = "0.5.0" dependencies = [ "iai", "malloc_buf", diff --git a/crates/block2/CHANGELOG.md b/crates/block2/CHANGELOG.md index 415ee0ca6..b8da77c2c 100644 --- a/crates/block2/CHANGELOG.md +++ b/crates/block2/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased - YYYY-MM-DD +### Changed +* **BREAKING**: Updated `objc2` dependency to `v0.5.0`. + ## 0.3.0 - 2023-07-31 diff --git a/crates/block2/Cargo.toml b/crates/block2/Cargo.toml index 09736c981..257338cf4 100644 --- a/crates/block2/Cargo.toml +++ b/crates/block2/Cargo.toml @@ -35,7 +35,7 @@ gnustep-2-0 = ["gnustep-1-9", "block-sys/gnustep-2-0", "objc2/gnustep-2-0"] gnustep-2-1 = ["gnustep-2-0", "block-sys/gnustep-2-1", "objc2/gnustep-2-1"] [dependencies] -objc2 = { path = "../objc2", version = "0.4.1", default-features = false } +objc2 = { path = "../objc2", version = "0.5.0", default-features = false } block-sys = { path = "../block-sys", version = "0.2.0", default-features = false } [package.metadata.docs.rs] diff --git a/crates/icrate/CHANGELOG.md b/crates/icrate/CHANGELOG.md index 6ff1ee68f..0b343635c 100644 --- a/crates/icrate/CHANGELOG.md +++ b/crates/icrate/CHANGELOG.md @@ -62,7 +62,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). `NS[Mutable]Dictionary::from_vec`. * **BREAKING**: Renamed `NSMutableDictionary::insert` and `NSMutableSet::insert` to `insert_id`. -- **BREAKING**: `CWWiFiClient::interfaceNames` has been renamed to `CWWiFiClient::interfaceNames_class`. +* **BREAKING**: `CWWiFiClient::interfaceNames` has been renamed to `CWWiFiClient::interfaceNames_class`. +* **BREAKING**: Updated `objc2` to `v0.5.0`. ### Removed * **BREAKING**: Removed the `MainThreadMarker` argument from the closure @@ -92,8 +93,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). `AnyObject` instead of the correct `ProtocolObject`). * Update the minimum deployment target, which adds a few missing protocol implementations and methods for `NSPopover` and `NSLayoutAnchor`. -- **BREAKING**: `CKSystemSharingUIObserver` and `CKLocationSortDescriptor` are no longer marked thread safe. -- **BREAKING**: `NSColor::ignoresAlpha` now requires a main thread marker. +* **BREAKING**: `CKSystemSharingUIObserver` and `CKLocationSortDescriptor` are no longer marked thread safe. +* **BREAKING**: `NSColor::ignoresAlpha` now requires a main thread marker. ## icrate 0.0.4 - 2023-07-31 diff --git a/crates/icrate/Cargo.toml b/crates/icrate/Cargo.toml index 8f9d64438..67321b175 100644 --- a/crates/icrate/Cargo.toml +++ b/crates/icrate/Cargo.toml @@ -20,7 +20,7 @@ documentation = "https://docs.rs/icrate/" license = "MIT" [dependencies] -objc2 = { path = "../objc2", version = "0.4.1", default-features = false, optional = true } +objc2 = { path = "../objc2", version = "0.5.0", default-features = false, optional = true } block2 = { path = "../block2", version = "0.3.0", default-features = false, optional = true } dispatch = { version = "0.2.0", optional = true } diff --git a/crates/objc2/CHANGELOG.md b/crates/objc2/CHANGELOG.md index 36de8a4de..98c105f18 100644 --- a/crates/objc2/CHANGELOG.md +++ b/crates/objc2/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased - YYYY-MM-DD + +## 0.5.0 - 2023-12-03 + ### Added * Added the following traits to the `mutability` module (see the documentation for motivation and usage info): diff --git a/crates/objc2/Cargo.toml b/crates/objc2/Cargo.toml index 9ea63ec6c..47a45530c 100644 --- a/crates/objc2/Cargo.toml +++ b/crates/objc2/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "objc2" -version = "0.4.1" # Remember to update html_root_url in lib.rs +version = "0.5.0" # Remember to update html_root_url in lib.rs authors = ["Steven Sheldon", "Mads Marquart "] edition = "2021" rust-version = "1.60" diff --git a/crates/objc2/src/lib.rs b/crates/objc2/src/lib.rs index c6cec5447..c1ccd9aaf 100644 --- a/crates/objc2/src/lib.rs +++ b/crates/objc2/src/lib.rs @@ -170,7 +170,7 @@ #![warn(clippy::missing_errors_doc)] #![warn(clippy::missing_panics_doc)] // Update in Cargo.toml as well. -#![doc(html_root_url = "https://docs.rs/objc2/0.4.1")] +#![doc(html_root_url = "https://docs.rs/objc2/0.5.0")] #[cfg(not(feature = "alloc"))] compile_error!("The `alloc` feature currently must be enabled."); From 6712bb1d6654fd5371f519adfbcc643f59c4b7a2 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 09:30:55 +0100 Subject: [PATCH 04/12] Bump block2 version 0.3.0 -> 0.4.0 --- Cargo.lock | 2 +- crates/block2/CHANGELOG.md | 3 +++ crates/block2/Cargo.toml | 2 +- crates/block2/src/lib.rs | 2 +- crates/icrate/CHANGELOG.md | 1 + crates/icrate/Cargo.toml | 2 +- 6 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 852798432..75ff93876 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,7 +58,7 @@ dependencies = [ [[package]] name = "block2" -version = "0.3.0" +version = "0.4.0" dependencies = [ "block-sys", "objc2", diff --git a/crates/block2/CHANGELOG.md b/crates/block2/CHANGELOG.md index b8da77c2c..379095fd6 100644 --- a/crates/block2/CHANGELOG.md +++ b/crates/block2/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## Unreleased - YYYY-MM-DD + +## 0.4.0 - 2023-12-03 + ### Changed * **BREAKING**: Updated `objc2` dependency to `v0.5.0`. diff --git a/crates/block2/Cargo.toml b/crates/block2/Cargo.toml index 257338cf4..86fd02465 100644 --- a/crates/block2/Cargo.toml +++ b/crates/block2/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "block2" # Remember to update html_root_url in lib.rs and README.md -version = "0.3.0" +version = "0.4.0" authors = ["Steven Sheldon", "Mads Marquart "] edition = "2021" rust-version = "1.60" diff --git a/crates/block2/src/lib.rs b/crates/block2/src/lib.rs index 73346095c..1bb7edd03 100644 --- a/crates/block2/src/lib.rs +++ b/crates/block2/src/lib.rs @@ -87,7 +87,7 @@ #![warn(clippy::missing_errors_doc)] #![warn(clippy::missing_panics_doc)] // Update in Cargo.toml as well. -#![doc(html_root_url = "https://docs.rs/block2/0.3.0")] +#![doc(html_root_url = "https://docs.rs/block2/0.4.0")] extern crate alloc; extern crate std; diff --git a/crates/icrate/CHANGELOG.md b/crates/icrate/CHANGELOG.md index 0b343635c..4787a64a9 100644 --- a/crates/icrate/CHANGELOG.md +++ b/crates/icrate/CHANGELOG.md @@ -64,6 +64,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). `NSMutableSet::insert` to `insert_id`. * **BREAKING**: `CWWiFiClient::interfaceNames` has been renamed to `CWWiFiClient::interfaceNames_class`. * **BREAKING**: Updated `objc2` to `v0.5.0`. +* **BREAKING**: Updated `block2` to `v0.4.0`. ### Removed * **BREAKING**: Removed the `MainThreadMarker` argument from the closure diff --git a/crates/icrate/Cargo.toml b/crates/icrate/Cargo.toml index 67321b175..e94ea7df2 100644 --- a/crates/icrate/Cargo.toml +++ b/crates/icrate/Cargo.toml @@ -21,7 +21,7 @@ license = "MIT" [dependencies] objc2 = { path = "../objc2", version = "0.5.0", default-features = false, optional = true } -block2 = { path = "../block2", version = "0.3.0", default-features = false, optional = true } +block2 = { path = "../block2", version = "0.4.0", default-features = false, optional = true } dispatch = { version = "0.2.0", optional = true } [dev-dependencies] From 1eb0c10f9a3c276e9d3ce4cfa92db518ad4bdab1 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 09:33:26 +0100 Subject: [PATCH 05/12] Bump icrate version 0.0.4 -> 0.1.0 --- Cargo.lock | 2 +- crates/icrate/CHANGELOG.md | 3 +++ crates/icrate/Cargo.toml | 2 +- crates/icrate/src/lib.rs | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 75ff93876..2177547c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,7 +189,7 @@ dependencies = [ [[package]] name = "icrate" -version = "0.0.4" +version = "0.1.0" dependencies = [ "block2", "dispatch", diff --git a/crates/icrate/CHANGELOG.md b/crates/icrate/CHANGELOG.md index 4787a64a9..69a93184d 100644 --- a/crates/icrate/CHANGELOG.md +++ b/crates/icrate/CHANGELOG.md @@ -10,6 +10,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## icrate Unreleased - YYYY-MM-DD + +## icrate 0.1.0 - 2023-12-03 + ### Added * Added `MainThreadMarker` `From` implementation for `MainThreadOnly` types. * Added `Send` and `Sync` implementations for a bunch more types (same as the diff --git a/crates/icrate/Cargo.toml b/crates/icrate/Cargo.toml index e94ea7df2..1d0cc7bb2 100644 --- a/crates/icrate/Cargo.toml +++ b/crates/icrate/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icrate" -version = "0.0.4" # Remember to update html_root_url in lib.rs +version = "0.1.0" # Remember to update html_root_url in lib.rs authors = ["Mads Marquart "] edition = "2021" rust-version = "1.60" diff --git a/crates/icrate/src/lib.rs b/crates/icrate/src/lib.rs index c76955190..dcdc3db93 100644 --- a/crates/icrate/src/lib.rs +++ b/crates/icrate/src/lib.rs @@ -111,7 +111,7 @@ #![allow(clippy::identity_op)] #![allow(clippy::missing_safety_doc)] // Update in Cargo.toml as well. -#![doc(html_root_url = "https://docs.rs/icrate/0.0.4")] +#![doc(html_root_url = "https://docs.rs/icrate/0.1.0")] #![recursion_limit = "512"] #[cfg(feature = "alloc")] From 3cfb7c88dcf052d9a99f3de6f256e42e137618be Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 09:46:35 +0100 Subject: [PATCH 06/12] Fix doc test on NSMutableDictionary --- crates/icrate/src/additions/Foundation/dictionary.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/icrate/src/additions/Foundation/dictionary.rs b/crates/icrate/src/additions/Foundation/dictionary.rs index 411c49d24..e3536e84c 100644 --- a/crates/icrate/src/additions/Foundation/dictionary.rs +++ b/crates/icrate/src/additions/Foundation/dictionary.rs @@ -296,7 +296,11 @@ impl NSDictionary { /// /// # Examples /// - /// ``` + #[cfg_attr(all(feature = "Foundation_NSMutableDictionary"), doc = "```")] + #[cfg_attr( + not(all(feature = "Foundation_NSMutableDictionary")), + doc = "```ignore" + )] /// use icrate::Foundation::{ns_string, NSMutableDictionary, NSObject, NSString}; /// /// let mut dict = NSMutableDictionary::new(); From 6fef80d978fa135d7f53adbae113b97ff85a1eef Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 11:53:24 +0100 Subject: [PATCH 07/12] Fix tests on aarch64 / with newer LLVM --- crates/objc2/src/rc/id.rs | 9 ++- crates/objc2/src/rc/test_object.rs | 5 +- crates/objc2/tests/id_retain_autoreleased.rs | 2 +- .../test_msg_send_id/expected/apple-aarch64.s | 19 ++++- .../test_msg_send_id/expected/apple-armv7s.s | 24 +++++-- .../test_msg_send_id/expected/apple-x86.s | 37 ++++++++-- .../test_msg_send_id/expected/apple-x86_64.s | 23 ++++++- .../test_msg_send_id/expected/gnustep-x86.s | 69 +++++++++++++++---- .../expected/gnustep-x86_64.s | 38 ++++++++-- .../crates/test_msg_send_id/lib.rs | 10 +++ crates/tests/src/exception.rs | 18 +++-- 11 files changed, 202 insertions(+), 52 deletions(-) diff --git a/crates/objc2/src/rc/id.rs b/crates/objc2/src/rc/id.rs index 3714462de..8198830cc 100644 --- a/crates/objc2/src/rc/id.rs +++ b/crates/objc2/src/rc/id.rs @@ -377,6 +377,13 @@ impl Id { // swiftc: https://github.com/apple/swift/blob/swift-5.5.3-RELEASE/lib/IRGen/GenObjC.cpp#L148-L173 // Clang: https://github.com/llvm/llvm-project/blob/889317d47b7f046cf0e68746da8f7f264582fb5b/clang/lib/CodeGen/CGObjC.cpp#L2339-L2373 // + // Note that LLVM may sometimes insert extra instructions between the + // assembly and the `objc_retainAutoreleasedReturnValue` call, + // especially when doing tail calls and it needs to clean up the + // function frame. Unsure how to avoid this in a performant manner? + // Maybe force not doing tail calls by inserting assembly to do the + // call manually? + // // Resources: // - https://www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic-reference-counting.html // - https://www.galloway.me.uk/2012/02/how-does-objc_retainautoreleasedreturnvalue-work/ @@ -423,7 +430,7 @@ impl Id { // https://developer.apple.com/videos/play/wwdc2022/110363/ #[cfg(all(target_arch = "aarch64", not(feature = "unstable-apple-new")))] unsafe { - // Same as `mov x29, x29` + // Same as `mov x29, x29`. core::arch::asm!("mov fp, fp", options(nomem, preserves_flags, nostack)) }; diff --git a/crates/objc2/src/rc/test_object.rs b/crates/objc2/src/rc/test_object.rs index f86953842..16ccebcf2 100644 --- a/crates/objc2/src/rc/test_object.rs +++ b/crates/objc2/src/rc/test_object.rs @@ -405,7 +405,10 @@ mod tests { // x86 autorelease_return is not currently tail-called, so the // optimization doesn't work on declare_class! functions. 2 - } else if cfg!(any(debug_assertions, feature = "exception")) { + } else if cfg!(target_arch = "aarch64") { + // Currently doesn't work + 2 + } else if cfg!(any(debug_assertions, feature = "catch-all")) { 2 } else { 1 diff --git a/crates/objc2/tests/id_retain_autoreleased.rs b/crates/objc2/tests/id_retain_autoreleased.rs index fcde7c05e..58cfd5dd5 100644 --- a/crates/objc2/tests/id_retain_autoreleased.rs +++ b/crates/objc2/tests/id_retain_autoreleased.rs @@ -34,7 +34,7 @@ fn test_retain_autoreleased() { } else if cfg!(all(target_arch = "arm", panic = "unwind")) { // 32-bit ARM unwinding interferes with the optimization 2 - } else if cfg!(any(debug_assertions, feature = "exception")) { + } else if cfg!(any(debug_assertions, feature = "catch-all")) { 2 } else { 1 diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/apple-aarch64.s b/crates/test-assembly/crates/test_msg_send_id/expected/apple-aarch64.s index 96c3233ce..c1ba91800 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/apple-aarch64.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/apple-aarch64.s @@ -130,6 +130,19 @@ _handle_autoreleased: ldp x29, x30, [sp], #16 b _objc_retainAutoreleasedReturnValue + .globl _handle_autoreleased_with_arg + .p2align 2 +_handle_autoreleased_with_arg: + stp x29, x30, [sp, #-16]! + mov x29, sp + and w2, w2, #0xff + bl _objc_msgSend + ; InlineAsm Start + mov x29, x29 + ; InlineAsm End + ldp x29, x30, [sp], #16 + b _objc_retainAutoreleasedReturnValue + .globl _handle_autoreleased_fallible .p2align 2 _handle_autoreleased_fallible: @@ -143,11 +156,11 @@ _handle_autoreleased_fallible: mov x29, x29 ; InlineAsm End bl _objc_retainAutoreleasedReturnValue - cbz x0, LBB11_2 + cbz x0, LBB12_2 ldp x29, x30, [sp, #16] ldp x20, x19, [sp], #32 ret -LBB11_2: +LBB12_2: Lloh6: adrp x2, l_anon.[ID].4@PAGE Lloh7: @@ -204,6 +217,6 @@ l_anon.[ID].3: .p2align 3, 0x0 l_anon.[ID].4: .quad l_anon.[ID].0 - .asciz "3\000\000\000\000\000\000\000B\000\000\000\005\000\000" + .asciz "3\000\000\000\000\000\000\000L\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7s.s b/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7s.s index 2ce7d7c91..35d3183ed 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7s.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7s.s @@ -131,6 +131,20 @@ _handle_autoreleased: pop {r7, lr} b _objc_retainAutoreleasedReturnValue + .globl _handle_autoreleased_with_arg + .p2align 2 + .code 32 +_handle_autoreleased_with_arg: + push {r7, lr} + mov r7, sp + uxtb r2, r2 + bl _objc_msgSend + @ InlineAsm Start + mov r7, r7 + @ InlineAsm End + pop {r7, lr} + b _objc_retainAutoreleasedReturnValue + .globl _handle_autoreleased_fallible .p2align 2 .code 32 @@ -146,10 +160,10 @@ _handle_autoreleased_fallible: bl _objc_retainAutoreleasedReturnValue cmp r0, #0 popne {r4, r5, r7, pc} -LBB11_1: - movw r2, :lower16:(l_anon.[ID].4-(LPC11_0+8)) - movt r2, :upper16:(l_anon.[ID].4-(LPC11_0+8)) -LPC11_0: +LBB12_1: + movw r2, :lower16:(l_anon.[ID].4-(LPC12_0+8)) + movt r2, :upper16:(l_anon.[ID].4-(LPC12_0+8)) +LPC12_0: add r2, pc, r2 mov r0, r5 mov r1, r4 @@ -200,6 +214,6 @@ l_anon.[ID].3: .p2align 2, 0x0 l_anon.[ID].4: .long l_anon.[ID].0 - .asciz "3\000\000\000B\000\000\000\005\000\000" + .asciz "3\000\000\000L\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86.s b/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86.s index db83a9f6e..c33ee9625 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86.s @@ -211,6 +211,31 @@ _handle_autoreleased: pop ebp ret + .globl _handle_autoreleased_with_arg + .p2align 4, 0x90 +_handle_autoreleased_with_arg: + push ebp + mov ebp, esp + sub esp, 8 + movzx eax, byte ptr [ebp + 16] + sub esp, 4 + push eax + push dword ptr [ebp + 12] + push dword ptr [ebp + 8] + call _objc_msgSend + add esp, 16 + ## InlineAsm Start + + mov ebp, ebp + + ## InlineAsm End + sub esp, 12 + push eax + call _objc_retainAutoreleasedReturnValue + add esp, 24 + pop ebp + ret + .globl _handle_autoreleased_fallible .p2align 4, 0x90 _handle_autoreleased_fallible: @@ -220,8 +245,8 @@ _handle_autoreleased_fallible: push edi push esi sub esp, 12 - call L11$pb -L11$pb: + call L12$pb +L12$pb: pop ebx mov edi, dword ptr [ebp + 12] mov esi, dword ptr [ebp + 8] @@ -240,16 +265,16 @@ L11$pb: call _objc_retainAutoreleasedReturnValue add esp, 16 test eax, eax - je LBB11_2 + je LBB12_2 add esp, 12 pop esi pop edi pop ebx pop ebp ret -LBB11_2: +LBB12_2: sub esp, 4 - lea eax, [ebx + l_anon.[ID].4-L11$pb] + lea eax, [ebx + l_anon.[ID].4-L12$pb] push eax push edi push esi @@ -315,6 +340,6 @@ l_anon.[ID].3: .p2align 2, 0x0 l_anon.[ID].4: .long l_anon.[ID].0 - .asciz "3\000\000\000B\000\000\000\005\000\000" + .asciz "3\000\000\000L\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86_64.s b/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86_64.s index 35c4835d0..26b1c9cd1 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86_64.s @@ -150,6 +150,23 @@ _handle_autoreleased: pop rbp ret + .globl _handle_autoreleased_with_arg + .p2align 4, 0x90 +_handle_autoreleased_with_arg: + push rbp + mov rbp, rsp + movzx edx, dl + call _objc_msgSend + mov rdi, rax + call _objc_retainAutoreleasedReturnValue + ## InlineAsm Start + + nop + + ## InlineAsm End + pop rbp + ret + .globl _handle_autoreleased_fallible .p2align 4, 0x90 _handle_autoreleased_fallible: @@ -168,12 +185,12 @@ _handle_autoreleased_fallible: ## InlineAsm End test rax, rax - je LBB11_2 + je LBB12_2 pop rbx pop r14 pop rbp ret -LBB11_2: +LBB12_2: lea rdx, [rip + l_anon.[ID].4] mov rdi, r14 mov rsi, rbx @@ -233,6 +250,6 @@ l_anon.[ID].3: .p2align 3, 0x0 l_anon.[ID].4: .quad l_anon.[ID].0 - .asciz "3\000\000\000\000\000\000\000B\000\000\000\005\000\000" + .asciz "3\000\000\000\000\000\000\000L\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86.s b/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86.s index 0ef07f806..493660724 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86.s @@ -411,6 +411,45 @@ handle_autoreleased: .Lfunc_end10: .size handle_autoreleased, .Lfunc_end10-handle_autoreleased + .section .text.handle_autoreleased_with_arg,"ax",@progbits + .globl handle_autoreleased_with_arg + .p2align 4, 0x90 + .type handle_autoreleased_with_arg,@function +handle_autoreleased_with_arg: + push ebp + push ebx + push edi + push esi + sub esp, 12 + movzx edi, byte ptr [esp + 40] + mov esi, dword ptr [esp + 32] + mov ebp, dword ptr [esp + 36] + call .L11$pb +.L11$pb: + pop ebx +.Ltmp11: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp11-.L11$pb) + sub esp, 8 + push ebp + push esi + call objc_msg_lookup@PLT + add esp, 12 + push edi + push ebp + push esi + call eax + add esp, 4 + push eax + call objc_retainAutoreleasedReturnValue@PLT + add esp, 28 + pop esi + pop edi + pop ebx + pop ebp + ret +.Lfunc_end11: + .size handle_autoreleased_with_arg, .Lfunc_end11-handle_autoreleased_with_arg + .section .text.handle_autoreleased_fallible,"ax",@progbits .globl handle_autoreleased_fallible .p2align 4, 0x90 @@ -421,11 +460,11 @@ handle_autoreleased_fallible: push esi mov edi, dword ptr [esp + 20] mov esi, dword ptr [esp + 16] - call .L11$pb -.L11$pb: + call .L12$pb +.L12$pb: pop ebx -.Ltmp11: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp11-.L11$pb) +.Ltmp12: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp12-.L12$pb) sub esp, 8 push edi push esi @@ -439,12 +478,12 @@ handle_autoreleased_fallible: call objc_retainAutoreleasedReturnValue@PLT add esp, 16 test eax, eax - je .LBB11_1 + je .LBB12_1 pop esi pop edi pop ebx ret -.LBB11_1: +.LBB12_1: sub esp, 4 lea eax, [ebx + .Lanon.[ID].4@GOTOFF] push eax @@ -453,8 +492,8 @@ handle_autoreleased_fallible: call SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@PLT add esp, 16 ud2 -.Lfunc_end11: - .size handle_autoreleased_fallible, .Lfunc_end11-handle_autoreleased_fallible +.Lfunc_end12: + .size handle_autoreleased_fallible, .Lfunc_end12-handle_autoreleased_fallible .section .text.handle_with_out_param,"ax",@progbits .globl handle_with_out_param @@ -469,11 +508,11 @@ handle_with_out_param: mov ebp, dword ptr [esp + 40] mov eax, dword ptr [esp + 32] mov esi, dword ptr [esp + 36] - call .L12$pb -.L12$pb: + call .L13$pb +.L13$pb: pop ebx -.Ltmp12: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp12-.L12$pb) +.Ltmp13: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp13-.L13$pb) mov edi, dword ptr [ebp] mov dword ptr [esp + 4], esi mov dword ptr [esp], eax @@ -497,8 +536,8 @@ handle_with_out_param: pop ebx pop ebp ret -.Lfunc_end12: - .size handle_with_out_param, .Lfunc_end12-handle_with_out_param +.Lfunc_end13: + .size handle_with_out_param, .Lfunc_end13-handle_with_out_param .type .Lanon.[ID].0,@object .section .rodata..Lanon.[ID].0,"a",@progbits @@ -535,7 +574,7 @@ handle_with_out_param: .p2align 2, 0x0 .Lanon.[ID].4: .long .Lanon.[ID].0 - .asciz "3\000\000\000B\000\000\000\005\000\000" + .asciz "3\000\000\000L\000\000\000\005\000\000" .size .Lanon.[ID].4, 16 .section ".note.GNU-stack","",@progbits diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86_64.s b/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86_64.s index 4f328183a..93492d441 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86_64.s @@ -289,6 +289,30 @@ handle_autoreleased: .Lfunc_end10: .size handle_autoreleased, .Lfunc_end10-handle_autoreleased + .section .text.handle_autoreleased_with_arg,"ax",@progbits + .globl handle_autoreleased_with_arg + .p2align 4, 0x90 + .type handle_autoreleased_with_arg,@function +handle_autoreleased_with_arg: + push r15 + push r14 + push rbx + mov ebx, edx + mov r14, rsi + mov r15, rdi + call qword ptr [rip + objc_msg_lookup@GOTPCREL] + movzx edx, bl + mov rdi, r15 + mov rsi, r14 + call rax + mov rdi, rax + pop rbx + pop r14 + pop r15 + jmp qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] +.Lfunc_end11: + .size handle_autoreleased_with_arg, .Lfunc_end11-handle_autoreleased_with_arg + .section .text.handle_autoreleased_fallible,"ax",@progbits .globl handle_autoreleased_fallible .p2align 4, 0x90 @@ -306,19 +330,19 @@ handle_autoreleased_fallible: mov rdi, rax call qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] test rax, rax - je .LBB11_1 + je .LBB12_1 add rsp, 8 pop rbx pop r14 ret -.LBB11_1: +.LBB12_1: lea rdx, [rip + .Lanon.[ID].4] mov rdi, r14 mov rsi, rbx call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@GOTPCREL] ud2 -.Lfunc_end11: - .size handle_autoreleased_fallible, .Lfunc_end11-handle_autoreleased_fallible +.Lfunc_end12: + .size handle_autoreleased_fallible, .Lfunc_end12-handle_autoreleased_fallible .section .text.handle_with_out_param,"ax",@progbits .globl handle_with_out_param @@ -351,8 +375,8 @@ handle_with_out_param: pop r14 pop r15 jmp qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] -.Lfunc_end12: - .size handle_with_out_param, .Lfunc_end12-handle_with_out_param +.Lfunc_end13: + .size handle_with_out_param, .Lfunc_end13-handle_with_out_param .type .Lanon.[ID].0,@object .section .rodata..Lanon.[ID].0,"a",@progbits @@ -389,7 +413,7 @@ handle_with_out_param: .p2align 3, 0x0 .Lanon.[ID].4: .quad .Lanon.[ID].0 - .asciz "3\000\000\000\000\000\000\000B\000\000\000\005\000\000" + .asciz "3\000\000\000\000\000\000\000L\000\000\000\005\000\000" .size .Lanon.[ID].4, 24 .section ".note.GNU-stack","",@progbits diff --git a/crates/test-assembly/crates/test_msg_send_id/lib.rs b/crates/test-assembly/crates/test_msg_send_id/lib.rs index 555bc13df..75c26e9a2 100644 --- a/crates/test-assembly/crates/test_msg_send_id/lib.rs +++ b/crates/test-assembly/crates/test_msg_send_id/lib.rs @@ -61,6 +61,16 @@ unsafe fn handle_autoreleased(obj: &AnyObject, sel: Sel) -> Option Other::send_message_id(obj, sel, ()) } +// TODO: The optimization does not happen here on aarch64, fix this! +#[no_mangle] +unsafe fn handle_autoreleased_with_arg( + obj: &AnyObject, + sel: Sel, + arg: u8, +) -> Option> { + Other::send_message_id(obj, sel, (arg,)) +} + #[no_mangle] unsafe fn handle_autoreleased_fallible(obj: &AnyObject, sel: Sel) -> Id { Other::send_message_id(obj, sel, ()) diff --git a/crates/tests/src/exception.rs b/crates/tests/src/exception.rs index 98763eedc..d57f9511c 100644 --- a/crates/tests/src/exception.rs +++ b/crates/tests/src/exception.rs @@ -1,4 +1,5 @@ use alloc::format; +use alloc::string::ToString; use icrate::Foundation::{NSArray, NSException, NSString}; use objc2::exception::{catch, throw}; @@ -136,21 +137,18 @@ fn catch_actual() { let reason = if cfg!(feature = "gnustep-1-7") { "Index 0 is out of range 0 (in 'objectAtIndex:')" } else { - "*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray" + "*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty " // + "NSArray" or "array" }; - assert_eq!(format!("{}", exc), reason); - assert_eq!( - format!("{:?}", exc), - format!( - "exception '{}' reason:{}", - &*exc, name, reason - ) - ); + assert!(format!("{}", exc).starts_with(reason)); + assert!(format!("{:?}", exc).starts_with(&format!( + "exception '{}' reason:{}", + &*exc, name, reason + ))); let exc = NSException::from_exception(exc).unwrap(); assert_eq!(exc.name(), NSString::from_str(name)); - assert_eq!(exc.reason().unwrap(), NSString::from_str(reason)); + assert!(exc.reason().unwrap().to_string().starts_with(reason)); let user_info = exc.userInfo(); if cfg!(feature = "gnustep-1-7") { let user_info = user_info.unwrap(); From e2abb0d051faa5ea65cefc64e145ba8a82a7dd9f Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 11:03:42 +0100 Subject: [PATCH 08/12] Show diff for UI tests --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23db090e9..fc4f011cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -193,6 +193,9 @@ jobs: - fmt - lint + env: + TRYBUILD: overwrite + steps: - uses: actions/checkout@v3 with: @@ -213,6 +216,10 @@ jobs: - name: Run UI tests run: cargo run --features=run --bin=test-ui + - name: Check diff + if: ${{ always() }} + run: git diff --exit-code + assembly: name: Assembly tests runs-on: ubuntu-latest From cfc226e2b5ab79983e0652ef43d3e137db2c9dce Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 11:12:07 +0100 Subject: [PATCH 09/12] Fix flaky UI test --- crates/test-ui/ui/declare_class_invalid_type.stderr | 12 ++++++------ .../ui/mutability_traits_unimplementable2.stderr | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/test-ui/ui/declare_class_invalid_type.stderr b/crates/test-ui/ui/declare_class_invalid_type.stderr index 5ffa70b3a..05bfea296 100644 --- a/crates/test-ui/ui/declare_class_invalid_type.stderr +++ b/crates/test-ui/ui/declare_class_invalid_type.stderr @@ -99,11 +99,11 @@ note: required by a bound in `ConvertArgument` | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ConvertArgument` = note: `ConvertArgument` is a "sealed trait", because to implement it you also need to implement `objc2::__macro_helpers::convert::argument_private::Sealed`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it = help: the following types implement the trait: - &mut std::option::Option> &mut objc2::rc::Id - std::option::Option<&mut objc2::rc::Id> - std::option::Option<&mut std::option::Option>> + &mut std::option::Option> bool + std::option::Option<&mut std::option::Option>> + std::option::Option<&mut objc2::rc::Id> T = note: this error originates in the macro `$crate::__declare_class_rewrite_params` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -138,10 +138,10 @@ note: required by a bound in `ConvertArgument` | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ConvertArgument` = note: `ConvertArgument` is a "sealed trait", because to implement it you also need to implement `objc2::__macro_helpers::convert::argument_private::Sealed`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it = help: the following types implement the trait: - &mut std::option::Option> &mut objc2::rc::Id - std::option::Option<&mut objc2::rc::Id> - std::option::Option<&mut std::option::Option>> + &mut std::option::Option> bool + std::option::Option<&mut std::option::Option>> + std::option::Option<&mut objc2::rc::Id> T = note: this error originates in the macro `$crate::__declare_class_rewrite_params` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/mutability_traits_unimplementable2.stderr b/crates/test-ui/ui/mutability_traits_unimplementable2.stderr index efb5e7cf3..c52bc087c 100644 --- a/crates/test-ui/ui/mutability_traits_unimplementable2.stderr +++ b/crates/test-ui/ui/mutability_traits_unimplementable2.stderr @@ -16,8 +16,8 @@ note: required by a bound in `IsIdCloneable` | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `IsIdCloneable` = note: `IsIdCloneable` is a "sealed trait", because to implement it you also need to implement `objc2::mutability::private_traits::Sealed`, which is not accessible; this is usually done to force you to use one of the provided types that already implement it = help: the following types implement the trait: - objc2::runtime::AnyObject objc2::runtime::ProtocolObject

+ objc2::runtime::AnyObject T error[E0277]: the trait bound `CustomStruct: ClassType` is not satisfied From 8e3ff1282b0305145b3185c5b70bb91ad690863e Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 11:43:22 +0100 Subject: [PATCH 10/12] Fix `unstable-c-unwind` tests --- crates/objc2/src/__macro_helpers/declared_ivars.rs | 8 ++++++++ crates/objc2/src/__macro_helpers/msg_send_id.rs | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/crates/objc2/src/__macro_helpers/declared_ivars.rs b/crates/objc2/src/__macro_helpers/declared_ivars.rs index d3ae34a35..79e300638 100644 --- a/crates/objc2/src/__macro_helpers/declared_ivars.rs +++ b/crates/objc2/src/__macro_helpers/declared_ivars.rs @@ -875,6 +875,10 @@ mod tests { #[test] #[should_panic = "panic in drop"] + #[cfg_attr( + any(feature = "unstable-c-unwind", target_arch = "x86"), + ignore = "panicking in Drop requires that we actually implement `dealloc` as `C-unwind`" + )] fn test_panic_in_drop() { declare_class!( struct DropPanics; @@ -901,6 +905,10 @@ mod tests { #[test] #[should_panic = "panic in ivar drop"] + #[cfg_attr( + any(feature = "unstable-c-unwind", target_arch = "x86"), + ignore = "panicking in Drop requires that we actually implement `dealloc` as `C-unwind`" + )] fn test_panic_in_ivar_drop() { struct DropPanics; diff --git a/crates/objc2/src/__macro_helpers/msg_send_id.rs b/crates/objc2/src/__macro_helpers/msg_send_id.rs index 11112b552..c5c63abd3 100644 --- a/crates/objc2/src/__macro_helpers/msg_send_id.rs +++ b/crates/objc2/src/__macro_helpers/msg_send_id.rs @@ -770,6 +770,13 @@ mod tests { #[test] #[should_panic = "tried to initialize ivars after they were already initialized"] #[cfg_attr(not(debug_assertions), ignore = "only checked with debug assertions")] + #[cfg_attr( + all( + debug_assertions, + any(feature = "unstable-c-unwind", target_arch = "x86") + ), + ignore = "panicking in `init` requires that we emit the function as `C-unwind`" + )] fn test_super_init_not_initialized() { let obj = __RcTestObject::alloc().set_ivars(()); let _: Id<__RcTestObject> = From 611e5f1d8dc7bf15fa69b1b3c6ee1ed0adcfab28 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 11:40:57 +0100 Subject: [PATCH 11/12] Don't require AppKit in UI tests --- crates/test-ui/Cargo.toml | 2 - ...clare_class_delegate_not_mainthreadonly.rs | 30 +++++--- ...e_class_delegate_not_mainthreadonly.stderr | 4 +- .../ui/implement_protocol_missing_super.rs | 9 ++- .../implement_protocol_missing_super.stderr | 28 ++++---- .../test-ui/ui/msg_send_invalid_error.stderr | 4 +- crates/test-ui/ui/nsarray_not_message.stderr | 14 ++-- .../ui/protocol_object_only_protocols.stderr | 70 +++++++++---------- 8 files changed, 83 insertions(+), 78 deletions(-) diff --git a/crates/test-ui/Cargo.toml b/crates/test-ui/Cargo.toml index 2fbdba4ec..9b37daa79 100644 --- a/crates/test-ui/Cargo.toml +++ b/crates/test-ui/Cargo.toml @@ -23,8 +23,6 @@ default = [ "icrate/Foundation_NSMutableArray", "icrate/Foundation_NSValue", "icrate/Foundation_NSSet", - "icrate/AppKit", - "icrate/AppKit_NSApplication", "objc2/unstable-msg-send-always-comma", ] std = ["block2/std", "objc2/std", "icrate/std"] diff --git a/crates/test-ui/ui/declare_class_delegate_not_mainthreadonly.rs b/crates/test-ui/ui/declare_class_delegate_not_mainthreadonly.rs index cb43b051e..389ee4bfb 100644 --- a/crates/test-ui/ui/declare_class_delegate_not_mainthreadonly.rs +++ b/crates/test-ui/ui/declare_class_delegate_not_mainthreadonly.rs @@ -1,10 +1,25 @@ //! Test that implementing `NSApplicationDelegate` and similar requires //! a `MainThreadOnly` class. -use icrate::AppKit::{NSApplication, NSApplicationDelegate}; use icrate::Foundation::{MainThreadMarker, NSNotification, NSObject, NSObjectProtocol}; +use objc2::mutability::IsMainThreadOnly; use objc2::rc::Id; -use objc2::runtime::ProtocolObject; -use objc2::{declare_class, extern_methods, mutability, ClassType, DeclaredClass}; +use objc2::{ + declare_class, extern_methods, extern_protocol, mutability, ClassType, DeclaredClass, + ProtocolType, +}; + +// Use fake `NSApplicationDelegate` so that this works on iOS too. +extern_protocol!( + pub unsafe trait NSApplicationDelegate: NSObjectProtocol + IsMainThreadOnly { + #[optional] + #[method(applicationDidFinishLaunching:)] + unsafe fn applicationDidFinishLaunching(&self, notification: &NSNotification); + + // snip + } + + unsafe impl ProtocolType for dyn NSApplicationDelegate {} +); declare_class!( struct CustomObject; @@ -35,11 +50,4 @@ extern_methods!( } ); -fn main() { - let mtm = MainThreadMarker::new().unwrap(); - let app = NSApplication::sharedApplication(mtm); - - let delegate = CustomObject::new(mtm); - let delegate = ProtocolObject::from_ref(&*delegate); - app.setDelegate(Some(delegate)); -} +fn main() {} diff --git a/crates/test-ui/ui/declare_class_delegate_not_mainthreadonly.stderr b/crates/test-ui/ui/declare_class_delegate_not_mainthreadonly.stderr index 127a469d4..e83d698bf 100644 --- a/crates/test-ui/ui/declare_class_delegate_not_mainthreadonly.stderr +++ b/crates/test-ui/ui/declare_class_delegate_not_mainthreadonly.stderr @@ -7,13 +7,13 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsMainThre = help: the trait `mutability::MutabilityIsMainThreadOnly` is implemented for `MainThreadOnly` = note: required for `CustomObject` to implement `IsMainThreadOnly` note: required by a bound in `NSApplicationDelegate` - --> $WORKSPACE/crates/icrate/src/generated/AppKit/NSApplication.rs + --> ui/declare_class_delegate_not_mainthreadonly.rs | | / extern_protocol!( | | pub unsafe trait NSApplicationDelegate: NSObjectProtocol + IsMainThreadOnly { | | --------------------- required by a bound in this trait - | | #[cfg(feature = "AppKit_NSApplication")] | | #[optional] + | | #[method(applicationDidFinishLaunching:)] ... | | | unsafe impl ProtocolType for dyn NSApplicationDelegate {} | | ); diff --git a/crates/test-ui/ui/implement_protocol_missing_super.rs b/crates/test-ui/ui/implement_protocol_missing_super.rs index dbb131610..eec257fd3 100644 --- a/crates/test-ui/ui/implement_protocol_missing_super.rs +++ b/crates/test-ui/ui/implement_protocol_missing_super.rs @@ -1,7 +1,6 @@ -//! Test that implementing traits like `NSApplicationDelegate` requires super -//! protocols like `NSObjectProtocol` to also be implemented. -use icrate::AppKit::NSApplicationDelegate; -use icrate::Foundation::NSObject; +//! Test that implementing certain traits like `NSURLSessionDelegate` requires +//! super protocols like `NSObjectProtocol` to also be implemented. +use icrate::Foundation::{NSObject, NSURLSessionDelegate}; use objc2::{declare_class, mutability, ClassType, DeclaredClass}; declare_class!( @@ -15,7 +14,7 @@ declare_class!( impl DeclaredClass for CustomObject {} - unsafe impl NSApplicationDelegate for CustomObject {} + unsafe impl NSURLSessionDelegate for CustomObject {} ); fn main() {} diff --git a/crates/test-ui/ui/implement_protocol_missing_super.stderr b/crates/test-ui/ui/implement_protocol_missing_super.stderr index eaa533bca..14d7fba50 100644 --- a/crates/test-ui/ui/implement_protocol_missing_super.stderr +++ b/crates/test-ui/ui/implement_protocol_missing_super.stderr @@ -1,29 +1,29 @@ error[E0277]: the trait bound `CustomObject: NSObjectProtocol` is not satisfied --> ui/implement_protocol_missing_super.rs | - | unsafe impl NSApplicationDelegate for CustomObject {} - | ^^^^^^^^^^^^ the trait `NSObjectProtocol` is not implemented for `CustomObject` + | unsafe impl NSURLSessionDelegate for CustomObject {} + | ^^^^^^^^^^^^ the trait `NSObjectProtocol` is not implemented for `CustomObject` | = help: the following other types implement trait `NSObjectProtocol`: NSObject __NSProxy ProtocolObject - NSApplication - NSCollectionView - NSCollectionLayoutSection - NSCollectionLayoutGroupCustomItem - NSControl + NSArray + NSMutableArray + NSDictionary + NSSet + NSEnumerator and $N others -note: required by a bound in `NSApplicationDelegate` - --> $WORKSPACE/crates/icrate/src/generated/AppKit/NSApplication.rs +note: required by a bound in `NSURLSessionDelegate` + --> $WORKSPACE/crates/icrate/src/generated/Foundation/NSURLSession.rs | | / extern_protocol!( - | | pub unsafe trait NSApplicationDelegate: NSObjectProtocol + IsMainThreadOnly { - | | --------------------- required by a bound in this trait - | | #[cfg(feature = "AppKit_NSApplication")] + | | pub unsafe trait NSURLSessionDelegate: NSObjectProtocol { + | | -------------------- required by a bound in this trait + | | #[cfg(all(feature = "Foundation_NSError", feature = "Foundation_NSURLSession"))] | | #[optional] ... | - | | unsafe impl ProtocolType for dyn NSApplicationDelegate {} + | | unsafe impl ProtocolType for dyn NSURLSessionDelegate {} | | ); - | |_^ required by this bound in `NSApplicationDelegate` + | |_^ required by this bound in `NSURLSessionDelegate` = note: this error originates in the macro `extern_protocol` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_invalid_error.stderr b/crates/test-ui/ui/msg_send_invalid_error.stderr index f3881f94a..56969b188 100644 --- a/crates/test-ui/ui/msg_send_invalid_error.stderr +++ b/crates/test-ui/ui/msg_send_invalid_error.stderr @@ -45,9 +45,9 @@ error[E0277]: the trait bound `i32: Message` is not satisfied __NSProxy ProtocolObject

AnyObject + NSArray + NSMutableArray __RcTestObject - NSApplication - NSCollectionView and $N others note: required by a bound in `send_message_error` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs diff --git a/crates/test-ui/ui/nsarray_not_message.stderr b/crates/test-ui/ui/nsarray_not_message.stderr index 01f4daa4b..b5df5b5ea 100644 --- a/crates/test-ui/ui/nsarray_not_message.stderr +++ b/crates/test-ui/ui/nsarray_not_message.stderr @@ -10,9 +10,9 @@ error[E0277]: the trait bound `i32: Message` is not satisfied __NSProxy ProtocolObject

AnyObject + NSArray + NSMutableArray __RcTestObject - NSApplication - NSCollectionView and $N others note: required by a bound in `Foundation::__NSArray::>::new` --> $WORKSPACE/crates/icrate/src/generated/Foundation/NSArray.rs @@ -40,12 +40,12 @@ error[E0277]: the trait bound `Id: ClassType` is not satisfied = help: the following other types implement trait `ClassType`: NSObject __NSProxy + NSArray + NSMutableArray __RcTestObject - NSApplication - NSCollectionView - NSCollectionLayoutSection - NSCollectionLayoutGroupCustomItem - NSControl + NSDictionary + NSMutableDictionary + NSSet and $N others = note: required for `Id` to implement `IsRetainable` note: required by a bound in `icrate::Foundation::array::>::from_slice` diff --git a/crates/test-ui/ui/protocol_object_only_protocols.stderr b/crates/test-ui/ui/protocol_object_only_protocols.stderr index 038ea3af0..1eb7b3d9b 100644 --- a/crates/test-ui/ui/protocol_object_only_protocols.stderr +++ b/crates/test-ui/ui/protocol_object_only_protocols.stderr @@ -11,10 +11,10 @@ error[E0277]: the trait bound `NSObject: ImplementedBy` is not satisfi (dyn NSObjectProtocol + Send + 'static) (dyn NSObjectProtocol + Sync + 'static) (dyn NSObjectProtocol + Send + Sync + 'static) - (dyn NSAccessibilityColor + 'static) - (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) - (dyn NSAccessibilityElementProtocol + 'static) - (dyn NSAccessibilityGroup + 'static) + (dyn NSCopying + 'static) + (dyn NSMutableCopying + 'static) + (dyn NSCacheDelegate + 'static) + (dyn NSConnectionDelegate + 'static) and $N others note: required by a bound in `ProtocolObject::

::from_ref` --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs @@ -38,10 +38,10 @@ error[E0277]: the trait bound `dyn Send: ImplementedBy` is not satisfi (dyn NSObjectProtocol + Send + 'static) (dyn NSObjectProtocol + Sync + 'static) (dyn NSObjectProtocol + Send + Sync + 'static) - (dyn NSAccessibilityColor + 'static) - (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) - (dyn NSAccessibilityElementProtocol + 'static) - (dyn NSAccessibilityGroup + 'static) + (dyn NSCopying + 'static) + (dyn NSMutableCopying + 'static) + (dyn NSCacheDelegate + 'static) + (dyn NSConnectionDelegate + 'static) and $N others note: required by a bound in `ProtocolObject::

::from_ref` --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs @@ -65,10 +65,10 @@ error[E0277]: the trait bound `dyn Foo: ImplementedBy` is not satisfie (dyn NSObjectProtocol + Send + 'static) (dyn NSObjectProtocol + Sync + 'static) (dyn NSObjectProtocol + Send + Sync + 'static) - (dyn NSAccessibilityColor + 'static) - (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) - (dyn NSAccessibilityElementProtocol + 'static) - (dyn NSAccessibilityGroup + 'static) + (dyn NSCopying + 'static) + (dyn NSMutableCopying + 'static) + (dyn NSCacheDelegate + 'static) + (dyn NSConnectionDelegate + 'static) and $N others note: required by a bound in `ProtocolObject::

::from_ref` --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs @@ -93,10 +93,10 @@ error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely (dyn NSObjectProtocol + Send + 'static) (dyn NSObjectProtocol + Sync + 'static) (dyn NSObjectProtocol + Send + Sync + 'static) - (dyn NSAccessibilityColor + 'static) - (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) - (dyn NSAccessibilityElementProtocol + 'static) - (dyn NSAccessibilityGroup + 'static) + (dyn NSCopying + 'static) + (dyn NSMutableCopying + 'static) + (dyn NSCacheDelegate + 'static) + (dyn NSConnectionDelegate + 'static) and $N others = note: required because it appears within the type `(*const UnsafeCell<()>, PhantomPinned)` note: required because it appears within the type `PhantomData<(*const UnsafeCell<()>, PhantomPinned)>` @@ -148,10 +148,10 @@ error[E0277]: `UnsafeCell, PhantomPinned)>>` (dyn NSObjectProtocol + Send + 'static) (dyn NSObjectProtocol + Sync + 'static) (dyn NSObjectProtocol + Send + Sync + 'static) - (dyn NSAccessibilityColor + 'static) - (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) - (dyn NSAccessibilityElementProtocol + 'static) - (dyn NSAccessibilityGroup + 'static) + (dyn NSCopying + 'static) + (dyn NSMutableCopying + 'static) + (dyn NSCacheDelegate + 'static) + (dyn NSConnectionDelegate + 'static) and $N others note: required because it appears within the type `objc_object` --> $WORKSPACE/crates/objc-sys/src/object.rs @@ -192,10 +192,10 @@ error[E0277]: `UnsafeCell, PhantomPinned)>>` (dyn NSObjectProtocol + Send + 'static) (dyn NSObjectProtocol + Sync + 'static) (dyn NSObjectProtocol + Send + Sync + 'static) - (dyn NSAccessibilityColor + 'static) - (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) - (dyn NSAccessibilityElementProtocol + 'static) - (dyn NSAccessibilityGroup + 'static) + (dyn NSCopying + 'static) + (dyn NSMutableCopying + 'static) + (dyn NSCacheDelegate + 'static) + (dyn NSConnectionDelegate + 'static) and $N others note: required because it appears within the type `objc_object` --> $WORKSPACE/crates/objc-sys/src/object.rs @@ -236,10 +236,10 @@ error[E0277]: `*const UnsafeCell<()>` cannot be sent between threads safely (dyn NSObjectProtocol + Send + 'static) (dyn NSObjectProtocol + Sync + 'static) (dyn NSObjectProtocol + Send + Sync + 'static) - (dyn NSAccessibilityColor + 'static) - (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) - (dyn NSAccessibilityElementProtocol + 'static) - (dyn NSAccessibilityGroup + 'static) + (dyn NSCopying + 'static) + (dyn NSMutableCopying + 'static) + (dyn NSCacheDelegate + 'static) + (dyn NSConnectionDelegate + 'static) and $N others = note: required because it appears within the type `(*const UnsafeCell<()>, PhantomPinned)` note: required because it appears within the type `PhantomData<(*const UnsafeCell<()>, PhantomPinned)>` @@ -287,13 +287,13 @@ error[E0277]: the trait bound `NSObject: NSCopying` is not satisfied | = help: the following other types implement trait `NSCopying`: ProtocolObject - __RcTestObject - NSCollectionLayoutSection - NSCollectionLayoutGroupCustomItem NSArray NSMutableArray + __RcTestObject NSDictionary NSSet + NSAppleEventDescriptor + NSError and $N others = note: required for `dyn NSCopying` to implement `ImplementedBy` note: required by a bound in `ProtocolObject::

::from_ref` @@ -318,10 +318,10 @@ error[E0277]: the trait bound `dyn NSCopying + Send: ImplementedBy` is (dyn NSObjectProtocol + Send + 'static) (dyn NSObjectProtocol + Sync + 'static) (dyn NSObjectProtocol + Send + Sync + 'static) - (dyn NSAccessibilityColor + 'static) - (dyn NSAccessibilityCustomRotorItemSearchDelegate + 'static) - (dyn NSAccessibilityElementProtocol + 'static) - (dyn NSAccessibilityGroup + 'static) + (dyn NSCopying + 'static) + (dyn NSMutableCopying + 'static) + (dyn NSCacheDelegate + 'static) + (dyn NSConnectionDelegate + 'static) and $N others note: required by a bound in `ProtocolObject::

::from_ref` --> $WORKSPACE/crates/objc2/src/runtime/protocol_object.rs From a7ca37c1bf4195ec825578e47e691c7707e8ba3b Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Sun, 3 Dec 2023 12:11:53 +0100 Subject: [PATCH 12/12] Remove production-readyness warning from README icrate may not really be ready for user-consumption, but it's vastly better than the alternative, so let's start recommending it! --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index e4e3b41cd..4e46e0eb9 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,6 @@ [![License](https://badgen.net/badge/license/MIT/blue)](./LICENSE.txt) [![CI](https://github.com/madsmtm/objc2/actions/workflows/ci.yml/badge.svg)](https://github.com/madsmtm/objc2/actions/workflows/ci.yml) -# DISCLAIMER! These crates are work in progress, and should not be used in production environments. Use the battle-tested `objc` family instead! - -Anyway, thanks for being here, any help testing things out is highly -appreciated! - The two crates you're interested in is probably [`icrate`], which provide a mostly autogenerated interface for Apple's Objective-C frameworks (`AppKit`, `Foundation`, `Metal`, `WebKit`, you name it), and [`objc2`], which contains