Skip to content

Commit

Permalink
Reduce usage of Immutable
Browse files Browse the repository at this point in the history
This is no longer useful since a820fb6 / #626.
  • Loading branch information
madsmtm committed Jun 20, 2024
1 parent 47abe0b commit 8c88e4c
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 65 deletions.
2 changes: 1 addition & 1 deletion crates/objc2/src/__macro_helpers/msg_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod tests {
unsafe impl ClassType for RcTestObjectSubclass {
#[inherits(NSObject)]
type Super = RcTestObject;
type Mutability = mutability::Immutable;
type Mutability = mutability::InteriorMutable;
const NAME: &'static str = "RcTestObjectSubclass";
}

Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/rc/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ use crate::{ffi, ClassType, Message};
/// # unsafe impl ClassType for NSString {
/// # type Super = NSObject;
/// # // This is wrong, but let's do it for the example
/// # type Mutability = objc2::mutability::Immutable;
/// # type Mutability = objc2::mutability::InteriorMutable;
/// # }
/// # );
///
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/src/rc/test_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use core::cell::RefCell;
use core::ptr;

use crate::mutability::Immutable;
use crate::mutability::InteriorMutable;
use crate::rc::{Allocated, DefaultRetained, Retained};
use crate::runtime::{NSObject, NSZone};
use crate::{declare_class, msg_send, msg_send_id, ClassType, DeclaredClass};
Expand Down Expand Up @@ -70,7 +70,7 @@ declare_class!(

unsafe impl ClassType for RcTestObject {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "__RcTestObject";
}

Expand Down
6 changes: 3 additions & 3 deletions crates/objc2/src/runtime/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ mod tests {

use super::*;
use crate::encode::RefEncode;
use crate::mutability::Immutable;
use crate::mutability::InteriorMutable;
use crate::rc::Retained;
use crate::runtime::{NSObject, NSObjectProtocol};
use crate::{
Expand Down Expand Up @@ -824,7 +824,7 @@ mod tests {

unsafe impl<T> ClassType for GenericDeclareClass<T> {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "GenericDeclareClass";

#[inline]
Expand Down Expand Up @@ -867,7 +867,7 @@ mod tests {

unsafe impl ClassType for Custom {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "TestInheritedNSObjectMethodsWork";
}

Expand Down
16 changes: 8 additions & 8 deletions crates/objc2/tests/declare_class.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![deny(deprecated, unreachable_code)]
use core::ptr::{self, NonNull};

use objc2::mutability::Immutable;
use objc2::mutability::InteriorMutable;
use objc2::rc::Retained;
use objc2::runtime::NSObject;
use objc2::{declare_class, extern_methods, sel, ClassType, DeclaredClass};
Expand All @@ -13,7 +13,7 @@ declare_class!(

unsafe impl ClassType for DeclareClassDepreactedMethod {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "DeclareClassDepreactedMethod";
}

Expand Down Expand Up @@ -46,7 +46,7 @@ declare_class!(

unsafe impl ClassType for DeclareClassCfg {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "DeclareClassCfg";
}

Expand Down Expand Up @@ -190,7 +190,7 @@ declare_class!(

unsafe impl ClassType for TestMultipleColonSelector {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "TestMultipleColonSelector";
}

Expand Down Expand Up @@ -265,7 +265,7 @@ declare_class!(

unsafe impl ClassType for DeclareClassAllTheBool {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "DeclareClassAllTheBool";
}

Expand Down Expand Up @@ -330,7 +330,7 @@ declare_class!(

unsafe impl ClassType for DeclareClassUnreachable {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "DeclareClassUnreachable";
}

Expand Down Expand Up @@ -381,7 +381,7 @@ declare_class!(

unsafe impl ClassType for OutParam {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "OutParam";
}

Expand Down Expand Up @@ -471,7 +471,7 @@ fn test_pointer_receiver_allowed() {

unsafe impl ClassType for PointerReceiver {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "PointerReceiver";
}

Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/tests/no_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ new_objc2::declare_class!(

unsafe impl ClassType for CustomObject {
type Super = new_objc2::runtime::NSObject;
type Mutability = new_objc2::mutability::Immutable;
type Mutability = new_objc2::mutability::InteriorMutable;
const NAME: &'static str = "CustomObject";
}

Expand Down Expand Up @@ -134,7 +134,7 @@ new_objc2::extern_class!(

unsafe impl ClassType for NSObject2 {
type Super = new_objc2::runtime::NSObject;
type Mutability = new_objc2::mutability::Immutable;
type Mutability = new_objc2::mutability::InteriorMutable;
const NAME: &'static str = "NSObject";
}
);
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/tests/use_macros.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use objc2::mutability::Immutable;
use objc2::mutability::InteriorMutable;
use objc2::runtime::{AnyClass, NSObject};
use objc2::{class, declare_class, msg_send, sel, ClassType, DeclaredClass};

Expand All @@ -7,7 +7,7 @@ declare_class!(

unsafe impl ClassType for MyObject {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "MyObject";
}

Expand Down
16 changes: 8 additions & 8 deletions crates/tests/src/test_declare_class_protocol.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![cfg(feature = "all")]
use objc2::mutability::Immutable;
use objc2::mutability::InteriorMutable;
use objc2::rc::Retained;
use objc2::runtime::{NSObject, NSZone};
use objc2::{declare_class, ClassType, DeclaredClass, ProtocolType};
Expand All @@ -13,7 +13,7 @@ fn test_declare_class_duplicate() {

unsafe impl ClassType for Custom1 {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "TestDeclareClassDuplicate";
}

Expand All @@ -25,7 +25,7 @@ fn test_declare_class_duplicate() {

unsafe impl ClassType for Custom2 {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "TestDeclareClassDuplicate";
}

Expand All @@ -44,7 +44,7 @@ fn test_declare_class_protocol() {

unsafe impl ClassType for Custom {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "TestDeclareClassProtocolNotFound";
}

Expand Down Expand Up @@ -73,7 +73,7 @@ fn test_declare_class_invalid_method() {

unsafe impl ClassType for Custom {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "TestDeclareClassInvalidMethod";
}

Expand All @@ -100,7 +100,7 @@ fn test_declare_class_missing_protocol_method() {

unsafe impl ClassType for Custom {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "TestDeclareClassMissingProtocolMethod";
}

Expand All @@ -122,7 +122,7 @@ fn test_declare_class_invalid_protocol_method() {

unsafe impl ClassType for Custom {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "TestDeclareClassInvalidProtocolMethod";
}

Expand Down Expand Up @@ -151,7 +151,7 @@ fn test_declare_class_extra_protocol_method() {

unsafe impl ClassType for Custom {
type Super = NSObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "TestDeclareClassExtraProtocolMethod";
}

Expand Down
4 changes: 2 additions & 2 deletions crates/tests/src/test_foundation_retain_semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::ptr;
use std::vec::Vec;

use objc2::mutability::Immutable;
use objc2::mutability::InteriorMutable;
use objc2::rc::Retained;
use objc2::{declare_class, extern_methods, ClassType, DeclaredClass};
use objc2_foundation::{
Expand Down Expand Up @@ -356,7 +356,7 @@ declare_class!(

unsafe impl ClassType for NSCopyingRcTestObject {
type Super = RcTestObject;
type Mutability = Immutable;
type Mutability = InteriorMutable;
const NAME: &'static str = "NSCopyingRcTestObject";
}

Expand Down
19 changes: 19 additions & 0 deletions framework-crates/objc2-app-kit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ pub use self::text::*;
#[allow(unused)]
pub(crate) type UTF32Char = u32; // Or maybe Rust's char?

// TODO: Send + Sync for NSColor. Documentation says:
// > Color objects are immutable and thread-safe
//
// But unsure if this applies for things like `-setFill`?

// TODO: Send + Sync for NSCursor. It is immutable, stated here:
// https://developer.apple.com/documentation/appkit/nscursor/1527062-image?language=objc
//
// But unsure if `push`/`pop` methods are safe from non-main threads?

// NOTE: NSEvent is immutable, so it _may_ be possible to make Send + Sync,
// but let's refrain from doing so, because of:
// > Safely handled only on the same thread, whether that be the main
// > thread or a secondary thread; otherwise you run the risk of having
// > events get out of sequence.
//
// <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaFundamentals/AddingBehaviortoaCocoaProgram/AddingBehaviorCocoa.html#//apple_ref/doc/uid/TP40002974-CH5-SW47>
// <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#//apple_ref/doc/uid/10000057i-CH12-123383>

#[cfg(test)]
mod tests {
#[test]
Expand Down
24 changes: 0 additions & 24 deletions framework-crates/objc2-app-kit/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -217,30 +217,6 @@ class.NSWindow.mutability = "MainThreadOnly"
# Documented as "Thread-Unsafe"
# class.NSResponder.mutability = "InteriorMutable"

# Documentation says:
# > Color objects are immutable and thread-safe
#
# TODO: Send + Sync
class.NSColor.mutability = "Immutable"

# NSCursor is immutable, stated here:
# https://developer.apple.com/documentation/appkit/nscursor/1527062-image?language=objc
#
# TODO: Send + Sync
class.NSCursor.mutability = "Immutable"

# Since this is immutable, it _may_ be possible to make Send+Sync, but
# let's refrain from doing so, because of:
# > Safely handled only on the same thread, whether that be the main
# > thread or a secondary thread; otherwise you run the risk of having
# > events get out of sequence.
# <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaFundamentals/AddingBehaviortoaCocoaProgram/AddingBehaviorCocoa.html#//apple_ref/doc/uid/TP40002974-CH5-SW47>
# <https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html#//apple_ref/doc/uid/10000057i-CH12-123383>
class.NSEvent.mutability = "Immutable"

class.NSTouch.mutability = "Immutable"
class.NSUserInterfaceCompressionOptions.mutability = "Immutable"

###
### Safety
###
Expand Down
3 changes: 0 additions & 3 deletions framework-crates/objc2-cloud-kit/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ ios = "8.0"
tvos = "9.0"
watchos = "3.0"
visionos = "1.0"

class.CKRecordID.mutability = "Immutable"
class.CKRecordZoneID.mutability = "Immutable"
8 changes: 0 additions & 8 deletions framework-crates/objc2-foundation/translation-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,6 @@ class.NSMutableURLRequest.mutability = "InteriorMutableWithSuperclass(Foundation
class.NSEnumerator.mutability = "Mutable"
class.NSDirectoryEnumerator.mutability = "Mutable"

class.NSValue.mutability = "Immutable"
class.NSNumber.mutability = "Immutable"
class.NSDecimalNumber.mutability = "Immutable"

class.NSIndexPath.mutability = "Immutable"

class.NSUUID.mutability = "Immutable"

###
### Safety
###
Expand Down

0 comments on commit 8c88e4c

Please sign in to comment.