From d8db2f1352e3b5851cabd95799d10acfb8774138 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 18 Apr 2024 14:30:27 +0200 Subject: [PATCH] Mark Metal protocols as IsRetainable This may technically be a breaking change if the user implemented these protocols themselves on a `Mutable` class, but that'd be unsound anyhow, so I'll consider this a correctness fix. This is useful for wgpu, see https://github.com/gfx-rs/wgpu/pull/5641, and the hack will become unnecessary after https://github.com/madsmtm/objc2/issues/563. --- crates/header-translator/src/stmt.rs | 16 ++++++++++++++ crates/objc2/src/__framework_prelude.rs | 2 +- .../src/topics/about_generated/CHANGELOG.md | 21 ++++++++++++------- generated | 2 +- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/crates/header-translator/src/stmt.rs b/crates/header-translator/src/stmt.rs index 41cc05d1b..89dfb4bf4 100644 --- a/crates/header-translator/src/stmt.rs +++ b/crates/header-translator/src/stmt.rs @@ -2018,6 +2018,22 @@ impl Stmt { } write!(f, "IsMainThreadOnly")?; } + // HACK: Make all Metal protocols retainable (i.e. allow + // using `.retain()` on `&ProtocolObject`). + // + // This is a problem generally, but especially useful in + // Metal, as most of the functionality is only exposed + // through protocols (instead of concrete classes). + // + // This should become unnecessary after #563. + if id.library_name() == "Metal" { + if protocols.is_empty() { + write!(f, ": ")?; + } else { + write!(f, "+ ")?; + } + write!(f, "IsRetainable")?; + } writeln!(f, " {{")?; let required_items = self.required_items(); diff --git a/crates/objc2/src/__framework_prelude.rs b/crates/objc2/src/__framework_prelude.rs index 1b38f575c..4c063469a 100644 --- a/crates/objc2/src/__framework_prelude.rs +++ b/crates/objc2/src/__framework_prelude.rs @@ -15,7 +15,7 @@ pub use crate::encode::{Encode, Encoding, RefEncode}; pub use crate::ffi::{NSInteger, NSIntegerMax, NSUInteger, NSUIntegerMax, IMP}; pub use crate::mutability::{ Immutable, ImmutableWithMutableSubclass, InteriorMutable, IsIdCloneable, IsMainThreadOnly, - MainThreadOnly, Mutable, MutableWithImmutableSuperclass, + IsRetainable, MainThreadOnly, Mutable, MutableWithImmutableSuperclass, }; pub use crate::rc::{Allocated, DefaultId, Id}; pub use crate::runtime::{ diff --git a/crates/objc2/src/topics/about_generated/CHANGELOG.md b/crates/objc2/src/topics/about_generated/CHANGELOG.md index 0de630ce2..f487df374 100644 --- a/crates/objc2/src/topics/about_generated/CHANGELOG.md +++ b/crates/objc2/src/topics/about_generated/CHANGELOG.md @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). This means that they have the usual `ops::BitAnd`, `ops::BitOr`, `ops::Not`, etc. implementations that you would expect from an option enum. +* Added optional support for a few methods depending on types from `libc`. * Added new framework crates: - `CoreBluetooth` / `objc2-core-bluetooth`. - `Virtualization` / `objc2-virtualization`. @@ -40,12 +41,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `PhotosUI` / `objc2-photos-ui`. - `FinderSync` / `objc2-finder-sync`. - `Social` / `objc2-social`. -* Added `objc2_quartz_core::CAMetalDrawable` and - `objc2_quartz_core::CAMetalLayer`. -* Added methods to access `CALayer` from `objc2_app_kit::NSView`. -* Added optional support for a few methods depending on types from `libc`. -* Added `MTLCounterErrorValue`, `MTLCounterDontSample` and - `MTLTextureSwizzleChannelsDefault` Metal constants. +* `objc2-quartz-core`: Added `CAMetalDrawable` and `CAMetalLayer`. +* `objc2-app-kit`: Added methods to access `CALayer` from `NSView`. +* `objc2-metal`: Added `MTLCounterErrorValue`, `MTLCounterDontSample` and + `MTLTextureSwizzleChannelsDefault` constants. ### Changed * Updated SDK from Xcode 15.3 to 15.4. @@ -53,8 +52,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). View the release notes to learn more details: - [15.4](https://developer.apple.com/documentation/xcode-release-notes/xcode-15_4-release-notes) +### Fixed +* `objc2-metal`: All protocols are now marked as `IsRetainable`. + + This may technically break your code if you had some custom object that + implements the protocol, but was marked with `Mutability = Mutable`, but + Metal protocols are assumed retainable by Objective-C code, so that'd have + been unsound anyway. + ### Removed -* `objc2_metal`: Removed internal `__MTLPackedFloat3` and made `MTLPackedFloat3` public. +* `objc2-metal`: Removed internal `__MTLPackedFloat3` and made `MTLPackedFloat3` public. ## 0.2.0 - 2024-04-17 diff --git a/generated b/generated index f666ab4ea..1536b8291 160000 --- a/generated +++ b/generated @@ -1 +1 @@ -Subproject commit f666ab4eaddc36770248493e461a675ccccb0896 +Subproject commit 1536b8291cdfed54711d5f1d105e3a62111470da