Skip to content

Commit

Permalink
Mark Metal protocols as IsRetainable
Browse files Browse the repository at this point in the history
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 gfx-rs/wgpu#5641,
and the hack will become unnecessary after
#563.
  • Loading branch information
madsmtm committed May 20, 2024
1 parent 6b30466 commit d8db2f1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
16 changes: 16 additions & 0 deletions crates/header-translator/src/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2018,6 +2018,22 @@ impl Stmt {
}
write!(f, "IsMainThreadOnly")?;
}
// HACK: Make all Metal protocols retainable (i.e. allow
// using `.retain()` on `&ProtocolObject<dyn MTLDevice>`).
//
// 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();
Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/__framework_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
21 changes: 14 additions & 7 deletions crates/objc2/src/topics/about_generated/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -40,21 +41,27 @@ 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.

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
Expand Down

0 comments on commit d8db2f1

Please sign in to comment.