diff --git a/crates/header-translator/src/method.rs b/crates/header-translator/src/method.rs index 91d61c8c4..eb152a75d 100644 --- a/crates/header-translator/src/method.rs +++ b/crates/header-translator/src/method.rs @@ -767,32 +767,21 @@ impl fmt::Display for Method { writeln!(f, " #[optional]")?; } - let method_kind = if self.memory_management == MemoryManagement::Normal { - "method" - } else { - "method_id" - }; let error_trailing = if self.is_error { "_" } else { "" }; - writeln!( - f, - " #[{}({}{})]", - method_kind, self.selector, error_trailing - )?; - - let id_mm_name = match &self.memory_management { - // MemoryManagement::IdAlloc => Some("alloc"), // Unsupported - MemoryManagement::IdCopy => Some("copy"), - MemoryManagement::IdMutableCopy => Some("mutableCopy"), - MemoryManagement::IdNew => Some("new"), - MemoryManagement::IdInit => Some("init"), - MemoryManagement::IdOther => Some("none"), - MemoryManagement::Normal => None, - }; - if let Some(id_mm_name) = id_mm_name { - // TODO: Be explicit about when we emit this for better - // compile-times, and when we do it for soundness. - writeln!(f, " #[unsafe(method_family = {id_mm_name})]")?; + writeln!(f, " #[method({}{})]", self.selector, error_trailing)?; + + let method_family = match &self.memory_management { + // MemoryManagement::IdAlloc => "alloc", // Unsupported + MemoryManagement::IdCopy => "copy", + MemoryManagement::IdMutableCopy => "mutableCopy", + MemoryManagement::IdNew => "new", + MemoryManagement::IdInit => "init", + MemoryManagement::IdOther => "none", + MemoryManagement::Normal => "none", }; + // TODO: Be explicit about when we emit this for better + // compile-times, and when we do it for soundness. + writeln!(f, " #[unsafe(method_family = {method_family})]")?; // // Signature diff --git a/crates/header-translator/src/rust_type.rs b/crates/header-translator/src/rust_type.rs index 2bb2768db..7fa58ea95 100644 --- a/crates/header-translator/src/rust_type.rs +++ b/crates/header-translator/src/rust_type.rs @@ -2404,7 +2404,7 @@ impl Ty { // As in `parse_property_return`, the nullability is not guaranteed by // the method, and can also fail in OOM situations, but that is - // handled by `#[method_id(...)]` + // handled by `#[method(...)]` if default_nonnull { match &mut ty { Self::Pointer { nullability, .. } => { @@ -2512,8 +2512,8 @@ impl Ty { // can also fail in OOM situations, so we must still perform an unwrap // to be sure (Swift also uses forced unwrapping here). // - // This unwrap is done by `#[method_id(...)]` when we specify the - // return type as `Retained`. + // This unwrap is done by `#[method(...)]` when we specify the return + // type as `Retained`. if is_copy { match &mut ty { Self::Pointer { nullability, .. } => { diff --git a/crates/objc2/CHANGELOG.md b/crates/objc2/CHANGELOG.md index 0181f483e..845fd3ce1 100644 --- a/crates/objc2/CHANGELOG.md +++ b/crates/objc2/CHANGELOG.md @@ -172,6 +172,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). `AnyObject::downcast_ref` method instead. * Deprecated `Retained::cast`, this has been renamed to `Retained::cast_unchecked`. * Renamed `DeclaredClass` to `DefinedClass`. +* Merged `msg_send!` and `msg_send_id!`. The latter is now deprecated. +* Merged `#[method(...)]` and `#[method_id(...)]` in `extern_methods!` and + `extern_protocol!`. The latter is now deprecated. ### Removed * **BREAKING**: Removed the `ffi::SEL` and `ffi::objc_selector` types. Use diff --git a/crates/objc2/Cargo.toml b/crates/objc2/Cargo.toml index 5b21be633..9beabfe81 100644 --- a/crates/objc2/Cargo.toml +++ b/crates/objc2/Cargo.toml @@ -141,6 +141,8 @@ objc2-foundation = { path = "../../framework-crates/objc2-foundation", default-f "NSObject", "NSRunLoop", "NSString", + "NSURL", + "NSValue", ] } libc = "0.2.158" diff --git a/crates/objc2/examples/class_with_lifetime.rs b/crates/objc2/examples/class_with_lifetime.rs index a93a3d215..28f503c81 100644 --- a/crates/objc2/examples/class_with_lifetime.rs +++ b/crates/objc2/examples/class_with_lifetime.rs @@ -5,10 +5,9 @@ use std::cell::Cell; use std::marker::PhantomData; use std::sync::Once; -use objc2::msg_send_id; use objc2::rc::Retained; use objc2::runtime::{AnyClass, AnyObject, ClassBuilder, NSObject}; -use objc2::{ClassType, Encoding, Message, RefEncode}; +use objc2::{msg_send, ClassType, Encoding, Message, RefEncode}; /// The type of the instance variable that we want to store type Ivar<'a> = &'a Cell; @@ -49,7 +48,7 @@ impl<'a> MyObject<'a> { fn new(number: &'a mut u8) -> Retained { // SAFETY: The instance variable is initialized below. - let this: Retained = unsafe { msg_send_id![Self::class(), new] }; + let this: Retained = unsafe { msg_send![Self::class(), new] }; // It is generally very hard to use `mut` in Objective-C, so let's use // interior mutability instead. diff --git a/crates/objc2/src/__macro_helpers/common_selectors.rs b/crates/objc2/src/__macro_helpers/common_selectors.rs index c1766e771..34217b4df 100644 --- a/crates/objc2/src/__macro_helpers/common_selectors.rs +++ b/crates/objc2/src/__macro_helpers/common_selectors.rs @@ -82,7 +82,7 @@ mod tests { use crate::rc::Retained; use crate::runtime::ClassBuilder; use crate::runtime::NSObject; - use crate::{msg_send_id, ClassType}; + use crate::{msg_send, ClassType}; use super::*; @@ -103,7 +103,7 @@ mod tests { let cls = builder.register(); - let obj: Retained = unsafe { msg_send_id![cls, new] }; + let obj: Retained = unsafe { msg_send![cls, new] }; drop(obj); let has_run_destruct = HAS_RUN.load(Ordering::Relaxed); diff --git a/crates/objc2/src/__macro_helpers/convert.rs b/crates/objc2/src/__macro_helpers/convert.rs index 72f6a4ca0..877e4bf10 100644 --- a/crates/objc2/src/__macro_helpers/convert.rs +++ b/crates/objc2/src/__macro_helpers/convert.rs @@ -1,6 +1,6 @@ use crate::encode::{EncodeArgument, EncodeArguments, EncodeReturn}; -use crate::rc::Retained; -use crate::runtime::Bool; +use crate::rc::{Allocated, Retained}; +use crate::runtime::{AnyObject, Bool, Sel}; use crate::Message; mod argument_private { @@ -88,48 +88,64 @@ mod return_private { } /// Same as [`ConvertArgument`], but for return types. -pub trait ConvertReturn: return_private::Sealed { - /// The inner type that this can be converted to and from. - #[doc(hidden)] - type __Inner: EncodeReturn; - - #[doc(hidden)] - fn __into_defined_return(self) -> Self::__Inner; - - #[doc(hidden)] - fn __from_return(inner: Self::__Inner) -> Self; +/// +/// See `RetainSemantics` for more details. +pub trait ConvertReturn: return_private::Sealed { + type Inner: EncodeReturn; + + #[track_caller] + unsafe fn convert_message_return( + inner: Self::Inner, + receiver_ptr: *mut AnyObject, + sel: Sel, + ) -> Self; + + fn convert_defined_return(self) -> Self::Inner; } impl return_private::Sealed for T {} -impl ConvertReturn for T { - type __Inner = Self; +impl ConvertReturn for T { + type Inner = Self; #[inline] - fn __into_defined_return(self) -> Self::__Inner { - self + unsafe fn convert_message_return( + inner: Self::Inner, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Self { + inner } #[inline] - fn __from_return(inner: Self::__Inner) -> Self { - inner + fn convert_defined_return(self) -> Self::Inner { + self } } impl return_private::Sealed for bool {} -impl ConvertReturn for bool { - type __Inner = Bool; +impl ConvertReturn for bool { + type Inner = Bool; #[inline] - fn __into_defined_return(self) -> Self::__Inner { - Bool::new(self) + unsafe fn convert_message_return( + inner: Self::Inner, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Self { + inner.as_bool() } #[inline] - fn __from_return(inner: Self::__Inner) -> Self { - inner.as_bool() + fn convert_defined_return(self) -> Self::Inner { + Bool::new(self) } } +// Implemented in retain_semantics.rs +impl return_private::Sealed for Retained {} +impl return_private::Sealed for Option> {} +impl return_private::Sealed for Allocated {} + pub trait ConvertArguments { #[doc(hidden)] type __Inner: EncodeArguments; @@ -287,6 +303,9 @@ mod tests { use super::*; use core::any::TypeId; + use core::ptr; + + use crate::sel; #[test] fn convert_normally_noop() { @@ -310,15 +329,22 @@ mod tests { #[test] fn convert_bool() { + let receiver_ptr = ptr::null_mut::(); + let sel = sel!(foo); + assert!(!::__from_defined_param(Bool::NO)); assert!(::__from_defined_param(Bool::YES)); - assert!(!::__from_return(Bool::NO)); - assert!(::__from_return(Bool::YES)); + assert!(!unsafe { + >::convert_message_return(Bool::NO, receiver_ptr, sel) + }); + assert!(unsafe { + >::convert_message_return(Bool::YES, receiver_ptr, sel) + }); assert!(!unsafe { ConvertArgument::__into_argument(false).0 }.as_bool()); assert!(unsafe { ConvertArgument::__into_argument(true).0 }.as_bool()); - assert!(!ConvertReturn::__into_defined_return(false).as_bool()); - assert!(ConvertReturn::__into_defined_return(true).as_bool()); + assert!(!ConvertReturn::<()>::convert_defined_return(false).as_bool()); + assert!(ConvertReturn::<()>::convert_defined_return(true).as_bool()); #[cfg(all(target_vendor = "apple", target_os = "macos", target_arch = "x86_64"))] assert_eq!( diff --git a/crates/objc2/src/__macro_helpers/define_class.rs b/crates/objc2/src/__macro_helpers/define_class.rs index 455a6e557..09d53eed6 100644 --- a/crates/objc2/src/__macro_helpers/define_class.rs +++ b/crates/objc2/src/__macro_helpers/define_class.rs @@ -16,7 +16,7 @@ use crate::runtime::{AnyProtocol, MethodDescription}; use crate::{AllocAnyThread, ClassType, DefinedClass, Message, ProtocolType}; use super::defined_ivars::{register_with_ivars, setup_dealloc}; -use super::{CopyFamily, InitFamily, MaybeUnwrap, MutableCopyFamily, NewFamily, NoneFamily}; +use super::{CopyFamily, InitFamily, MutableCopyFamily, NewFamily, NoneFamily}; /// Helper for determining auto traits of defined classes. /// @@ -97,7 +97,7 @@ where impl MessageReceiveRetained, Ret> for InitFamily where T: Message, - Ret: MaybeOptionRetained>>, + Ret: MaybeOptionRetained, { #[inline] fn into_return(obj: Ret) -> RetainedReturnValue { @@ -144,12 +144,16 @@ where /// Helper trait for specifying an `Retained` or an `Option>`. /// /// (Both of those are valid return types from define_class! `#[method_id]`). -pub trait MaybeOptionRetained: MaybeUnwrap { +pub trait MaybeOptionRetained { + type Inner; + fn consumed_return(self) -> RetainedReturnValue; fn autorelease_return(self) -> RetainedReturnValue; } impl MaybeOptionRetained for Retained { + type Inner = T; + #[inline] fn consumed_return(self) -> RetainedReturnValue { let ptr: *mut T = Retained::into_raw(self); @@ -164,6 +168,8 @@ impl MaybeOptionRetained for Retained { } impl MaybeOptionRetained for Option> { + type Inner = T; + #[inline] fn consumed_return(self) -> RetainedReturnValue { let ptr: *mut T = Retained::consume_as_ptr_option(self); diff --git a/crates/objc2/src/__macro_helpers/defined_ivars.rs b/crates/objc2/src/__macro_helpers/defined_ivars.rs index c20c21fd2..0ecffb7d7 100644 --- a/crates/objc2/src/__macro_helpers/defined_ivars.rs +++ b/crates/objc2/src/__macro_helpers/defined_ivars.rs @@ -435,7 +435,7 @@ mod tests { use super::*; use crate::rc::{Allocated, PartialInit, RcTestObject, Retained, ThreadTestData}; use crate::runtime::NSObject; - use crate::{define_class, msg_send, msg_send_id, AllocAnyThread, Message}; + use crate::{define_class, msg_send, AllocAnyThread, Message}; /// Initialize superclasses, but not own class. unsafe fn init_only_superclasses(obj: Allocated) -> Retained @@ -445,7 +445,8 @@ mod tests { unsafe { Retained::from_raw(msg_send![super(Allocated::into_ptr(obj)), init]) }.unwrap() } - /// Initialize, but fail to finalize (which is only done by `msg_send_id!`). + /// Initialize, but fail to finalize (which is done internally by + /// `msg_send!` when returning `Retained`). unsafe fn init_no_finalize(obj: Allocated) -> Retained where T::Super: ClassType, @@ -457,7 +458,7 @@ mod tests { /// Initialize properly. unsafe fn init(obj: Allocated) -> Retained { - unsafe { msg_send_id![obj, init] } + unsafe { msg_send![obj, init] } } #[test] @@ -505,7 +506,7 @@ mod tests { unsafe impl ImplsDrop { #[method_id(init)] fn init(this: Allocated) -> Option> { - unsafe { msg_send_id![super(this.set_ivars(())), init] } + unsafe { msg_send![super(this.set_ivars(())), init] } } } ); @@ -539,7 +540,7 @@ mod tests { unsafe impl IvarsImplDrop { #[method_id(init)] fn init(this: Allocated) -> Option> { - unsafe { msg_send_id![super(this.set_ivars(IvarThatImplsDrop)), init] } + unsafe { msg_send![super(this.set_ivars(IvarThatImplsDrop)), init] } } } ); @@ -567,7 +568,7 @@ mod tests { unsafe impl BothIvarsAndTypeImplsDrop { #[method_id(init)] fn init(this: Allocated) -> Option> { - unsafe { msg_send_id![super(this.set_ivars(IvarThatImplsDrop)), init] } + unsafe { msg_send![super(this.set_ivars(IvarThatImplsDrop)), init] } } } ); @@ -637,7 +638,7 @@ mod tests { unsafe impl IvarZst { #[method_id(init)] fn init(this: Allocated) -> Option> { - unsafe { msg_send_id![super(this.set_ivars(Cell::new(Ivar))), init] } + unsafe { msg_send![super(this.set_ivars(Cell::new(Ivar))), init] } } } ); @@ -701,7 +702,7 @@ mod tests { #[method_id(init)] fn init(this: Allocated) -> Option> { let this = this.set_ivars(Cell::new(Some(RcTestObject::new()))); - unsafe { msg_send_id![super(this), init] } + unsafe { msg_send![super(this), init] } } } ); @@ -764,7 +765,7 @@ mod tests { int: Cell::new(42), obj: Cell::new(RcTestObject::new()), }); - unsafe { msg_send_id![super(this), init] } + unsafe { msg_send![super(this), init] } } } ); @@ -846,7 +847,7 @@ mod tests { } let obj = DropPanics::alloc().set_ivars(()); - let obj: Retained = unsafe { msg_send_id![super(obj), init] }; + let obj: Retained = unsafe { msg_send![super(obj), init] }; drop(obj); } @@ -870,7 +871,7 @@ mod tests { ); let obj = IvarDropPanics::alloc().set_ivars(DropPanics); - let obj: Retained = unsafe { msg_send_id![super(obj), init] }; + let obj: Retained = unsafe { msg_send![super(obj), init] }; drop(obj); } @@ -907,7 +908,7 @@ mod tests { } let obj = DropRetainsAndLeaksSelf::alloc().set_ivars(()); - let obj: Retained = unsafe { msg_send_id![super(obj), init] }; + let obj: Retained = unsafe { msg_send![super(obj), init] }; drop(obj); // Suddenly, the object is alive again! diff --git a/crates/objc2/src/__macro_helpers/method_family.rs b/crates/objc2/src/__macro_helpers/method_family.rs index c28d25f09..74447ab21 100644 --- a/crates/objc2/src/__macro_helpers/method_family.rs +++ b/crates/objc2/src/__macro_helpers/method_family.rs @@ -6,7 +6,7 @@ /// The slight difference here is: /// - The method may be annotated with the `objc_method_family` attribute, /// which would cause it to be in a different family. That this is not the -/// case is part of the `unsafe` contract of `msg_send_id!`. +/// case is part of the `unsafe` contract of `msg_send!`. /// - The method may not obey the added restrictions of the method family. /// The added restrictions are: /// - `new`, `alloc`, `copy` and `mutableCopy`: The method must return a @@ -39,6 +39,18 @@ pub type NoneFamily = MethodFamily<6>; /// Used for a fast-path optimization using `objc_alloc`. pub type AllocSelector = MethodFamily<7>; +// These are used to avoid trying to do retain-semantics for these special +// selectors that would otherwise fall under `NoneFamily`. + +/// The `retain` selector itself. +pub type RetainSelector = MethodFamily<8>; +/// The `release` selector itself. +pub type ReleaseSelector = MethodFamily<9>; +/// The `autorelease` selector itself. +pub type AutoreleaseSelector = MethodFamily<10>; +/// The `dealloc` selector itself. +pub type DeallocSelector = MethodFamily<11>; + /// Helper module where `#[unsafe(method_family = $family:ident)]` will import /// its value from. #[allow(non_camel_case_types)] diff --git a/crates/objc2/src/__macro_helpers/mod.rs b/crates/objc2/src/__macro_helpers/mod.rs index 7956514b3..4e96dd312 100644 --- a/crates/objc2/src/__macro_helpers/mod.rs +++ b/crates/objc2/src/__macro_helpers/mod.rs @@ -23,10 +23,10 @@ pub(crate) mod defined_ivars; mod image_info; mod method_family; mod module_info; -mod msg_send; mod msg_send_retained; mod null_error; mod os_version; +mod retain_semantics; mod sync_unsafe_cell; mod writeback; @@ -41,13 +41,16 @@ pub use self::define_class::{ pub use self::defined_ivars::DefinedIvarsHelper; pub use self::image_info::ImageInfo; pub use self::method_family::{ - method_family, method_family_import, AllocFamily, AllocSelector, CopyFamily, InitFamily, - MethodFamily, MutableCopyFamily, NewFamily, NoneFamily, + method_family, method_family_import, AllocFamily, AllocSelector, AutoreleaseSelector, + CopyFamily, DeallocSelector, InitFamily, MethodFamily, MutableCopyFamily, NewFamily, + NoneFamily, ReleaseSelector, RetainSelector, }; pub use self::module_info::ModuleInfo; -pub use self::msg_send::MsgSend; -pub use self::msg_send_retained::{MaybeUnwrap, MsgSendRetained, MsgSendSuperRetained}; +pub use self::msg_send_retained::{MsgSend, MsgSendError, MsgSendSuper, MsgSendSuperError}; pub use self::os_version::{is_available, AvailableVersion, OSVersion}; +pub use self::retain_semantics::{ + KindDefined, KindSendMessage, KindSendMessageSuper, RetainSemantics, +}; pub use self::sync_unsafe_cell::SyncUnsafeCell; /// Disallow using this passed in value in const and statics for forwards diff --git a/crates/objc2/src/__macro_helpers/msg_send.rs b/crates/objc2/src/__macro_helpers/msg_send.rs deleted file mode 100644 index 58f543352..000000000 --- a/crates/objc2/src/__macro_helpers/msg_send.rs +++ /dev/null @@ -1,254 +0,0 @@ -use core::mem::ManuallyDrop; -use core::ptr; - -use crate::encode::RefEncode; -use crate::rc::Retained; -use crate::runtime::{AnyClass, AnyObject, MessageReceiver, Sel}; -use crate::{ClassType, Encode, Message}; - -use super::null_error::encountered_error; -use super::{ConvertArguments, ConvertReturn, TupleExtender}; - -pub trait MsgSend: Sized { - type Inner: ?Sized + RefEncode; - - fn into_raw_receiver(self) -> *mut AnyObject; - - #[inline] - #[track_caller] - unsafe fn send_message(self, sel: Sel, args: A) -> R - where - A: ConvertArguments, - R: ConvertReturn, - { - // SAFETY: The writeback helper is not leaked (it is dropped at the - // end of this scope). - // - // TODO: If we want `objc_retainAutoreleasedReturnValue` to work, we - // must not do any work before it has been run; so somehow, we should - // do that _before_ the helper is dropped! - let (args, _helper) = unsafe { A::__into_arguments(args) }; - - // SAFETY: Upheld by caller. - let result = unsafe { MessageReceiver::send_message(self.into_raw_receiver(), sel, args) }; - - R::__from_return(result) - } - - #[inline] - #[track_caller] - unsafe fn send_super_message(self, superclass: &AnyClass, sel: Sel, args: A) -> R - where - A: ConvertArguments, - R: ConvertReturn, - { - // SAFETY: The writeback helper is not leaked (it is dropped at the - // end of this scope). - let (args, _helper) = unsafe { A::__into_arguments(args) }; - - // SAFETY: Upheld by caller. - let result = unsafe { - MessageReceiver::send_super_message(self.into_raw_receiver(), superclass, sel, args) - }; - - R::__from_return(result) - } - - #[inline] - #[track_caller] - unsafe fn send_super_message_static(self, sel: Sel, args: A) -> R - where - Self::Inner: ClassType, - ::Super: ClassType, - A: ConvertArguments, - R: ConvertReturn, - { - unsafe { self.send_super_message(::Super::class(), sel, args) } - } - - // Error functions below. See MsgSendRetained::send_message_retained_error for further - // details. - // - // Some of this could be abstracted away using closures, but that would - // interfere with `#[track_caller]`, so we avoid doing that. - - #[inline] - #[track_caller] - unsafe fn send_message_error(self, sel: Sel, args: A) -> Result<(), Retained> - where - *mut *mut E: Encode, - A: TupleExtender<*mut *mut E>, - >::PlusOneArgument: ConvertArguments, - E: ClassType, - { - let mut err: *mut E = ptr::null_mut(); - let args = args.add_argument(&mut err); - let res: bool = unsafe { self.send_message(sel, args) }; - if res { - Ok(()) - } else { - Err(unsafe { encountered_error(err) }) - } - } - - #[inline] - #[track_caller] - unsafe fn send_super_message_error( - self, - superclass: &AnyClass, - sel: Sel, - args: A, - ) -> Result<(), Retained> - where - *mut *mut E: Encode, - A: TupleExtender<*mut *mut E>, - >::PlusOneArgument: ConvertArguments, - E: ClassType, - { - let mut err: *mut E = ptr::null_mut(); - let args = args.add_argument(&mut err); - let res: bool = unsafe { self.send_super_message(superclass, sel, args) }; - if res { - Ok(()) - } else { - Err(unsafe { encountered_error(err) }) - } - } - - #[inline] - #[track_caller] - unsafe fn send_super_message_static_error( - self, - sel: Sel, - args: A, - ) -> Result<(), Retained> - where - Self::Inner: ClassType, - ::Super: ClassType, - *mut *mut E: Encode, - A: TupleExtender<*mut *mut E>, - >::PlusOneArgument: ConvertArguments, - E: ClassType, - { - let mut err: *mut E = ptr::null_mut(); - let args = args.add_argument(&mut err); - let res: bool = unsafe { self.send_super_message_static(sel, args) }; - if res { - Ok(()) - } else { - Err(unsafe { encountered_error(err) }) - } - } -} - -impl MsgSend for T { - type Inner = T::__Inner; - - #[inline] - fn into_raw_receiver(self) -> *mut AnyObject { - MessageReceiver::__as_raw_receiver(self) - } -} - -impl MsgSend for &Retained { - type Inner = T; - - #[inline] - fn into_raw_receiver(self) -> *mut AnyObject { - (Retained::as_ptr(self) as *mut T).cast() - } -} - -impl MsgSend for ManuallyDrop> { - type Inner = T; - - #[inline] - fn into_raw_receiver(self) -> *mut AnyObject { - Retained::into_raw(ManuallyDrop::into_inner(self)).cast() - } -} - -#[cfg(test)] -mod tests { - use crate::rc::{autoreleasepool, RcTestObject, ThreadTestData}; - use crate::runtime::NSObject; - use crate::{define_class, msg_send, msg_send_id, test_utils}; - - use super::*; - - #[test] - fn test_send_message_manuallydrop() { - let obj = ManuallyDrop::new(test_utils::custom_object()); - unsafe { - let _: () = msg_send![obj, release]; - }; - // `obj` is consumed, can't use here - } - - macro_rules! test_error_bool { - ($expected:expr, $($obj:tt)*) => { - // Succeeds - let res: Result<(), Retained> = unsafe { - msg_send![$($obj)*, boolAndShouldError: false, error: _] - }; - assert_eq!(res, Ok(())); - $expected.assert_current(); - - // Errors - let res = autoreleasepool(|_pool| { - // `Ok` type is inferred to be `()` - let res: Retained = unsafe { - msg_send![$($obj)*, boolAndShouldError: true, error: _] - }.expect_err("not err"); - $expected.alloc += 1; - $expected.init += 1; - $expected.autorelease += 1; - $expected.retain += 1; - $expected.assert_current(); - res - }); - $expected.release += 1; - $expected.assert_current(); - - drop(res); - $expected.release += 1; - $expected.drop += 1; - $expected.assert_current(); - } - } - - define_class!( - #[unsafe(super(RcTestObject, NSObject))] - #[name = "RcTestObjectSubclass"] - #[derive(Debug, PartialEq, Eq)] - struct RcTestObjectSubclass; - ); - - #[cfg_attr(not(test), allow(unused))] - impl RcTestObjectSubclass { - fn new() -> Retained { - unsafe { msg_send_id![Self::class(), new] } - } - } - - #[test] - fn test_error_bool() { - let mut expected = ThreadTestData::current(); - - let cls = RcTestObject::class(); - test_error_bool!(expected, cls); - - let obj = RcTestObject::new(); - expected.alloc += 1; - expected.init += 1; - test_error_bool!(expected, &obj); - - let obj = RcTestObjectSubclass::new(); - expected.alloc += 1; - expected.init += 1; - test_error_bool!(expected, &obj); - test_error_bool!(expected, super(&obj)); - test_error_bool!(expected, super(&obj, RcTestObjectSubclass::class())); - test_error_bool!(expected, super(&obj, RcTestObject::class())); - } -} diff --git a/crates/objc2/src/__macro_helpers/msg_send_retained.rs b/crates/objc2/src/__macro_helpers/msg_send_retained.rs index 9d8c1632d..86e32c4ba 100644 --- a/crates/objc2/src/__macro_helpers/msg_send_retained.rs +++ b/crates/objc2/src/__macro_helpers/msg_send_retained.rs @@ -1,253 +1,56 @@ -use core::ptr::{self, NonNull}; +use core::ptr; use crate::encode::{Encode, RefEncode}; -use crate::rc::{Allocated, PartialInit, Retained}; -use crate::runtime::{AnyClass, AnyObject, Sel}; -use crate::{sel, ClassType, DefinedClass, Message}; +use crate::rc::{Allocated, Retained}; +use crate::runtime::{AnyClass, MessageReceiver, Sel}; +use crate::{ClassType, Message}; -use super::defined_ivars::set_finalized; use super::null_error::encountered_error; use super::{ - AllocFamily, AllocSelector, ConvertArguments, CopyFamily, InitFamily, MsgSend, - MutableCopyFamily, NewFamily, NoneFamily, TupleExtender, + AllocSelector, ConvertArguments, KindSendMessage, KindSendMessageSuper, RetainSemantics, + TupleExtender, }; -pub trait MsgSendRetained { - #[track_caller] - unsafe fn send_message_retained>( - obj: T, - sel: Sel, - args: A, - ) -> R; +// +// MsgSend +// - /// Add an extra error argument to the argument list, call - /// `send_message_retained` with that, and return an error if one occurred. - #[inline] +pub trait MsgSend { #[track_caller] - unsafe fn send_message_retained_error( - obj: T, - sel: Sel, - args: A, - ) -> Result> - where - *mut *mut E: Encode, - A: TupleExtender<*mut *mut E>, - >::PlusOneArgument: ConvertArguments, - E: ClassType, - Option: MaybeUnwrap, - { - let mut err: *mut E = ptr::null_mut(); - let args = args.add_argument(&mut err); - let res: Option = unsafe { Self::send_message_retained(obj, sel, args) }; - // As per the Cocoa documentation: - // > Success or failure is indicated by the return value of the - // > method. Although Cocoa methods that indirectly return error - // > objects in the Cocoa error domain are guaranteed to return such - // > objects if the method indicates failure by directly returning - // > `nil` or `NO`, you should always check that the return value is - // > `nil` or `NO` before attempting to do anything with the `NSError` - // > object. - if let Some(res) = res { - // In this case, the error is likely not created. If it is, it is - // autoreleased anyhow, so it would be a waste to retain and - // release it here. - Ok(res) - } else { - // In this case, the error has very likely been created, but has - // been autoreleased (as is common for "out parameters", see - // `src/__macro_helpers/writeback.rs`). Hence we need to retain it - // if we want it to live across autorelease pools. - // - // SAFETY: The message send is guaranteed to populate the error - // object, or leave it as NULL. The error is shared, and all - // holders of the error know this, so is safe to retain. - Err(unsafe { encountered_error(err) }) - } - } + unsafe fn send_message(receiver: Receiver, sel: Sel, args: A) -> Return; } -/// new: T -> Option> -/// alloc: &AnyClass -> Allocated -/// init: PartialInit -> Option> // Changed -/// copy/mutableCopy: T -> Option> -/// others: T -> Option> -#[doc(hidden)] -pub trait MsgSendSuperRetained { - type Inner: ?Sized + RefEncode; - - unsafe fn send_super_message_retained>( - obj: T, - superclass: &AnyClass, - sel: Sel, - args: A, - ) -> R; - - #[inline] - #[track_caller] - unsafe fn send_super_message_retained_static>( - obj: T, - sel: Sel, - args: A, - ) -> R - where - Self::Inner: ClassType, - ::Super: ClassType, - { - unsafe { - Self::send_super_message_retained( - obj, - ::Super::class(), - sel, - args, - ) - } - } - - #[inline] - #[track_caller] - unsafe fn send_super_message_retained_error( - obj: T, - superclass: &AnyClass, - sel: Sel, - args: A, - ) -> Result> - where - *mut *mut E: Encode, - A: TupleExtender<*mut *mut E>, - >::PlusOneArgument: ConvertArguments, - E: ClassType, - Option: MaybeUnwrap, - { - let mut err: *mut E = ptr::null_mut(); - let args = args.add_argument(&mut err); - // SAFETY: See `send_message_retained_error` - let res: Option = - unsafe { Self::send_super_message_retained(obj, superclass, sel, args) }; - if let Some(res) = res { - Ok(res) - } else { - // SAFETY: See `send_message_retained_error` - Err(unsafe { encountered_error(err) }) - } - } - - #[inline] - #[track_caller] - unsafe fn send_super_message_retained_static_error( - obj: T, - sel: Sel, - args: A, - ) -> Result> - where - Self::Inner: ClassType, - ::Super: ClassType, - *mut *mut E: Encode, - A: TupleExtender<*mut *mut E>, - >::PlusOneArgument: ConvertArguments, - E: ClassType, - Option: MaybeUnwrap, - { - let mut err: *mut E = ptr::null_mut(); - let args = args.add_argument(&mut err); - // SAFETY: See `send_message_retained_error` - let res: Option = unsafe { Self::send_super_message_retained_static(obj, sel, args) }; - if let Some(res) = res { - Ok(res) - } else { - // SAFETY: See `send_message_retained_error` - Err(unsafe { encountered_error(err) }) - } - } -} - -impl MsgSendRetained>> for NewFamily { - #[inline] - unsafe fn send_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>>, - >( - obj: T, - sel: Sel, - args: A, - ) -> R { - let ptr = obj.into_raw_receiver(); - // SAFETY: Checked by caller - let obj = unsafe { MsgSend::send_message(ptr, sel, args) }; - // SAFETY: The selector is `new`, so this has +1 retain count - let obj = unsafe { Retained::from_raw(obj) }; - - // SAFETY: The object is still valid after a message send to a `new` - // method - it would not be if the method was `init`. - R::maybe_unwrap::(obj, (unsafe { ptr.as_ref() }, sel)) - } -} - -impl MsgSendSuperRetained>> for NewFamily { - type Inner = T::Inner; - +impl MsgSend for MethodFamily +where + MethodFamily: RetainSemantics, +{ #[inline] - unsafe fn send_super_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>>, - >( - obj: T, - superclass: &AnyClass, - sel: Sel, - args: A, - ) -> R { - let ptr = obj.into_raw_receiver(); - // SAFETY: Same as in `send_message_retained` - let obj = unsafe { MsgSend::send_super_message(ptr, superclass, sel, args) }; - // SAFETY: Same as in `send_message_retained` - let obj = unsafe { Retained::from_raw(obj) }; - // SAFETY: Same as in `send_message_retained` - R::maybe_unwrap::(obj, (unsafe { ptr.as_ref() }, sel)) - } -} + unsafe fn send_message(receiver: Receiver, sel: Sel, args: A) -> Return { + let ptr = Self::prepare_message_send(receiver).__as_raw_receiver(); -impl MsgSendRetained<&'_ AnyClass, Allocated> for AllocFamily { - #[inline] - unsafe fn send_message_retained>>( - cls: &AnyClass, - sel: Sel, - args: A, - ) -> R { - // SAFETY: Checked by caller - let obj = unsafe { MsgSend::send_message(cls, sel, args) }; - // SAFETY: The selector is `alloc`, so this has +1 retain count - let obj = unsafe { Allocated::new(obj) }; - R::maybe_unwrap::(obj, ()) - } -} + // SAFETY: The writeback helper is not leaked (it is dropped at the + // end of this scope). + let (args, _helper) = unsafe { A::__into_arguments(args) }; -impl MsgSendSuperRetained<&'_ AnyClass, Allocated> for AllocFamily { - type Inner = AnyClass; + // SAFETY: Upheld by caller. + let ret = unsafe { MessageReceiver::send_message(ptr, sel, args) }; - #[inline] - unsafe fn send_super_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>, - >( - cls: &AnyClass, - superclass: &AnyClass, - sel: Sel, - args: A, - ) -> R { - // SAFETY: Same as in `send_message_retained` - let obj = unsafe { MsgSend::send_super_message(cls, superclass, sel, args) }; - // SAFETY: Same as in `send_message_retained` - let obj = unsafe { Allocated::new(obj) }; - R::maybe_unwrap::(obj, ()) + // SAFETY: The pointers are valid (or, in the case of the receiver + // pointer, at least valid when the message send is not `init`). + unsafe { Self::convert_message_return(ret, ptr, sel) } } } -impl MsgSendRetained<&'_ AnyClass, Allocated> for AllocSelector { +impl MsgSend<&AnyClass, Allocated> for AllocSelector +where + Return: Message, +{ #[inline] - unsafe fn send_message_retained>>( + unsafe fn send_message( cls: &AnyClass, sel: Sel, args: A, - ) -> R { + ) -> Allocated { // Available on non-fragile Apple runtimes. #[cfg(all( target_vendor = "apple", @@ -261,10 +64,9 @@ impl MsgSendRetained<&'_ AnyClass, Allocated> for AllocSelector { let _ = args; // SAFETY: Checked by caller. - let obj: *mut T = unsafe { crate::ffi::objc_alloc(cls).cast() }; + let obj: *mut Return = unsafe { crate::ffi::objc_alloc(cls).cast() }; // SAFETY: The object is newly allocated, so this has +1 retain count - let obj = unsafe { Allocated::new(obj) }; - R::maybe_unwrap::(obj, ()) + unsafe { Allocated::new(obj) } } #[cfg(not(all( target_vendor = "apple", @@ -272,358 +74,382 @@ impl MsgSendRetained<&'_ AnyClass, Allocated> for AllocSelector { )))] { // SAFETY: Checked by caller - unsafe { AllocFamily::send_message_retained(cls, sel, args) } + unsafe { super::AllocFamily::send_message(cls, sel, args) } } } } -impl MsgSendRetained, Option>> for InitFamily { - #[inline] - unsafe fn send_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>>, - >( - obj: Allocated, - sel: Sel, - args: A, - ) -> R { - let ptr = Allocated::into_ptr(obj); - // SAFETY: `ptr` may be null here, but that's fine since the return - // is `*mut T`, which is one of the few types where messages to nil is - // allowed. - // - // We do this for efficiency, to avoid having a branch that the user - // did not intend after every `alloc`. - let obj = unsafe { MsgSend::send_message(ptr, sel, args) }; - // SAFETY: The selector is `init`, so this has +1 retain count - let obj = unsafe { Retained::from_raw(obj) }; - R::maybe_unwrap::(obj, (ptr.cast(), sel)) - } -} +// +// MsgSendSuper +// -impl MsgSendSuperRetained, Option>> for InitFamily { - type Inner = T; +pub trait MsgSendSuper { + type Inner: ?Sized + RefEncode; - #[inline] - unsafe fn send_super_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>>, - >( - obj: PartialInit, + #[track_caller] + unsafe fn send_super_message( + receiver: Receiver, superclass: &AnyClass, sel: Sel, args: A, - ) -> R { - let ptr = PartialInit::into_ptr(obj); - // SAFETY: Same as `send_message_retained`. - let ptr = unsafe { MsgSend::send_super_message(ptr, superclass, sel, args) }; - // SAFETY: The returned pointer is the same as the one we passed in. - // - // TODO: If this is not the case, a lot will have gone wrong anyhow, - // so unsure if we can do anything better than just ignore the issue? - if let Some(ptr) = NonNull::new(ptr) { - unsafe { set_finalized(ptr) }; - } - // SAFETY: Same as `send_message_retained` - let obj = unsafe { Retained::from_raw(ptr) }; - R::maybe_unwrap::(obj, (ptr.cast(), sel)) - } -} + ) -> Return; -impl MsgSendRetained>> for CopyFamily { #[inline] - unsafe fn send_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>>, - >( - obj: T, + #[track_caller] + unsafe fn send_super_message_static( + receiver: Receiver, sel: Sel, args: A, - ) -> R { - // SAFETY: Checked by caller - let obj = unsafe { MsgSend::send_message(obj, sel, args) }; - // SAFETY: The selector is `copy` or `mutableCopy`, so this has +1 - // retain count - let obj = unsafe { Retained::from_raw(obj) }; - R::maybe_unwrap::(obj, ()) + ) -> Return + where + Self::Inner: ClassType, + ::Super: ClassType, + { + unsafe { + Self::send_super_message( + receiver, + ::Super::class(), + sel, + args, + ) + } } } -impl MsgSendSuperRetained>> for CopyFamily { - type Inner = T::Inner; +impl MsgSendSuper for MethodFamily +where + MethodFamily: RetainSemantics, +{ + type Inner = <>::ReceiverInner as MessageReceiver>::__Inner; #[inline] - unsafe fn send_super_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>>, - >( - obj: T, + unsafe fn send_super_message( + receiver: Receiver, superclass: &AnyClass, sel: Sel, args: A, - ) -> R { - // SAFETY: Same as in `send_message_retained` - let obj = unsafe { MsgSend::send_super_message(obj, superclass, sel, args) }; - // SAFETY: Same as in `send_message_retained` - let obj = unsafe { Retained::from_raw(obj) }; - R::maybe_unwrap::(obj, ()) + ) -> Return { + let ptr = Self::prepare_message_send(receiver).__as_raw_receiver(); + + // SAFETY: The writeback helper is not leaked (it is dropped at the + // end of this scope). + let (args, _helper) = unsafe { A::__into_arguments(args) }; + + // SAFETY: Upheld by caller. + let ret = unsafe { MessageReceiver::send_super_message(ptr, superclass, sel, args) }; + + // SAFETY: The pointers are valid (or, in the case of the receiver + // pointer, at least valid when the message send is not `init`). + unsafe { Self::convert_message_return(ret, ptr, sel) } } } -impl MsgSendRetained>> - for MutableCopyFamily -{ - #[inline] - unsafe fn send_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>>, - >( - obj: T, +// +// MsgSendError +// + +pub trait MsgSendError { + /// Add an extra error argument to the argument list, call `send_message` + /// with that, and return an error if one occurred. + #[track_caller] + unsafe fn send_message_error( + receiver: Receiver, sel: Sel, args: A, - ) -> R { - // SAFETY: Checked by caller - let obj = unsafe { MsgSend::send_message(obj, sel, args) }; - // SAFETY: The selector is `copy` or `mutableCopy`, so this has +1 - // retain count - let obj = unsafe { Retained::from_raw(obj) }; - R::maybe_unwrap::(obj, ()) - } + ) -> Result> + where + *mut *mut E: Encode, + A: TupleExtender<*mut *mut E>, + >::PlusOneArgument: ConvertArguments, + E: ClassType; } -impl MsgSendSuperRetained>> - for MutableCopyFamily +// `Option>` return. +impl MsgSendError> for MethodFamily +where + MethodFamily: MsgSend>>, { - type Inner = T::Inner; - #[inline] - unsafe fn send_super_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>>, - >( - obj: T, - superclass: &AnyClass, + unsafe fn send_message_error( + receiver: Receiver, sel: Sel, args: A, - ) -> R { - // SAFETY: Same as in `send_message_retained` - let obj = unsafe { MsgSend::send_super_message(obj, superclass, sel, args) }; - // SAFETY: Same as in `send_message_retained` - let obj = unsafe { Retained::from_raw(obj) }; - R::maybe_unwrap::(obj, ()) + ) -> Result, Retained> + where + *mut *mut E: Encode, + A: TupleExtender<*mut *mut E>, + >::PlusOneArgument: ConvertArguments, + E: ClassType, + { + let mut err: *mut E = ptr::null_mut(); + let args = args.add_argument(&mut err); + let ret = unsafe { Self::send_message(receiver, sel, args) }; + // As per the Cocoa documentation: + // > Success or failure is indicated by the return value of the + // > method. Although Cocoa methods that indirectly return error + // > objects in the Cocoa error domain are guaranteed to return such + // > objects if the method indicates failure by directly returning + // > `nil` or `NO`, you should always check that the return value is + // > `nil` or `NO` before attempting to do anything with the `NSError` + // > object. + if let Some(ret) = ret { + // In this case, the error is likely not created. If it is, it is + // autoreleased anyhow, so it would be a waste to retain and + // release it here. + Ok(ret) + } else { + // In this case, the error has very likely been created, but has + // been autoreleased (as is common for "out parameters", see + // `src/__macro_helpers/writeback.rs`). Hence we need to retain it + // if we want it to live across autorelease pools. + // + // SAFETY: The message send is guaranteed to populate the error + // object, or leave it as NULL. The error is shared, and all + // holders of the error know this, so is safe to retain. + Err(unsafe { encountered_error(err) }) + } } } -impl MsgSendRetained>> for NoneFamily { +// Bool return. +impl MsgSendError for MethodFamily +where + MethodFamily: MsgSend, +{ #[inline] - unsafe fn send_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>>, - >( - obj: T, + unsafe fn send_message_error( + receiver: Receiver, sel: Sel, args: A, - ) -> R { - let ptr = obj.into_raw_receiver(); - // SAFETY: Checked by caller - let obj = unsafe { MsgSend::send_message(ptr, sel, args) }; - // All code between the message send and the `retain_autoreleased` - // must be able to be optimized away for this to work. - - // SAFETY: The selector is not `new`, `alloc`, `init`, `copy` nor - // `mutableCopy`, so the object must be manually retained. - let obj = unsafe { Retained::retain_autoreleased(obj) }; - - // SAFETY: The object is still valid after a message send to a - // normal method - it would not be if the method was `init`. - R::maybe_unwrap::(obj, (unsafe { ptr.as_ref() }, sel)) + ) -> Result<(), Retained> + where + *mut *mut E: Encode, + A: TupleExtender<*mut *mut E>, + >::PlusOneArgument: ConvertArguments, + E: ClassType, + { + let mut err: *mut E = ptr::null_mut(); + let args = args.add_argument(&mut err); + let ret = unsafe { Self::send_message(receiver, sel, args) }; + if ret { + Ok(()) + } else { + Err(unsafe { encountered_error(err) }) + } } } -impl MsgSendSuperRetained>> for NoneFamily { - type Inner = T::Inner; +// +// MsgSendSuperError +// + +pub trait MsgSendSuperError { + type Inner: ?Sized + RefEncode; - #[inline] - unsafe fn send_super_message_retained< - A: ConvertArguments, - R: MaybeUnwrap>>, - >( - obj: T, + #[track_caller] + unsafe fn send_super_message_error( + receiver: Receiver, superclass: &AnyClass, sel: Sel, args: A, - ) -> R { - let ptr = obj.into_raw_receiver(); - // SAFETY: Same as `send_message_retained` - let obj = unsafe { MsgSend::send_super_message(ptr, superclass, sel, args) }; - // SAFETY: Same as `send_message_retained` - let obj = unsafe { Retained::retain_autoreleased(obj) }; - // SAFETY: Same as `send_message_retained` - R::maybe_unwrap::(obj, (unsafe { ptr.as_ref() }, sel)) - } -} + ) -> Result> + where + *mut *mut E: Encode, + A: TupleExtender<*mut *mut E>, + >::PlusOneArgument: ConvertArguments, + E: ClassType; -pub trait MaybeUnwrap { - type Input; #[track_caller] - fn maybe_unwrap<'a, F: MsgSendRetainedFailed<'a>>(obj: Self::Input, args: F::Args) -> Self; -} - -impl MaybeUnwrap for Option> { - type Input = Option>; - #[inline] - fn maybe_unwrap<'a, F: MsgSendRetainedFailed<'a>>( - obj: Option>, - _args: F::Args, - ) -> Self { - obj + unsafe fn send_super_message_static_error( + receiver: Receiver, + sel: Sel, + args: A, + ) -> Result> + where + Self::Inner: ClassType, + ::Super: ClassType, + *mut *mut E: Encode, + A: TupleExtender<*mut *mut E>, + >::PlusOneArgument: ConvertArguments, + E: ClassType, + { + unsafe { + Self::send_super_message_error( + receiver, + ::Super::class(), + sel, + args, + ) + } } } -impl MaybeUnwrap for Retained { - type Input = Option>; +// `Option>` return. +impl MsgSendSuperError> for MethodFamily +where + MethodFamily: MsgSendSuper>>, +{ + type Inner = >>>::Inner; #[inline] - fn maybe_unwrap<'a, F: MsgSendRetainedFailed<'a>>( - obj: Option>, - args: F::Args, - ) -> Self { - match obj { - Some(obj) => obj, - None => F::failed(args), + unsafe fn send_super_message_error( + receiver: Receiver, + superclass: &AnyClass, + sel: Sel, + args: A, + ) -> Result, Retained> + where + *mut *mut E: Encode, + A: TupleExtender<*mut *mut E>, + >::PlusOneArgument: ConvertArguments, + E: ClassType, + { + let mut err: *mut E = ptr::null_mut(); + let args = args.add_argument(&mut err); + // SAFETY: See `send_message_error` + let ret = unsafe { Self::send_super_message(receiver, superclass, sel, args) }; + if let Some(ret) = ret { + Ok(ret) + } else { + // SAFETY: See `send_message_error` + Err(unsafe { encountered_error(err) }) } } } -impl MaybeUnwrap for Allocated { - type Input = Allocated; +// Bool return. +impl MsgSendSuperError for MethodFamily +where + MethodFamily: MsgSendSuper, +{ + type Inner = >::Inner; #[inline] - fn maybe_unwrap<'a, F: MsgSendRetainedFailed<'a>>(obj: Allocated, _args: F::Args) -> Self { - obj - } -} - -// Note: It would have been much easier to do this kind of thing using -// closures, but then `track_caller` doesn't work properly! -// -// Also note: This behavior (that #[method_id(...)] always unwraps instead of -// using `unwrap_unchecked`) is relied upon by `header-translator` for -// soundness, see e.g. `parse_property_return`. -pub trait MsgSendRetainedFailed<'a> { - type Args; - - #[track_caller] - fn failed(args: Self::Args) -> !; -} - -impl<'a> MsgSendRetainedFailed<'a> for NewFamily { - type Args = (Option<&'a AnyObject>, Sel); - - #[cold] - fn failed((obj, sel): Self::Args) -> ! { - if let Some(obj) = obj { - let cls = obj.class(); - if cls.is_metaclass() { - if sel == sel!(new) { - panic!("failed creating new instance of {cls}") - } else { - panic!("failed creating new instance using +[{cls} {sel}]") - } - } else { - panic!("unexpected NULL returned from -[{cls} {sel}]") - } + unsafe fn send_super_message_error( + receiver: Receiver, + superclass: &AnyClass, + sel: Sel, + args: A, + ) -> Result<(), Retained> + where + *mut *mut E: Encode, + A: TupleExtender<*mut *mut E>, + >::PlusOneArgument: ConvertArguments, + E: ClassType, + { + let mut err: *mut E = ptr::null_mut(); + let args = args.add_argument(&mut err); + // SAFETY: See `send_message_error` + let ret = unsafe { Self::send_super_message(receiver, superclass, sel, args) }; + if ret { + Ok(()) } else { - panic!("unexpected NULL {sel}; receiver was NULL"); + // SAFETY: See `send_message_error` + Err(unsafe { encountered_error(err) }) } } } -impl MsgSendRetainedFailed<'_> for AllocFamily { - type Args = (); +#[cfg(test)] +mod tests { + use core::mem::ManuallyDrop; - #[cold] - fn failed(_: Self::Args) -> ! { - unreachable!() - } -} + use super::*; -impl MsgSendRetainedFailed<'_> for InitFamily { - type Args = (*mut AnyObject, Sel); + use crate::rc::{autoreleasepool, PartialInit, RcTestObject, ThreadTestData}; + use crate::runtime::{AnyObject, NSObject, NSZone}; + use crate::{class, define_class, extern_methods, msg_send, test_utils, AllocAnyThread}; - #[cold] - fn failed((ptr, sel): Self::Args) -> ! { - if ptr.is_null() { - panic!("failed allocating object") - } else { - // We can't really display a more descriptive message here since the - // object is consumed by `init` and may not be valid any more. - if sel == sel!(init) { - panic!("failed initializing object") - } else { - panic!("failed initializing object with -{sel}") - } - } + #[test] + fn test_send_message_manuallydrop() { + let obj = ManuallyDrop::new(test_utils::custom_object()); + unsafe { + let _: () = msg_send![obj, release]; + }; + // `obj` is consumed, can't use here } -} - -impl MsgSendRetainedFailed<'_> for CopyFamily { - type Args = (); - #[cold] - fn failed(_: Self::Args) -> ! { - panic!("failed copying object") - } -} + macro_rules! test_error_bool { + ($expected:expr, $($obj:tt)*) => { + // Succeeds + let res: Result<(), Retained> = unsafe { + msg_send![$($obj)*, boolAndShouldError: false, error: _] + }; + assert_eq!(res, Ok(())); + $expected.assert_current(); -impl MsgSendRetainedFailed<'_> for MutableCopyFamily { - type Args = (); + // Errors + let res = autoreleasepool(|_pool| { + let res: Result<(), Retained> = unsafe { + msg_send![$($obj)*, boolAndShouldError: true, error: _] + }; + let res = res.expect_err("not err"); + $expected.alloc += 1; + $expected.init += 1; + $expected.autorelease += 1; + $expected.retain += 1; + $expected.assert_current(); + res + }); + $expected.release += 1; + $expected.assert_current(); - #[cold] - fn failed(_: Self::Args) -> ! { - panic!("failed copying object") + drop(res); + $expected.release += 1; + $expected.drop += 1; + $expected.assert_current(); + } } -} -impl<'a> MsgSendRetainedFailed<'a> for NoneFamily { - type Args = (Option<&'a AnyObject>, Sel); + define_class!( + #[unsafe(super(RcTestObject, NSObject))] + #[name = "RcTestObjectSubclass"] + #[derive(Debug, PartialEq, Eq)] + struct RcTestObjectSubclass; + ); - #[cold] - fn failed((obj, sel): Self::Args) -> ! { - if let Some(obj) = obj { - let cls = obj.class(); - panic!( - "unexpected NULL returned from {}[{cls} {sel}]", - if cls.is_metaclass() { "+" } else { "-" }, - ) - } else { - panic!("unexpected NULL {sel}; receiver was NULL"); + #[cfg_attr(not(test), allow(unused))] + impl RcTestObjectSubclass { + fn new() -> Retained { + unsafe { msg_send![Self::class(), new] } } } -} -#[cfg(test)] -mod tests { - use super::*; + #[test] + fn test_error_bool() { + let mut expected = ThreadTestData::current(); + + let cls = RcTestObject::class(); + test_error_bool!(expected, cls); + + let obj = RcTestObject::new(); + expected.alloc += 1; + expected.init += 1; + test_error_bool!(expected, &obj); - use crate::rc::{autoreleasepool, RcTestObject, ThreadTestData}; - use crate::runtime::{NSObject, NSZone}; - use crate::{class, extern_methods, msg_send_id, AllocAnyThread}; + let obj = RcTestObjectSubclass::new(); + expected.alloc += 1; + expected.init += 1; + test_error_bool!(expected, &obj); + test_error_bool!(expected, super(&obj)); + test_error_bool!(expected, super(&obj, RcTestObjectSubclass::class())); + test_error_bool!(expected, super(&obj, RcTestObject::class())); + } mod test_trait_disambugated { use super::*; #[allow(dead_code)] trait Abc { - fn send_message_retained(&self) {} + fn send_message(&self) {} } impl Abc for T {} #[test] fn test_macro_still_works() { - let _: Retained = unsafe { msg_send_id![NSObject::class(), new] }; + let _: Retained = unsafe { msg_send![NSObject::class(), new] }; } } @@ -634,17 +460,17 @@ mod tests { let mut expected = ThreadTestData::current(); let cls = RcTestObject::class(); - let _obj: Retained = unsafe { msg_send_id![cls, new] }; - let _obj: Option> = unsafe { msg_send_id![cls, new] }; + let _obj: Retained = unsafe { msg_send![cls, new] }; + let _obj: Option> = unsafe { msg_send![cls, new] }; // This is just a roundabout way of calling `[__RcTestObject new]`. - let _obj: Retained = unsafe { msg_send_id![super(cls, cls.metaclass()), new] }; + let _obj: Retained = unsafe { msg_send![super(cls, cls.metaclass()), new] }; let _obj: Option> = - unsafe { msg_send_id![super(cls, cls.metaclass()), new] }; + unsafe { msg_send![super(cls, cls.metaclass()), new] }; // `__RcTestObject` does not override `new`, so this just ends up // calling `[[__RcTestObject alloc] init]` as usual. let _obj: Retained = - unsafe { msg_send_id![super(cls, NSObject::class().metaclass()), new] }; + unsafe { msg_send![super(cls, NSObject::class().metaclass()), new] }; expected.alloc += 5; expected.init += 5; @@ -659,12 +485,12 @@ mod tests { expected.init += 1; expected.assert_current(); - let _obj: Retained = unsafe { msg_send_id![&obj, newMethodOnInstance] }; - let _obj: Option> = unsafe { msg_send_id![&obj, newMethodOnInstance] }; + let _obj: Retained = unsafe { msg_send![&obj, newMethodOnInstance] }; + let _obj: Option> = unsafe { msg_send![&obj, newMethodOnInstance] }; let _obj: Retained = - unsafe { msg_send_id![super(&obj, RcTestObject::class()), newMethodOnInstance] }; + unsafe { msg_send![super(&obj, RcTestObject::class()), newMethodOnInstance] }; let _obj: Option> = - unsafe { msg_send_id![super(&obj, RcTestObject::class()), newMethodOnInstance] }; + unsafe { msg_send![super(&obj, RcTestObject::class()), newMethodOnInstance] }; expected.alloc += 4; expected.init += 4; expected.assert_current(); @@ -677,12 +503,12 @@ mod tests { let mut expected = ThreadTestData::current(); let object_class = RcTestObject::class(); - let key: Retained = unsafe { msg_send_id![class!(NSString), new] }; + let key: Retained = unsafe { msg_send![class!(NSString), new] }; let contents_value: *const AnyObject = ptr::null(); - let properties: Retained = unsafe { msg_send_id![class!(NSDictionary), new] }; + let properties: Retained = unsafe { msg_send![class!(NSDictionary), new] }; let _obj: Option> = unsafe { - msg_send_id![ + msg_send![ NSObject::class(), newScriptingObjectOfClass: object_class, forValueForKey: &*key, @@ -700,21 +526,21 @@ mod tests { // GNUStep instead returns an invalid instance that panics on accesses #[cfg_attr(feature = "gnustep-1-7", ignore)] fn new_nsvalue_fails() { - let _val: Retained = unsafe { msg_send_id![class!(NSValue), new] }; + let _val: Retained = unsafe { msg_send![class!(NSValue), new] }; } #[test] #[should_panic = "failed creating new instance using +[__RcTestObject newReturningNull]"] fn test_new_with_null() { let _obj: Retained = - unsafe { msg_send_id![RcTestObject::class(), newReturningNull] }; + unsafe { msg_send![RcTestObject::class(), newReturningNull] }; } #[test] #[should_panic = "failed creating new instance using +[__RcTestObject newReturningNull]"] fn test_super_new_with_null() { let _: Retained = unsafe { - msg_send_id![ + msg_send![ super(RcTestObject::class(), RcTestObject::class().metaclass()), newReturningNull ] @@ -725,7 +551,7 @@ mod tests { #[should_panic = "unexpected NULL returned from -[__RcTestObject newMethodOnInstanceNull]"] fn test_new_any_with_null() { let obj = RcTestObject::new(); - let _obj: Retained = unsafe { msg_send_id![&obj, newMethodOnInstanceNull] }; + let _obj: Retained = unsafe { msg_send![&obj, newMethodOnInstanceNull] }; } #[test] @@ -733,7 +559,7 @@ mod tests { fn test_super_new_any_with_null() { let obj = RcTestObject::new(); let _obj: Retained = - unsafe { msg_send_id![super(&obj, RcTestObject::class()), newMethodOnInstanceNull] }; + unsafe { msg_send![super(&obj, RcTestObject::class()), newMethodOnInstanceNull] }; } #[test] @@ -747,7 +573,7 @@ mod tests { )] fn test_new_any_with_null_receiver() { let obj: *const NSObject = ptr::null(); - let _obj: Retained = unsafe { msg_send_id![obj, newMethodOnInstance] }; + let _obj: Retained = unsafe { msg_send![obj, newMethodOnInstance] }; } #[test] @@ -761,7 +587,7 @@ mod tests { )] fn test_super_new_any_with_null_receiver() { let obj: *const RcTestObject = ptr::null(); - let _obj: Retained = unsafe { msg_send_id![super(obj), newMethodOnInstance] }; + let _obj: Retained = unsafe { msg_send![super(obj), newMethodOnInstance] }; } // `alloc` family @@ -771,7 +597,7 @@ mod tests { let mut expected = ThreadTestData::current(); let cls = RcTestObject::class(); - let obj: Allocated = unsafe { msg_send_id![cls, alloc] }; + let obj: Allocated = unsafe { msg_send![cls, alloc] }; expected.alloc += 1; expected.assert_current(); @@ -784,7 +610,7 @@ mod tests { // `+[NSObject alloc]` forwards to `allocWithZone:`, so this still // allocates a `__RcTestObject`. let _: Allocated = - unsafe { msg_send_id![super(cls, NSObject::class().metaclass()), alloc] }; + unsafe { msg_send![super(cls, NSObject::class().metaclass()), alloc] }; expected.alloc += 1; expected.release += 1; // Drop flag ensures uninitialized do not Drop @@ -798,24 +624,24 @@ mod tests { let cls = RcTestObject::class(); let zone: *const NSZone = ptr::null(); - let _obj: Allocated = unsafe { msg_send_id![cls, allocWithZone: zone] }; + let _obj: Allocated = unsafe { msg_send![cls, allocWithZone: zone] }; expected.alloc += 1; expected.assert_current(); let _obj: Allocated = - unsafe { msg_send_id![super(cls, cls.metaclass()), allocWithZone: zone] }; + unsafe { msg_send![super(cls, cls.metaclass()), allocWithZone: zone] }; expected.alloc += 1; expected.assert_current(); let _obj: Allocated = - unsafe { msg_send_id![super(cls, NSObject::class().metaclass()), allocWithZone: zone] }; + unsafe { msg_send![super(cls, NSObject::class().metaclass()), allocWithZone: zone] }; expected.assert_current(); } #[test] fn test_alloc_with_null() { let obj: Allocated = - unsafe { msg_send_id![RcTestObject::class(), allocReturningNull] }; + unsafe { msg_send![RcTestObject::class(), allocReturningNull] }; assert!(Allocated::as_ptr(&obj).is_null()); } @@ -825,7 +651,7 @@ mod tests { fn test_init() { let mut expected = ThreadTestData::current(); - let _: Retained = unsafe { msg_send_id![RcTestObject::alloc(), init] }; + let _: Retained = unsafe { msg_send![RcTestObject::alloc(), init] }; expected.alloc += 1; expected.init += 1; expected.release += 1; @@ -833,7 +659,7 @@ mod tests { expected.assert_current(); let obj = RcTestObject::alloc().set_ivars(()); - let _: Retained = unsafe { msg_send_id![super(obj), init] }; + let _: Retained = unsafe { msg_send![super(obj), init] }; expected.alloc += 1; expected.release += 1; expected.drop += 1; @@ -843,7 +669,7 @@ mod tests { let obj = RcTestObject::alloc(); expected.alloc += 1; assert!(!Allocated::as_ptr(&obj).is_null()); - let _: Retained = unsafe { msg_send_id![obj, init] }; + let _: Retained = unsafe { msg_send![obj, init] }; expected.init += 1; expected.release += 1; expected.drop += 1; @@ -853,8 +679,8 @@ mod tests { #[test] #[should_panic = "failed initializing object with -initReturningNull"] fn test_init_with_null() { - let obj: Allocated = unsafe { msg_send_id![RcTestObject::class(), alloc] }; - let _obj: Retained = unsafe { msg_send_id![obj, initReturningNull] }; + let obj: Allocated = unsafe { msg_send![RcTestObject::class(), alloc] }; + let _obj: Retained = unsafe { msg_send![obj, initReturningNull] }; } #[test] @@ -862,8 +688,8 @@ mod tests { #[cfg_attr(not(debug_assertions), ignore = "failed allocating object")] fn test_init_with_null_receiver() { let obj: Allocated = - unsafe { msg_send_id![RcTestObject::class(), allocReturningNull] }; - let _obj: Retained = unsafe { msg_send_id![obj, init] }; + unsafe { msg_send![RcTestObject::class(), allocReturningNull] }; + let _obj: Retained = unsafe { msg_send![obj, init] }; } #[test] @@ -876,7 +702,7 @@ mod tests { fn test_super_init_not_initialized() { let obj = RcTestObject::alloc().set_ivars(()); let _: Retained = - unsafe { msg_send_id![super(obj, RcTestObject::class()), init] }; + unsafe { msg_send![super(obj, RcTestObject::class()), init] }; } #[test] @@ -885,7 +711,7 @@ mod tests { fn test_super_init_not_finalized() { let obj = unsafe { PartialInit::new(Allocated::into_ptr(RcTestObject::alloc())) }; let _: Retained = - unsafe { msg_send_id![super(obj, RcTestObject::class()), init] }; + unsafe { msg_send![super(obj, RcTestObject::class()), init] }; } // `copy` family @@ -895,7 +721,7 @@ mod tests { let obj = RcTestObject::new(); let mut expected = ThreadTestData::current(); - let _: Retained = unsafe { msg_send_id![&obj, copy] }; + let _: Retained = unsafe { msg_send![&obj, copy] }; expected.copy += 1; expected.alloc += 1; expected.init += 1; @@ -905,7 +731,7 @@ mod tests { // `+[NSObject copy]` forwards to `copyWithZone:`, so this still // creates a `__RcTestObject`. - let _: Retained = unsafe { msg_send_id![super(&obj), copy] }; + let _: Retained = unsafe { msg_send![super(&obj), copy] }; expected.copy += 1; expected.alloc += 1; expected.init += 1; @@ -918,7 +744,7 @@ mod tests { #[should_panic = "failed copying object"] fn test_copy_with_null() { let obj = RcTestObject::new(); - let _obj: Retained = unsafe { msg_send_id![&obj, copyReturningNull] }; + let _obj: Retained = unsafe { msg_send![&obj, copyReturningNull] }; } #[test] @@ -926,7 +752,7 @@ mod tests { fn test_super_copy_with_null() { let obj = RcTestObject::new(); let _obj: Retained = - unsafe { msg_send_id![super(&obj, RcTestObject::class()), copyReturningNull] }; + unsafe { msg_send![super(&obj, RcTestObject::class()), copyReturningNull] }; } // `mutableCopy` family @@ -936,7 +762,7 @@ mod tests { let obj = RcTestObject::new(); let mut expected = ThreadTestData::current(); - let _: Retained = unsafe { msg_send_id![&obj, mutableCopy] }; + let _: Retained = unsafe { msg_send![&obj, mutableCopy] }; expected.mutable_copy += 1; expected.alloc += 1; expected.init += 1; @@ -946,7 +772,7 @@ mod tests { // `+[NSObject mutableCopy]` forwards to `mutableCopyWithZone:`, so // this still creates a `__RcTestObject`. - let _: Retained = unsafe { msg_send_id![super(&obj), mutableCopy] }; + let _: Retained = unsafe { msg_send![super(&obj), mutableCopy] }; expected.mutable_copy += 1; expected.alloc += 1; expected.init += 1; @@ -962,20 +788,20 @@ mod tests { let obj = RcTestObject::new(); let mut expected = ThreadTestData::current(); - let _: Retained = unsafe { msg_send_id![&obj, self] }; + let _: Retained = unsafe { msg_send![&obj, self] }; expected.retain += 1; expected.release += 1; expected.assert_current(); - let _: Retained = unsafe { msg_send_id![super(&obj), self] }; + let _: Retained = unsafe { msg_send![super(&obj), self] }; expected.retain += 1; expected.release += 1; expected.assert_current(); - let _: Option> = unsafe { msg_send_id![&obj, description] }; + let _: Option> = unsafe { msg_send![&obj, description] }; expected.assert_current(); - let _: Option> = unsafe { msg_send_id![super(&obj), description] }; + let _: Option> = unsafe { msg_send![super(&obj), description] }; expected.assert_current(); } @@ -983,14 +809,14 @@ mod tests { #[should_panic = "unexpected NULL returned from -[__RcTestObject methodReturningNull]"] fn test_normal_with_null() { let obj = RcTestObject::new(); - let _obj: Retained = unsafe { msg_send_id![&obj, methodReturningNull] }; + let _obj: Retained = unsafe { msg_send![&obj, methodReturningNull] }; } #[test] #[should_panic = "unexpected NULL returned from -[__RcTestObject aMethod:]"] fn test_normal_with_param_and_null() { let obj = RcTestObject::new(); - let _obj: Retained = unsafe { msg_send_id![&obj, aMethod: false] }; + let _obj: Retained = unsafe { msg_send![&obj, aMethod: false] }; } #[test] @@ -1001,7 +827,7 @@ mod tests { )] fn test_normal_with_null_receiver() { let obj: *const NSObject = ptr::null(); - let _obj: Retained = unsafe { msg_send_id![obj, description] }; + let _obj: Retained = unsafe { msg_send![obj, description] }; } // This is imperfect, but will do for now. @@ -1038,7 +864,7 @@ mod tests { // Succeeds let res = autoreleasepool(|_pool| { let res: Result, Retained> = unsafe { - msg_send_id![$($obj)*, $sel: false, error: _] + msg_send![$($obj)*, $sel: false, error: _] }; let res = res.expect("not ok"); $expected.alloc += 1; @@ -1059,7 +885,7 @@ mod tests { // Errors let res = autoreleasepool(|_pool| { let res: Result, Retained> = unsafe { - msg_send_id![$($obj)*, $sel: true, error: _] + msg_send![$($obj)*, $sel: true, error: _] }; $expected.alloc += 1; $expected.init += 1; @@ -1113,7 +939,7 @@ mod tests { } #[test] - fn test_method_id_with_param() { + fn test_method_with_param() { let mut expected = ThreadTestData::current(); let obj = RcTestObject::new(); @@ -1121,12 +947,12 @@ mod tests { expected.init += 1; expected.assert_current(); - let res: Option> = unsafe { msg_send_id![&obj, aMethod: false] }; + let res: Option> = unsafe { msg_send![&obj, aMethod: false] }; assert!(res.is_none()); expected.assert_current(); let _res = autoreleasepool(|_pool| { - let res: Option> = unsafe { msg_send_id![&obj, aMethod: true] }; + let res: Option> = unsafe { msg_send![&obj, aMethod: true] }; assert!(res.is_some()); expected.alloc += 1; expected.init += 1; @@ -1143,33 +969,33 @@ mod tests { fn msg_send_class() { let cls = NSObject::class(); - let retained: Retained = unsafe { msg_send_id![cls, self] }; + let retained: Retained = unsafe { msg_send![cls, self] }; assert_eq!(&*retained, cls); - let retained: Option> = unsafe { msg_send_id![cls, self] }; + let retained: Option> = unsafe { msg_send![cls, self] }; let retained = retained.unwrap(); assert_eq!(&*retained, cls); } extern_methods!( unsafe impl RcTestObject { - #[method_id(copy)] + #[method(copy)] #[unsafe(method_family = new)] fn copy_new(&self) -> Retained; - #[method_id(copy)] + #[method(copy)] #[unsafe(method_family = init)] fn copy_init(this: Allocated) -> Retained; - #[method_id(copy)] + #[method(copy)] #[unsafe(method_family = copy)] fn copy_copy(&self) -> Retained; - #[method_id(copy)] + #[method(copy)] #[unsafe(method_family = mutableCopy)] fn copy_mutable_copy(&self) -> Retained; - #[method_id(copy)] + #[method(copy)] #[unsafe(method_family = none)] fn copy_none(&self) -> Retained; } diff --git a/crates/objc2/src/__macro_helpers/null_error.rs b/crates/objc2/src/__macro_helpers/null_error.rs index c52417d8f..fb5ad19c7 100644 --- a/crates/objc2/src/__macro_helpers/null_error.rs +++ b/crates/objc2/src/__macro_helpers/null_error.rs @@ -4,7 +4,7 @@ use std::sync::OnceLock; use crate::ffi::NSInteger; use crate::rc::{autoreleasepool, Retained}; use crate::runtime::{AnyClass, NSObject}; -use crate::{msg_send_id, ClassType}; +use crate::{msg_send, ClassType}; // Marked `#[cold]` to tell the optimizer that errors are comparatively rare. // @@ -96,7 +96,7 @@ fn create_null_error() -> NSErrorWrapper { // SAFETY: The signate is correct, and the string is UTF-8 encoded and // NUL terminated. let domain: Retained = - unsafe { msg_send_id![cls, stringWithUTF8String: domain.as_ptr()] }; + unsafe { msg_send![cls, stringWithUTF8String: domain.as_ptr()] }; // SAFETY: The string is valid. let cls = unsafe { CStr::from_bytes_with_nul_unchecked(b"NSError\0") }; @@ -108,7 +108,7 @@ fn create_null_error() -> NSErrorWrapper { let user_info: Option<&NSObject> = None; // SAFETY: The signate is correct. let err: Retained = - unsafe { msg_send_id![cls, errorWithDomain: domain, code: code, userInfo: user_info] }; + unsafe { msg_send![cls, errorWithDomain: domain, code: code, userInfo: user_info] }; NSErrorWrapper(err) }) } diff --git a/crates/objc2/src/__macro_helpers/os_version/apple.rs b/crates/objc2/src/__macro_helpers/os_version/apple.rs index ef88e7f23..35b9f15c1 100644 --- a/crates/objc2/src/__macro_helpers/os_version/apple.rs +++ b/crates/objc2/src/__macro_helpers/os_version/apple.rs @@ -9,7 +9,7 @@ use super::OSVersion; use crate::rc::{autoreleasepool, Allocated, Retained}; use crate::runtime::__nsstring::{nsstring_to_str, UTF8_ENCODING}; use crate::runtime::{NSObject, NSObjectProtocol}; -use crate::{class, msg_send_id}; +use crate::{class, msg_send}; /// The deployment target for the current OS. pub(crate) const DEPLOYMENT_TARGET: OSVersion = { @@ -208,11 +208,11 @@ fn version_from_plist() -> OSVersion { let path = path.as_os_str().as_bytes(); // SAFETY: Allocating a string is valid. - let alloc: Allocated = unsafe { msg_send_id![class!(NSString), alloc] }; + let alloc: Allocated = unsafe { msg_send![class!(NSString), alloc] }; // SAFETY: The bytes are valid, and the length is correct. unsafe { let bytes_ptr: *const c_void = path.as_ptr().cast(); - msg_send_id![ + msg_send![ alloc, initWithBytes: bytes_ptr, length: path.len(), @@ -225,12 +225,12 @@ fn version_from_plist() -> OSVersion { .as_ptr() .cast(); // SAFETY: The path is NULL terminated. - unsafe { msg_send_id![class!(NSString), stringWithUTF8String: path] } + unsafe { msg_send![class!(NSString), stringWithUTF8String: path] } }; // SAFETY: dictionaryWithContentsOfFile: is safe to call. let data: Option> = - unsafe { msg_send_id![class!(NSDictionary), dictionaryWithContentsOfFile: &*path] }; + unsafe { msg_send![class!(NSDictionary), dictionaryWithContentsOfFile: &*path] }; let data = data.expect( "`/System/Library/CoreServices/SystemVersion.plist` must be readable, and contain a valid PList", @@ -245,10 +245,9 @@ fn version_from_plist() -> OSVersion { }; // SAFETY: The lookup key is NULL terminated. let lookup_key: Retained = - unsafe { msg_send_id![class!(NSString), stringWithUTF8String: lookup_key] }; + unsafe { msg_send![class!(NSString), stringWithUTF8String: lookup_key] }; - let version: Retained = - unsafe { msg_send_id![&data, objectForKey: &*lookup_key] }; + let version: Retained = unsafe { msg_send![&data, objectForKey: &*lookup_key] }; assert!( version.isKindOfClass(class!(NSString)), diff --git a/crates/objc2/src/__macro_helpers/retain_semantics.rs b/crates/objc2/src/__macro_helpers/retain_semantics.rs new file mode 100644 index 000000000..7dae478ba --- /dev/null +++ b/crates/objc2/src/__macro_helpers/retain_semantics.rs @@ -0,0 +1,796 @@ +use core::mem::ManuallyDrop; + +use crate::encode::EncodeReturn; +use crate::rc::{Allocated, PartialInit, Retained}; +use crate::runtime::{AnyClass, AnyObject, MessageReceiver, Sel}; +use crate::{sel, DefinedClass, Message}; + +use super::defined_ivars::set_finalized; +use super::{ + AllocFamily, ConvertReturn, CopyFamily, InitFamily, MutableCopyFamily, NewFamily, NoneFamily, +}; + +// TODO: Differentiate between instance and class methods? + +#[derive(Debug, Copy, Clone)] +pub struct KindSendMessageSuper; + +#[derive(Debug, Copy, Clone)] +pub struct KindSendMessage; + +#[derive(Debug, Copy, Clone)] +pub struct KindDefined; + +trait SendMessage {} + +impl SendMessage for KindSendMessage {} +impl SendMessage for KindSendMessageSuper {} + +trait NotSuper {} + +impl NotSuper for KindSendMessage {} +impl NotSuper for KindDefined {} + +trait IsSuper {} + +impl IsSuper for KindSendMessageSuper {} + +/// Trait for restricting the possible Receiver/Return type combinations. +/// +/// This is used to convert receiver and return types in `extern_methods!` +/// and `msg_send!`. +/// +/// Having both the receiver, return type and whether the message send is a +/// super-message send is especially important for `init` methods, which must +/// return the same type as they were called with, and must restrict the +/// receiver to either `Allocated` or `PartialInit` depending on the super-ness. +/// +/// # Summary +/// +/// ```text +/// new: Receiver -> Option> +/// alloc: &AnyClass -> Allocated +/// init: Allocated -> Option> +/// init super: PartialInit -> Option> +/// copy: Receiver -> Option> +/// mutableCopy: Receiver -> Option> +/// others: Receiver -> Option> +/// ``` +pub trait RetainSemantics: Sized { + /// The inner receiver type that is used directly at the ABI boundary of + /// the message send. + type ReceiverInner: MessageReceiver; + + /// Prepare the receiver for sending a message. + fn prepare_message_send(receiver: Receiver) -> Self::ReceiverInner; + + /// Prepare the receiver for receiving a message. + /// + /// + /// # Safety + /// + /// The receiver must be valid. + unsafe fn prepare_defined_method(receiver: Self::ReceiverInner) -> Receiver; + + /// The inner return type that is used directly at the ABI boundary of the + /// message send. + type ReturnInner: EncodeReturn; + + /// Convert a received return value according to the specified retain + /// semantics. + /// + /// + /// # Panics + /// + /// If conversion fails (such as when converting to `Retained`), this + /// uses the receiver and selector to panic with a nice error message. + /// + /// NOTE: The behavior that returning `Retained` always unwraps + /// instead of using `unwrap_unchecked` is relied upon by + /// `header-translator` for soundness, see e.g. `parse_property_return`. + /// + /// + /// # Safety + /// + /// The return value must be valid, and the receiver pointer must have + /// come from `prepare_message_send`. + #[track_caller] + unsafe fn convert_message_return( + ret: Self::ReturnInner, + receiver_ptr: *mut AnyObject, + sel: Sel, + ) -> Return; + + // TODO: Use this in `define_class!`. + fn convert_defined_return(ret: Return) -> Self::ReturnInner; +} + +// +// Implementations for all method families. +// + +/// Generic implementation allowing message sending to normal encode return +/// types. +impl RetainSemantics for MethodFamily +where + Receiver: MessageReceiver, + Return: ConvertReturn, +{ + type ReceiverInner = Receiver; + + #[inline] + fn prepare_message_send(receiver: Receiver) -> Receiver { + receiver + } + + #[inline] + unsafe fn prepare_defined_method(receiver: Receiver) -> Receiver { + receiver + } + + type ReturnInner = Return::Inner; + + #[inline] + unsafe fn convert_message_return( + ret: Return::Inner, + receiver_ptr: *mut AnyObject, + sel: Sel, + ) -> Return { + // SAFETY: Upheld by caller. + unsafe { Return::convert_message_return(ret, receiver_ptr, sel) } + } + + #[inline] + fn convert_defined_return(ret: Return) -> Return::Inner { + Return::convert_defined_return(ret) + } +} + +/// Convenience implementation for sending messages to `&Retained`. +impl<'a, T, Return, Kind, MethodFamily> RetainSemantics<&'a Retained, Return, Kind> + for MethodFamily +where + T: Message, + // Only allow on message sends, this won't work in `define_class!`. + Kind: SendMessage, + MethodFamily: RetainSemantics<*const T, Return, Kind>, +{ + type ReceiverInner = *const T; + + #[inline] + fn prepare_message_send(receiver: &'a Retained) -> *const T { + &**receiver + } + + #[inline] + unsafe fn prepare_defined_method(_receiver: *const T) -> &'a Retained { + // Should be prevented statically by `Kind: SendMessage`. + unreachable!() + } + + type ReturnInner = >::ReturnInner; + + #[inline] + unsafe fn convert_message_return( + ret: Self::ReturnInner, + receiver_ptr: *mut AnyObject, + sel: Sel, + ) -> Return { + unsafe { + >::convert_message_return( + ret, + receiver_ptr, + sel, + ) + } + } + + #[inline] + fn convert_defined_return(ret: Return) -> Self::ReturnInner { + >::convert_defined_return(ret) + } +} + +/// Convenience implementation for sending messages to `ManuallyDrop>`. +impl RetainSemantics>, Return, Kind> + for MethodFamily +where + T: Message, + // Only allow on message sends, this doesn't make sense to do in + // `define_class!`. + Kind: SendMessage, + MethodFamily: RetainSemantics<*mut T, Return, Kind>, +{ + type ReceiverInner = *mut T; + + #[inline] + fn prepare_message_send(receiver: ManuallyDrop>) -> *mut T { + Retained::into_raw(ManuallyDrop::into_inner(receiver)) + } + + #[inline] + unsafe fn prepare_defined_method(_receiver: *mut T) -> ManuallyDrop> { + // Should be prevented statically by `Kind: SendMessage`. + unreachable!() + } + + type ReturnInner = >::ReturnInner; + + #[inline] + unsafe fn convert_message_return( + ret: Self::ReturnInner, + receiver_ptr: *mut AnyObject, + sel: Sel, + ) -> Return { + unsafe { + >::convert_message_return( + ret, + receiver_ptr, + sel, + ) + } + } + + #[inline] + fn convert_defined_return(ret: Return) -> Self::ReturnInner { + >::convert_defined_return(ret) + } +} + +// +// NewFamily +// +// Receiver -> Option> +// Receiver -> Retained +// + +impl ConvertReturn for Option> { + type Inner = *mut T; + + #[inline] + unsafe fn convert_message_return( + inner: Self::Inner, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Self { + // SAFETY: The selector is `new`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + unsafe { Retained::from_raw(inner) } + } + + #[inline] + fn convert_defined_return(self) -> Self::Inner { + // Return with +1 retain count. + Retained::consume_as_ptr_option(self) + } +} + +impl ConvertReturn for Retained { + type Inner = *mut T; + + #[inline] + unsafe fn convert_message_return( + inner: Self::Inner, + receiver_ptr: *mut AnyObject, + sel: Sel, + ) -> Self { + // SAFETY: The selector is `new`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + let ret = unsafe { Retained::from_raw(inner) }; + if let Some(ret) = ret { + ret + } else { + // SAFETY: The receiver is still valid after a message send to + // a `new` method - it would not be if the method was `init`. + let receiver = unsafe { receiver_ptr.as_ref() }; + new_fail(receiver, sel) + } + } + + #[inline] + fn convert_defined_return(self) -> Self::Inner { + // Return with +1 retain count. + Retained::into_raw(self) + } +} + +#[cold] +#[track_caller] +fn new_fail(receiver: Option<&AnyObject>, sel: Sel) -> ! { + if let Some(receiver) = receiver { + let cls = receiver.class(); + if cls.is_metaclass() { + if sel == sel!(new) { + panic!("failed creating new instance of {cls}") + } else { + panic!("failed creating new instance using +[{cls} {sel}]") + } + } else { + panic!("unexpected NULL returned from -[{cls} {sel}]") + } + } else { + panic!("unexpected NULL {sel}; receiver was NULL"); + } +} + +// +// AllocFamily +// +// &AnyClass -> Allocated +// + +// Restrict `alloc` methods to the simplest case of a class reference. This +// could possibly be relaxed in the future, but there's likely no need for +// that. +impl<'a, Return, Kind> RetainSemantics<&'a AnyClass, Allocated, Kind> for AllocFamily +where + Return: Message, +{ + type ReceiverInner = &'a AnyClass; + + #[inline] + fn prepare_message_send(receiver: &'a AnyClass) -> &'a AnyClass { + receiver + } + + #[inline] + unsafe fn prepare_defined_method(receiver: &'a AnyClass) -> &'a AnyClass { + receiver + } + + type ReturnInner = *mut Return; + + #[inline] + unsafe fn convert_message_return( + ret: *mut Return, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Allocated { + // SAFETY: The selector is `alloc`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + unsafe { Allocated::new(ret) } + } + + #[inline] + fn convert_defined_return(ret: Allocated) -> *mut Return { + // Return with +1 retain count. + Allocated::into_ptr(ret) + } +} + +// +// InitFamily +// +// We restrict `init` methods such that, if they return `Id`, the receiver +// must be `Allocated` with the same generic parameter. +// +// Simple return types have no restriction. +// +// See +// +// normal: +// Allocated -> Option> +// Allocated -> Retained +// +// super: +// PartialInit -> Option> +// PartialInit -> Retained +// + +impl RetainSemantics, Option>, Kind> for InitFamily +where + T: Message, + Kind: NotSuper, +{ + type ReceiverInner = *mut T; + + #[inline] + fn prepare_message_send(receiver: Allocated) -> *mut T { + // Pass the +1 retain count to the callee. + Allocated::into_ptr(receiver) + } + + #[inline] + unsafe fn prepare_defined_method(receiver: *mut T) -> Allocated { + // SAFETY: The receiver of an `init` method is `Allocated` and + // consumed, and thus has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + unsafe { Allocated::new(receiver) } + } + + type ReturnInner = *mut T; + + #[inline] + unsafe fn convert_message_return( + ret: *mut T, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Option> { + // SAFETY: The selector is `init`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + unsafe { Retained::from_raw(ret) } + } + + #[inline] + fn convert_defined_return(ret: Option>) -> *mut T { + // Return with +1 retain count. + Retained::consume_as_ptr_option(ret) + } +} + +impl RetainSemantics, Retained, Kind> for InitFamily +where + T: Message, + Kind: NotSuper, +{ + type ReceiverInner = *mut T; + + #[inline] + fn prepare_message_send(receiver: Allocated) -> *mut T { + // Pass the +1 retain count to the callee. + Allocated::into_ptr(receiver) + } + + #[inline] + unsafe fn prepare_defined_method(receiver: *mut T) -> Allocated { + // SAFETY: The receiver of an `init` method is `Allocated` and + // consumed, and thus has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + unsafe { Allocated::new(receiver) } + } + + type ReturnInner = *mut T; + + #[inline] + unsafe fn convert_message_return( + ret: *mut T, + receiver_ptr: *mut AnyObject, + sel: Sel, + ) -> Retained { + // SAFETY: The selector is `init`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + let ret = unsafe { Retained::from_raw(ret) }; + if let Some(ret) = ret { + ret + } else { + init_fail(receiver_ptr, sel) + } + } + + #[inline] + fn convert_defined_return(ret: Retained) -> *mut T { + // Return with +1 retain count. + Retained::into_raw(ret) + } +} + +impl RetainSemantics, Option>, Kind> for InitFamily +where + T: DefinedClass, + Kind: IsSuper, +{ + type ReceiverInner = *mut T; + + #[inline] + fn prepare_message_send(receiver: PartialInit) -> *mut T { + // Pass the +1 retain count to the callee. + PartialInit::into_ptr(receiver) + } + + #[inline] + unsafe fn prepare_defined_method(receiver: *mut T) -> PartialInit { + // SAFETY: The receiver of a super `init` method is `PartialInit` and + // consumed, and thus has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + unsafe { PartialInit::new(receiver) } + } + + type ReturnInner = *mut T; + + #[inline] + unsafe fn convert_message_return( + ret: *mut T, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Option> { + // SAFETY: The selector is `init`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + let ret = unsafe { Retained::from_raw(ret) }; + if let Some(ret) = ret { + // SAFETY: We just got back from `init`, so the super initializer + // will have run. + // + // Caller ensures that the pointer is valid. + unsafe { set_finalized(ret.as_nonnull_ptr()) }; + + Some(ret) + } else { + None + } + } + + #[inline] + fn convert_defined_return(ret: Option>) -> *mut T { + // Return with +1 retain count. + Retained::consume_as_ptr_option(ret) + } +} + +impl RetainSemantics, Retained, Kind> for InitFamily +where + T: DefinedClass, + Kind: IsSuper, +{ + type ReceiverInner = *mut T; + + #[inline] + fn prepare_message_send(receiver: PartialInit) -> *mut T { + // Pass the +1 retain count to the callee. + PartialInit::into_ptr(receiver) + } + + #[inline] + unsafe fn prepare_defined_method(receiver: *mut T) -> PartialInit { + // SAFETY: The receiver of a super `init` method is `PartialInit` and + // consumed, and thus has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + unsafe { PartialInit::new(receiver) } + } + + type ReturnInner = *mut T; + + #[inline] + unsafe fn convert_message_return( + ret: *mut T, + receiver_ptr: *mut AnyObject, + sel: Sel, + ) -> Retained { + // SAFETY: The selector is `init`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + let ret = unsafe { Retained::from_raw(ret) }; + if let Some(ret) = ret { + // SAFETY: We just got back from `init`, so the super initializer + // will have run. + // + // Caller ensures that the pointer is valid. + unsafe { set_finalized(ret.as_nonnull_ptr()) }; + + ret + } else { + init_fail(receiver_ptr, sel) + } + } + + #[inline] + fn convert_defined_return(ret: Retained) -> *mut T { + // Return with +1 retain count. + Retained::into_raw(ret) + } +} + +#[cold] +#[track_caller] +fn init_fail(receiver: *mut AnyObject, sel: Sel) -> ! { + if receiver.is_null() { + panic!("failed allocating object") + } else { + // We can't really display a more descriptive message here since the + // object is consumed by `init` and may not be valid any more. + if sel == sel!(init) { + panic!("failed initializing object") + } else { + panic!("failed initializing object with -{sel}") + } + } +} + +// +// CopyFamily +// +// Receiver -> Option> +// Receiver -> Retained +// + +impl ConvertReturn for Option> { + type Inner = *mut T; + + #[inline] + unsafe fn convert_message_return( + inner: Self::Inner, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Self { + // SAFETY: The selector is `copy`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + unsafe { Retained::from_raw(inner) } + } + + #[inline] + fn convert_defined_return(self) -> Self::Inner { + // Return with +1 retain count. + Retained::consume_as_ptr_option(self) + } +} + +impl ConvertReturn for Retained { + type Inner = *mut T; + + #[inline] + unsafe fn convert_message_return( + inner: Self::Inner, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Self { + // SAFETY: The selector is `copy`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + let ret = unsafe { Retained::from_raw(inner) }; + if let Some(ret) = ret { + ret + } else { + copy_fail() + } + } + + #[inline] + fn convert_defined_return(self) -> Self::Inner { + // Return with +1 retain count. + Retained::into_raw(self) + } +} + +#[cold] +#[track_caller] +fn copy_fail() -> ! { + panic!("failed copying object") +} + +// +// MutableCopyFamily +// +// Receiver -> Option> +// Receiver -> Retained +// + +impl ConvertReturn for Option> { + type Inner = *mut T; + + #[inline] + unsafe fn convert_message_return( + inner: Self::Inner, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Self { + // SAFETY: The selector is `mutableCopy`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + unsafe { Retained::from_raw(inner) } + } + + #[inline] + fn convert_defined_return(self) -> Self::Inner { + // Return with +1 retain count. + Retained::consume_as_ptr_option(self) + } +} + +impl ConvertReturn for Retained { + type Inner = *mut T; + + #[inline] + unsafe fn convert_message_return( + inner: Self::Inner, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Self { + // SAFETY: The selector is `mutableCopy`, so this has +1 retain count. + // + // Validity of the pointer is upheld by the caller. + let ret = unsafe { Retained::from_raw(inner) }; + if let Some(ret) = ret { + ret + } else { + mutable_copy_fail() + } + } + + #[inline] + fn convert_defined_return(self) -> Self::Inner { + // Return with +1 retain count. + Retained::into_raw(self) + } +} + +#[cold] +#[track_caller] +fn mutable_copy_fail() -> ! { + panic!("failed copying object") +} + +// +// NoneFamily +// +// Receiver -> Option> +// Receiver -> Retained +// + +impl ConvertReturn for Option> { + type Inner = *mut T; + + #[inline] + unsafe fn convert_message_return( + inner: Self::Inner, + _receiver_ptr: *mut AnyObject, + _sel: Sel, + ) -> Self { + // NOTE: All code between the message send and `retain_autoreleased` + // must be able to be optimized away for it to work optimally. + + // SAFETY: The selector is not `new`, `alloc`, `init`, `copy` nor + // `mutableCopy`, so the object must be manually retained. + // + // Validity of the pointer is upheld by the caller. + unsafe { Retained::retain_autoreleased(inner) } + } + + #[inline] + fn convert_defined_return(self) -> Self::Inner { + Retained::autorelease_return_option(self) + } +} + +impl ConvertReturn for Retained { + type Inner = *mut T; + + #[inline] + unsafe fn convert_message_return( + inner: Self::Inner, + receiver_ptr: *mut AnyObject, + sel: Sel, + ) -> Self { + // SAFETY: The selector is not `new`, `alloc`, `init`, `copy` nor + // `mutableCopy`, so the object must be manually retained. + // + // Validity of the pointer is upheld by the caller. + let ret = unsafe { Retained::retain_autoreleased(inner) }; + if let Some(ret) = ret { + ret + } else { + // SAFETY: The receiver is still valid after a message send to + // a `none` method - it would not be if the method was `init`. + let receiver = unsafe { receiver_ptr.as_ref() }; + none_fail(receiver, sel) + } + } + + #[inline] + fn convert_defined_return(self) -> Self::Inner { + Retained::autorelease_return(self) + } +} + +#[cold] +#[track_caller] +fn none_fail(receiver: Option<&AnyObject>, sel: Sel) -> ! { + if let Some(receiver) = receiver { + let cls = receiver.class(); + panic!( + "unexpected NULL returned from {}[{cls} {sel}]", + if cls.is_metaclass() { "+" } else { "-" }, + ) + } else { + panic!("unexpected NULL {sel}; receiver was NULL"); + } +} diff --git a/crates/objc2/src/__macro_helpers/writeback.rs b/crates/objc2/src/__macro_helpers/writeback.rs index 5bf2db73c..d1837ef7c 100644 --- a/crates/objc2/src/__macro_helpers/writeback.rs +++ b/crates/objc2/src/__macro_helpers/writeback.rs @@ -225,7 +225,7 @@ mod tests { use super::*; use crate::rc::{autoreleasepool, Allocated, RcTestObject, ThreadTestData}; - use crate::{msg_send, msg_send_id, ClassType}; + use crate::{msg_send, ClassType}; #[test] fn test_bool_error() { @@ -319,7 +319,7 @@ mod tests { autoreleasepool(|_| { let obj: Option> = - unsafe { msg_send_id![cls, idAndShouldError: false, error: &mut err] }; + unsafe { msg_send![cls, idAndShouldError: false, error: &mut err] }; expected.alloc += 1; expected.init += 1; if !AUTORELEASE_SKIPPED { @@ -357,7 +357,7 @@ mod tests { // Succeeds let mut error: Option> = None; let res: Allocated = unsafe { - msg_send_id![RcTestObject::class(), allocAndShouldError: false, error: &mut error] + msg_send![RcTestObject::class(), allocAndShouldError: false, error: &mut error] }; expected.alloc += 1; expected.assert_current(); @@ -374,7 +374,7 @@ mod tests { let res: Retained = autoreleasepool(|_pool| { let mut error = None; let res: Allocated = unsafe { - msg_send_id![RcTestObject::class(), allocAndShouldError: true, error: &mut error] + msg_send![RcTestObject::class(), allocAndShouldError: true, error: &mut error] }; expected.alloc += 1; expected.init += 1; diff --git a/crates/objc2/src/exception.rs b/crates/objc2/src/exception.rs index 74081e7ff..a545b9275 100644 --- a/crates/objc2/src/exception.rs +++ b/crates/objc2/src/exception.rs @@ -41,12 +41,12 @@ use crate::encode::{Encoding, RefEncode}; use crate::ffi; #[cfg(feature = "catch-all")] use crate::ffi::NSUInteger; +#[cfg(feature = "catch-all")] +use crate::msg_send; use crate::rc::{autoreleasepool_leaking, Retained}; use crate::runtime::__nsstring::nsstring_to_str; use crate::runtime::{AnyClass, AnyObject, NSObject, NSObjectProtocol}; use crate::{extern_methods, sel, Message}; -#[cfg(feature = "catch-all")] -use crate::{msg_send, msg_send_id}; /// An Objective-C exception. /// @@ -105,7 +105,7 @@ impl Exception { // SAFETY: The object is an `NSException`. // Returns `NSArray`. let call_stack_symbols: Option> = - unsafe { msg_send_id![self.0, callStackSymbols] }; + unsafe { msg_send![self.0, callStackSymbols] }; if let Some(call_stack_symbols) = call_stack_symbols { writeln!(f, "stack backtrace:")?; @@ -117,7 +117,7 @@ impl Exception { while i < count { // SAFETY: The index is in-bounds (so no exception will be thrown). let symbol: Retained = - unsafe { msg_send_id![&call_stack_symbols, objectAtIndex: i] }; + unsafe { msg_send![&call_stack_symbols, objectAtIndex: i] }; // SAFETY: The symbol is an NSString, and is not used // beyond this scope. let symbol = unsafe { nsstring_to_str(&symbol, pool) }; @@ -141,12 +141,14 @@ extern_methods!( unsafe impl Exception { // Only safe on NSException // Returns NSString - #[method_id(name)] + #[method(name)] + #[unsafe(method_family = none)] unsafe fn name(&self) -> Option>; // Only safe on NSException // Returns NSString - #[method_id(reason)] + #[method(reason)] + #[unsafe(method_family = none)] unsafe fn reason(&self) -> Option>; } ); @@ -347,7 +349,7 @@ mod tests { use std::panic::catch_unwind; use super::*; - use crate::msg_send_id; + use crate::msg_send; #[test] fn test_catch() { @@ -384,7 +386,7 @@ mod tests { let obj = AssertUnwindSafe(NSObject::new()); let ptr = Retained::as_ptr(&obj); let result = catch(|| { - let _: Retained = unsafe { msg_send_id![&*obj, copy] }; + let _: Retained = unsafe { msg_send![&*obj, copy] }; }); let err = result.unwrap_err().unwrap(); diff --git a/crates/objc2/src/lib.rs b/crates/objc2/src/lib.rs index 2232402ab..53d0e3fd4 100644 --- a/crates/objc2/src/lib.rs +++ b/crates/objc2/src/lib.rs @@ -25,13 +25,12 @@ //! Next, we initialize this object. It is ensured to be deallocated using //! [`rc::Retained`]. //! Now we're free to send messages to the object to our hearts desire using -//! the [`msg_send!`] or [`msg_send_id!`] macros (depending on the return type -//! of the method). +//! the [`msg_send!`] macro. //! Finally, the `Retained` goes out of scope, and the object is released and //! deallocated. //! //! ``` -//! use objc2::{msg_send, msg_send_id, AllocAnyThread, ClassType}; +//! use objc2::{msg_send, AllocAnyThread, ClassType}; //! use objc2::ffi::NSUInteger; //! use objc2::rc::Retained; //! use objc2::runtime::{NSObject, NSObjectProtocol}; @@ -39,7 +38,7 @@ //! // Creation //! //! let obj1: Retained = unsafe { -//! msg_send_id![NSObject::alloc(), init] +//! msg_send![NSObject::alloc(), init] //! }; //! // Or //! let obj2 = NSObject::new(); @@ -55,7 +54,7 @@ //! }; //! assert!(is_kind); //! -//! let obj1_self: Retained = unsafe { msg_send_id![&obj1, self] }; +//! let obj1_self: Retained = unsafe { msg_send![&obj1, self] }; //! assert_eq!(obj1, obj1_self); //! //! // Deallocation on drop diff --git a/crates/objc2/src/macros/__attribute_helpers.rs b/crates/objc2/src/macros/__attribute_helpers.rs index 8d81f0fd7..d54d31ef3 100644 --- a/crates/objc2/src/macros/__attribute_helpers.rs +++ b/crates/objc2/src/macros/__attribute_helpers.rs @@ -72,7 +72,7 @@ macro_rules! __extract_and_apply_cfg_attributes { /// 2. The requested method family, if any was present. /// /// One of `new`, `alloc`, `init`, `copy`, `mutableCopy` or `none`. -/// ($($method_family:ident)?) +/// ($($method_family:tt)*) /// /// 3. The `optional` attribute, if any. /// ($(#[optional])?) @@ -183,7 +183,7 @@ macro_rules! __extract_method_attributes_inner { ($out_macro:path) $($out_args:tt)* } => { - $crate::__handle_duplicate!("method`/`method_id"; $($method)*); + $crate::__handle_duplicate!("method"; $($method)*); $crate::__extract_method_attributes_inner! { ($($rest)*) diff --git a/crates/objc2/src/macros/__method_msg_send.rs b/crates/objc2/src/macros/__method_msg_send.rs index 321f6922e..3aeec439d 100644 --- a/crates/objc2/src/macros/__method_msg_send.rs +++ b/crates/objc2/src/macros/__method_msg_send.rs @@ -13,10 +13,12 @@ macro_rules! __method_msg_send { () () + ($($method_family:tt)*) ) => { $crate::__msg_send_helper! { ($receiver) - (send_message) + ($($method_family)*) + (MsgSend::send_message) ($sel) () } @@ -34,6 +36,7 @@ macro_rules! __method_msg_send { ($($sel_parsed:tt)*) ($($arg_parsed:tt)*) + ($($method_family:tt)*) ) => ({ let _ = $arg; $crate::__method_msg_send! { @@ -43,6 +46,7 @@ macro_rules! __method_msg_send { ($($sel_parsed)*) ($($arg_parsed)*) + ($($method_family)*) } }); @@ -54,6 +58,7 @@ macro_rules! __method_msg_send { ($($sel_parsed:tt)*) ($($arg_parsed:tt)*) + ($($method_family:tt)*) ) => { $crate::__method_msg_send! { ($receiver) @@ -62,6 +67,7 @@ macro_rules! __method_msg_send { ($($sel_parsed)* $($sel)? :) ($($arg_parsed)* $arg,) + ($($method_family)*) } }; // Handle path separator token @@ -72,6 +78,7 @@ macro_rules! __method_msg_send { ($($sel_parsed:tt)*) ($($arg_parsed:tt)*) + ($($method_family:tt)*) ) => { $crate::__method_msg_send! { ($receiver) @@ -80,6 +87,7 @@ macro_rules! __method_msg_send { ($($sel_parsed)* $($sel)? : :) ($($arg_parsed)* $arg1, $arg2,) + ($($method_family)*) } }; @@ -93,10 +101,12 @@ macro_rules! __method_msg_send { // a selector, and haven't just gotten an empty `#[method()]`. ($($sel_parsed:tt)+) ($($arg_parsed:tt)*) + ($($method_family:tt)*) ) => { $crate::__msg_send_helper! { ($receiver) - (send_message) + ($($method_family)*) + (MsgSend::send_message) ($($sel_parsed)*) ($($arg_parsed)*) } @@ -111,11 +121,13 @@ macro_rules! __method_msg_send { ($($sel_parsed:tt)*) ($($arg_parsed:tt)*) + ($($method_family:tt)*) ) => { $crate::__msg_send_helper! { ($receiver) + ($($method_family)*) // Use error method - (send_message_error) + (MsgSendError::send_message_error) ($($sel_parsed)* $sel :) ($($arg_parsed)*) } @@ -129,6 +141,7 @@ macro_rules! __method_msg_send { ($($sel_parsed:tt)*) ($($arg_parsed:tt)*) + ($($method_family:tt)*) ) => ({ $crate::__macro_helpers::compile_error!( "variadic methods are not yet supported" @@ -143,172 +156,7 @@ macro_rules! __method_msg_send { ($($sel_parsed:tt)*) ($($arg_parsed:tt)*) - ) => ({ - $crate::__macro_helpers::compile_error!( - "number of arguments in function and selector did not match" - ) - }); -} - -/// Same as `__method_msg_send`, just for `msg_send_id!`. -#[doc(hidden)] -#[macro_export] -macro_rules! __method_msg_send_id { - // Selector with no arguments - ( - ($receiver:expr) - ($sel:ident) - () - - () - () - ($($method_family:ident)?) - ) => { - $crate::__msg_send_id_helper! { - ($receiver) - ($($method_family)?) - (MsgSendRetained) - (send_message_retained) - ($sel) - () - } - }; - - // Skip using `MainThreadMarker` in the message send. - // - // This is a purely textual match, and using e.g. `objc2::MainThreadMarker` - // would fail - but that would just be detected as giving a wrong number - // of arguments, so it's fine for now. - ( - ($receiver:expr) - ($($sel_rest:tt)*) - ($arg:ident: MainThreadMarker $(, $($params_rest:tt)*)?) - - ($($sel_parsed:tt)*) - ($($arg_parsed:tt)*) - ($($method_family:ident)?) - ) => ({ - let _ = $arg; - $crate::__method_msg_send_id! { - ($receiver) - ($($sel_rest)*) - ($($($params_rest)*)?) - - ($($sel_parsed)*) - ($($arg_parsed)*) - ($($method_family)?) - } - }); - - // Parse each argument-selector pair - ( - ($receiver:expr) - ($($sel:ident)? : $($sel_rest:tt)*) - ($arg:ident : $_arg_ty:ty $(, $($params_rest:tt)*)?) - - ($($sel_parsed:tt)*) - ($($arg_parsed:tt)*) - ($($method_family:ident)?) - ) => { - $crate::__method_msg_send_id! { - ($receiver) - ($($sel_rest)*) - ($($($params_rest)*)?) - - ($($sel_parsed)* $($sel)? :) - ($($arg_parsed)* $arg,) - ($($method_family)?) - } - }; - // Handle path separator token - ( - ($receiver:expr) - ($($sel:ident)? :: $($sel_rest:tt)*) - ($arg1:ident : $_arg_ty1:ty, $arg2:ident : $_arg_ty2:ty $(, $($params_rest:tt)*)?) - - ($($sel_parsed:tt)*) - ($($arg_parsed:tt)*) - ($($method_family:ident)?) - ) => { - $crate::__method_msg_send_id! { - ($receiver) - ($($sel_rest)*) - ($($($params_rest)*)?) - - ($($sel_parsed)* $($sel)? : :) - ($($arg_parsed)* $arg1, $arg2,) - ($($method_family)?) - } - }; - - // Normal return - ( - ($receiver:expr) - () - () - - // Notice the "+" here; we must make sure we actually _did_ parse - // a selector, and haven't just gotten an empty `#[method()]`. - ($($sel_parsed:tt)+) - ($($arg_parsed:tt)*) - ($($method_family:ident)?) - ) => { - $crate::__msg_send_id_helper! { - ($receiver) - ($($method_family)?) - (MsgSendRetained) - (send_message_retained) - ($($sel_parsed)*) - ($($arg_parsed)*) - } - }; - - // Error return - ( - ($receiver:expr) - // `sel:_` without a corresponding argument - ($sel:ident : _) - () - - ($($sel_parsed:tt)*) - ($($arg_parsed:tt)*) - ($($method_family:ident)?) - ) => { - $crate::__msg_send_id_helper! { - ($receiver) - ($($method_family)?) - (MsgSendRetained) - // Use error method - (send_message_retained_error) - ($($sel_parsed)* $sel :) - ($($arg_parsed)*) - } - }; - - // Variadic method - ( - ($receiver:expr) - ($($sel:ident : _)?) - ($($arg:ident :)? ...) - - ($($sel_parsed:tt)*) - ($($arg_parsed:tt)*) - ($($method_family:ident)?) - ) => ({ - $crate::__macro_helpers::compile_error!( - "variadic methods are not yet supported" - ) - }); - - // Mismatched selector/argument - ( - ($receiver:expr) - ($($sel_rest:tt)*) - ($($params_rest:tt)*) - - ($($sel_parsed:tt)*) - ($($arg_parsed:tt)*) - ($($method_family:ident)?) + ($($method_family:tt)*) ) => ({ $crate::__macro_helpers::compile_error!( "number of arguments in function and selector did not match" diff --git a/crates/objc2/src/macros/__msg_send_parse.rs b/crates/objc2/src/macros/__msg_send_parse.rs index 5bd65d945..e14ac03ba 100644 --- a/crates/objc2/src/macros/__msg_send_parse.rs +++ b/crates/objc2/src/macros/__msg_send_parse.rs @@ -3,22 +3,24 @@ macro_rules! __msg_send_parse { // No arguments { - ($error_fn:ident) // Intentionally empty () () ($selector:ident $(,)?) - ($fn:ident) + + ($($error_data:tt)*) + ($($data:tt)*) ($out_macro:path) $($macro_args:tt)* } => { $crate::__msg_send_parse! { - ($error_fn) ($selector) () () - ($fn) + + ($($error_data)*) + ($($data)*) ($out_macro) $($macro_args)* @@ -28,11 +30,12 @@ macro_rules! __msg_send_parse { // tt-munch remaining `selector: argument` pairs, looking for a pattern // that ends with `sel: _`. { - ($_error_fn:ident) ($($selector_output:tt)*) ($($argument_output:tt)*) () - ($fn:ident) + + ($($error_data:tt)*) + ($($data:tt)*) ($out_macro:path) $($macro_args:tt)* @@ -40,50 +43,54 @@ macro_rules! __msg_send_parse { $out_macro! { $($macro_args)* - ($fn) + ($($data)*) ($($selector_output)*) ($($argument_output)*) } }); { - ($error_fn:ident) ($($selector_output:tt)*) ($($argument_output:tt)*) ($selector:ident: _ $(,)?) - ($fn:ident) + + ($($error_data:tt)*) + ($($data:tt)*) ($out_macro:path) $($macro_args:tt)* } => { $crate::__msg_send_parse! { - ($error_fn) ($($selector_output)* $selector:) // Don't pass an argument ($($argument_output)*) () - // Instead, we change the called function to the error function. - ($error_fn) + + // Instead, we change the data to the error data. + ($($error_data)*) + ($($error_data)*) ($out_macro) $($macro_args)* } }; { - ($error_fn:ident) ($($selector_output:tt)*) ($($argument_output:tt)*) ($selector:ident : $argument:expr $(, $($rest:tt)*)?) - ($fn:ident) + + ($($error_data:tt)*) + ($($data:tt)*) ($out_macro:path) $($macro_args:tt)* } => { $crate::__msg_send_parse! { - ($error_fn) ($($selector_output)* $selector:) ($($argument_output)* $argument,) ($($($rest)*)?) - ($fn) + + ($($error_data)*) + ($($data)*) ($out_macro) $($macro_args)* @@ -92,18 +99,19 @@ macro_rules! __msg_send_parse { // Handle calls without comma between `selector: argument` pair. { - ($error_fn:ident) // Intentionally empty () () ($($selector:ident : $argument:expr)*) - ($fn:ident) + + ($($error_data:tt)*) + ($($data:tt)*) ($out_macro:path) $($macro_args:tt)* } => {{ $crate::__comma_between_args!( - ($fn) + ($($data)*) ($( ", ", @@ -116,11 +124,12 @@ macro_rules! __msg_send_parse { ); $crate::__msg_send_parse! { - ($error_fn) () () ($($selector : $argument),*) - ($fn) + + ($($error_data)*) + ($($data)*) ($out_macro) $($macro_args)* @@ -139,71 +148,36 @@ macro_rules! __comma_between_args { #[macro_export] #[cfg(feature = "unstable-msg-send-always-comma")] macro_rules! __comma_between_args { - // msg_send! ( - (send_super_message_static) - ($($args:tt)*) - ($obj:expr) - ) => { - $crate::__comma_between_args_inner! { - ("msg_send") - ("super", $crate::__macro_helpers::stringify!(($obj)), $($args)*) - } - }; - ( - (send_super_message) - ($($args:tt)*) - ($obj:expr, $superclass:expr) - ) => { - $crate::__comma_between_args_inner! { - ("msg_send") - ("super", $crate::__macro_helpers::stringify!(($obj, $superclass)), $($args)*) - } - }; - ( - (send_message) - ($($args:tt)*) - ($obj:expr) - ) => { - $crate::__comma_between_args_inner! { - ("msg_send") - ($crate::__macro_helpers::stringify!($obj), $($args)*) - } - }; - // msg_send_id! - ( - (send_super_message_retained_static) + (MsgSendSuper::send_super_message_static) ($($args:tt)*) ($obj:expr) () - (MsgSendSuperRetained) ) => { $crate::__comma_between_args_inner! { - ("msg_send_id") + ("msg_send") ("super", $crate::__macro_helpers::stringify!(($obj)), $($args)*) } }; ( - (send_super_message_retained) + (MsgSendSuper::send_super_message) ($($args:tt)*) ($obj:expr, $superclass:expr) () - (MsgSendSuperRetained) ) => { $crate::__comma_between_args_inner! { - ("msg_send_id") + ("msg_send") ("super", $crate::__macro_helpers::stringify!(($obj, $superclass)), $($args)*) } }; ( - (send_message_retained) + (MsgSend::send_message) ($($args:tt)*) ($obj:expr) () - (MsgSendRetained) ) => { $crate::__comma_between_args_inner! { - ("msg_send_id") + ("msg_send") ($crate::__macro_helpers::stringify!($obj), $($args)*) } }; diff --git a/crates/objc2/src/macros/define_class.rs b/crates/objc2/src/macros/define_class.rs index d9cb903da..72217e4bc 100644 --- a/crates/objc2/src/macros/define_class.rs +++ b/crates/objc2/src/macros/define_class.rs @@ -268,8 +268,8 @@ /// use objc2_foundation::{NSCopying, NSObject, NSObjectProtocol, NSZone}; /// use objc2::rc::{Allocated, Retained}; /// use objc2::{ -/// define_class, extern_protocol, msg_send, msg_send_id, AllocAnyThread, -/// ClassType, DefinedClass, ProtocolType, +/// define_class, extern_protocol, msg_send, AllocAnyThread, ClassType, +/// DefinedClass, ProtocolType, /// }; /// /// #[derive(Clone)] @@ -299,7 +299,7 @@ /// bar: 42, /// object: NSObject::new(), /// }); -/// unsafe { msg_send_id![super(this), init] } +/// unsafe { msg_send![super(this), init] } /// } /// /// #[method(foo)] @@ -320,7 +320,7 @@ /// # #[method_id(copyWithZone:)] /// # fn copyWithZone(&self, _zone: *const NSZone) -> Retained { /// # let new = Self::alloc().set_ivars(self.ivars().clone()); -/// # unsafe { msg_send_id![super(new), init] } +/// # unsafe { msg_send![super(new), init] } /// # } /// } /// @@ -331,7 +331,7 @@ /// #[method_id(copyWithZone:)] /// fn copyWithZone(&self, _zone: *const NSZone) -> Retained { /// let new = Self::alloc().set_ivars(self.ivars().clone()); -/// unsafe { msg_send_id![super(new), init] } +/// unsafe { msg_send![super(new), init] } /// } /// /// // If we have tried to add other methods here, or had forgotten @@ -346,7 +346,7 @@ /// /// impl MyCustomObject { /// pub fn new(foo: u8) -> Retained { -/// unsafe { msg_send_id![Self::alloc(), initWithFoo: foo] } +/// unsafe { msg_send![Self::alloc(), initWithFoo: foo] } /// } /// /// pub fn get_foo(&self) -> u8 { @@ -354,7 +354,7 @@ /// } /// /// pub fn get_object(&self) -> Retained { -/// unsafe { msg_send_id![self, object] } +/// unsafe { msg_send![self, object] } /// } /// /// pub fn my_class_method() -> bool { @@ -368,7 +368,7 @@ /// assert_eq!(obj.ivars().bar, 42); /// assert!(obj.ivars().object.isKindOfClass(NSObject::class())); /// -/// # let obj: Retained = unsafe { msg_send_id![&obj, copy] }; +/// # let obj: Retained = unsafe { msg_send![&obj, copy] }; /// # #[cfg(available_in_foundation)] /// let obj = obj.copy(); /// @@ -1266,7 +1266,7 @@ macro_rules! __define_class_method_out_inner { $($qualifiers)* extern "C-unwind" fn $name( $($params_prefix)* $($params_converted)* - ) $(-> <$ret as $crate::__macro_helpers::ConvertReturn>::__Inner)? { + ) $(-> <$ret as $crate::__macro_helpers::ConvertReturn<()>>::Inner)? { $($body_prefix)* $crate::__convert_result! { $body $(; $ret)? @@ -1358,7 +1358,7 @@ macro_rules! __convert_result { ($body:block; $ret:ty) => { let __objc2_result = $body; #[allow(unreachable_code)] - <$ret as $crate::__macro_helpers::ConvertReturn>::__into_defined_return(__objc2_result) + <$ret as $crate::__macro_helpers::ConvertReturn<()>>::convert_defined_return(__objc2_result) }; } diff --git a/crates/objc2/src/macros/extern_class.rs b/crates/objc2/src/macros/extern_class.rs index 4f78ce90b..959ceff78 100644 --- a/crates/objc2/src/macros/extern_class.rs +++ b/crates/objc2/src/macros/extern_class.rs @@ -106,7 +106,7 @@ /// # use objc2::runtime::NSObjectProtocol; /// use objc2::rc::Retained; /// use objc2::runtime::NSObject; -/// use objc2::{extern_class, msg_send_id, ClassType}; +/// use objc2::{extern_class, msg_send, ClassType}; /// /// extern_class!( /// /// An example description, to show that doc comments work. @@ -134,7 +134,7 @@ /// let cls = NSFormatter::class(); /// /// // `NSFormatter` implements `Message`: -/// let obj: Retained = unsafe { msg_send_id![cls, new] }; +/// let obj: Retained = unsafe { msg_send![cls, new] }; /// } /// ``` /// diff --git a/crates/objc2/src/macros/extern_methods.rs b/crates/objc2/src/macros/extern_methods.rs index 91f5042a1..a097da959 100644 --- a/crates/objc2/src/macros/extern_methods.rs +++ b/crates/objc2/src/macros/extern_methods.rs @@ -1,10 +1,9 @@ /// Define methods on an external class. /// /// This is a convenience macro to generate associated functions and methods -/// that call [`msg_send!`] or [`msg_send_id!`] appropriately. +/// that delegate to [`msg_send!`]. /// /// [`msg_send!`]: crate::msg_send -/// [`msg_send_id!`]: crate::msg_send_id /// /// /// # Specification @@ -41,17 +40,14 @@ /// Exceptions and special attributes are noted below. /// /// -/// ### `#[method(...)]` or `#[method_id(...)]` (required) +/// ### `#[method(...)]` (required) /// -/// Specify the desired selector using the `#[method(my:selector:)]` or -/// `#[method_id(my:selector:)]` attributes. `method` makes the macro delegate -/// to [`msg_send!`], while `method_id` delegates to [`msg_send_id!`]. +/// Specify the desired selector using this attribute. /// -/// If the selector ends with "_", as in `#[method(my:error:_)]` or -/// `#[method_id(my:error:_)]`, the method is assumed to take an -/// implicit `NSError**` parameter, which is automatically converted to a -/// [`Result`]. See the error section in [`msg_send!`] and [`msg_send_id!`] -/// for details. +/// If the selector ends with "_", as in `#[method(my:error:_)]`, the method +/// is assumed to take an implicit `NSError**` parameter, which is +/// automatically converted to a [`Result`]. See the error section in +/// [`msg_send!`] for details. /// /// /// ### `#[unsafe(method_family = ...)]` (optional) @@ -98,10 +94,6 @@ /// attribute upholds the safety guarantees described in the [`msg_send!`] /// macro, _or_ are marked `unsafe`. /// -/// Likewise, you must ensure that any methods you declare with the -/// `#[method_id(...)]` attribute upholds the safety guarantees described in -/// the [`msg_send_id!`] macro, _or_ are marked `unsafe`. -/// /// /// # Examples /// @@ -133,10 +125,10 @@ /// extern_methods!( /// /// Creation methods. /// unsafe impl MyObject { -/// #[method_id(new)] +/// #[method(new)] /// pub fn new() -> Retained; /// -/// #[method_id(initWithVal:)] +/// #[method(initWithVal:)] /// // arbitrary self types are not stable, but we can work around it /// // with the special name `this`. /// pub fn init(this: Allocated, val: usize) -> Retained; @@ -147,7 +139,7 @@ /// #[method(foo)] /// pub fn foo(&self) -> NSUInteger; /// -/// #[method_id(fooObject)] +/// #[method(fooObject)] /// pub fn foo_object(&self) -> Retained; /// /// #[method(withError:_)] @@ -180,16 +172,16 @@ /// # } /// # ); /// # -/// use objc2::{msg_send, msg_send_id}; +/// use objc2::msg_send; /// /// /// Creation methods. /// impl MyObject { /// pub fn new() -> Retained { -/// unsafe { msg_send_id![Self::class(), new] } +/// unsafe { msg_send![Self::class(), new] } /// } /// /// pub fn init(this: Allocated, val: usize) -> Retained { -/// unsafe { msg_send_id![this, initWithVal: val] } +/// unsafe { msg_send![this, initWithVal: val] } /// } /// } /// @@ -200,7 +192,7 @@ /// } /// /// pub fn foo_object(&self) -> Retained { -/// unsafe { msg_send_id![self, fooObject] } +/// unsafe { msg_send![self, fooObject] } /// } /// /// // Since the selector specifies one more argument than we @@ -328,7 +320,6 @@ macro_rules! __extern_methods_rewrite_methods { #[doc(hidden)] #[macro_export] macro_rules! __extern_methods_method_out { - // #[method(...)] { ($($function_start:tt)*) ($($where:ty : $bound:path ,)*) @@ -339,7 +330,7 @@ macro_rules! __extern_methods_method_out { ($($__params_prefix:tt)*) ($($params_rest:tt)*) - (#[method($($sel:tt)*)]) + (#[$method_or_method_id:ident($($sel:tt)*)]) ($($method_family:tt)*) ($($optional:tt)*) ($($attr_method:tt)*) @@ -350,7 +341,7 @@ macro_rules! __extern_methods_method_out { where $($where : $bound,)* { - $crate::__extern_methods_no_method_family!($($method_family)*); + $crate::__extern_methods_method_id_deprecated!($method_or_method_id($($sel)*)); $crate::__extern_methods_no_optional!($($optional)*); #[allow(unused_unsafe)] @@ -360,44 +351,6 @@ macro_rules! __extern_methods_method_out { ($($sel)*) ($($params_rest)*) - () - () - } - } - } - }; - - // #[method_id(...)] - { - ($($function_start:tt)*) - ($($where:ty : $bound:path ,)*) - - ($__builder_method:ident) - ($receiver:expr) - ($__receiver_ty:ty) - ($($__params_prefix:tt)*) - ($($params_rest:tt)*) - - (#[method_id($($sel:tt)*)]) - ($($method_family:tt)*) - ($($optional:tt)*) - ($($attr_method:tt)*) - ($($attr_use:tt)*) - } => { - $($attr_method)* - $($function_start)* - where - $($where : $bound,)* - { - $crate::__extern_methods_no_optional!($($optional)*); - - #[allow(unused_unsafe)] - unsafe { - $crate::__method_msg_send_id! { - ($receiver) - ($($sel)*) - ($($params_rest)*) - () () ($($method_family)*) @@ -409,22 +362,29 @@ macro_rules! __extern_methods_method_out { #[doc(hidden)] #[macro_export] -macro_rules! __extern_methods_no_method_family { +macro_rules! __extern_methods_no_optional { () => {}; - ($($t:tt)+) => { + (#[optional]) => { $crate::__macro_helpers::compile_error!( - "`#[method_family = ...]` is only supported together with `#[method_id(...)]`" + "`#[optional]` is only supported in `extern_protocol!`" ) }; } #[doc(hidden)] #[macro_export] -macro_rules! __extern_methods_no_optional { - () => {}; - (#[optional]) => { - $crate::__macro_helpers::compile_error!( - "`#[optional]` is only supported in `extern_protocol!`" - ) - }; +macro_rules! __extern_methods_method_id_deprecated { + (method($($sel:tt)*)) => {}; + (method_id($($sel:tt)*)) => {{ + #[deprecated = $crate::__macro_helpers::concat!( + "using #[method_id(", + $crate::__macro_helpers::stringify!($($sel)*), + ")] inside extern_methods! is deprecated.\nUse #[method(", + $crate::__macro_helpers::stringify!($($sel)*), + ")] instead", + )] + #[inline] + fn method_id() {} + method_id(); + }}; } diff --git a/crates/objc2/src/macros/extern_protocol.rs b/crates/objc2/src/macros/extern_protocol.rs index 7c9b1c2d1..17bbee48d 100644 --- a/crates/objc2/src/macros/extern_protocol.rs +++ b/crates/objc2/src/macros/extern_protocol.rs @@ -329,7 +329,7 @@ macro_rules! __extern_protocol_rewrite_methods { #[doc(hidden)] #[macro_export] macro_rules! __extern_protocol_method_out { - // Instance #[method(...)] + // Instance method { ($($function_start:tt)*) ($($where:ty : $bound:path ,)*) @@ -340,7 +340,7 @@ macro_rules! __extern_protocol_method_out { ($($__params_prefix:tt)*) ($($params_rest:tt)*) - (#[method($($sel:tt)*)]) + (#[$method_or_method_id:ident($($sel:tt)*)]) ($($method_family:tt)*) ($($optional:tt)*) ($($attr_method:tt)*) @@ -352,7 +352,7 @@ macro_rules! __extern_protocol_method_out { Self: $crate::__macro_helpers::Sized + $crate::Message $(, $where : $bound)* { - $crate::__extern_protocol_no_method_family!($($method_family)*); + $crate::__extern_methods_method_id_deprecated!($method_or_method_id($($sel)*)); #[allow(unused_unsafe)] unsafe { @@ -361,43 +361,6 @@ macro_rules! __extern_protocol_method_out { ($($sel)*) ($($params_rest)*) - () - () - } - } - } - }; - - // Instance #[method_id(...)] - { - ($($function_start:tt)*) - ($($where:ty : $bound:path ,)*) - - (add_method) - ($receiver:expr) - ($__receiver_ty:ty) - ($($__params_prefix:tt)*) - ($($params_rest:tt)*) - - (#[method_id($($sel:tt)*)]) - ($($method_family:tt)*) - ($($optional:tt)*) - ($($attr_method:tt)*) - ($($attr_use:tt)*) - } => { - $($attr_method)* - $($function_start)* - where - Self: $crate::__macro_helpers::Sized + $crate::Message - $(, $where : $bound)* - { - #[allow(unused_unsafe)] - unsafe { - $crate::__method_msg_send_id! { - ($receiver) - ($($sel)*) - ($($params_rest)*) - () () ($($method_family)*) @@ -406,7 +369,7 @@ macro_rules! __extern_protocol_method_out { } }; - // Class #[method(...)] + // Class method { ($($function_start:tt)*) ($($where:ty : $bound:path ,)*) @@ -417,7 +380,7 @@ macro_rules! __extern_protocol_method_out { ($($__params_prefix:tt)*) ($($params_rest:tt)*) - (#[method($($sel:tt)*)]) + (#[$method_or_method_id:ident($($sel:tt)*)]) ($($method_family:tt)*) ($($optional:tt)*) ($($attr_method:tt)*) @@ -429,7 +392,7 @@ macro_rules! __extern_protocol_method_out { Self: $crate::__macro_helpers::Sized + $crate::ClassType $(, $where : $bound)* { - $crate::__extern_protocol_no_method_family!($($method_family)*); + $crate::__extern_methods_method_id_deprecated!($method_or_method_id($($sel)*)); #[allow(unused_unsafe)] unsafe { @@ -438,43 +401,6 @@ macro_rules! __extern_protocol_method_out { ($($sel)*) ($($params_rest)*) - () - () - } - } - } - }; - - // Class #[method_id(...)] - { - ($($function_start:tt)*) - ($($where:ty : $bound:path ,)*) - - (add_class_method) - ($receiver:expr) - ($__receiver_ty:ty) - ($($__params_prefix:tt)*) - ($($params_rest:tt)*) - - (#[method_id($($sel:tt)*)]) - ($($method_family:tt)*) - ($($optional:tt)*) - ($($attr_method:tt)*) - ($($attr_use:tt)*) - } => { - $($attr_method)* - $($function_start)* - where - Self: $crate::__macro_helpers::Sized + $crate::ClassType - $(, $where : $bound)* - { - #[allow(unused_unsafe)] - unsafe { - $crate::__method_msg_send_id! { - ($receiver) - ($($sel)*) - ($($params_rest)*) - () () ($($method_family)*) @@ -486,13 +412,20 @@ macro_rules! __extern_protocol_method_out { #[doc(hidden)] #[macro_export] -macro_rules! __extern_protocol_no_method_family { - () => {}; - ($($t:tt)+) => { - $crate::__macro_helpers::compile_error!( - "`#[method_family = ...]` is only supported together with `#[method_id(...)]`" - ) - }; +macro_rules! __extern_protocol_method_id_deprecated { + (method($($sel:tt)*)) => {}; + (method_id($($sel:tt)*)) => {{ + #[deprecated = $crate::__macro_helpers::concat!( + "using #[method_id(", + $crate::__macro_helpers::stringify!($($sel)*), + ")] inside extern_protocol! is deprecated.\nUse #[method(", + $crate::__macro_helpers::stringify!($($sel)*), + ")] instead", + )] + #[inline] + fn method_id() {} + method_id(); + }}; } #[cfg(test)] diff --git a/crates/objc2/src/macros/mod.rs b/crates/objc2/src/macros/mod.rs index 15415bf63..8aa93c862 100644 --- a/crates/objc2/src/macros/mod.rs +++ b/crates/objc2/src/macros/mod.rs @@ -721,12 +721,49 @@ macro_rules! __class_inner { /// C-compatible string. Now it's much, _much_ easier to make a safe /// abstraction around this! /// -/// There exists a variant of this macro, [`msg_send_id!`], which can help -/// with upholding certain requirements of methods that return Objective-C's -/// `id`, or other object pointers. Use that whenever you want to call such a -/// method! +/// The [`extern_methods!`] macro can help with coding this pattern. /// -/// [`msg_send_id!`]: crate::msg_send_id +/// [`extern_methods!`]: crate::extern_methods +/// +/// +/// # Memory management +/// +/// If an Objective-C method returns `id`, `NSObject*`, or similar object +/// pointers, you should use [`Retained`] on the Rust side, or +/// `Option>` if the pointer is nullable. +/// +/// This is necessary because object pointers in Objective-C have certain +/// rules for when they should be retained and released across function calls. +/// +/// [`Retained`]: crate::rc::Retained +/// +/// +/// ## A little history +/// +/// Objective-C's type system is... limited, so you can't tell without +/// consulting the documentation who is responsible for releasing an object. +/// To remedy this problem, Apple/Cocoa introduced (approximately) the +/// following rule: +/// +/// The caller is responsible for releasing objects return from methods that +/// begin with `new`, `alloc`, `copy`, `mutableCopy` or `init`, and method +/// that begins with `init` takes ownership of the receiver. See [Cocoa's +/// Memory Management Policy][mmRules] for a user-friendly introduction to +/// this concept. +/// +/// In the past, users had to do `retain` and `release` calls themselves to +/// properly follow these rules. To avoid the memory management problems +/// associated with manual stuff like that, they [introduced "ARC"][arc-rel], +/// which codifies the rules as part of the language, and inserts the required +/// `retain` and `release` calls automatically. +/// +/// Returning a `*const T` pointer is similar to pre-ARC; you have to know +/// when to retain and when to release an object. Returning `Retained` is +/// similar to ARC; the rules are simple enough that we can do them +/// automatically! +/// +/// [mmRules]: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html#//apple_ref/doc/uid/20000994-SW1 +/// [arc-rel]: https://developer.apple.com/library/archive/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011226 /// /// /// # Specification @@ -739,7 +776,7 @@ macro_rules! __class_inner { /// /// The first expression, know as the "receiver", can be any type that /// implements [`MessageReceiver`], like a reference or a pointer to an -/// object. Additionally, it can even be a reference to an [`rc::Retained`] +/// object. Additionally, it can even be a reference to an [`Retained`] /// containing an object. /// /// The expression can be wrapped in `super`, with an optional superclass @@ -750,7 +787,7 @@ macro_rules! __class_inner { /// the exceptions below). /// /// If the last argument is the special marker `_`, the macro will return a -/// `Result<(), Retained>`, see below. +/// `Result<_, Retained>`, see below. /// /// This macro roughly translates into a call to [`sel!`], and afterwards a /// fully qualified call to [`MessageReceiver::send_message`]. Note that this @@ -762,13 +799,71 @@ macro_rules! __class_inner { /// Variadic arguments are currently not supported. /// /// [`MessageReceiver`]: crate::runtime::MessageReceiver -/// [`rc::Retained`]: crate::rc::Retained +/// [`Retained`]: crate::rc::Retained /// [`ClassType`]: crate::ClassType /// [`Encode`]: crate::Encode /// [`sel!`]: crate::sel /// [`MessageReceiver::send_message`]: crate::runtime::MessageReceiver::send_message /// /// +/// ## Memory management details +/// +/// The accepted receiver and return types, and how we handle them, differ +/// depending on which, if any, of the [recognized selector +/// families][sel-families] the selector belongs to: +/// +/// - The `new` family: The receiver may be anything that implements +/// [`MessageReceiver`] (though often you'll want to use `&AnyClass`). The +/// return type is a generic `Retained` or `Option>`. +/// +/// - The `alloc` family: The receiver must be `&AnyClass`, and the return +/// type is a generic `Allocated`. +/// +/// - The `init` family: The receiver must be `Allocated` as returned from +/// `alloc`, or if sending messages to the superclass, it must be +/// `PartialInit`. +/// +/// The receiver is consumed, and a the now-initialized `Retained` or +/// `Option>` (with the same `T`) is returned. +/// +/// - The `copy` family: The receiver may be anything that implements +/// [`MessageReceiver`] and the return type is a generic `Retained` or +/// `Option>`. +/// +/// - The `mutableCopy` family: Same as the `copy` family. +/// +/// - No family: The receiver may be anything that implements +/// [`MessageReceiver`]. The result is retained using +/// [`Retained::retain_autoreleased`], and a generic `Retained` or +/// `Option>` is returned. This retain is in most cases faster +/// than using autorelease pools! +/// +/// See [the clang documentation][arc-retainable] for the precise +/// specification of Objective-C's ownership rules. +/// +/// As you may have noticed, the return type is usually either `Retained` or +/// `Option`. Internally, the return type is always +/// `Option` (for example: almost all `new` methods can fail if the +/// allocation failed), but for convenience, if the return type is +/// `Retained`, this macro will automatically unwrap the object, or panic +/// with an error message if it couldn't be retrieved. +/// +/// As a special case, if the last argument is the marker `_`, the macro will +/// return a `Result, Retained>`, see below. +/// +/// The `retain`, `release` and `autorelease` selectors are not supported, use +/// [`Retained::retain`], [`Retained::drop`] and [`Retained::autorelease_ptr`] +/// for that. +/// +/// [sel-families]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-method-families +/// [`MessageReceiver`]: crate::runtime::MessageReceiver +/// [`Retained::retain_autoreleased`]: crate::rc::Retained::retain_autoreleased +/// [arc-retainable]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#retainable-object-pointers-as-operands-and-arguments +/// [`Retained::retain`]: crate::rc::Retained::retain +/// [`Retained::drop`]: crate::rc::Retained::drop +/// [`Retained::autorelease_ptr`]: crate::rc::Retained::autorelease_ptr +/// +/// /// # `bool` handling /// /// Objective-C's `BOOL` is slightly different from Rust's [`bool`], and hence @@ -815,22 +910,20 @@ macro_rules! __class_inner { /// /// Similar to Swift's [importing of error parameters][swift-error], this /// macro supports an even more convenient version than the out-parameter -/// support, which transforms methods whose last parameter is `NSError**` and -/// returns `BOOL`, into the Rust equivalent, the [`Result`] type. +/// support, which transforms methods whose last parameter is `NSError**` into +/// the Rust equivalent, the [`Result`] type. /// /// In particular, if you make the last argument the special marker `_`, then -/// the macro will return a `Result<(), Retained>` (where you must specify -/// `E` yourself, and where `E` must be either [`NSObject`] or -/// `objc2_foundation::NSError`). +/// the macro will return a `Result>`. The error type `E` must +/// be either [`NSObject`] or `objc2_foundation::NSError`. +/// +/// The success type `R` must be either `()` or `Retained`. /// /// At runtime, we create the temporary error variable for you on the stack /// and send it as the out-parameter to the method. If the method then returns -/// `NO`/`false` (or in the case of `msg_send_id!`, `NULL`), the error +/// `NO`/`false`, or in the case of an object pointer, `NULL`, the error /// variable is loaded and returned in [`Err`]. /// -/// Do beware that this is only valid on methods that return `BOOL`, see -/// [`msg_send_id!`] for methods that return instance types. -/// /// [cocoa-error]: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorHandling/ErrorHandling.html /// [swift-error]: https://developer.apple.com/documentation/swift/about-imported-cocoa-error-parameters /// [`NSObject`]: crate::runtime::NSObject @@ -845,8 +938,10 @@ macro_rules! __class_inner { /// Panics if `debug_assertions` are enabled and the Objective-C method's /// encoding does not match the encoding of the given arguments and return. /// -/// And panics if the `NSError**` handling functionality described above is -/// used, and the error object was unexpectedly `NULL`. +/// Finally, panics if the return type is specified as `Retained<_>`, but the +/// method actually returned NULL. If this happens, you should change the +/// signature to instead return `Option>` to handle the error +/// yourself. /// /// /// # Safety @@ -871,74 +966,139 @@ macro_rules! __class_inner { /// are allowed (though heavily discouraged), but _only_ if the return type /// itself is a pointer. /// -/// 6. The method must not (yet) throw an exception. -/// -/// 7. You must uphold any additional safety requirements (explicit and +/// 6. You must uphold any additional safety requirements (explicit and /// implicit) that the method has. For example: /// - Methods that take pointers usually require that the pointer is valid, /// and sometimes non-null. /// - Sometimes, a method may only be called on the main thread. /// - The lifetime of returned pointers usually follows certain rules, and -/// may not be valid outside of an [`autoreleasepool`] ([`msg_send_id!`] -/// can greatly help with that). +/// may not be valid outside of an [`autoreleasepool`] (returning +/// `Retained` usually helps with these cases). /// -/// 8. Each out-parameter must have the correct nullability, and the method +/// 7. Each out-parameter must have the correct nullability, and the method /// must not have any attributes that changes the how it handles memory /// management for these. /// -/// 9. TODO: Maybe more? +/// 8. If using the automatic memory management facilities of this macro, the +/// method must not have any attributes such as `objc_method_family`, +/// `ns_returns_retained`, `ns_consumed` that changes the how it handles +/// memory management. +/// +/// 8. TODO: Maybe more? /// /// [`autoreleasepool`]: crate::rc::autoreleasepool -/// [`msg_send_id!`]: crate::msg_send_id /// /// /// # Examples /// -/// Sending messages to an object. +/// Interacting with [`NSURLComponents`], [`NSString`] and [`NSNumber`]. /// -/// ```no_run -/// use objc2::msg_send; -/// use objc2::runtime::NSObject; +/// [`NSURLComponents`]: https://developer.apple.com/documentation/foundation/nsurlcomponents?language=objc +/// [`NSString`]: https://developer.apple.com/documentation/foundation/nsstring?language=objc +/// [`NSNumber`]: https://developer.apple.com/documentation/foundation/nsnumber?language=objc /// -/// let obj: *mut NSObject; -/// # obj = 0 as *mut NSObject; -/// let description: *const NSObject = unsafe { msg_send![obj, description] }; -/// // Usually you'd use msg_send_id here ^ -/// let _: () = unsafe { msg_send![obj, setArg1: 1i32, arg2: true] }; -/// let arg1: i32 = unsafe { msg_send![obj, getArg1] }; -/// let arg2: bool = unsafe { msg_send![obj, getArg2] }; /// ``` +/// use objc2::rc::Retained; +/// use objc2::{msg_send, ClassType}; +/// use objc2_foundation::{NSNumber, NSString, NSURLComponents}; +/// +/// +/// // Create an empty `NSURLComponents` by calling the class method `new`. +/// let components: Retained = unsafe { +/// // ^^^^^^^^^^^^^^^^^^^^^^^^^ the return type, a memory-managed +/// // `NSURLComponents` instance +/// // +/// msg_send![NSURLComponents::class(), new] +/// // ------------------------ ^^^ the selector `new` +/// // | +/// // the receiver, in this case the class itself +/// }; +/// +/// +/// // Create a new `NSNumber` from an integer. +/// let port: Retained = unsafe { +/// msg_send![NSNumber::class(), numberWithInt: 8080i32] +/// // -------------- ^^^^^^^ the argument to the method +/// // | +/// // the selector `numberWithInt:` +/// // +/// // Note how we must fully specify the argument as `8080i32` instead of just `8080`. +/// }; /// -/// Sending messages to the direct superclass of an object. +/// +/// // Set the port property of the URL. +/// let _: () = unsafe { msg_send![&components, setPort: &*port] }; +/// // -- -------- ^^^^^^ the port is deref'd to +/// // | | become the correct type +/// // | | +/// // | the selector `setPort:` is derived +/// // | from the property name `port`. +/// // | +/// // return type (i.e. nothing / void) +/// // +/// // Note that even return types of `void` must be explicitly specified as `()`. +/// +/// +/// // Set the `host` property of the URL. +/// let host: Retained = unsafe { +/// msg_send![NSString::class(), stringWithUTF8String: c"example.com".as_ptr()] +/// }; +/// let _: () = unsafe { msg_send![&components, setHost: &*host] }; +/// +/// +/// // Set the `scheme` property of the URL. +/// let scheme: Retained = unsafe { +/// msg_send![NSString::class(), stringWithUTF8String: c"http".as_ptr()] +/// }; +/// let _: () = unsafe { msg_send![&components, setScheme: &*scheme] }; +/// +/// +/// // Get the combined URL in string form. +/// let string: Option> = unsafe { msg_send![&components, string] }; +/// // ^^^^^^ the method can return NULL, so we specify an option here +/// +/// +/// assert_eq!(string.unwrap().to_string(), "http://example.com:8080"); +/// ``` +/// +/// The example above uses only `msg_send!` for demonstration purposes; note +/// that usually the interface you seek is already present in [the framework +/// crates] and then the equivalent code can be as simple as: +/// +/// [the framework crates]: crate::topics::about_generated +/// +/// ``` +/// use objc2_foundation::{NSNumber, NSString, NSURLComponents}; +/// +/// let components = unsafe { NSURLComponents::new() }; +/// unsafe { components.setPort(Some(&NSNumber::new_i32(8080))) }; +/// unsafe { components.setHost(Some(&NSString::from_str("example.com"))) }; +/// unsafe { components.setScheme(Some(&NSString::from_str("http"))) }; +/// let string = unsafe { components.string() }; +/// +/// assert_eq!(string.unwrap().to_string(), "http://example.com:8080"); +/// ``` +/// +/// Sending messages to the superclass of an object. /// /// ```no_run -/// use objc2::msg_send; +/// use objc2::runtime::NSObject; +/// use objc2::{msg_send, ClassType}; /// # /// # objc2::define_class!( -/// # #[unsafe(super(objc2::runtime::NSObject))] +/// # #[unsafe(super(NSObject))] /// # #[name = "MyObject"] /// # struct MyObject; /// # ); +/// # +/// # let obj: objc2::rc::Retained = todo!(); /// -/// let obj: &MyObject; // Some object that implements ClassType -/// # obj = todo!(); -/// let _: () = unsafe { msg_send![super(obj), someMethod] }; -/// ``` -/// -/// Sending messages to a specific superclass of an object. +/// // Call `someMethod` on the direct super class. +/// let _: () = unsafe { msg_send![super(&obj), someMethod] }; /// -/// ```no_run -/// # use objc2::class; -/// use objc2::msg_send; -/// use objc2::runtime::{AnyClass, NSObject}; -/// -/// // Since we specify the superclass ourselves, this doesn't need to -/// // implement ClassType -/// let obj: *mut NSObject; -/// # obj = 0 as *mut NSObject; -/// let superclass: &AnyClass; -/// # superclass = class!(NSObject); -/// let arg3: u32 = unsafe { msg_send![super(obj, superclass), getArg3] }; +/// // Or lower-level, a method on a specific superclass. +/// let superclass = NSObject::class(); +/// let arg3: u32 = unsafe { msg_send![super(&obj, superclass), getArg3] }; /// ``` /// /// Sending a message with automatic error handling. @@ -946,14 +1106,25 @@ macro_rules! __class_inner { /// ```no_run /// use objc2::msg_send; /// use objc2::rc::Retained; +/// # #[cfg(requires_foundation)] +/// use objc2_foundation::{NSBundle, NSError}; +/// # use objc2::runtime::NSObject as NSBundle; +/// # use objc2::runtime::NSObject as NSError; +/// +/// # #[cfg(requires_foundation)] +/// let bundle = NSBundle::mainBundle(); +/// # let bundle = NSBundle::new(); /// -/// # type NSBundle = objc2::runtime::NSObject; -/// # type NSError = objc2::runtime::NSObject; -/// let obj: &NSBundle; -/// # obj = todo!(); -/// // The `_` tells the macro that the return type should be `Result`. /// let res: Result<(), Retained> = unsafe { -/// msg_send![obj, preflightAndReturnError: _] +/// // -- -------- ^^^^^^^ must be NSError or NSObject +/// // | | +/// // | always retained +/// // | +/// // `()` means that the method returns `bool`, we check +/// // that and return success if `true`, an error if `false` +/// // +/// msg_send![&bundle, preflightAndReturnError: _] +/// // ^ activate error handling /// }; /// ``` /// @@ -989,273 +1160,35 @@ macro_rules! __class_inner { macro_rules! msg_send { [super($obj:expr), $($selector_and_arguments:tt)+] => { $crate::__msg_send_parse! { - (send_super_message_static_error) () () ($($selector_and_arguments)+) - (send_super_message_static) - ($crate::__msg_send_helper) - ($obj) - } - }; - [super($obj:expr, $superclass:expr), $($selector_and_arguments:tt)+] => { - $crate::__msg_send_parse! { - (send_super_message_error) - () - () - ($($selector_and_arguments)+) - (send_super_message) + (MsgSendSuperError::send_super_message_static_error) + (MsgSendSuper::send_super_message_static) ($crate::__msg_send_helper) - ($obj, $superclass) - } - }; - [$obj:expr, $($selector_and_arguments:tt)+] => { - $crate::__msg_send_parse! { - (send_message_error) - () - () - ($($selector_and_arguments)+) - (send_message) - - ($crate::__msg_send_helper) - ($obj) - } - }; -} - -#[doc(hidden)] -#[macro_export] -macro_rules! __msg_send_helper { - { - ($($fn_args:tt)+) - ($fn:ident) - ($($selector:tt)*) - ($($argument:expr,)*) - } => ({ - // Assign to intermediary variable for better UI, and to prevent - // miscompilation on older Rust versions. - // - // Note: This can be accessed from any expression in `fn_args` and - // `arguments` - we won't (yet) bother with preventing that though. - let result; - // Always add trailing comma after each argument, so that we get a - // 1-tuple if there is only one. - // - // And use `::<_, _>` for better UI - result = $crate::__macro_helpers::MsgSend::$fn::<_, _>($($fn_args)+, $crate::sel!($($selector)*), ($($argument,)*)); - result - }); -} - -/// Deprecated. Use [`msg_send!`] instead. -#[macro_export] -#[deprecated = "use a normal msg_send! instead, it will perform the conversion for you"] -macro_rules! msg_send_bool { - [$($msg_send_args:tt)+] => ({ - // Use old impl for backwards compat - let result: $crate::runtime::Bool = $crate::msg_send![$($msg_send_args)+]; - result.as_bool() - }); -} - -/// [`msg_send!`] for methods returning `id`, `NSObject*`, or similar object -/// pointers. -/// -/// Object pointers in Objective-C have certain rules for when they should be -/// retained and released across function calls. This macro helps doing that, -/// and returns an [`rc::Retained`] with the object, optionally wrapped in an -/// [`Option`] if you want to handle failures yourself. -/// -/// [`rc::Retained`]: crate::rc::Retained -/// -/// -/// # A little history -/// -/// Objective-C's type system is... limited, so you can't tell without -/// consulting the documentation who is responsible for releasing an object. -/// To remedy this problem, Apple/Cocoa introduced (approximately) the -/// following rule: -/// -/// The caller is responsible for releasing objects return from methods that -/// begin with `new`, `alloc`, `copy`, `mutableCopy` or `init`, and method -/// that begins with `init` takes ownership of the receiver. See [Cocoa's -/// Memory Management Policy][mmRules] for a user-friendly introduction to -/// this concept. -/// -/// In the past, users had to do `retain` and `release` calls themselves to -/// properly follow these rules. To avoid the memory management problems -/// associated with manual stuff like that, they [introduced "ARC"][arc-rel], -/// which codifies the rules as part of the language, and inserts the required -/// `retain` and `release` calls automatically. -/// -/// [`msg_send!`] is similar to pre-ARC; you have to know when to retain and -/// when to release an object. [`msg_send_id!`] is similar to ARC; the rules -/// are simple enough that we can do them automatically! -/// -/// [mmRules]: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html#//apple_ref/doc/uid/20000994-SW1 -/// [arc-rel]: https://developer.apple.com/library/archive/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011226 -/// -/// [`msg_send_id!`]: crate::msg_send_id -/// -/// -/// # Specification -/// -/// The syntax is the same as in [`msg_send!`]. -/// -/// Attributes like `objc_method_family`, `ns_returns_retained`, `ns_consumed` -/// and so on must not present on the method - if they are, you should do -/// manual memory management using the [`msg_send!`] macro instead. -/// -/// The accepted receiver and return types, and how we handle them, differ -/// depending on which, if any, of the [recognized selector -/// families][sel-families] the selector belongs to: -/// -/// - The `new` family: The receiver may be anything that implements -/// [`MessageReceiver`] (though often you'll want to use `&AnyClass`). The -/// return type is a generic `Retained` or `Option>`. -/// -/// - The `alloc` family: The receiver must be `&AnyClass`, and the return -/// type is a generic `Allocated`. -/// -/// - The `init` family: The receiver must be `Allocated` as returned from -/// `alloc`, or if sending messages to the superclass, it must be -/// `PartialInit`. -/// -/// The receiver is consumed, and a the now-initialized `Retained` or -/// `Option>` (with the same `T`) is returned. -/// -/// - The `copy` family: The receiver may be anything that implements -/// [`MessageReceiver`] and the return type is a generic `Retained` or -/// `Option>`. -/// -/// - The `mutableCopy` family: Same as the `copy` family. -/// -/// - No family: The receiver may be anything that implements -/// [`MessageReceiver`]. The result is retained using -/// [`Retained::retain_autoreleased`], and a generic `Retained` or -/// `Option>` is returned. This retain is in most cases faster -/// than using autorelease pools! -/// -/// See [the clang documentation][arc-retainable] for the precise -/// specification of Objective-C's ownership rules. -/// -/// As you may have noticed, the return type is usually either `Retained` or -/// `Option`. Internally, the return type is always -/// `Option` (for example: almost all `new` methods can fail if the -/// allocation failed), but for convenience, if the return type is -/// `Retained`, this macro will automatically unwrap the object, or panic -/// with an error message if it couldn't be retrieved. -/// -/// As a special case, if the last argument is the marker `_`, the macro will -/// return a `Result, Retained>`, see below. -/// -/// The `retain`, `release` and `autorelease` selectors are not supported, use -/// [`Retained::retain`], [`Retained::drop`] and [`Retained::autorelease_ptr`] -/// for that. -/// -/// [sel-families]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-method-families -/// [`MessageReceiver`]: crate::runtime::MessageReceiver -/// [`Retained::retain_autoreleased`]: crate::rc::Retained::retain_autoreleased -/// [arc-retainable]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html#retainable-object-pointers-as-operands-and-arguments -/// [`Retained::retain`]: crate::rc::Retained::retain -/// [`Retained::drop`]: crate::rc::Retained::drop -/// [`Retained::autorelease_ptr`]: crate::rc::Retained::autorelease_ptr -/// -/// -/// # Errors -/// -/// Very similarly to [`msg_send!`], this macro supports transforming the -/// return type of methods whose last parameter is `NSError**` into the Rust -/// equivalent, the [`Result`] type. -/// -/// In particular, you can make the last argument the special marker `_`, and -/// then the macro will return a `Result, Retained>` (where you -/// must specify `E` yourself, usually you'd use `objc2_foundation::NSError`). -/// -/// -/// # Panics -/// -/// Panics if the return type is specified as `Retained<_, _>` and the method -/// returned NULL. -/// -/// Additional panicking cases are documented in [`msg_send!`]. -/// -/// -/// # Safety -/// -/// Same as [`msg_send!`], with an expected return type of `id`, -/// `instancetype`, `NSObject*`, or other such object pointers. The method -/// must not have any attributes that changes the how it handles memory -/// management. -/// -/// Note that if you're using this inside a context that expects unwinding to -/// have Objective-C semantics (like [`exception::catch`]), you should make -/// sure that the return type is `Option>` so that you don't -/// get an unexpected unwind through incompatible ABIs! -/// -#[cfg_attr( - feature = "exception", - doc = "[`exception::catch`]: crate::exception::catch" -)] -#[cfg_attr( - not(feature = "exception"), - doc = "[`exception::catch`]: crate::exception#feature-not-enabled" -)] -/// -/// -/// # Examples -/// -/// ```no_run -/// use objc2::{class, msg_send_id}; -/// use objc2::ffi::NSUInteger; -/// use objc2::rc::Retained; -/// use objc2::runtime::NSObject; -/// // Allocate new object -/// let obj = unsafe { msg_send_id![class!(NSObject), alloc] }; -/// // Consume the allocated object, return initialized object -/// let obj: Retained = unsafe { msg_send_id![obj, init] }; -/// // Copy the object -/// let copy: Retained = unsafe { msg_send_id![&obj, copy] }; -/// // Call ordinary selector that returns an object -/// // This time, we handle failures ourselves -/// let s: Option> = unsafe { msg_send_id![&obj, description] }; -/// let s = s.expect("description was NULL"); -/// ``` -#[macro_export] -macro_rules! msg_send_id { - [super($obj:expr), $($selector_and_arguments:tt)+] => { - $crate::__msg_send_parse! { - (send_super_message_retained_static_error) - () - () - ($($selector_and_arguments)+) - (send_super_message_retained_static) - - ($crate::__msg_send_id_helper) ($obj) () // No method family - (MsgSendSuperRetained) } }; [super($obj:expr, $superclass:expr), $($selector_and_arguments:tt)+] => { $crate::__msg_send_parse! { - (send_super_message_retained_error) () () ($($selector_and_arguments)+) - (send_super_message_retained) - ($crate::__msg_send_id_helper) + (MsgSendSuperError::send_super_message_error) + (MsgSendSuper::send_super_message) + + ($crate::__msg_send_helper) ($obj, $superclass) () // No method family - (MsgSendSuperRetained) } }; [$obj:expr, new $(,)?] => ({ let result; - result = <$crate::__macro_helpers::NewFamily as $crate::__macro_helpers::MsgSendRetained<_, _>>::send_message_retained( + result = <$crate::__macro_helpers::NewFamily as $crate::__macro_helpers::MsgSend<_, _>>::send_message( $obj, $crate::sel!(new), (), @@ -1264,7 +1197,7 @@ macro_rules! msg_send_id { }); [$obj:expr, alloc $(,)?] => ({ let result; - result = <$crate::__macro_helpers::AllocSelector as $crate::__macro_helpers::MsgSendRetained<_, _>>::send_message_retained( + result = <$crate::__macro_helpers::AllocSelector as $crate::__macro_helpers::MsgSend<_, _>>::send_message( $obj, $crate::sel!(alloc), (), @@ -1273,7 +1206,7 @@ macro_rules! msg_send_id { }); [$obj:expr, init $(,)?] => ({ let result; - result = <$crate::__macro_helpers::InitFamily as $crate::__macro_helpers::MsgSendRetained<_, _>>::send_message_retained( + result = <$crate::__macro_helpers::InitFamily as $crate::__macro_helpers::MsgSend<_, _>>::send_message( $obj, $crate::sel!(init), (), @@ -1282,91 +1215,123 @@ macro_rules! msg_send_id { }); [$obj:expr, $($selector_and_arguments:tt)+] => { $crate::__msg_send_parse! { - (send_message_retained_error) () () ($($selector_and_arguments)+) - (send_message_retained) - ($crate::__msg_send_id_helper) + (MsgSendError::send_message_error) + (MsgSend::send_message) + + ($crate::__msg_send_helper) ($obj) () // No method family - (MsgSendRetained) } }; } -/// Helper macro to avoid exposing these in the docs for [`msg_send_id!`]. +/// Use [`msg_send!`] instead, it now supports converting to/from `bool`. +#[macro_export] +#[deprecated = "use a normal msg_send! instead, it will perform the conversion for you"] +macro_rules! msg_send_bool { + [$($msg_send_args:tt)+] => ({ + // Use old impl for backwards compat + let result: $crate::runtime::Bool = $crate::msg_send![$($msg_send_args)+]; + result.as_bool() + }); +} + +/// Use [`msg_send!`] instead, it now supports converting to/from +/// [`Retained`][crate::rc::Retained]. +#[macro_export] +#[deprecated = "use a normal msg_send! instead, it will now perform the conversion to/from `Retained` for you"] +macro_rules! msg_send_id { + [$($msg_send_args:tt)+] => { + $crate::msg_send![$($msg_send_args)*] + } +} + +/// Helper macro to avoid exposing the retain/release/... specializations in +/// the docs for [`msg_send!`]. #[doc(hidden)] #[macro_export] -macro_rules! __msg_send_id_helper { +macro_rules! __msg_send_helper { { ($($fn_args:tt)+) - ($($method_family:ident)?) - ($trait:ident) - ($fn:ident) + ($($method_family:tt)+) + ($trait:ident :: $fn:ident) + ($($selector:tt)*) + ($($argument:expr,)*) + } => ({ + <$crate::__macro_helpers::method_family_import::$($method_family)+ as $crate::__macro_helpers::$trait<_, _>>::$fn( + $($fn_args)+, + $crate::sel!($($selector)*), + ($($argument,)*), + ) + }); + ( + ($($fn_args:tt)+) + () + ($trait:ident :: $fn:ident) (retain) () - } => {{ - $crate::__macro_helpers::compile_error!( - "msg_send_id![obj, retain] is not supported. Use `Retained::retain` instead" - ) - }}; - { + ) => ({ + let result; + result = <$crate::__macro_helpers::RetainSelector as $crate::__macro_helpers::$trait<_, _>>::$fn( + $($fn_args)+, + $crate::sel!(retain), + (), + ); + result + }); + ( ($($fn_args:tt)+) - ($($method_family:ident)?) - ($trait:ident) - ($fn:ident) + () + ($trait:ident :: $fn:ident) (release) () - } => {{ - $crate::__macro_helpers::compile_error!( - "msg_send_id![obj, release] is not supported. Drop an `Retained` instead" - ) - }}; - { + ) => ({ + let result; + result = <$crate::__macro_helpers::ReleaseSelector as $crate::__macro_helpers::$trait<_, _>>::$fn( + $($fn_args)+, + $crate::sel!(release), + (), + ); + result + }); + ( ($($fn_args:tt)+) - ($($method_family:ident)?) - ($trait:ident) - ($fn:ident) + () + ($trait:ident :: $fn:ident) (autorelease) () - } => {{ - $crate::__macro_helpers::compile_error!( - "msg_send_id![obj, autorelease] is not supported. Use `Retained::autorelease`" - ) - }}; - { + ) => ({ + let result; + result = <$crate::__macro_helpers::AutoreleaseSelector as $crate::__macro_helpers::$trait<_, _>>::$fn( + $($fn_args)+, + $crate::sel!(autorelease), + (), + ); + result + }); + ( ($($fn_args:tt)+) - ($($method_family:ident)?) - ($trait:ident) - ($fn:ident) + () + ($trait:ident :: $fn:ident) (dealloc) () - } => {{ - $crate::__macro_helpers::compile_error!( - "msg_send_id![obj, dealloc] is not supported. Drop an `Retained` instead" - ) - }}; - { - ($($fn_args:tt)+) - ($($method_family:tt)+) - ($trait:ident) - ($fn:ident) - ($($selector:tt)*) - ($($argument:expr,)*) - } => ({ - <$crate::__macro_helpers::method_family_import::$($method_family)+ as $crate::__macro_helpers::$trait<_, _>>::$fn( + ) => ({ + let result; + result = <$crate::__macro_helpers::DeallocSelector as $crate::__macro_helpers::$trait<_, _>>::$fn( $($fn_args)+, - $crate::sel!($($selector)*), - ($($argument,)*), - ) + $crate::sel!(dealloc), + (), + ); + result }); { ($($fn_args:tt)+) () - ($trait:ident) - ($fn:ident) + ($trait:ident :: $fn:ident) ($($selector:tt)*) ($($argument:expr,)*) } => ({ @@ -1374,7 +1339,18 @@ macro_rules! __msg_send_id_helper { const __SELECTOR_DATA: &$crate::__macro_helpers::str = $crate::__sel_data!( $($selector)* ); + + // Assign to intermediary variable for better UI, and to prevent + // miscompilation on older Rust versions (TODO: Which ones?). + // + // Note: This can be accessed from any expression in `fn_args` and + // `argument` - we won't (yet) bother with preventing that though. let result; + + // Always add trailing comma after each argument, so that we get a + // 1-tuple if there is only one. + // + // And use `::<_, _>` for better UI. result = <$crate::__macro_helpers::MethodFamily<{ $crate::__macro_helpers::method_family(__SELECTOR_DATA) }> as $crate::__macro_helpers::$trait<_, _>>::$fn( diff --git a/crates/objc2/src/main_thread_marker.rs b/crates/objc2/src/main_thread_marker.rs index a05b00acc..4b9310cf3 100644 --- a/crates/objc2/src/main_thread_marker.rs +++ b/crates/objc2/src/main_thread_marker.rs @@ -2,7 +2,7 @@ use core::fmt; use core::marker::PhantomData; use crate::rc::Allocated; -use crate::{msg_send_id, ClassType, MainThreadOnly}; +use crate::{msg_send, ClassType, MainThreadOnly}; /// Whether the current thread is the main thread. #[inline] @@ -161,7 +161,7 @@ impl MainThreadMarker { // SAFETY: We hold `MainThreadMarker`, and classes are either only // safe to allocate on the main thread, or safe to allocate // everywhere. - unsafe { msg_send_id![T::class(), alloc] } + unsafe { msg_send![T::class(), alloc] } } } diff --git a/crates/objc2/src/rc/allocated_partial_init.rs b/crates/objc2/src/rc/allocated_partial_init.rs index 0dec00703..9550304f0 100644 --- a/crates/objc2/src/rc/allocated_partial_init.rs +++ b/crates/objc2/src/rc/allocated_partial_init.rs @@ -139,12 +139,12 @@ impl Allocated { /// /// This consumes the allocated instance, and returns the now partially /// initialized instance instead, which can be further used in - /// [`msg_send_id!`] `super` calls. + /// [`msg_send!`] `super` calls. /// /// This works very similarly to [Swift's two-phase initialization /// scheme][two-phase-init], see that for details. /// - /// [`msg_send_id!`]: crate::msg_send_id + /// [`msg_send!`]: crate::msg_send /// [two-phase-init]: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/initialization/#Two-Phase-Initialization /// /// @@ -216,9 +216,9 @@ impl fmt::Pointer for Allocated { /// current class, but not yet initialized in the superclass. /// /// This is returned by [`Allocated::set_ivars`], and is intended to be used -/// further in [`msg_send_id!`] `super` calls. +/// further in [`msg_send!`] `super` calls. /// -/// [`msg_send_id!`]: crate::msg_send_id +/// [`msg_send!`]: crate::msg_send /// /// /// # Memory layout @@ -369,7 +369,7 @@ mod tests { extern_methods!( unsafe impl RcTestObject { - #[method_id(init)] + #[method(init)] fn init_with_self(self: Allocated) -> Retained; } ); diff --git a/crates/objc2/src/rc/autorelease.rs b/crates/objc2/src/rc/autorelease.rs index f429ee640..65ba48977 100644 --- a/crates/objc2/src/rc/autorelease.rs +++ b/crates/objc2/src/rc/autorelease.rs @@ -326,13 +326,13 @@ impl !AutoreleaseSafe for AutoreleasePool<'_> {} /// Note that this is mostly useful for preventing leaks (as any Objective-C /// method may autorelease internally - see also [`autoreleasepool_leaking`]). /// If implementing an interface to an object, you should try to return -/// retained pointers with [`msg_send_id!`] wherever you can instead, since +/// retained pointers with [`msg_send!`] wherever you can instead, since /// it is usually more efficient, safer, and having to use this function can /// be quite cumbersome for users. /// /// [apple-autorelease]: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html /// [The pool]: AutoreleasePool -/// [`msg_send_id!`]: crate::msg_send_id +/// [`msg_send!`]: crate::msg_send /// /// /// # Restrictions diff --git a/crates/objc2/src/rc/mod.rs b/crates/objc2/src/rc/mod.rs index b879972c5..05309520f 100644 --- a/crates/objc2/src/rc/mod.rs +++ b/crates/objc2/src/rc/mod.rs @@ -5,7 +5,7 @@ //! //! Most importantly, a smart pointer [`Retained`] is provided to ensure that //! objects are correctly retained and released when created and dropped, -//! respectively. This ties in strongly with the [`msg_send_id!`] macro. +//! respectively. //! //! Weak references may be created using the [`Weak`] struct; these will not //! retain the object, but one can attempt to load them and obtain an `Retained`, or @@ -18,7 +18,6 @@ //! It can also be useful to [enable Malloc Debugging][mem-debug] if you're trying //! to figure out if/where your application has memory errors and leaks. //! -//! [`msg_send_id!`]: crate::msg_send_id //! [clang-arc]: https://clang.llvm.org/docs/AutomaticReferenceCounting.html //! [mem-mgmt]: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html //! [cf]: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/CFMemoryMgmt.html diff --git a/crates/objc2/src/rc/retained.rs b/crates/objc2/src/rc/retained.rs index 21565f7c6..b22415faf 100644 --- a/crates/objc2/src/rc/retained.rs +++ b/crates/objc2/src/rc/retained.rs @@ -19,12 +19,12 @@ use crate::{ffi, ClassType, DowncastTarget, Message}; /// [`Message`]. /// /// This can usually be gotten from one of the methods in [the framework -/// crates], but can also be created manually with the [`msg_send_id!`] macro, -/// or even more manually with the [`Retained::retain`], -/// [`Retained::from_raw`] and [`Retained::retain_autoreleased`] methods. +/// crates], but can also be created manually with the [`msg_send!`] macro, or +/// even more manually with the [`Retained::retain`], [`Retained::from_raw`] +/// and [`Retained::retain_autoreleased`] methods. /// /// [the framework crates]: crate::topics::about_generated -/// [`msg_send_id!`]: crate::msg_send_id +/// [`msg_send!`]: crate::msg_send /// /// /// # Comparison to `std` types @@ -86,18 +86,18 @@ use crate::{ffi, ClassType, DowncastTarget, Message}; /// # #[cfg(available_in_foundation)] /// use objc2_foundation::{NSObject, NSString}; /// use objc2::rc::Retained; -/// use objc2::{ClassType, msg_send_id}; +/// use objc2::{ClassType, msg_send}; /// # /// # objc2::extern_class!( /// # #[unsafe(super(NSObject))] /// # pub struct NSString; /// # ); /// -/// // Use `msg_send_id!` to create an `Retained` with correct memory management +/// // Use `msg_send!` to create an `Retained` with correct memory management /// // /// // SAFETY: The types are correct, and it is safe to call the `new` /// // selector on `NSString`. -/// let string: Retained = unsafe { msg_send_id![NSString::class(), new] }; +/// let string: Retained = unsafe { msg_send![NSString::class(), new] }; /// // Or: /// // let string = NSString::new(); /// @@ -194,16 +194,17 @@ impl Retained { /// ``` /// use objc2::rc::Retained; /// use objc2::runtime::NSObject; - /// use objc2::{msg_send, msg_send_id, AllocAnyThread, ClassType}; + /// use objc2::{msg_send, AllocAnyThread, ClassType}; /// - /// // Manually using `msg_send!` and `Retained::from_raw` + /// // Manually using `msg_send!`, pointers and `Retained::from_raw` /// let obj: *mut NSObject = unsafe { msg_send![NSObject::class(), alloc] }; /// let obj: *mut NSObject = unsafe { msg_send![obj, init] }; /// // SAFETY: `-[NSObject init]` returns +1 retain count /// let obj: Retained = unsafe { Retained::from_raw(obj).unwrap() }; /// - /// // Or with `msg_send_id!` - /// let obj: Retained = unsafe { msg_send_id![NSObject::alloc(), init] }; + /// // Or automatically by specifying `Retained` as the return value from + /// // `msg_send!` (it will do the correct conversion internally). + /// let obj: Retained = unsafe { msg_send![NSObject::alloc(), init] }; /// /// // Or using the `NSObject::new` method /// let obj = NSObject::new(); @@ -267,6 +268,11 @@ impl Retained { this.ptr.as_ptr() } + #[inline] + pub(crate) fn as_nonnull_ptr(&self) -> NonNull { + self.ptr + } + #[inline] pub(crate) fn consume_as_ptr_option(this: Option) -> *mut T where @@ -661,14 +667,14 @@ impl Retained { /// [`define_class!`] macro supports doing this for you automatically). /// /// ``` - /// use objc2::{class, msg_send_id, sel}; + /// use objc2::{class, msg_send, sel}; /// use objc2::rc::Retained; /// use objc2::runtime::{AnyClass, AnyObject, ClassBuilder, Sel}; /// /// let mut builder = ClassBuilder::new(c"ExampleObject", class!(NSObject)).unwrap(); /// /// extern "C-unwind" fn get(cls: &AnyClass, _cmd: Sel) -> *mut AnyObject { - /// let obj: Retained = unsafe { msg_send_id![cls, new] }; + /// let obj: Retained = unsafe { msg_send![cls, new] }; /// Retained::autorelease_return(obj) /// } /// diff --git a/crates/objc2/src/rc/retained_traits.rs b/crates/objc2/src/rc/retained_traits.rs index a60f6ff1d..4d22385da 100644 --- a/crates/objc2/src/rc/retained_traits.rs +++ b/crates/objc2/src/rc/retained_traits.rs @@ -118,7 +118,7 @@ impl> FromIterator for Retained { mod tests { use super::*; use crate::runtime::NSObject; - use crate::{define_class, msg_send_id, ClassType}; + use crate::{define_class, msg_send, ClassType}; define_class!( #[unsafe(super(NSObject))] @@ -129,7 +129,7 @@ mod tests { impl DefaultRetained for Collection { fn default_retained() -> Retained { - unsafe { msg_send_id![Collection::class(), new] } + unsafe { msg_send![Collection::class(), new] } } } diff --git a/crates/objc2/src/rc/test_object.rs b/crates/objc2/src/rc/test_object.rs index d62e93994..1c23b886c 100644 --- a/crates/objc2/src/rc/test_object.rs +++ b/crates/objc2/src/rc/test_object.rs @@ -4,7 +4,7 @@ use core::ptr; use crate::rc::{Allocated, DefaultRetained, Retained}; use crate::runtime::{NSObject, NSObjectProtocol, NSZone}; -use crate::{define_class, msg_send, msg_send_id, ClassType}; +use crate::{define_class, msg_send, ClassType}; // TODO: Put tests that use this in another crate #[derive(Debug, Clone, Default, PartialEq, Eq)] @@ -109,7 +109,7 @@ define_class!( unsafe fn init(this: Allocated) -> Retained { TEST_DATA.with(|data| data.borrow_mut().init += 1); let this = this.set_ivars(()); - unsafe { msg_send_id![super(this), init] } + unsafe { msg_send![super(this), init] } } #[method_id(initReturningNull)] @@ -243,7 +243,7 @@ define_class!( } None } else { - unsafe { msg_send_id![Self::class(), new] } + unsafe { msg_send![Self::class(), new] } } } @@ -271,7 +271,7 @@ define_class!( } None } else { - unsafe { msg_send_id![this, init] } + unsafe { msg_send![this, init] } } } @@ -314,7 +314,7 @@ impl DefaultRetained for RcTestObject { impl RcTestObject { #[doc(hidden)] pub(crate) fn new() -> Retained { - // Use msg_send! - msg_send_id! is tested elsewhere! + // Use raw `msg_send!`, the automatic conversion are tested elsewhere. unsafe { Retained::from_raw(msg_send![Self::class(), new]) }.unwrap() } } diff --git a/crates/objc2/src/runtime/bool.rs b/crates/objc2/src/runtime/bool.rs index 5e59991ac..23152dda8 100644 --- a/crates/objc2/src/runtime/bool.rs +++ b/crates/objc2/src/runtime/bool.rs @@ -261,8 +261,8 @@ mod tests { ::__Inner::ENCODING ); assert_eq!( - ::__Inner::__ENCODING, - ::__Inner::ENCODING + >::Inner::__ENCODING, + >::Inner::ENCODING ); } diff --git a/crates/objc2/src/runtime/define.rs b/crates/objc2/src/runtime/define.rs index 20f7c7284..c3d03ff28 100644 --- a/crates/objc2/src/runtime/define.rs +++ b/crates/objc2/src/runtime/define.rs @@ -58,7 +58,7 @@ impl Log2Alignment for T { /// /// use objc2::rc::Retained; /// use objc2::runtime::{AnyClass, AnyObject, ClassBuilder, NSObject, Sel}; -/// use objc2::{sel, msg_send, msg_send_id, ClassType}; +/// use objc2::{sel, msg_send, ClassType}; /// /// fn register_class() -> &'static AnyClass { /// // Inherit from NSObject @@ -100,8 +100,8 @@ impl Log2Alignment for T { /// number: u32, /// ) -> *mut NSObject { /// let obj: Option> = unsafe { -/// msg_send_id![ -/// msg_send_id![cls, alloc], +/// msg_send![ +/// msg_send![cls, alloc], /// initWithNumber: number, /// ] /// }; @@ -144,7 +144,7 @@ impl Log2Alignment for T { /// let cls = register_class(); /// /// let obj: Retained = unsafe { -/// msg_send_id![cls, withNumber: 42u32] +/// msg_send![cls, withNumber: 42u32] /// }; /// /// let n: u32 = unsafe { msg_send![&obj, number] }; @@ -581,9 +581,7 @@ mod tests { use crate::encode::RefEncode; use crate::rc::Retained; use crate::runtime::{NSObject, NSObjectProtocol}; - use crate::{ - define_class, extern_methods, msg_send, msg_send_id, test_utils, ClassType, ProtocolType, - }; + use crate::{define_class, extern_methods, msg_send, test_utils, ClassType, ProtocolType}; // TODO: Remove once c"" strings are in MSRV fn c(s: &str) -> CString { @@ -901,7 +899,7 @@ mod tests { extern_methods!( unsafe impl Custom { - #[method_id(new)] + #[method(new)] fn new() -> Retained; } ); @@ -1069,7 +1067,7 @@ mod tests { ); // Ensure our ivar loading works correctly - let obj: Retained = unsafe { msg_send_id![subclass, new] }; + let obj: Retained = unsafe { msg_send![subclass, new] }; let ptr = unsafe { *subclass_ivar3.load::<*const AnyObject>(&obj) }; assert!(ptr.is_null()); diff --git a/crates/objc2/src/runtime/message_receiver.rs b/crates/objc2/src/runtime/message_receiver.rs index f09c54dbc..bf4dd117c 100644 --- a/crates/objc2/src/runtime/message_receiver.rs +++ b/crates/objc2/src/runtime/message_receiver.rs @@ -537,10 +537,10 @@ mod tests { use core::ptr; use super::*; + use crate::msg_send; use crate::rc::{Allocated, Retained}; use crate::runtime::NSObject; use crate::test_utils; - use crate::{msg_send, msg_send_id}; #[allow(unused)] fn test_different_receivers(obj: &mut AnyObject) { @@ -593,7 +593,7 @@ mod tests { let nil: *mut NSObject = ::core::ptr::null_mut(); // This result should not be relied on - let result: Option> = unsafe { msg_send_id![nil, description] }; + let result: Option> = unsafe { msg_send![nil, description] }; assert!(result.is_none()); // This result should not be relied on @@ -611,12 +611,12 @@ mod tests { // This result should not be relied on let result: Option> = - unsafe { msg_send_id![nil, multiple: 1u32, arguments: 2i8] }; + unsafe { msg_send![nil, multiple: 1u32, arguments: 2i8] }; assert!(result.is_none()); // This result should not be relied on let obj = unsafe { Allocated::new(ptr::null_mut()) }; - let result: Option> = unsafe { msg_send_id![obj, init] }; + let result: Option> = unsafe { msg_send![obj, init] }; assert!(result.is_none()); } diff --git a/crates/objc2/src/runtime/nsobject.rs b/crates/objc2/src/runtime/nsobject.rs index 49d423975..2389c6b0a 100644 --- a/crates/objc2/src/runtime/nsobject.rs +++ b/crates/objc2/src/runtime/nsobject.rs @@ -7,9 +7,7 @@ use crate::ffi::NSUInteger; use crate::rc::{Allocated, DefaultRetained, Retained}; use crate::runtime::{AnyClass, AnyObject, AnyProtocol, ImplementedBy, ProtocolObject, Sel}; use crate::DowncastTarget; -use crate::{ - extern_methods, msg_send, msg_send_id, AllocAnyThread, ClassType, Message, ProtocolType, -}; +use crate::{extern_methods, msg_send, AllocAnyThread, ClassType, Message, ProtocolType}; /// The root class of most Objective-C class hierarchies. /// @@ -267,7 +265,7 @@ pub unsafe trait NSObjectProtocol { where Self: Sized + Message, { - unsafe { msg_send_id![self, description] } + unsafe { msg_send![self, description] } } /// A textual representation of the object to use when debugging. @@ -286,7 +284,7 @@ pub unsafe trait NSObjectProtocol { where Self: Sized + Message, { - unsafe { msg_send_id![self, debugDescription] } + unsafe { msg_send![self, debugDescription] } } /// Check whether the receiver is a subclass of the `NSProxy` root class @@ -397,7 +395,8 @@ extern_methods!( /// [`init`][Self::init]. /// /// [`alloc`]: AllocAnyThread::alloc - #[method_id(new)] + #[method(new)] + #[unsafe(method_family = new)] pub fn new() -> Retained; /// Initialize an already allocated object. @@ -415,10 +414,12 @@ extern_methods!( /// /// let obj = NSObject::init(NSObject::alloc()); /// ``` - #[method_id(init)] + #[method(init)] + #[unsafe(method_family = init)] pub fn init(this: Allocated) -> Retained; #[method(doesNotRecognizeSelector:)] + #[unsafe(method_family = none)] fn doesNotRecognizeSelector_inner(&self, sel: Sel); /// Handle messages the object doesn’t recognize. diff --git a/crates/objc2/src/runtime/nszone.rs b/crates/objc2/src/runtime/nszone.rs index 4984e7723..0eb46acba 100644 --- a/crates/objc2/src/runtime/nszone.rs +++ b/crates/objc2/src/runtime/nszone.rs @@ -66,7 +66,7 @@ mod tests { use core::ptr; use super::*; - use crate::msg_send_id; + use crate::msg_send; use crate::rc::Allocated; use crate::runtime::NSObject; use crate::ClassType; @@ -75,7 +75,7 @@ mod tests { fn alloc_with_zone() { let zone: *const NSZone = ptr::null(); let _obj: Allocated = - unsafe { msg_send_id![NSObject::class(), allocWithZone: zone] }; + unsafe { msg_send![NSObject::class(), allocWithZone: zone] }; } #[test] diff --git a/crates/objc2/src/runtime/protocol_object.rs b/crates/objc2/src/runtime/protocol_object.rs index 400af4c28..5e2fdaf06 100644 --- a/crates/objc2/src/runtime/protocol_object.rs +++ b/crates/objc2/src/runtime/protocol_object.rs @@ -199,7 +199,7 @@ mod tests { use super::*; use crate::runtime::{ClassBuilder, NSObject}; - use crate::{define_class, extern_methods, extern_protocol, msg_send_id, ClassType}; + use crate::{define_class, extern_methods, extern_protocol, msg_send, ClassType}; extern_protocol!( unsafe trait Foo { @@ -257,7 +257,7 @@ mod tests { extern_methods!( unsafe impl DummyClass { - #[method_id(new)] + #[method(new)] fn new() -> Retained; } ); @@ -389,7 +389,7 @@ mod tests { let s = CStr::from_bytes_with_nul(b"My\xF0\x90\x80Class\0").unwrap(); let cls = ClassBuilder::new(s, NSObject::class()).unwrap().register(); - let obj: Retained = unsafe { msg_send_id![cls, new] }; + let obj: Retained = unsafe { msg_send![cls, new] }; let expected = format!("", &*obj); assert_eq!(format!("{obj:?}"), expected); diff --git a/crates/objc2/src/top_level_traits.rs b/crates/objc2/src/top_level_traits.rs index c4997ac23..f64633c49 100644 --- a/crates/objc2/src/top_level_traits.rs +++ b/crates/objc2/src/top_level_traits.rs @@ -5,7 +5,7 @@ use crate::__macro_helpers::defined_ivars::get_initialized_ivar_ptr; use crate::encode::RefEncode; use crate::rc::{Allocated, Retained}; use crate::runtime::{AnyClass, AnyProtocol, ProtocolObject}; -use crate::{msg_send_id, MainThreadMarker}; +use crate::{msg_send, MainThreadMarker}; /// Types that can be sent Objective-C messages. /// @@ -143,7 +143,7 @@ pub unsafe trait Message: RefEncode { /// Use the trait to access the [`AnyClass`] of an object. /// /// ``` -/// use objc2::{ClassType, msg_send_id}; +/// use objc2::{ClassType, msg_send}; /// use objc2::rc::Retained; /// # use objc2::runtime::{NSObject as MyObject}; /// @@ -160,13 +160,13 @@ pub unsafe trait Message: RefEncode { /// // SAFETY: /// // - The class is `MyObject`, which can safely be initialized with `new`. /// // - The return type is correctly specified. -/// let obj: Retained = unsafe { msg_send_id![cls, new] }; +/// let obj: Retained = unsafe { msg_send![cls, new] }; /// ``` /// /// Use the trait to allocate a new instance of an object. /// /// ``` -/// use objc2::{msg_send_id, AllocAnyThread}; +/// use objc2::{msg_send, AllocAnyThread}; /// use objc2::rc::Retained; /// # use objc2::runtime::{NSObject as MyObject}; /// @@ -175,7 +175,7 @@ pub unsafe trait Message: RefEncode { /// // Now we can call initializers on this newly allocated object. /// // /// // SAFETY: `MyObject` can safely be initialized with `init`. -/// let obj: Retained = unsafe { msg_send_id![obj, init] }; +/// let obj: Retained = unsafe { msg_send![obj, init] }; /// ``` /// /// Use the [`extern_class!`][crate::extern_class] macro to implement this @@ -429,10 +429,10 @@ mod private { pub unsafe trait AllocAnyThread: private::SealedAllocAnyThread { /// Allocate a new instance of the class. /// - /// The return value can be used directly inside [`msg_send_id!`] to + /// The return value can be used directly inside [`msg_send!`] to /// initialize the object. /// - /// [`msg_send_id!`]: crate::msg_send_id + /// [`msg_send!`]: crate::msg_send #[inline] fn alloc() -> Allocated where @@ -455,7 +455,7 @@ pub unsafe trait AllocAnyThread: private::SealedAllocAnyThread { // to be allowed to `init` on the current thread. // // See also `MainThreadMarker::alloc`. - unsafe { msg_send_id![Self::class(), alloc] } + unsafe { msg_send![Self::class(), alloc] } } } @@ -535,7 +535,7 @@ pub unsafe trait MainThreadOnly: private::SealedMainThreadOnly { /// # impl NSView { /// # fn initWithFrame(this: Allocated, _frame: CGRect) -> Retained { /// # // Don't use frame, this is NSObject - /// # unsafe { objc2::msg_send_id![this, init] } + /// # unsafe { objc2::msg_send![this, init] } /// # } /// # } /// diff --git a/crates/objc2/src/topics/kvo.md b/crates/objc2/src/topics/kvo.md index b222277eb..1a18a4d5b 100644 --- a/crates/objc2/src/topics/kvo.md +++ b/crates/objc2/src/topics/kvo.md @@ -21,7 +21,7 @@ use core::ptr; use objc2::rc::Retained; use objc2::runtime::AnyObject; -use objc2::{define_class, msg_send_id, AllocAnyThread, ClassType, DefinedClass}; +use objc2::{define_class, msg_send, AllocAnyThread, ClassType, DefinedClass}; use objc2_foundation::{ ns_string, NSCopying, NSDictionary, NSKeyValueChangeKey, NSKeyValueObservingOptions, NSObject, NSObjectNSKeyValueObserverRegistration, NSObjectProtocol, NSString, @@ -78,7 +78,7 @@ impl MyObserver { key_path: key_path.copy(), handler: Box::new(handler), }); - let observer: Retained = unsafe { msg_send_id![super(observer), init] }; + let observer: Retained = unsafe { msg_send![super(observer), init] }; // SAFETY: We make sure to un-register the observer before it's deallocated. // diff --git a/crates/objc2/src/topics/layered_safety.md b/crates/objc2/src/topics/layered_safety.md index 42d83c4de..2954cc4d9 100644 --- a/crates/objc2/src/topics/layered_safety.md +++ b/crates/objc2/src/topics/layered_safety.md @@ -104,7 +104,7 @@ let hash_code: NSUInteger = unsafe { ``` -## Layer 3a: `msg_send!` +## Layer 3: `msg_send!` Introducing macros: [`msg_send!`] can abstract away the tediousness of writing the selector expression, as well as ensuring that the number of arguments to @@ -145,7 +145,7 @@ let _: () = unsafe { msg_send![obj, release] }; [`NSData`]: https://developer.apple.com/documentation/foundation/nsdata?language=objc -## Layer 3b: `msg_send_id!` +## Layer 4: `Retained` As you can see in the new example involving `NSData`, it can be quite tedious to remember the `release` call when you're done with the object. Furthermore, @@ -153,12 +153,11 @@ whether you need to `retain` and `release` the object involves subtle rules that depend on the name of the method! Objective-C solved this years ago with the introduction of "ARC". Similarly, -we can solve this with [`msg_send_id!`] and the smart pointer [`rc::Retained`], -which work together to ensure that the memory management of the object is done -correctly. +we can solve this by changing the return value to the smart pointer +[`Retained`], which works together with `msg_send!` to ensure that the +memory management of the object is done correctly. -[`msg_send_id!`]: crate::msg_send_id -[`rc::Retained`]: crate::rc::Retained +[`Retained`]: crate::rc::Retained ### Example @@ -169,15 +168,15 @@ The `NSData` example again. use objc2::ffi::NSUInteger; use objc2::rc::Retained; use objc2::runtime::NSObject; -use objc2::{class, msg_send, msg_send_id}; +use objc2::{class, msg_send}; -let obj: Retained = unsafe { msg_send_id![class!(NSData), new] }; +let obj: Retained = unsafe { msg_send![class!(NSData), new] }; let length: NSUInteger = unsafe { msg_send![&obj, length] }; // `obj` goes out of scope, `release` is automatically sent to the object ``` -## Layer 4: `extern_x` macros +## Layer 5: `extern_x!` macros There's still a problem with the above: we can't actually make a reusable `hash` nor `length` function, since `NSObject` can refer to any object, and @@ -189,9 +188,9 @@ type resembling `NSObject`, but which represents the `NSData` class instead. This allows us to make a completely safe API for downstream users! Along with this, we can now use the [`extern_methods!`] macro to help with -defining our methods, which is also a big improvement over the `msg_send!` / -`msg_send_id!` macros, since it allows us to directly "see" the types, instead -of having them work by type-inference. +defining our methods, which is also a big improvement over the `msg_send!` +macro, since it allows us to directly "see" the types, instead of having them +work by type-inference. [`extern_class!`]: crate::extern_class [`extern_methods!`]: crate::extern_methods @@ -215,7 +214,7 @@ extern_class!( extern_methods!( unsafe impl NSData { - #[method_id(new)] + #[method(new)] pub fn new() -> Retained; #[method(length)] @@ -228,7 +227,7 @@ let length = obj.length(); ``` -## Layer 5: Framework crates +## Layer 6: Framework crates Apple has a _lot_ of Objective-C code, and manually defining an interface to all of it would take a lifetime. Especially keeping track of which methods are diff --git a/crates/objc2/src/topics/run_loop.md b/crates/objc2/src/topics/run_loop.md index 19d07e0c4..3878e4762 100644 --- a/crates/objc2/src/topics/run_loop.md +++ b/crates/objc2/src/topics/run_loop.md @@ -37,7 +37,7 @@ In graphical applications, the main run loop needs to be managed by the applicat ```rust, no_run use objc2::rc::{Allocated, Retained}; -use objc2::{define_class, msg_send_id, ClassType, DefinedClass, MainThreadOnly}; +use objc2::{define_class, msg_send, ClassType, DefinedClass, MainThreadOnly}; use objc2_foundation::{NSNotification, NSObject, NSObjectProtocol}; // Application delegate protocols happens to share a few methods, @@ -64,11 +64,11 @@ define_class!( unsafe impl AppDelegate { // Called by `NSApplicationMain`, `UIApplicationMain` - // or our `msg_send_id![AppDelegate::class(), new]`. + // or our `msg_send![AppDelegate::class(), new]`. #[method_id(init)] fn init(this: Allocated) -> Retained { let this = this.set_ivars(AppState::default()); - unsafe { msg_send_id![super(this), init] } + unsafe { msg_send![super(this), init] } } } @@ -98,7 +98,7 @@ define_class!( fn main() { let mtm = objc2::MainThreadMarker::new().unwrap(); let app = objc2_app_kit::NSApplication::sharedApplication(mtm); - let delegate: Retained = unsafe { msg_send_id![AppDelegate::class(), new] }; + let delegate: Retained = unsafe { msg_send![AppDelegate::class(), new] }; app.setDelegate(Some(objc2::runtime::ProtocolObject::from_ref(&*delegate))); app.run(); } diff --git a/crates/objc2/tests/define_class.rs b/crates/objc2/tests/define_class.rs index 1bf6a111c..0d3c4745c 100644 --- a/crates/objc2/tests/define_class.rs +++ b/crates/objc2/tests/define_class.rs @@ -147,7 +147,7 @@ define_class!( extern_methods!( unsafe impl DefineClassCfg { - #[method_id(new)] + #[method(new)] fn new() -> Retained; } @@ -258,7 +258,7 @@ define_class!( extern_methods!( unsafe impl TestMultipleColonSelector { - #[method_id(new)] + #[method(new)] fn new() -> Retained; #[method(test::arg3:)] @@ -270,7 +270,7 @@ extern_methods!( #[method(test::error:_)] fn test_error(&self, arg1: i32, arg2: i32) -> Result<(), Retained>; - #[method_id(test:::withObject:)] + #[method(test:::withObject:)] fn test_object( &self, arg1: i32, @@ -417,7 +417,7 @@ define_class!( extern_methods!( unsafe impl OutParam { - #[method_id(new)] + #[method(new)] fn new() -> Retained; #[method(unsupported1:)] diff --git a/crates/objc2/tests/macros_mainthreadmarker.rs b/crates/objc2/tests/macros_mainthreadmarker.rs index c5cc007c5..35a3d4eaf 100644 --- a/crates/objc2/tests/macros_mainthreadmarker.rs +++ b/crates/objc2/tests/macros_mainthreadmarker.rs @@ -9,8 +9,8 @@ extern_protocol!( #[method(myMethod:)] fn protocol_method(mtm: MainThreadMarker, arg: i32) -> i32; - #[method_id(myMethodId:)] - fn protocol_method_id(mtm: MainThreadMarker, arg: &Self) -> Retained; + #[method(myMethodId:)] + fn protocol_method_retained(mtm: MainThreadMarker, arg: &Self) -> Retained; } ); @@ -29,7 +29,7 @@ define_class!( } #[method_id(myMethodId:)] - fn _my_mainthreadonly_method_id(arg: &Self) -> Retained { + fn _my_mainthreadonly_method_retained(arg: &Self) -> Retained { unsafe { Retained::retain(arg as *const Self as *mut Self).unwrap() } } } @@ -45,14 +45,18 @@ struct MainThreadMarker { extern_methods!( unsafe impl Cls { - #[method_id(new)] + #[method(new)] fn new(mtm: MainThreadMarker) -> Retained; #[method(myMethod:)] fn method(mtm: MainThreadMarker, arg: i32, mtm2: MainThreadMarker) -> i32; - #[method_id(myMethodId:)] - fn method_id(mtm: MainThreadMarker, arg: &Self, mtm2: MainThreadMarker) -> Retained; + #[method(myMethodId:)] + fn method_retained( + mtm: MainThreadMarker, + arg: &Self, + mtm2: MainThreadMarker, + ) -> Retained; } ); @@ -66,9 +70,9 @@ fn call() { let res = Cls::protocol_method(mtm, 3); assert_eq!(res, 4); - let obj2 = Cls::method_id(mtm, &obj1, mtm); + let obj2 = Cls::method_retained(mtm, &obj1, mtm); assert_eq!(obj1, obj2); - let obj2 = Cls::protocol_method_id(mtm, &obj1); + let obj2 = Cls::protocol_method_retained(mtm, &obj1); assert_eq!(obj1, obj2); } diff --git a/crates/objc2/tests/no_prelude.rs b/crates/objc2/tests/no_prelude.rs index 077369d06..2f362b183 100644 --- a/crates/objc2/tests/no_prelude.rs +++ b/crates/objc2/tests/no_prelude.rs @@ -153,14 +153,12 @@ fn test_msg_send(obj: &CustomObject) { let _: () = unsafe { new_objc2::msg_send![super(obj), a: obj, b: obj] }; let _: () = unsafe { new_objc2::msg_send![super(obj, superclass), a] }; let _: () = unsafe { new_objc2::msg_send![super(obj, superclass), a: obj, b: obj] }; -} -fn test_msg_send_id(obj: &new_objc2::runtime::AnyObject) { let _: new_objc2::rc::Retained = - unsafe { new_objc2::msg_send_id![obj, a] }; + unsafe { new_objc2::msg_send![obj, a] }; let _: new_objc2::__macro_helpers::Option< new_objc2::rc::Retained, - > = unsafe { new_objc2::msg_send_id![obj, a] }; + > = unsafe { new_objc2::msg_send![obj, a] }; let _: new_objc2::rc::Retained = - unsafe { new_objc2::msg_send_id![obj, a: obj, b: obj] }; + unsafe { new_objc2::msg_send![obj, a: obj, b: obj] }; } diff --git a/crates/objc2/tests/track_caller.rs b/crates/objc2/tests/track_caller.rs index 28ac67b8a..a80b68d8d 100644 --- a/crates/objc2/tests/track_caller.rs +++ b/crates/objc2/tests/track_caller.rs @@ -10,7 +10,7 @@ use std::sync::Mutex; use objc2::encode::Encode; use objc2::rc::{self, Allocated, Retained}; use objc2::runtime::{self, NSObject}; -use objc2::{class, define_class, msg_send, msg_send_id, AllocAnyThread, ClassType}; +use objc2::{class, define_class, msg_send, AllocAnyThread, ClassType}; #[path = "../src/rc/test_object.rs"] #[allow(dead_code)] @@ -107,7 +107,7 @@ fn test_nil(checker: &PanicChecker) { let _: *mut NSObject = unsafe { msg_send![super(nil, NSObject::class()), description] }; }); checker.assert_panics(msg, line!() + 1, || { - let _: Option> = unsafe { msg_send_id![nil, description] }; + let _: Option> = unsafe { msg_send![nil, description] }; }); } @@ -121,7 +121,7 @@ fn test_verify(checker: &PanicChecker) { let msg = format!("invalid message send to -[NSObject hash]: expected return to have type code '{}', but found '@'", usize::ENCODING); checker.assert_panics(&msg, line!() + 1, || { - let _: Option> = unsafe { msg_send_id![&obj, hash] }; + let _: Option> = unsafe { msg_send![&obj, hash] }; }); } @@ -138,7 +138,7 @@ fn test_error_methods(checker: &PanicChecker) { }); checker.assert_panics(msg, line!() + 2, || { let _: Result, Retained> = - unsafe { msg_send_id![nil, someSelectorWithError: _] }; + unsafe { msg_send![nil, someSelectorWithError: _] }; }); let msg = "invalid message send to -[NSObject someSelectorWithError:]: method not found"; @@ -155,7 +155,7 @@ fn test_id_unwrap(checker: &PanicChecker) { let msg = "failed creating new instance using +[__RcTestObject newReturningNull]"; checker.assert_panics(msg, line!() + 1, || { - let _obj: Retained = unsafe { msg_send_id![cls, newReturningNull] }; + let _obj: Retained = unsafe { msg_send![cls, newReturningNull] }; }); let msg = if cfg!(debug_assertions) { @@ -164,29 +164,29 @@ fn test_id_unwrap(checker: &PanicChecker) { "failed allocating object" }; checker.assert_panics(msg, line!() + 2, || { - let obj: Allocated = unsafe { msg_send_id![cls, allocReturningNull] }; - let _obj: Retained = unsafe { msg_send_id![obj, init] }; + let obj: Allocated = unsafe { msg_send![cls, allocReturningNull] }; + let _obj: Retained = unsafe { msg_send![obj, init] }; }); let msg = "failed initializing object with -initReturningNull"; checker.assert_panics(msg, line!() + 2, || { let _obj: Retained = - unsafe { msg_send_id![RcTestObject::alloc(), initReturningNull] }; + unsafe { msg_send![RcTestObject::alloc(), initReturningNull] }; }); let msg = "failed copying object"; checker.assert_panics(msg, line!() + 1, || { - let _obj: Retained = unsafe { msg_send_id![&obj, copyReturningNull] }; + let _obj: Retained = unsafe { msg_send![&obj, copyReturningNull] }; }); let msg = "unexpected NULL returned from -[__RcTestObject methodReturningNull]"; checker.assert_panics(msg, line!() + 1, || { - let _obj: Retained = unsafe { msg_send_id![&obj, methodReturningNull] }; + let _obj: Retained = unsafe { msg_send![&obj, methodReturningNull] }; }); } fn test_catch_all(checker: &PanicChecker) { - let obj: Retained = unsafe { msg_send_id![class!(NSArray), new] }; + let obj: Retained = unsafe { msg_send![class!(NSArray), new] }; let msg = "NSRangeException"; checker.assert_panics(msg, line!() + 1, || { @@ -195,7 +195,7 @@ fn test_catch_all(checker: &PanicChecker) { let msg = "NSRangeException"; checker.assert_panics(msg, line!() + 1, || { - let _: Retained = unsafe { msg_send_id![&obj, objectAtIndex: 0usize] }; + let _: Retained = unsafe { msg_send![&obj, objectAtIndex: 0usize] }; }); } @@ -219,7 +219,7 @@ fn test_unwind(checker: &PanicChecker) { let _: *mut NSObject = unsafe { msg_send![PanickingClass::class(), panic] }; }); checker.assert_panics(msg, line, || { - let _: Retained = unsafe { msg_send_id![PanickingClass::class(), panic] }; + let _: Retained = unsafe { msg_send![PanickingClass::class(), panic] }; }); } diff --git a/crates/test-assembly/crates/test_autorelease_return/lib.rs b/crates/test-assembly/crates/test_autorelease_return/lib.rs index fea29286f..4282d4ce3 100644 --- a/crates/test-assembly/crates/test_autorelease_return/lib.rs +++ b/crates/test-assembly/crates/test_autorelease_return/lib.rs @@ -1,6 +1,6 @@ //! Test that `Retained::autorelease_return` is tail-called properly. -use objc2::__macro_helpers::{MsgSendRetained, NewFamily}; +use objc2::__macro_helpers::{MsgSend, NewFamily}; use objc2::rc::Retained; use objc2::runtime::{AnyClass, AnyObject, Sel}; @@ -11,6 +11,6 @@ fn simple(obj: Retained) -> *mut AnyObject { #[no_mangle] unsafe fn with_body(cls: &AnyClass, sel: Sel) -> *mut AnyObject { - let obj: Option> = NewFamily::send_message_retained(cls, sel, ()); + let obj: Option> = NewFamily::send_message(cls, sel, ()); Retained::autorelease_return(obj.unwrap_unchecked()) } diff --git a/crates/test-assembly/crates/test_define_class/expected/apple-aarch64.s b/crates/test-assembly/crates/test_define_class/expected/apple-aarch64.s index fe4d32e9e..fa9c78be0 100644 --- a/crates/test-assembly/crates/test_define_class/expected/apple-aarch64.s +++ b/crates/test-assembly/crates/test_define_class/expected/apple-aarch64.s @@ -134,9 +134,9 @@ Lloh13: bl SYM(objc2::__macro_helpers::define_class::create_builder::GENERATED_ID, 0) str x0, [sp, #8] Lloh14: - adrp x8, L_OBJC_SELECTOR_REFERENCES_4ee60abb2719f036@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_da7dfba076f8819b@PAGE Lloh15: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_4ee60abb2719f036@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_da7dfba076f8819b@PAGEOFF] Ltmp6: Lloh16: adrp x4, l_anon.[ID].16@PAGE @@ -152,9 +152,9 @@ Lloh19: bl SYM(objc2::runtime::define::ClassBuilder::add_class_method_inner::GENERATED_ID, 0) Ltmp7: Lloh20: - adrp x8, L_OBJC_SELECTOR_REFERENCES_94f56691766f024b@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_27735778f6c77cc7@PAGE Lloh21: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_94f56691766f024b@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_27735778f6c77cc7@PAGEOFF] Ltmp8: Lloh22: adrp x4, l_anon.[ID].3@PAGE @@ -170,9 +170,9 @@ Lloh25: bl SYM(objc2::runtime::define::ClassBuilder::add_method_inner::GENERATED_ID, 0) Ltmp9: Lloh26: - adrp x8, L_OBJC_SELECTOR_REFERENCES_d6661a0373fc878f@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_2d06566c3d71d374@PAGE Lloh27: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_d6661a0373fc878f@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_2d06566c3d71d374@PAGEOFF] Ltmp10: Lloh28: adrp x2, l_anon.[ID].17@PAGE @@ -188,9 +188,9 @@ Lloh31: bl SYM(objc2::runtime::define::ClassBuilder::add_method_inner::GENERATED_ID, 0) Ltmp11: Lloh32: - adrp x8, L_OBJC_SELECTOR_REFERENCES_8677be6883ccd195@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_d6bd69ea010cdb74@PAGE Lloh33: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_8677be6883ccd195@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_d6bd69ea010cdb74@PAGEOFF] Ltmp12: Lloh34: adrp x4, l_anon.[ID].18@PAGE @@ -206,9 +206,9 @@ Lloh37: bl SYM(objc2::runtime::define::ClassBuilder::add_method_inner::GENERATED_ID, 0) Ltmp13: Lloh38: - adrp x8, L_OBJC_SELECTOR_REFERENCES_3f5c953c5f98b853@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_83e80b6a812131de@PAGE Lloh39: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_3f5c953c5f98b853@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_83e80b6a812131de@PAGEOFF] Ltmp14: Lloh40: adrp x2, l_anon.[ID].17@PAGE @@ -253,9 +253,9 @@ Ltmp19: bl _class_addProtocol LBB1_12: Lloh50: - adrp x8, L_OBJC_SELECTOR_REFERENCES_76a1da9e60049d4f@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_a42df1bdbbfe0f96@PAGE Lloh51: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_76a1da9e60049d4f@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_a42df1bdbbfe0f96@PAGEOFF] Ltmp20: Lloh52: adrp x2, l_anon.[ID].23@PAGE @@ -1280,9 +1280,9 @@ LBB20_2: stp x29, x30, [sp, #16] add x29, sp, #16 Lloh214: - adrp x8, L_OBJC_SELECTOR_REFERENCES_8ae30338ec8fe87d@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_3b26517fa48cbea8@PAGE Lloh215: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_8ae30338ec8fe87d@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_3b26517fa48cbea8@PAGEOFF] Lloh216: adrp x8, L_OBJC_CLASSLIST_REFERENCES_$_NSObject@GOTPAGE Lloh217: @@ -1391,9 +1391,9 @@ Ltmp58: bl _objc_release LBB22_6: Lloh233: - adrp x8, L_OBJC_SELECTOR_REFERENCES_c3d3047551604c9f@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_2e436b0daa293d6c@PAGE Lloh234: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_c3d3047551604c9f@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_2e436b0daa293d6c@PAGEOFF] Lloh235: adrp x8, L_OBJC_CLASSLIST_REFERENCES_$_NSObject@GOTPAGE Lloh236: @@ -1622,105 +1622,105 @@ l_anon.[ID].23: .space 24 .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_4ee60abb2719f036 -L_OBJC_METH_VAR_NAME_4ee60abb2719f036: + .globl L_OBJC_METH_VAR_NAME_da7dfba076f8819b +L_OBJC_METH_VAR_NAME_da7dfba076f8819b: .asciz "classMethod" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_4ee60abb2719f036 + .globl L_OBJC_SELECTOR_REFERENCES_da7dfba076f8819b .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_4ee60abb2719f036: - .quad L_OBJC_METH_VAR_NAME_4ee60abb2719f036 +L_OBJC_SELECTOR_REFERENCES_da7dfba076f8819b: + .quad L_OBJC_METH_VAR_NAME_da7dfba076f8819b .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_4ee60abb2719f036 + .globl L_OBJC_IMAGE_INFO_da7dfba076f8819b .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_4ee60abb2719f036: +L_OBJC_IMAGE_INFO_da7dfba076f8819b: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_94f56691766f024b -L_OBJC_METH_VAR_NAME_94f56691766f024b: + .globl L_OBJC_METH_VAR_NAME_27735778f6c77cc7 +L_OBJC_METH_VAR_NAME_27735778f6c77cc7: .asciz "method" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_94f56691766f024b + .globl L_OBJC_SELECTOR_REFERENCES_27735778f6c77cc7 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_94f56691766f024b: - .quad L_OBJC_METH_VAR_NAME_94f56691766f024b +L_OBJC_SELECTOR_REFERENCES_27735778f6c77cc7: + .quad L_OBJC_METH_VAR_NAME_27735778f6c77cc7 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_94f56691766f024b + .globl L_OBJC_IMAGE_INFO_27735778f6c77cc7 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_94f56691766f024b: +L_OBJC_IMAGE_INFO_27735778f6c77cc7: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_d6661a0373fc878f -L_OBJC_METH_VAR_NAME_d6661a0373fc878f: + .globl L_OBJC_METH_VAR_NAME_2d06566c3d71d374 +L_OBJC_METH_VAR_NAME_2d06566c3d71d374: .asciz "methodBool:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_d6661a0373fc878f + .globl L_OBJC_SELECTOR_REFERENCES_2d06566c3d71d374 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_d6661a0373fc878f: - .quad L_OBJC_METH_VAR_NAME_d6661a0373fc878f +L_OBJC_SELECTOR_REFERENCES_2d06566c3d71d374: + .quad L_OBJC_METH_VAR_NAME_2d06566c3d71d374 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_d6661a0373fc878f + .globl L_OBJC_IMAGE_INFO_2d06566c3d71d374 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_d6661a0373fc878f: +L_OBJC_IMAGE_INFO_2d06566c3d71d374: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_8677be6883ccd195 -L_OBJC_METH_VAR_NAME_8677be6883ccd195: + .globl L_OBJC_METH_VAR_NAME_d6bd69ea010cdb74 +L_OBJC_METH_VAR_NAME_d6bd69ea010cdb74: .asciz "methodRetained" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_8677be6883ccd195 + .globl L_OBJC_SELECTOR_REFERENCES_d6bd69ea010cdb74 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_8677be6883ccd195: - .quad L_OBJC_METH_VAR_NAME_8677be6883ccd195 +L_OBJC_SELECTOR_REFERENCES_d6bd69ea010cdb74: + .quad L_OBJC_METH_VAR_NAME_d6bd69ea010cdb74 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_8677be6883ccd195 + .globl L_OBJC_IMAGE_INFO_d6bd69ea010cdb74 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_8677be6883ccd195: +L_OBJC_IMAGE_INFO_d6bd69ea010cdb74: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_3f5c953c5f98b853 -L_OBJC_METH_VAR_NAME_3f5c953c5f98b853: + .globl L_OBJC_METH_VAR_NAME_83e80b6a812131de +L_OBJC_METH_VAR_NAME_83e80b6a812131de: .asciz "methodRetainedWithParam:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_3f5c953c5f98b853 + .globl L_OBJC_SELECTOR_REFERENCES_83e80b6a812131de .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_3f5c953c5f98b853: - .quad L_OBJC_METH_VAR_NAME_3f5c953c5f98b853 +L_OBJC_SELECTOR_REFERENCES_83e80b6a812131de: + .quad L_OBJC_METH_VAR_NAME_83e80b6a812131de .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_3f5c953c5f98b853 + .globl L_OBJC_IMAGE_INFO_83e80b6a812131de .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_3f5c953c5f98b853: +L_OBJC_IMAGE_INFO_83e80b6a812131de: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_76a1da9e60049d4f -L_OBJC_METH_VAR_NAME_76a1da9e60049d4f: + .globl L_OBJC_METH_VAR_NAME_a42df1bdbbfe0f96 +L_OBJC_METH_VAR_NAME_a42df1bdbbfe0f96: .asciz "copyWithZone:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_76a1da9e60049d4f + .globl L_OBJC_SELECTOR_REFERENCES_a42df1bdbbfe0f96 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_76a1da9e60049d4f: - .quad L_OBJC_METH_VAR_NAME_76a1da9e60049d4f +L_OBJC_SELECTOR_REFERENCES_a42df1bdbbfe0f96: + .quad L_OBJC_METH_VAR_NAME_a42df1bdbbfe0f96 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_76a1da9e60049d4f + .globl L_OBJC_IMAGE_INFO_a42df1bdbbfe0f96 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_76a1da9e60049d4f: +L_OBJC_IMAGE_INFO_a42df1bdbbfe0f96: .asciz "\000\000\000\000@\000\000" .globl SYM(test_define_class[CRATE_ID]::_::__OBJC2_IVAR_OFFSET, 1) @@ -1734,20 +1734,20 @@ l_anon.[ID].24: .asciz "4\000\000\000\000\000\000\000M\000\000\000\001\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_8ae30338ec8fe87d -L_OBJC_METH_VAR_NAME_8ae30338ec8fe87d: + .globl L_OBJC_METH_VAR_NAME_3b26517fa48cbea8 +L_OBJC_METH_VAR_NAME_3b26517fa48cbea8: .asciz "init" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_8ae30338ec8fe87d + .globl L_OBJC_SELECTOR_REFERENCES_3b26517fa48cbea8 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_8ae30338ec8fe87d: - .quad L_OBJC_METH_VAR_NAME_8ae30338ec8fe87d +L_OBJC_SELECTOR_REFERENCES_3b26517fa48cbea8: + .quad L_OBJC_METH_VAR_NAME_3b26517fa48cbea8 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_8ae30338ec8fe87d + .globl L_OBJC_IMAGE_INFO_3b26517fa48cbea8 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_8ae30338ec8fe87d: +L_OBJC_IMAGE_INFO_3b26517fa48cbea8: .asciz "\000\000\000\000@\000\000" .globl SYM(test_define_class[CRATE_ID]::_::__OBJC2_IVAR_OFFSET, 0) @@ -1761,20 +1761,20 @@ l_anon.[ID].25: .asciz "4\000\000\000\000\000\000\000o\000\000\000\001\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_c3d3047551604c9f -L_OBJC_METH_VAR_NAME_c3d3047551604c9f: + .globl L_OBJC_METH_VAR_NAME_2e436b0daa293d6c +L_OBJC_METH_VAR_NAME_2e436b0daa293d6c: .asciz "init" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_c3d3047551604c9f + .globl L_OBJC_SELECTOR_REFERENCES_2e436b0daa293d6c .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_c3d3047551604c9f: - .quad L_OBJC_METH_VAR_NAME_c3d3047551604c9f +L_OBJC_SELECTOR_REFERENCES_2e436b0daa293d6c: + .quad L_OBJC_METH_VAR_NAME_2e436b0daa293d6c .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_c3d3047551604c9f + .globl L_OBJC_IMAGE_INFO_2e436b0daa293d6c .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_c3d3047551604c9f: +L_OBJC_IMAGE_INFO_2e436b0daa293d6c: .asciz "\000\000\000\000@\000\000" .zerofill __DATA,__bss,__MergedGlobals,48,3 diff --git a/crates/test-assembly/crates/test_define_class/expected/apple-x86_64.s b/crates/test-assembly/crates/test_define_class/expected/apple-x86_64.s index 501681377..a5db896f6 100644 --- a/crates/test-assembly/crates/test_define_class/expected/apple-x86_64.s +++ b/crates/test-assembly/crates/test_define_class/expected/apple-x86_64.s @@ -117,7 +117,7 @@ Lfunc_begin1: mov esi, 7 call SYM(objc2::__macro_helpers::define_class::create_builder::GENERATED_ID, 0) mov qword ptr [rbp - 16], rax - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_4ee60abb2719f036] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_da7dfba076f8819b] Ltmp6: lea r8, [rip + l_anon.[ID].16] lea r9, [rip + _get_class] @@ -126,7 +126,7 @@ Ltmp6: xor ecx, ecx call SYM(objc2::runtime::define::ClassBuilder::add_class_method_inner::GENERATED_ID, 0) Ltmp7: - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_94f56691766f024b] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_27735778f6c77cc7] Ltmp8: lea r8, [rip + l_anon.[ID].3] lea r9, [rip + _method_simple] @@ -135,7 +135,7 @@ Ltmp8: xor ecx, ecx call SYM(objc2::runtime::define::ClassBuilder::add_method_inner::GENERATED_ID, 0) Ltmp9: - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_d6661a0373fc878f] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_2d06566c3d71d374] Ltmp10: lea rdx, [rip + l_anon.[ID].17] lea r9, [rip + _method_bool] @@ -144,7 +144,7 @@ Ltmp10: mov r8, rdx call SYM(objc2::runtime::define::ClassBuilder::add_method_inner::GENERATED_ID, 0) Ltmp11: - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_8677be6883ccd195] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_d6bd69ea010cdb74] Ltmp12: lea r8, [rip + l_anon.[ID].18] lea r9, [rip + _method_retained] @@ -153,7 +153,7 @@ Ltmp12: xor ecx, ecx call SYM(objc2::runtime::define::ClassBuilder::add_method_inner::GENERATED_ID, 0) Ltmp13: - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_3f5c953c5f98b853] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_83e80b6a812131de] Ltmp14: lea rdx, [rip + l_anon.[ID].17] lea r8, [rip + l_anon.[ID].18] @@ -184,7 +184,7 @@ Ltmp19: mov rsi, rax call _class_addProtocol LBB1_12: - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_76a1da9e60049d4f] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_a42df1bdbbfe0f96] Ltmp20: lea rdx, [rip + l_anon.[ID].23] lea r8, [rip + l_anon.[ID].18] @@ -866,7 +866,7 @@ LBB20_2: push rbp mov rbp, rsp sub rsp, 16 - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_8ae30338ec8fe87d] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_3b26517fa48cbea8] mov rax, qword ptr [rip + L_OBJC_CLASSLIST_REFERENCES_$_NSObject@GOTPCREL] mov rax, qword ptr [rax] mov qword ptr [rbp - 16], rdi @@ -939,7 +939,7 @@ Ltmp58: mov rdi, r12 call _objc_release LBB22_9: - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_c3d3047551604c9f] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_2e436b0daa293d6c] mov rax, qword ptr [rip + L_OBJC_CLASSLIST_REFERENCES_$_NSObject@GOTPCREL] mov rax, qword ptr [rax] mov qword ptr [rbp - 48], rbx @@ -1164,105 +1164,105 @@ l_anon.[ID].23: .space 24 .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_4ee60abb2719f036 -L_OBJC_METH_VAR_NAME_4ee60abb2719f036: + .globl L_OBJC_METH_VAR_NAME_da7dfba076f8819b +L_OBJC_METH_VAR_NAME_da7dfba076f8819b: .asciz "classMethod" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_4ee60abb2719f036 + .globl L_OBJC_SELECTOR_REFERENCES_da7dfba076f8819b .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_4ee60abb2719f036: - .quad L_OBJC_METH_VAR_NAME_4ee60abb2719f036 +L_OBJC_SELECTOR_REFERENCES_da7dfba076f8819b: + .quad L_OBJC_METH_VAR_NAME_da7dfba076f8819b .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_4ee60abb2719f036 + .globl L_OBJC_IMAGE_INFO_da7dfba076f8819b .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_4ee60abb2719f036: +L_OBJC_IMAGE_INFO_da7dfba076f8819b: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_94f56691766f024b -L_OBJC_METH_VAR_NAME_94f56691766f024b: + .globl L_OBJC_METH_VAR_NAME_27735778f6c77cc7 +L_OBJC_METH_VAR_NAME_27735778f6c77cc7: .asciz "method" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_94f56691766f024b + .globl L_OBJC_SELECTOR_REFERENCES_27735778f6c77cc7 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_94f56691766f024b: - .quad L_OBJC_METH_VAR_NAME_94f56691766f024b +L_OBJC_SELECTOR_REFERENCES_27735778f6c77cc7: + .quad L_OBJC_METH_VAR_NAME_27735778f6c77cc7 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_94f56691766f024b + .globl L_OBJC_IMAGE_INFO_27735778f6c77cc7 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_94f56691766f024b: +L_OBJC_IMAGE_INFO_27735778f6c77cc7: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_d6661a0373fc878f -L_OBJC_METH_VAR_NAME_d6661a0373fc878f: + .globl L_OBJC_METH_VAR_NAME_2d06566c3d71d374 +L_OBJC_METH_VAR_NAME_2d06566c3d71d374: .asciz "methodBool:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_d6661a0373fc878f + .globl L_OBJC_SELECTOR_REFERENCES_2d06566c3d71d374 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_d6661a0373fc878f: - .quad L_OBJC_METH_VAR_NAME_d6661a0373fc878f +L_OBJC_SELECTOR_REFERENCES_2d06566c3d71d374: + .quad L_OBJC_METH_VAR_NAME_2d06566c3d71d374 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_d6661a0373fc878f + .globl L_OBJC_IMAGE_INFO_2d06566c3d71d374 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_d6661a0373fc878f: +L_OBJC_IMAGE_INFO_2d06566c3d71d374: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_8677be6883ccd195 -L_OBJC_METH_VAR_NAME_8677be6883ccd195: + .globl L_OBJC_METH_VAR_NAME_d6bd69ea010cdb74 +L_OBJC_METH_VAR_NAME_d6bd69ea010cdb74: .asciz "methodRetained" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_8677be6883ccd195 + .globl L_OBJC_SELECTOR_REFERENCES_d6bd69ea010cdb74 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_8677be6883ccd195: - .quad L_OBJC_METH_VAR_NAME_8677be6883ccd195 +L_OBJC_SELECTOR_REFERENCES_d6bd69ea010cdb74: + .quad L_OBJC_METH_VAR_NAME_d6bd69ea010cdb74 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_8677be6883ccd195 + .globl L_OBJC_IMAGE_INFO_d6bd69ea010cdb74 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_8677be6883ccd195: +L_OBJC_IMAGE_INFO_d6bd69ea010cdb74: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_3f5c953c5f98b853 -L_OBJC_METH_VAR_NAME_3f5c953c5f98b853: + .globl L_OBJC_METH_VAR_NAME_83e80b6a812131de +L_OBJC_METH_VAR_NAME_83e80b6a812131de: .asciz "methodRetainedWithParam:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_3f5c953c5f98b853 + .globl L_OBJC_SELECTOR_REFERENCES_83e80b6a812131de .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_3f5c953c5f98b853: - .quad L_OBJC_METH_VAR_NAME_3f5c953c5f98b853 +L_OBJC_SELECTOR_REFERENCES_83e80b6a812131de: + .quad L_OBJC_METH_VAR_NAME_83e80b6a812131de .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_3f5c953c5f98b853 + .globl L_OBJC_IMAGE_INFO_83e80b6a812131de .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_3f5c953c5f98b853: +L_OBJC_IMAGE_INFO_83e80b6a812131de: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_76a1da9e60049d4f -L_OBJC_METH_VAR_NAME_76a1da9e60049d4f: + .globl L_OBJC_METH_VAR_NAME_a42df1bdbbfe0f96 +L_OBJC_METH_VAR_NAME_a42df1bdbbfe0f96: .asciz "copyWithZone:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_76a1da9e60049d4f + .globl L_OBJC_SELECTOR_REFERENCES_a42df1bdbbfe0f96 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_76a1da9e60049d4f: - .quad L_OBJC_METH_VAR_NAME_76a1da9e60049d4f +L_OBJC_SELECTOR_REFERENCES_a42df1bdbbfe0f96: + .quad L_OBJC_METH_VAR_NAME_a42df1bdbbfe0f96 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_76a1da9e60049d4f + .globl L_OBJC_IMAGE_INFO_a42df1bdbbfe0f96 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_76a1da9e60049d4f: +L_OBJC_IMAGE_INFO_a42df1bdbbfe0f96: .asciz "\000\000\000\000@\000\000" .zerofill __DATA,__bss,SYM(test_define_class[CRATE_ID]::_::__OBJC2_CLASS, 2).0,8,3 @@ -1278,20 +1278,20 @@ l_anon.[ID].24: .zerofill __DATA,__bss,SYM(::class::REGISTER_CLASS, 0),8,3 .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_8ae30338ec8fe87d -L_OBJC_METH_VAR_NAME_8ae30338ec8fe87d: + .globl L_OBJC_METH_VAR_NAME_3b26517fa48cbea8 +L_OBJC_METH_VAR_NAME_3b26517fa48cbea8: .asciz "init" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_8ae30338ec8fe87d + .globl L_OBJC_SELECTOR_REFERENCES_3b26517fa48cbea8 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_8ae30338ec8fe87d: - .quad L_OBJC_METH_VAR_NAME_8ae30338ec8fe87d +L_OBJC_SELECTOR_REFERENCES_3b26517fa48cbea8: + .quad L_OBJC_METH_VAR_NAME_3b26517fa48cbea8 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_8ae30338ec8fe87d + .globl L_OBJC_IMAGE_INFO_3b26517fa48cbea8 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_8ae30338ec8fe87d: +L_OBJC_IMAGE_INFO_3b26517fa48cbea8: .asciz "\000\000\000\000@\000\000" .zerofill __DATA,__bss,SYM(test_define_class[CRATE_ID]::_::__OBJC2_CLASS, 1).0,8,3 @@ -1307,20 +1307,20 @@ l_anon.[ID].25: .zerofill __DATA,__bss,SYM(::class::REGISTER_CLASS, 0),8,3 .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_c3d3047551604c9f -L_OBJC_METH_VAR_NAME_c3d3047551604c9f: + .globl L_OBJC_METH_VAR_NAME_2e436b0daa293d6c +L_OBJC_METH_VAR_NAME_2e436b0daa293d6c: .asciz "init" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_c3d3047551604c9f + .globl L_OBJC_SELECTOR_REFERENCES_2e436b0daa293d6c .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_c3d3047551604c9f: - .quad L_OBJC_METH_VAR_NAME_c3d3047551604c9f +L_OBJC_SELECTOR_REFERENCES_2e436b0daa293d6c: + .quad L_OBJC_METH_VAR_NAME_2e436b0daa293d6c .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_c3d3047551604c9f + .globl L_OBJC_IMAGE_INFO_2e436b0daa293d6c .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_c3d3047551604c9f: +L_OBJC_IMAGE_INFO_2e436b0daa293d6c: .asciz "\000\000\000\000@\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_define_class/lib.rs b/crates/test-assembly/crates/test_define_class/lib.rs index 5a12e1d9a..e63a36195 100644 --- a/crates/test-assembly/crates/test_define_class/lib.rs +++ b/crates/test-assembly/crates/test_define_class/lib.rs @@ -8,7 +8,7 @@ use core::ptr; use objc2::rc::{Allocated, Retained}; use objc2::runtime::AnyClass; -use objc2::{define_class, msg_send_id, ClassType, DefinedClass}; +use objc2::{define_class, msg_send, ClassType, DefinedClass}; use objc2_foundation::{CopyingHelper, NSCopying, NSObject, NSObjectProtocol, NSZone}; define_class!( @@ -37,7 +37,7 @@ define_class!( #[no_mangle] #[method_id(methodRetained)] fn method_retained(&self) -> Option> { - unsafe { msg_send_id![Self::class(), new] } + unsafe { msg_send![Self::class(), new] } } // Test that `objc_autoreleaseReturnValue` is tail-called @@ -60,7 +60,7 @@ define_class!( #[no_mangle] #[method_id(copyWithZone:)] fn copyWithZone(&self, _zone: *const NSZone) -> Option> { - unsafe { msg_send_id![Self::class(), new] } + unsafe { msg_send![Self::class(), new] } } } ); @@ -86,7 +86,7 @@ define_class!( #[method_id(init)] fn init_forgetable_ivars(this: Allocated) -> Option> { let this = this.set_ivars(ForgetableIvarsIvars { foo: 42, bar: 43 }); - unsafe { msg_send_id![super(this), init] } + unsafe { msg_send![super(this), init] } } } ); @@ -123,7 +123,7 @@ define_class!( obj: NSObject::new(), obj_option: Some(NSObject::new()), }); - unsafe { msg_send_id![super(this), init] } + unsafe { msg_send![super(this), init] } } } ); diff --git a/crates/test-assembly/crates/test_msg_send_error/lib.rs b/crates/test-assembly/crates/test_msg_send_error/lib.rs index 6c9178940..97c3ff535 100644 --- a/crates/test-assembly/crates/test_msg_send_error/lib.rs +++ b/crates/test-assembly/crates/test_msg_send_error/lib.rs @@ -1,6 +1,6 @@ //! Test that error parameters are handled correctly. use objc2::__macro_helpers::{ - CopyFamily, InitFamily, MsgSend, MsgSendRetained, MutableCopyFamily, NewFamily, NoneFamily, + CopyFamily, InitFamily, MsgSendError, MutableCopyFamily, NewFamily, NoneFamily, }; use objc2::rc::{Allocated, Retained}; use objc2::runtime::{AnyClass, AnyObject, NSObject, Sel}; @@ -9,32 +9,32 @@ type Result = std::result::Result>; #[no_mangle] unsafe fn error_bool(obj: &AnyObject, sel: Sel, param: u32) -> Result<()> { - MsgSend::send_message_error(obj, sel, (param,)) + NoneFamily::send_message_error(obj, sel, (param,)) } #[no_mangle] unsafe fn error_new(cls: &AnyClass, sel: Sel) -> Result> { - NewFamily::send_message_retained_error(cls, sel, ()) + NewFamily::send_message_error(cls, sel, ()) } // Note: Erroring allocation methods are intentionally not supported #[no_mangle] unsafe fn error_init(obj: Allocated, sel: Sel) -> Result> { - InitFamily::send_message_retained_error(obj, sel, ()) + InitFamily::send_message_error(obj, sel, ()) } #[no_mangle] unsafe fn error_copy(obj: &AnyObject, sel: Sel) -> Result> { - CopyFamily::send_message_retained_error(obj, sel, ()) + CopyFamily::send_message_error(obj, sel, ()) } #[no_mangle] unsafe fn error_mutable_copy(obj: &AnyObject, sel: Sel) -> Result> { - MutableCopyFamily::send_message_retained_error(obj, sel, ()) + MutableCopyFamily::send_message_error(obj, sel, ()) } #[no_mangle] unsafe fn error_autoreleased(obj: &AnyObject, sel: Sel) -> Result> { - NoneFamily::send_message_retained_error(obj, sel, ()) + NoneFamily::send_message_error(obj, sel, ()) } diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-aarch64.s b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-aarch64.s index a213499d1..79b2f8e21 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-aarch64.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-aarch64.s @@ -24,7 +24,7 @@ Lloh1: add x2, x2, l_anon.[ID].1@PAGEOFF mov x0, x20 mov x1, x19 - bl SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + bl SYM(objc2::__macro_helpers::retain_semantics::new_fail::GENERATED_ID, 0) .loh AdrpAdd Lloh0, Lloh1 .globl _handle_alloc @@ -57,7 +57,7 @@ Lloh3: add x2, x2, l_anon.[ID].2@PAGEOFF mov x0, x20 mov x1, x19 - bl SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + bl SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0) .loh AdrpAdd Lloh2, Lloh3 .globl _handle_alloc_init @@ -115,7 +115,7 @@ Lloh4: adrp x0, l_anon.[ID].3@PAGE Lloh5: add x0, x0, l_anon.[ID].3@PAGEOFF - bl SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + bl SYM(objc2::__macro_helpers::retain_semantics::copy_fail::GENERATED_ID, 0) .loh AdrpAdd Lloh4, Lloh5 .globl _handle_mutable_copy @@ -137,7 +137,7 @@ Lloh6: adrp x0, l_anon.[ID].4@PAGE Lloh7: add x0, x0, l_anon.[ID].4@PAGEOFF - bl SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + bl SYM(objc2::__macro_helpers::retain_semantics::mutable_copy_fail::GENERATED_ID, 0) .loh AdrpAdd Lloh6, Lloh7 .globl _handle_autoreleased @@ -189,7 +189,7 @@ Lloh9: add x2, x2, l_anon.[ID].5@PAGEOFF mov x0, x20 mov x1, x19 - bl SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + bl SYM(objc2::__macro_helpers::retain_semantics::none_fail::GENERATED_ID, 0) .loh AdrpAdd Lloh8, Lloh9 .globl _handle_with_out_param @@ -205,34 +205,37 @@ Lfunc_begin0: Ltmp0: bl _objc_msgSend Ltmp1: + ; InlineAsm Start + mov x29, x29 + ; InlineAsm End +Ltmp2: + bl _objc_retainAutoreleasedReturnValue +Ltmp3: mov x21, x0 ldr x0, [x20] bl _objc_retain mov x0, x19 bl _objc_release - ; InlineAsm Start - mov x29, x29 - ; InlineAsm End mov x0, x21 ldp x29, x30, [sp, #32] ldp x20, x19, [sp, #16] ldp x22, x21, [sp], #48 - b _objc_retainAutoreleasedReturnValue -LBB15_2: -Ltmp2: + ret +LBB15_3: +Ltmp4: mov x21, x0 ldr x0, [x20] -Ltmp3: - bl _objc_retain -Ltmp4: Ltmp5: + bl _objc_retain +Ltmp6: +Ltmp7: mov x0, x19 bl _objc_release -Ltmp6: +Ltmp8: mov x0, x21 bl __Unwind_Resume -LBB15_5: -Ltmp7: +LBB15_6: +Ltmp9: bl SYM(core::panicking::panic_in_cleanup::GENERATED_ID, 0) Lfunc_end0: .section __TEXT,__gcc_except_tab @@ -247,19 +250,19 @@ Lttbaseref0: .uleb128 Lcst_end0-Lcst_begin0 Lcst_begin0: .uleb128 Ltmp0-Lfunc_begin0 - .uleb128 Ltmp1-Ltmp0 - .uleb128 Ltmp2-Lfunc_begin0 + .uleb128 Ltmp3-Ltmp0 + .uleb128 Ltmp4-Lfunc_begin0 .byte 0 - .uleb128 Ltmp1-Lfunc_begin0 - .uleb128 Ltmp3-Ltmp1 + .uleb128 Ltmp3-Lfunc_begin0 + .uleb128 Ltmp5-Ltmp3 .byte 0 .byte 0 - .uleb128 Ltmp3-Lfunc_begin0 - .uleb128 Ltmp6-Ltmp3 - .uleb128 Ltmp7-Lfunc_begin0 + .uleb128 Ltmp5-Lfunc_begin0 + .uleb128 Ltmp8-Ltmp5 + .uleb128 Ltmp9-Lfunc_begin0 .byte 1 - .uleb128 Ltmp6-Lfunc_begin0 - .uleb128 Lfunc_end0-Ltmp6 + .uleb128 Ltmp8-Lfunc_begin0 + .uleb128 Lfunc_end0-Ltmp8 .byte 0 .byte 0 Lcst_end0: @@ -278,26 +281,26 @@ l_anon.[ID].0: .p2align 3, 0x0 l_anon.[ID].1: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\000\r\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000\017\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].2: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\000\034\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000\036\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].3: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\0008\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000:\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].4: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\000B\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000D\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].5: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\000V\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000X\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-armv7s.s b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-armv7s.s index 44b054e84..fd6a9e905 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-armv7s.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-armv7s.s @@ -25,7 +25,7 @@ LPC1_0: mov r0, r5 mov r1, r4 mov lr, pc - b SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + b SYM(objc2::__macro_helpers::retain_semantics::new_fail::GENERATED_ID, 0) .globl _handle_alloc .p2align 2 @@ -58,7 +58,7 @@ LPC4_0: mov r0, r5 mov r1, r4 mov lr, pc - b SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + b SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0) .globl _handle_alloc_init .p2align 2 @@ -116,7 +116,7 @@ LBB9_1: LPC9_0: add r0, pc, r0 mov lr, pc - b SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + b SYM(objc2::__macro_helpers::retain_semantics::copy_fail::GENERATED_ID, 0) .globl _handle_mutable_copy .p2align 2 @@ -139,7 +139,7 @@ LBB11_1: LPC11_0: add r0, pc, r0 mov lr, pc - b SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + b SYM(objc2::__macro_helpers::retain_semantics::mutable_copy_fail::GENERATED_ID, 0) .globl _handle_autoreleased .p2align 2 @@ -191,7 +191,7 @@ LPC14_0: mov r0, r5 mov r1, r4 mov lr, pc - b SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + b SYM(objc2::__macro_helpers::retain_semantics::none_fail::GENERATED_ID, 0) .globl _handle_with_out_param .p2align 2 @@ -239,6 +239,14 @@ Ltmp0: mov r2, r6 bl _objc_msgSend Ltmp1: + @ InlineAsm Start + mov r7, r7 + @ InlineAsm End + mov r1, #4 + str r1, [sp, #16] +Ltmp2: + bl _objc_retainAutoreleasedReturnValue +Ltmp3: mov r4, r0 ldr r0, [sp, #4] ldr r0, [r0] @@ -248,13 +256,6 @@ Ltmp1: ldr r0, [sp, #8] str r5, [sp, #16] bl _objc_release - @ InlineAsm Start - mov r7, r7 - @ InlineAsm End - str r5, [sp, #16] - mov r0, r4 - bl _objc_retainAutoreleasedReturnValue - mov r4, r0 add r0, sp, #12 bl __Unwind_SjLj_Unregister mov r0, r4 @@ -264,7 +265,7 @@ Ltmp1: sub sp, r7, #24 pop {r8, r10, r11} pop {r4, r5, r6, r7, pc} -LBB15_2: +LBB15_3: lsl r0, r0, #2 adr r1, LJTI15_0 ldr r0, [r0, r1] @@ -272,51 +273,52 @@ LBB15_2: .p2align 2 LJTI15_0: .data_region jt32 - .long LBB15_4-LJTI15_0 - .long LBB15_8-LJTI15_0 - .long LBB15_8-LJTI15_0 + .long LBB15_5-LJTI15_0 + .long LBB15_10-LJTI15_0 + .long LBB15_10-LJTI15_0 + .long LBB15_5-LJTI15_0 .end_data_region -LBB15_4: -Ltmp2: +LBB15_5: +Ltmp4: ldr r0, [sp, #20] str r0, [sp] ldr r0, [sp, #4] ldr r0, [r0] mov r1, #2 str r1, [sp, #16] -Ltmp3: +Ltmp5: bl _objc_retain -Ltmp4: +Ltmp6: ldr r0, [sp, #8] mov r1, #3 str r1, [sp, #16] -Ltmp5: +Ltmp7: bl _objc_release -Ltmp6: +Ltmp8: b LBB15_9 -LBB15_6: +LBB15_7: ldr r0, [sp, #16] - cmp r0, #3 - bls LBB15_2 + cmp r0, #4 + bls LBB15_3 trap -LBB15_8: -Ltmp7: - ldr r0, [sp, #20] - ldr r0, [sp, #24] - mov lr, pc - b SYM(core::panicking::panic_in_cleanup::GENERATED_ID, 0) LBB15_9: mvn r0, #0 str r0, [sp, #16] ldr r0, [sp] mov lr, pc b __Unwind_SjLj_Resume +LBB15_10: +Ltmp9: + ldr r0, [sp, #20] + ldr r0, [sp, #24] + mov lr, pc + b SYM(core::panicking::panic_in_cleanup::GENERATED_ID, 0) .p2align 2 .data_region LCPI15_0: .long Lexception0-(LPC15_0+8) LCPI15_1: - .long LBB15_6-(LPC15_1+8) + .long LBB15_7-(LPC15_1+8) .end_data_region Lfunc_end0: .section __TEXT,__gcc_except_tab @@ -336,6 +338,8 @@ Lcst_begin0: .byte 1 .byte 2 .byte 1 + .byte 3 + .byte 0 Lcst_end0: .byte 127 .byte 0 @@ -352,27 +356,27 @@ l_anon.[ID].0: .p2align 2, 0x0 l_anon.[ID].1: .long l_anon.[ID].0 - .asciz "9\000\000\000\r\000\000\000\005\000\000" + .asciz "9\000\000\000\017\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].2: .long l_anon.[ID].0 - .asciz "9\000\000\000\034\000\000\000\005\000\000" + .asciz "9\000\000\000\036\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].3: .long l_anon.[ID].0 - .asciz "9\000\000\0008\000\000\000\005\000\000" + .asciz "9\000\000\000:\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].4: .long l_anon.[ID].0 - .asciz "9\000\000\000B\000\000\000\005\000\000" + .asciz "9\000\000\000D\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].5: .long l_anon.[ID].0 - .asciz "9\000\000\000V\000\000\000\005\000\000" + .asciz "9\000\000\000X\000\000\000\005\000\000" .section __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers .p2align 2, 0x0 diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86.s b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86.s index 52a17b78e..222d45d5c 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86.s @@ -41,7 +41,7 @@ LBB1_2: push eax push edi push esi - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::new_fail::GENERATED_ID, 0) .globl _handle_alloc .p2align 4, 0x90 @@ -92,7 +92,7 @@ LBB4_2: push eax push edi push esi - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0) .globl _handle_alloc_init .p2align 4, 0x90 @@ -187,7 +187,7 @@ L9$pb: LBB9_2: lea eax, [esi + l_anon.[ID].3-L9$pb] mov dword ptr [esp], eax - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::copy_fail::GENERATED_ID, 0) .globl _handle_mutable_copy .p2align 4, 0x90 @@ -221,7 +221,7 @@ L11$pb: LBB11_2: lea eax, [esi + l_anon.[ID].4-L11$pb] mov dword ptr [esp], eax - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::mutable_copy_fail::GENERATED_ID, 0) .globl _handle_autoreleased .p2align 4, 0x90 @@ -312,7 +312,7 @@ LBB14_2: push eax push edi push esi - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::none_fail::GENERATED_ID, 0) .globl _handle_with_out_param .p2align 4, 0x90 @@ -334,41 +334,44 @@ Ltmp0: mov dword ptr [esp], eax call _objc_msgSend Ltmp1: - mov esi, eax - mov eax, dword ptr [ebx] - mov dword ptr [esp], eax - call _objc_retain - mov dword ptr [esp], edi - call _objc_release ## InlineAsm Start mov ebp, ebp ## InlineAsm End - mov dword ptr [esp], esi +Ltmp2: + mov dword ptr [esp], eax call _objc_retainAutoreleasedReturnValue +Ltmp3: + mov esi, eax + mov eax, dword ptr [ebx] + mov dword ptr [esp], eax + call _objc_retain + mov dword ptr [esp], edi + call _objc_release + mov eax, esi add esp, 12 pop esi pop edi pop ebx pop ebp ret -LBB15_2: -Ltmp2: +LBB15_3: +Ltmp4: mov esi, eax mov eax, dword ptr [ebx] -Ltmp3: +Ltmp5: mov dword ptr [esp], eax call _objc_retain -Ltmp4: -Ltmp5: +Ltmp6: +Ltmp7: mov dword ptr [esp], edi call _objc_release -Ltmp6: +Ltmp8: mov dword ptr [esp], esi call __Unwind_Resume -LBB15_5: -Ltmp7: +LBB15_6: +Ltmp9: call SYM(core::panicking::panic_in_cleanup::GENERATED_ID, 0) Lfunc_end0: .section __TEXT,__gcc_except_tab @@ -383,19 +386,19 @@ Lttbaseref0: .uleb128 Lcst_end0-Lcst_begin0 Lcst_begin0: .uleb128 Ltmp0-Lfunc_begin0 - .uleb128 Ltmp1-Ltmp0 - .uleb128 Ltmp2-Lfunc_begin0 + .uleb128 Ltmp3-Ltmp0 + .uleb128 Ltmp4-Lfunc_begin0 .byte 0 - .uleb128 Ltmp1-Lfunc_begin0 - .uleb128 Ltmp3-Ltmp1 + .uleb128 Ltmp3-Lfunc_begin0 + .uleb128 Ltmp5-Ltmp3 .byte 0 .byte 0 - .uleb128 Ltmp3-Lfunc_begin0 - .uleb128 Ltmp6-Ltmp3 - .uleb128 Ltmp7-Lfunc_begin0 + .uleb128 Ltmp5-Lfunc_begin0 + .uleb128 Ltmp8-Ltmp5 + .uleb128 Ltmp9-Lfunc_begin0 .byte 1 - .uleb128 Ltmp6-Lfunc_begin0 - .uleb128 Lfunc_end0-Ltmp6 + .uleb128 Ltmp8-Lfunc_begin0 + .uleb128 Lfunc_end0-Ltmp8 .byte 0 .byte 0 Lcst_end0: @@ -414,27 +417,27 @@ l_anon.[ID].0: .p2align 2, 0x0 l_anon.[ID].1: .long l_anon.[ID].0 - .asciz "9\000\000\000\r\000\000\000\005\000\000" + .asciz "9\000\000\000\017\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].2: .long l_anon.[ID].0 - .asciz "9\000\000\000\034\000\000\000\005\000\000" + .asciz "9\000\000\000\036\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].3: .long l_anon.[ID].0 - .asciz "9\000\000\0008\000\000\000\005\000\000" + .asciz "9\000\000\000:\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].4: .long l_anon.[ID].0 - .asciz "9\000\000\000B\000\000\000\005\000\000" + .asciz "9\000\000\000D\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].5: .long l_anon.[ID].0 - .asciz "9\000\000\000V\000\000\000\005\000\000" + .asciz "9\000\000\000X\000\000\000\005\000\000" .section __IMPORT,__pointers,non_lazy_symbol_pointers L_rust_eh_personality$non_lazy_ptr: diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86_64.s b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86_64.s index 2a519e30c..19a089343 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86_64.s @@ -28,7 +28,7 @@ LBB1_2: lea rdx, [rip + l_anon.[ID].1] mov rdi, r14 mov rsi, rbx - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::new_fail::GENERATED_ID, 0) .globl _handle_alloc .p2align 4, 0x90 @@ -66,7 +66,7 @@ LBB4_2: lea rdx, [rip + l_anon.[ID].2] mov rdi, r14 mov rsi, rbx - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0) .globl _handle_alloc_init .p2align 4, 0x90 @@ -132,7 +132,7 @@ _handle_copy_fallible: ret LBB9_2: lea rdi, [rip + l_anon.[ID].3] - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::copy_fail::GENERATED_ID, 0) .globl _handle_mutable_copy .p2align 4, 0x90 @@ -154,7 +154,7 @@ _handle_mutable_copy_fallible: ret LBB11_2: lea rdi, [rip + l_anon.[ID].4] - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::mutable_copy_fail::GENERATED_ID, 0) .globl _handle_autoreleased .p2align 4, 0x90 @@ -216,7 +216,7 @@ LBB14_2: lea rdx, [rip + l_anon.[ID].5] mov rdi, r14 mov rsi, rbx - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::none_fail::GENERATED_ID, 0) .globl _handle_with_out_param .p2align 4, 0x90 @@ -228,44 +228,47 @@ Lfunc_begin0: push r14 push rbx push rax - mov r15, rdx + mov r14, rdx mov rbx, qword ptr [rdx] Ltmp0: call _objc_msgSend Ltmp1: - mov r14, rax - mov rdi, qword ptr [r15] - call _objc_retain - mov rdi, rbx - call _objc_release - mov rdi, r14 +Ltmp2: + mov rdi, rax call _objc_retainAutoreleasedReturnValue +Ltmp3: + mov r15, rax ## InlineAsm Start nop ## InlineAsm End + mov rdi, qword ptr [r14] + call _objc_retain + mov rdi, rbx + call _objc_release + mov rax, r15 add rsp, 8 pop rbx pop r14 pop r15 pop rbp ret -LBB15_2: -Ltmp2: - mov r14, rax - mov rdi, qword ptr [r15] -Ltmp3: - call _objc_retain +LBB15_3: Ltmp4: + mov r15, rax + mov rdi, qword ptr [r14] Ltmp5: + call _objc_retain +Ltmp6: +Ltmp7: mov rdi, rbx call _objc_release -Ltmp6: - mov rdi, r14 +Ltmp8: + mov rdi, r15 call __Unwind_Resume -LBB15_5: -Ltmp7: +LBB15_6: +Ltmp9: call SYM(core::panicking::panic_in_cleanup::GENERATED_ID, 0) Lfunc_end0: .section __TEXT,__gcc_except_tab @@ -280,19 +283,19 @@ Lttbaseref0: .uleb128 Lcst_end0-Lcst_begin0 Lcst_begin0: .uleb128 Ltmp0-Lfunc_begin0 - .uleb128 Ltmp1-Ltmp0 - .uleb128 Ltmp2-Lfunc_begin0 + .uleb128 Ltmp3-Ltmp0 + .uleb128 Ltmp4-Lfunc_begin0 .byte 0 - .uleb128 Ltmp1-Lfunc_begin0 - .uleb128 Ltmp3-Ltmp1 + .uleb128 Ltmp3-Lfunc_begin0 + .uleb128 Ltmp5-Ltmp3 .byte 0 .byte 0 - .uleb128 Ltmp3-Lfunc_begin0 - .uleb128 Ltmp6-Ltmp3 - .uleb128 Ltmp7-Lfunc_begin0 + .uleb128 Ltmp5-Lfunc_begin0 + .uleb128 Ltmp8-Ltmp5 + .uleb128 Ltmp9-Lfunc_begin0 .byte 1 - .uleb128 Ltmp6-Lfunc_begin0 - .uleb128 Lfunc_end0-Ltmp6 + .uleb128 Ltmp8-Lfunc_begin0 + .uleb128 Lfunc_end0-Ltmp8 .byte 0 .byte 0 Lcst_end0: @@ -311,26 +314,26 @@ l_anon.[ID].0: .p2align 3, 0x0 l_anon.[ID].1: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\000\r\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000\017\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].2: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\000\034\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000\036\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].3: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\0008\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000:\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].4: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\000B\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000D\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].5: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\000V\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000X\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86.s b/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86.s index de69d37d4..2d543aea5 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86.s @@ -67,7 +67,7 @@ handle_new_fallible: push eax push edi push esi - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@PLT + call SYM(objc2::__macro_helpers::retain_semantics::new_fail::GENERATED_ID, 0)@PLT .Lfunc_end1: .size handle_new_fallible, .Lfunc_end1-handle_new_fallible @@ -179,7 +179,7 @@ handle_init_fallible: push eax push edi push esi - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@PLT + call SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0)@PLT .Lfunc_end4: .size handle_init_fallible, .Lfunc_end4-handle_init_fallible @@ -370,7 +370,7 @@ handle_copy_fallible: .LBB9_2: lea eax, [ebx + .Lanon.[ID].3@GOTOFF] mov dword ptr [esp], eax - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@PLT + call SYM(objc2::__macro_helpers::retain_semantics::copy_fail::GENERATED_ID, 0)@PLT .Lfunc_end9: .size handle_copy_fallible, .Lfunc_end9-handle_copy_fallible @@ -437,7 +437,7 @@ handle_mutable_copy_fallible: .LBB11_2: lea eax, [ebx + .Lanon.[ID].4@GOTOFF] mov dword ptr [esp], eax - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@PLT + call SYM(objc2::__macro_helpers::retain_semantics::mutable_copy_fail::GENERATED_ID, 0)@PLT .Lfunc_end11: .size handle_mutable_copy_fallible, .Lfunc_end11-handle_mutable_copy_fallible @@ -551,7 +551,7 @@ handle_autoreleased_fallible: push eax push edi push esi - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@PLT + call SYM(objc2::__macro_helpers::retain_semantics::none_fail::GENERATED_ID, 0)@PLT .Lfunc_end14: .size handle_autoreleased_fallible, .Lfunc_end14-handle_autoreleased_fallible @@ -572,8 +572,8 @@ handle_with_out_param: call .L15$pb .L15$pb: pop ebx -.Ltmp25: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp25-.L15$pb) +.Ltmp27: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp27-.L15$pb) mov eax, dword ptr [ebp] mov dword ptr [esp + 24], eax .Ltmp15: @@ -587,6 +587,10 @@ handle_with_out_param: mov dword ptr [esp], esi call eax .Ltmp18: +.Ltmp19: + mov dword ptr [esp], eax + call objc_retainAutoreleasedReturnValue@PLT +.Ltmp20: mov esi, eax mov eax, dword ptr [ebp] mov dword ptr [esp], eax @@ -594,31 +598,30 @@ handle_with_out_param: mov eax, dword ptr [esp + 24] mov dword ptr [esp], eax call objc_release@PLT - mov dword ptr [esp], esi - call objc_retainAutoreleasedReturnValue@PLT + mov eax, esi add esp, 28 pop esi pop edi pop ebx pop ebp ret -.LBB15_3: -.Ltmp19: +.LBB15_4: +.Ltmp21: mov esi, eax mov eax, dword ptr [ebp] -.Ltmp20: +.Ltmp22: mov dword ptr [esp], eax call objc_retain@PLT -.Ltmp21: -.Ltmp22: +.Ltmp23: +.Ltmp24: mov eax, dword ptr [esp + 24] mov dword ptr [esp], eax call objc_release@PLT -.Ltmp23: +.Ltmp25: mov dword ptr [esp], esi call _Unwind_Resume@PLT -.LBB15_6: -.Ltmp24: +.LBB15_7: +.Ltmp26: call SYM(core::panicking::panic_in_cleanup::GENERATED_ID, 0)@PLT .Lfunc_end15: .size handle_with_out_param, .Lfunc_end15-handle_with_out_param @@ -634,19 +637,19 @@ GCC_except_table15: .uleb128 .Lcst_end0-.Lcst_begin0 .Lcst_begin0: .uleb128 .Ltmp15-.Lfunc_begin0 - .uleb128 .Ltmp18-.Ltmp15 - .uleb128 .Ltmp19-.Lfunc_begin0 + .uleb128 .Ltmp20-.Ltmp15 + .uleb128 .Ltmp21-.Lfunc_begin0 .byte 0 - .uleb128 .Ltmp18-.Lfunc_begin0 - .uleb128 .Ltmp20-.Ltmp18 + .uleb128 .Ltmp20-.Lfunc_begin0 + .uleb128 .Ltmp22-.Ltmp20 .byte 0 .byte 0 - .uleb128 .Ltmp20-.Lfunc_begin0 - .uleb128 .Ltmp23-.Ltmp20 - .uleb128 .Ltmp24-.Lfunc_begin0 + .uleb128 .Ltmp22-.Lfunc_begin0 + .uleb128 .Ltmp25-.Ltmp22 + .uleb128 .Ltmp26-.Lfunc_begin0 .byte 1 - .uleb128 .Ltmp23-.Lfunc_begin0 - .uleb128 .Lfunc_end15-.Ltmp23 + .uleb128 .Ltmp25-.Lfunc_begin0 + .uleb128 .Lfunc_end15-.Ltmp25 .byte 0 .byte 0 .Lcst_end0: @@ -668,7 +671,7 @@ GCC_except_table15: .p2align 2, 0x0 .Lanon.[ID].1: .long .Lanon.[ID].0 - .asciz "9\000\000\000\r\000\000\000\005\000\000" + .asciz "9\000\000\000\017\000\000\000\005\000\000" .size .Lanon.[ID].1, 16 .type .Lanon.[ID].2,@object @@ -676,7 +679,7 @@ GCC_except_table15: .p2align 2, 0x0 .Lanon.[ID].2: .long .Lanon.[ID].0 - .asciz "9\000\000\000\034\000\000\000\005\000\000" + .asciz "9\000\000\000\036\000\000\000\005\000\000" .size .Lanon.[ID].2, 16 .type .Lanon.[ID].3,@object @@ -684,7 +687,7 @@ GCC_except_table15: .p2align 2, 0x0 .Lanon.[ID].3: .long .Lanon.[ID].0 - .asciz "9\000\000\0008\000\000\000\005\000\000" + .asciz "9\000\000\000:\000\000\000\005\000\000" .size .Lanon.[ID].3, 16 .type .Lanon.[ID].4,@object @@ -692,7 +695,7 @@ GCC_except_table15: .p2align 2, 0x0 .Lanon.[ID].4: .long .Lanon.[ID].0 - .asciz "9\000\000\000B\000\000\000\005\000\000" + .asciz "9\000\000\000D\000\000\000\005\000\000" .size .Lanon.[ID].4, 16 .type .Lanon.[ID].5,@object @@ -700,7 +703,7 @@ GCC_except_table15: .p2align 2, 0x0 .Lanon.[ID].5: .long .Lanon.[ID].0 - .asciz "9\000\000\000V\000\000\000\005\000\000" + .asciz "9\000\000\000X\000\000\000\005\000\000" .size .Lanon.[ID].5, 16 .hidden DW.ref.rust_eh_personality diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86_64.s b/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86_64.s index a0710a9de..6462ec670 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86_64.s @@ -44,7 +44,7 @@ handle_new_fallible: lea rdx, [rip + .Lanon.[ID].1] mov rdi, r14 mov rsi, rbx - call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@GOTPCREL] + call qword ptr [rip + SYM(objc2::__macro_helpers::retain_semantics::new_fail::GENERATED_ID, 0)@GOTPCREL] .Lfunc_end1: .size handle_new_fallible, .Lfunc_end1-handle_new_fallible @@ -121,7 +121,7 @@ handle_init_fallible: lea rdx, [rip + .Lanon.[ID].2] mov rdi, r14 mov rsi, rbx - call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@GOTPCREL] + call qword ptr [rip + SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0)@GOTPCREL] .Lfunc_end4: .size handle_init_fallible, .Lfunc_end4-handle_init_fallible @@ -260,7 +260,7 @@ handle_copy_fallible: ret .LBB9_2: lea rdi, [rip + .Lanon.[ID].3] - call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@GOTPCREL] + call qword ptr [rip + SYM(objc2::__macro_helpers::retain_semantics::copy_fail::GENERATED_ID, 0)@GOTPCREL] .Lfunc_end9: .size handle_copy_fallible, .Lfunc_end9-handle_copy_fallible @@ -306,7 +306,7 @@ handle_mutable_copy_fallible: ret .LBB11_2: lea rdi, [rip + .Lanon.[ID].4] - call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@GOTPCREL] + call qword ptr [rip + SYM(objc2::__macro_helpers::retain_semantics::mutable_copy_fail::GENERATED_ID, 0)@GOTPCREL] .Lfunc_end11: .size handle_mutable_copy_fallible, .Lfunc_end11-handle_mutable_copy_fallible @@ -382,7 +382,7 @@ handle_autoreleased_fallible: lea rdx, [rip + .Lanon.[ID].5] mov rdi, r14 mov rsi, rbx - call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@GOTPCREL] + call qword ptr [rip + SYM(objc2::__macro_helpers::retain_semantics::none_fail::GENERATED_ID, 0)@GOTPCREL] .Lfunc_end14: .size handle_autoreleased_fallible, .Lfunc_end14-handle_autoreleased_fallible @@ -410,33 +410,37 @@ handle_with_out_param: mov rdx, r14 call rax .Ltmp3: +.Ltmp4: + mov rdi, rax + call qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] +.Ltmp5: mov r15, rax mov rdi, qword ptr [r14] call qword ptr [rip + objc_retain@GOTPCREL] mov rdi, rbx call qword ptr [rip + objc_release@GOTPCREL] - mov rdi, r15 + mov rax, r15 add rsp, 8 pop rbx pop r12 pop r14 pop r15 - jmp qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] -.LBB15_3: -.Ltmp4: + ret +.LBB15_4: +.Ltmp6: mov r15, rax mov rdi, qword ptr [r14] -.Ltmp5: - call qword ptr [rip + objc_retain@GOTPCREL] -.Ltmp6: .Ltmp7: + call qword ptr [rip + objc_retain@GOTPCREL] +.Ltmp8: +.Ltmp9: mov rdi, rbx call qword ptr [rip + objc_release@GOTPCREL] -.Ltmp8: +.Ltmp10: mov rdi, r15 call _Unwind_Resume@PLT -.LBB15_6: -.Ltmp9: +.LBB15_7: +.Ltmp11: call qword ptr [rip + SYM(core::panicking::panic_in_cleanup::GENERATED_ID, 0)@GOTPCREL] .Lfunc_end15: .size handle_with_out_param, .Lfunc_end15-handle_with_out_param @@ -452,19 +456,19 @@ GCC_except_table15: .uleb128 .Lcst_end0-.Lcst_begin0 .Lcst_begin0: .uleb128 .Ltmp0-.Lfunc_begin0 - .uleb128 .Ltmp3-.Ltmp0 - .uleb128 .Ltmp4-.Lfunc_begin0 + .uleb128 .Ltmp5-.Ltmp0 + .uleb128 .Ltmp6-.Lfunc_begin0 .byte 0 - .uleb128 .Ltmp3-.Lfunc_begin0 - .uleb128 .Ltmp5-.Ltmp3 + .uleb128 .Ltmp5-.Lfunc_begin0 + .uleb128 .Ltmp7-.Ltmp5 .byte 0 .byte 0 - .uleb128 .Ltmp5-.Lfunc_begin0 - .uleb128 .Ltmp8-.Ltmp5 - .uleb128 .Ltmp9-.Lfunc_begin0 + .uleb128 .Ltmp7-.Lfunc_begin0 + .uleb128 .Ltmp10-.Ltmp7 + .uleb128 .Ltmp11-.Lfunc_begin0 .byte 1 - .uleb128 .Ltmp8-.Lfunc_begin0 - .uleb128 .Lfunc_end15-.Ltmp8 + .uleb128 .Ltmp10-.Lfunc_begin0 + .uleb128 .Lfunc_end15-.Ltmp10 .byte 0 .byte 0 .Lcst_end0: @@ -486,7 +490,7 @@ GCC_except_table15: .p2align 3, 0x0 .Lanon.[ID].1: .quad .Lanon.[ID].0 - .asciz "9\000\000\000\000\000\000\000\r\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000\017\000\000\000\005\000\000" .size .Lanon.[ID].1, 24 .type .Lanon.[ID].2,@object @@ -494,7 +498,7 @@ GCC_except_table15: .p2align 3, 0x0 .Lanon.[ID].2: .quad .Lanon.[ID].0 - .asciz "9\000\000\000\000\000\000\000\034\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000\036\000\000\000\005\000\000" .size .Lanon.[ID].2, 24 .type .Lanon.[ID].3,@object @@ -502,7 +506,7 @@ GCC_except_table15: .p2align 3, 0x0 .Lanon.[ID].3: .quad .Lanon.[ID].0 - .asciz "9\000\000\000\000\000\000\0008\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000:\000\000\000\005\000\000" .size .Lanon.[ID].3, 24 .type .Lanon.[ID].4,@object @@ -510,7 +514,7 @@ GCC_except_table15: .p2align 3, 0x0 .Lanon.[ID].4: .quad .Lanon.[ID].0 - .asciz "9\000\000\000\000\000\000\000B\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000D\000\000\000\005\000\000" .size .Lanon.[ID].4, 24 .type .Lanon.[ID].5,@object @@ -518,7 +522,7 @@ GCC_except_table15: .p2align 3, 0x0 .Lanon.[ID].5: .quad .Lanon.[ID].0 - .asciz "9\000\000\000\000\000\000\000V\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000X\000\000\000\005\000\000" .size .Lanon.[ID].5, 24 .hidden DW.ref.rust_eh_personality diff --git a/crates/test-assembly/crates/test_msg_send_retained/lib.rs b/crates/test-assembly/crates/test_msg_send_retained/lib.rs index 9ba9edcf4..66a6cb931 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/lib.rs +++ b/crates/test-assembly/crates/test_msg_send_retained/lib.rs @@ -1,74 +1,76 @@ -//! Test assembly output of `msg_send_id!` internals. -use objc2::__macro_helpers::{AllocFamily, CopyFamily, InitFamily, MsgSendRetained, MutableCopyFamily, NewFamily, NoneFamily}; +//! Test assembly output of `msg_send!` internals. +use objc2::__macro_helpers::{ + AllocFamily, CopyFamily, InitFamily, MsgSend, MutableCopyFamily, NewFamily, NoneFamily, +}; use objc2::rc::{Allocated, Retained}; use objc2::runtime::{AnyClass, AnyObject, Sel}; #[no_mangle] unsafe fn handle_new(cls: &AnyClass, sel: Sel) -> Option> { - NewFamily::send_message_retained(cls, sel, ()) + NewFamily::send_message(cls, sel, ()) } #[no_mangle] unsafe fn handle_new_fallible(cls: &AnyClass, sel: Sel) -> Retained { - NewFamily::send_message_retained(cls, sel, ()) + NewFamily::send_message(cls, sel, ()) } #[no_mangle] unsafe fn handle_alloc(cls: &AnyClass, sel: Sel) -> Allocated { - AllocFamily::send_message_retained(cls, sel, ()) + AllocFamily::send_message(cls, sel, ()) } #[no_mangle] unsafe fn handle_init(obj: Allocated, sel: Sel) -> Option> { - InitFamily::send_message_retained(obj, sel, ()) + InitFamily::send_message(obj, sel, ()) } #[no_mangle] unsafe fn handle_init_fallible(obj: Allocated, sel: Sel) -> Retained { - InitFamily::send_message_retained(obj, sel, ()) + InitFamily::send_message(obj, sel, ()) } #[no_mangle] unsafe fn handle_alloc_init(cls: &AnyClass, sel1: Sel, sel2: Sel) -> Option> { - let obj = AllocFamily::send_message_retained(cls, sel1, ()); - InitFamily::send_message_retained(obj, sel2, ()) + let obj = AllocFamily::send_message(cls, sel1, ()); + InitFamily::send_message(obj, sel2, ()) } #[no_mangle] unsafe fn handle_alloc_release(cls: &AnyClass, sel: Sel) { - let _obj: Allocated = AllocFamily::send_message_retained(cls, sel, ()); + let _obj: Allocated = AllocFamily::send_message(cls, sel, ()); } #[no_mangle] unsafe fn handle_alloc_init_release(cls: &AnyClass, sel1: Sel, sel2: Sel) { - let obj = AllocFamily::send_message_retained(cls, sel1, ()); - let obj: Option> = InitFamily::send_message_retained(obj, sel2, ()); + let obj = AllocFamily::send_message(cls, sel1, ()); + let obj: Option> = InitFamily::send_message(obj, sel2, ()); let _obj = obj.unwrap_unchecked(); } #[no_mangle] unsafe fn handle_copy(obj: &AnyObject, sel: Sel) -> Option> { - CopyFamily::send_message_retained(obj, sel, ()) + CopyFamily::send_message(obj, sel, ()) } #[no_mangle] unsafe fn handle_copy_fallible(obj: &AnyObject, sel: Sel) -> Retained { - CopyFamily::send_message_retained(obj, sel, ()) + CopyFamily::send_message(obj, sel, ()) } #[no_mangle] unsafe fn handle_mutable_copy(obj: &AnyObject, sel: Sel) -> Option> { - MutableCopyFamily::send_message_retained(obj, sel, ()) + MutableCopyFamily::send_message(obj, sel, ()) } #[no_mangle] unsafe fn handle_mutable_copy_fallible(obj: &AnyObject, sel: Sel) -> Retained { - MutableCopyFamily::send_message_retained(obj, sel, ()) + MutableCopyFamily::send_message(obj, sel, ()) } #[no_mangle] unsafe fn handle_autoreleased(obj: &AnyObject, sel: Sel) -> Option> { - NoneFamily::send_message_retained(obj, sel, ()) + NoneFamily::send_message(obj, sel, ()) } // TODO: The optimization does not happen here on aarch64, fix this! @@ -78,12 +80,12 @@ unsafe fn handle_autoreleased_with_arg( sel: Sel, arg: u8, ) -> Option> { - NoneFamily::send_message_retained(obj, sel, (arg,)) + NoneFamily::send_message(obj, sel, (arg,)) } #[no_mangle] unsafe fn handle_autoreleased_fallible(obj: &AnyObject, sel: Sel) -> Retained { - NoneFamily::send_message_retained(obj, sel, ()) + NoneFamily::send_message(obj, sel, ()) } // TODO: The optimization does not happen here, fix this! @@ -93,5 +95,5 @@ unsafe fn handle_with_out_param( sel: Sel, param: &mut Retained, ) -> Option> { - NoneFamily::send_message_retained(obj, sel, (param,)) + NoneFamily::send_message(obj, sel, (param,)) } diff --git a/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-aarch64.s b/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-aarch64.s index 0c48748bc..8def645fd 100644 --- a/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-aarch64.s +++ b/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-aarch64.s @@ -3,9 +3,9 @@ .p2align 2 _handle_with_sel: Lloh0: - adrp x8, L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b@PAGE Lloh1: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b@PAGEOFF] b _objc_msgSend .loh AdrpLdr Lloh0, Lloh1 @@ -36,7 +36,7 @@ Lloh6: add x2, x2, l_anon.[ID].1@PAGEOFF mov x0, x19 mov x1, x20 - bl SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + bl SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0) .loh AdrpLdrGotLdr Lloh2, Lloh3, Lloh4 .loh AdrpAdd Lloh5, Lloh6 @@ -48,24 +48,24 @@ _use_generic: add x29, sp, #16 mov x19, x0 Lloh7: - adrp x8, L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3@PAGE Lloh8: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8@PAGEOFF] - adrp x20, L_OBJC_SELECTOR_REFERENCES_80036160fc60677b@PAGE - ldr x2, [x20, L_OBJC_SELECTOR_REFERENCES_80036160fc60677b@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3@PAGEOFF] + adrp x20, L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5@PAGE + ldr x2, [x20, L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5@PAGEOFF] bl _objc_msgSend Lloh9: - adrp x8, L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941@PAGE Lloh10: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9@PAGEOFF] - ldr x2, [x20, L_OBJC_SELECTOR_REFERENCES_80036160fc60677b@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941@PAGEOFF] + ldr x2, [x20, L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5@PAGEOFF] mov x0, x19 bl _objc_msgSend Lloh11: - adrp x8, L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d@PAGE + adrp x8, L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52@PAGE Lloh12: - ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d@PAGEOFF] - ldr x2, [x20, L_OBJC_SELECTOR_REFERENCES_80036160fc60677b@PAGEOFF] + ldr x1, [x8, L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52@PAGEOFF] + ldr x2, [x20, L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5@PAGEOFF] mov x0, x19 ldp x29, x30, [sp, #16] ldp x20, x19, [sp], #32 @@ -85,88 +85,88 @@ l_anon.[ID].1: .asciz ";\000\000\000\000\000\000\000\016\000\000\000\005\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e -L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e: + .globl L_OBJC_METH_VAR_NAME_80f1580ed33ec51b +L_OBJC_METH_VAR_NAME_80f1580ed33ec51b: .asciz "someSelector" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e + .globl L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e: - .quad L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e +L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b: + .quad L_OBJC_METH_VAR_NAME_80f1580ed33ec51b .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_664c1e40eb8cd76e + .globl L_OBJC_IMAGE_INFO_80f1580ed33ec51b .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_664c1e40eb8cd76e: +L_OBJC_IMAGE_INFO_80f1580ed33ec51b: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_80036160fc60677b -L_OBJC_METH_VAR_NAME_80036160fc60677b: + .globl L_OBJC_METH_VAR_NAME_91c006d97540f4b5 +L_OBJC_METH_VAR_NAME_91c006d97540f4b5: .asciz "generic:selector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_80036160fc60677b + .globl L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_80036160fc60677b: - .quad L_OBJC_METH_VAR_NAME_80036160fc60677b +L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5: + .quad L_OBJC_METH_VAR_NAME_91c006d97540f4b5 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_80036160fc60677b + .globl L_OBJC_IMAGE_INFO_91c006d97540f4b5 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_80036160fc60677b: +L_OBJC_IMAGE_INFO_91c006d97540f4b5: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8 -L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8: + .globl L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3 +L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8 + .globl L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8: - .quad L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8 +L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3: + .quad L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_e4e4edcd2d17efb8 + .globl L_OBJC_IMAGE_INFO_67bf3e41c7e639a3 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_e4e4edcd2d17efb8: +L_OBJC_IMAGE_INFO_67bf3e41c7e639a3: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_bf9373a91792acd9 -L_OBJC_METH_VAR_NAME_bf9373a91792acd9: + .globl L_OBJC_METH_VAR_NAME_2c2c9a8191012941 +L_OBJC_METH_VAR_NAME_2c2c9a8191012941: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9 + .globl L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9: - .quad L_OBJC_METH_VAR_NAME_bf9373a91792acd9 +L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941: + .quad L_OBJC_METH_VAR_NAME_2c2c9a8191012941 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_bf9373a91792acd9 + .globl L_OBJC_IMAGE_INFO_2c2c9a8191012941 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_bf9373a91792acd9: +L_OBJC_IMAGE_INFO_2c2c9a8191012941: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d -L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d: + .globl L_OBJC_METH_VAR_NAME_993d94b40d47ed52 +L_OBJC_METH_VAR_NAME_993d94b40d47ed52: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d + .globl L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d: - .quad L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d +L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52: + .quad L_OBJC_METH_VAR_NAME_993d94b40d47ed52 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_65f663aa0a6ddc1d + .globl L_OBJC_IMAGE_INFO_993d94b40d47ed52 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_65f663aa0a6ddc1d: +L_OBJC_IMAGE_INFO_993d94b40d47ed52: .asciz "\000\000\000\000@\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-armv7s.s b/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-armv7s.s index 462ee8570..67b1e1676 100644 --- a/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-armv7s.s +++ b/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-armv7s.s @@ -4,8 +4,8 @@ .p2align 2 .code 32 _handle_with_sel: - movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e-(LPC0_0+8)) - movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e-(LPC0_0+8)) + movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b-(LPC0_0+8)) + movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b-(LPC0_0+8)) LPC0_0: ldr r1, [pc, r1] b _objc_msgSend @@ -35,7 +35,7 @@ LPC1_1: mov r0, r4 mov r1, r5 mov lr, pc - b SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + b SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0) .globl _use_generic .p2align 2 @@ -44,31 +44,31 @@ _use_generic: push {r4, r7, lr} add r7, sp, #4 mov r4, r0 - movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8-(LPC2_0+8)) - movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8-(LPC2_0+8)) + movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3-(LPC2_0+8)) + movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3-(LPC2_0+8)) LPC2_0: ldr r1, [pc, r1] - movw r2, :lower16:(L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-(LPC2_1+8)) - movt r2, :upper16:(L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-(LPC2_1+8)) + movw r2, :lower16:(L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-(LPC2_1+8)) + movt r2, :upper16:(L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-(LPC2_1+8)) LPC2_1: ldr r2, [pc, r2] bl _objc_msgSend - movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9-(LPC2_2+8)) - movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9-(LPC2_2+8)) + movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941-(LPC2_2+8)) + movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941-(LPC2_2+8)) LPC2_2: ldr r1, [pc, r1] - movw r2, :lower16:(L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-(LPC2_3+8)) - movt r2, :upper16:(L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-(LPC2_3+8)) + movw r2, :lower16:(L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-(LPC2_3+8)) + movt r2, :upper16:(L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-(LPC2_3+8)) LPC2_3: ldr r2, [pc, r2] mov r0, r4 bl _objc_msgSend - movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d-(LPC2_4+8)) - movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d-(LPC2_4+8)) + movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52-(LPC2_4+8)) + movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52-(LPC2_4+8)) LPC2_4: ldr r1, [pc, r1] - movw r2, :lower16:(L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-(LPC2_5+8)) - movt r2, :upper16:(L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-(LPC2_5+8)) + movw r2, :lower16:(L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-(LPC2_5+8)) + movt r2, :upper16:(L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-(LPC2_5+8)) LPC2_5: ldr r2, [pc, r2] mov r0, r4 @@ -86,88 +86,88 @@ l_anon.[ID].1: .asciz ";\000\000\000\016\000\000\000\005\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e -L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e: + .globl L_OBJC_METH_VAR_NAME_80f1580ed33ec51b +L_OBJC_METH_VAR_NAME_80f1580ed33ec51b: .asciz "someSelector" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e + .globl L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e: - .long L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e +L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b: + .long L_OBJC_METH_VAR_NAME_80f1580ed33ec51b .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_664c1e40eb8cd76e + .globl L_OBJC_IMAGE_INFO_80f1580ed33ec51b .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_664c1e40eb8cd76e: +L_OBJC_IMAGE_INFO_80f1580ed33ec51b: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_80036160fc60677b -L_OBJC_METH_VAR_NAME_80036160fc60677b: + .globl L_OBJC_METH_VAR_NAME_91c006d97540f4b5 +L_OBJC_METH_VAR_NAME_91c006d97540f4b5: .asciz "generic:selector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_80036160fc60677b + .globl L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_80036160fc60677b: - .long L_OBJC_METH_VAR_NAME_80036160fc60677b +L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5: + .long L_OBJC_METH_VAR_NAME_91c006d97540f4b5 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_80036160fc60677b + .globl L_OBJC_IMAGE_INFO_91c006d97540f4b5 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_80036160fc60677b: +L_OBJC_IMAGE_INFO_91c006d97540f4b5: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8 -L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8: + .globl L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3 +L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8 + .globl L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8: - .long L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8 +L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3: + .long L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_e4e4edcd2d17efb8 + .globl L_OBJC_IMAGE_INFO_67bf3e41c7e639a3 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_e4e4edcd2d17efb8: +L_OBJC_IMAGE_INFO_67bf3e41c7e639a3: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_bf9373a91792acd9 -L_OBJC_METH_VAR_NAME_bf9373a91792acd9: + .globl L_OBJC_METH_VAR_NAME_2c2c9a8191012941 +L_OBJC_METH_VAR_NAME_2c2c9a8191012941: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9 + .globl L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9: - .long L_OBJC_METH_VAR_NAME_bf9373a91792acd9 +L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941: + .long L_OBJC_METH_VAR_NAME_2c2c9a8191012941 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_bf9373a91792acd9 + .globl L_OBJC_IMAGE_INFO_2c2c9a8191012941 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_bf9373a91792acd9: +L_OBJC_IMAGE_INFO_2c2c9a8191012941: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d -L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d: + .globl L_OBJC_METH_VAR_NAME_993d94b40d47ed52 +L_OBJC_METH_VAR_NAME_993d94b40d47ed52: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d + .globl L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d: - .long L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d +L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52: + .long L_OBJC_METH_VAR_NAME_993d94b40d47ed52 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_65f663aa0a6ddc1d + .globl L_OBJC_IMAGE_INFO_993d94b40d47ed52 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_65f663aa0a6ddc1d: +L_OBJC_IMAGE_INFO_993d94b40d47ed52: .asciz "\000\000\000\000@\000\000" .section __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers diff --git a/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-old-x86.s b/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-old-x86.s index 5da8eb70f..59398838c 100644 --- a/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-old-x86.s +++ b/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-old-x86.s @@ -10,7 +10,7 @@ _handle_with_sel: L0$pb: pop eax sub esp, 8 - push dword ptr [eax + L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e-L0$pb] + push dword ptr [eax + L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b-L0$pb] push dword ptr [ebp + 8] call _objc_msgSend add esp, 24 @@ -57,7 +57,7 @@ LBB1_2: push eax push ebx push esi - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0) .globl _use_generic .p2align 4, 0x90 @@ -71,18 +71,18 @@ L2$pb: pop esi mov edi, dword ptr [ebp + 8] sub esp, 4 - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-L2$pb] - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3-L2$pb] push edi call _objc_msgSend add esp, 12 - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-L2$pb] - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941-L2$pb] push edi call _objc_msgSend add esp, 12 - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-L2$pb] - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52-L2$pb] push edi call _objc_msgSend add esp, 16 @@ -102,88 +102,88 @@ l_anon.[ID].1: .asciz ";\000\000\000\016\000\000\000\005\000\000" .section __TEXT,__cstring,cstring_literals - .globl L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e -L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e: + .globl L_OBJC_METH_VAR_NAME_80f1580ed33ec51b +L_OBJC_METH_VAR_NAME_80f1580ed33ec51b: .asciz "someSelector" .section __OBJC,__message_refs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e + .globl L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e: - .long L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e +L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b: + .long L_OBJC_METH_VAR_NAME_80f1580ed33ec51b .section __OBJC,__image_info - .globl L_OBJC_IMAGE_INFO_664c1e40eb8cd76e + .globl L_OBJC_IMAGE_INFO_80f1580ed33ec51b .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_664c1e40eb8cd76e: +L_OBJC_IMAGE_INFO_80f1580ed33ec51b: .asciz "\000\000\000\000@\000\000" .section __TEXT,__cstring,cstring_literals - .globl L_OBJC_METH_VAR_NAME_80036160fc60677b -L_OBJC_METH_VAR_NAME_80036160fc60677b: + .globl L_OBJC_METH_VAR_NAME_91c006d97540f4b5 +L_OBJC_METH_VAR_NAME_91c006d97540f4b5: .asciz "generic:selector:" .section __OBJC,__message_refs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_80036160fc60677b + .globl L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_80036160fc60677b: - .long L_OBJC_METH_VAR_NAME_80036160fc60677b +L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5: + .long L_OBJC_METH_VAR_NAME_91c006d97540f4b5 .section __OBJC,__image_info - .globl L_OBJC_IMAGE_INFO_80036160fc60677b + .globl L_OBJC_IMAGE_INFO_91c006d97540f4b5 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_80036160fc60677b: +L_OBJC_IMAGE_INFO_91c006d97540f4b5: .asciz "\000\000\000\000@\000\000" .section __TEXT,__cstring,cstring_literals - .globl L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8 -L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8: + .globl L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3 +L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3: .asciz "performSelector:" .section __OBJC,__message_refs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8 + .globl L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8: - .long L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8 +L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3: + .long L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3 .section __OBJC,__image_info - .globl L_OBJC_IMAGE_INFO_e4e4edcd2d17efb8 + .globl L_OBJC_IMAGE_INFO_67bf3e41c7e639a3 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_e4e4edcd2d17efb8: +L_OBJC_IMAGE_INFO_67bf3e41c7e639a3: .asciz "\000\000\000\000@\000\000" .section __TEXT,__cstring,cstring_literals - .globl L_OBJC_METH_VAR_NAME_bf9373a91792acd9 -L_OBJC_METH_VAR_NAME_bf9373a91792acd9: + .globl L_OBJC_METH_VAR_NAME_2c2c9a8191012941 +L_OBJC_METH_VAR_NAME_2c2c9a8191012941: .asciz "performSelector:" .section __OBJC,__message_refs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9 + .globl L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9: - .long L_OBJC_METH_VAR_NAME_bf9373a91792acd9 +L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941: + .long L_OBJC_METH_VAR_NAME_2c2c9a8191012941 .section __OBJC,__image_info - .globl L_OBJC_IMAGE_INFO_bf9373a91792acd9 + .globl L_OBJC_IMAGE_INFO_2c2c9a8191012941 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_bf9373a91792acd9: +L_OBJC_IMAGE_INFO_2c2c9a8191012941: .asciz "\000\000\000\000@\000\000" .section __TEXT,__cstring,cstring_literals - .globl L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d -L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d: + .globl L_OBJC_METH_VAR_NAME_993d94b40d47ed52 +L_OBJC_METH_VAR_NAME_993d94b40d47ed52: .asciz "performSelector:" .section __OBJC,__message_refs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d + .globl L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d: - .long L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d +L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52: + .long L_OBJC_METH_VAR_NAME_993d94b40d47ed52 .section __OBJC,__image_info - .globl L_OBJC_IMAGE_INFO_65f663aa0a6ddc1d + .globl L_OBJC_IMAGE_INFO_993d94b40d47ed52 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_65f663aa0a6ddc1d: +L_OBJC_IMAGE_INFO_993d94b40d47ed52: .asciz "\000\000\000\000@\000\000" .section __IMPORT,__pointers,non_lazy_symbol_pointers diff --git a/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-x86.s b/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-x86.s index cb6db54a0..46919075e 100644 --- a/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-x86.s +++ b/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-x86.s @@ -10,7 +10,7 @@ _handle_with_sel: L0$pb: pop eax sub esp, 8 - push dword ptr [eax + L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e-L0$pb] + push dword ptr [eax + L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b-L0$pb] push dword ptr [ebp + 8] call _objc_msgSend add esp, 24 @@ -55,7 +55,7 @@ LBB1_2: push eax push ebx push esi - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0) .globl _use_generic .p2align 4, 0x90 @@ -69,18 +69,18 @@ L2$pb: pop esi mov edi, dword ptr [ebp + 8] sub esp, 4 - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-L2$pb] - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3-L2$pb] push edi call _objc_msgSend add esp, 12 - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-L2$pb] - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941-L2$pb] push edi call _objc_msgSend add esp, 12 - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_80036160fc60677b-L2$pb] - push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5-L2$pb] + push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52-L2$pb] push edi call _objc_msgSend add esp, 16 @@ -100,88 +100,88 @@ l_anon.[ID].1: .asciz ";\000\000\000\016\000\000\000\005\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e -L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e: + .globl L_OBJC_METH_VAR_NAME_80f1580ed33ec51b +L_OBJC_METH_VAR_NAME_80f1580ed33ec51b: .asciz "someSelector" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e + .globl L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e: - .long L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e +L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b: + .long L_OBJC_METH_VAR_NAME_80f1580ed33ec51b .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_664c1e40eb8cd76e + .globl L_OBJC_IMAGE_INFO_80f1580ed33ec51b .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_664c1e40eb8cd76e: +L_OBJC_IMAGE_INFO_80f1580ed33ec51b: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_80036160fc60677b -L_OBJC_METH_VAR_NAME_80036160fc60677b: + .globl L_OBJC_METH_VAR_NAME_91c006d97540f4b5 +L_OBJC_METH_VAR_NAME_91c006d97540f4b5: .asciz "generic:selector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_80036160fc60677b + .globl L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_80036160fc60677b: - .long L_OBJC_METH_VAR_NAME_80036160fc60677b +L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5: + .long L_OBJC_METH_VAR_NAME_91c006d97540f4b5 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_80036160fc60677b + .globl L_OBJC_IMAGE_INFO_91c006d97540f4b5 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_80036160fc60677b: +L_OBJC_IMAGE_INFO_91c006d97540f4b5: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8 -L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8: + .globl L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3 +L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8 + .globl L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8: - .long L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8 +L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3: + .long L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_e4e4edcd2d17efb8 + .globl L_OBJC_IMAGE_INFO_67bf3e41c7e639a3 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_e4e4edcd2d17efb8: +L_OBJC_IMAGE_INFO_67bf3e41c7e639a3: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_bf9373a91792acd9 -L_OBJC_METH_VAR_NAME_bf9373a91792acd9: + .globl L_OBJC_METH_VAR_NAME_2c2c9a8191012941 +L_OBJC_METH_VAR_NAME_2c2c9a8191012941: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9 + .globl L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9: - .long L_OBJC_METH_VAR_NAME_bf9373a91792acd9 +L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941: + .long L_OBJC_METH_VAR_NAME_2c2c9a8191012941 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_bf9373a91792acd9 + .globl L_OBJC_IMAGE_INFO_2c2c9a8191012941 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_bf9373a91792acd9: +L_OBJC_IMAGE_INFO_2c2c9a8191012941: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d -L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d: + .globl L_OBJC_METH_VAR_NAME_993d94b40d47ed52 +L_OBJC_METH_VAR_NAME_993d94b40d47ed52: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d + .globl L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52 .p2align 2, 0x0 -L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d: - .long L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d +L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52: + .long L_OBJC_METH_VAR_NAME_993d94b40d47ed52 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_65f663aa0a6ddc1d + .globl L_OBJC_IMAGE_INFO_993d94b40d47ed52 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_65f663aa0a6ddc1d: +L_OBJC_IMAGE_INFO_993d94b40d47ed52: .asciz "\000\000\000\000@\000\000" .section __IMPORT,__pointers,non_lazy_symbol_pointers diff --git a/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-x86_64.s b/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-x86_64.s index 69781dd91..e6092b8f4 100644 --- a/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_static_sel/expected/apple-x86_64.s @@ -5,7 +5,7 @@ _handle_with_sel: push rbp mov rbp, rsp - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b] pop rbp jmp _objc_msgSend @@ -33,7 +33,7 @@ LBB1_2: lea rdx, [rip + l_anon.[ID].1] mov rdi, rbx mov rsi, r14 - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM(objc2::__macro_helpers::retain_semantics::init_fail::GENERATED_ID, 0) .globl _use_generic .p2align 4, 0x90 @@ -43,15 +43,15 @@ _use_generic: push rbx push rax mov rbx, rdi - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8] - mov rdx, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_80036160fc60677b] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3] + mov rdx, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5] call _objc_msgSend - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9] - mov rdx, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_80036160fc60677b] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941] + mov rdx, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5] mov rdi, rbx call _objc_msgSend - mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d] - mov rdx, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_80036160fc60677b] + mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52] + mov rdx, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5] mov rdi, rbx add rsp, 8 pop rbx @@ -69,88 +69,88 @@ l_anon.[ID].1: .asciz ";\000\000\000\000\000\000\000\016\000\000\000\005\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e -L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e: + .globl L_OBJC_METH_VAR_NAME_80f1580ed33ec51b +L_OBJC_METH_VAR_NAME_80f1580ed33ec51b: .asciz "someSelector" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e + .globl L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_664c1e40eb8cd76e: - .quad L_OBJC_METH_VAR_NAME_664c1e40eb8cd76e +L_OBJC_SELECTOR_REFERENCES_80f1580ed33ec51b: + .quad L_OBJC_METH_VAR_NAME_80f1580ed33ec51b .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_664c1e40eb8cd76e + .globl L_OBJC_IMAGE_INFO_80f1580ed33ec51b .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_664c1e40eb8cd76e: +L_OBJC_IMAGE_INFO_80f1580ed33ec51b: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_80036160fc60677b -L_OBJC_METH_VAR_NAME_80036160fc60677b: + .globl L_OBJC_METH_VAR_NAME_91c006d97540f4b5 +L_OBJC_METH_VAR_NAME_91c006d97540f4b5: .asciz "generic:selector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_80036160fc60677b + .globl L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_80036160fc60677b: - .quad L_OBJC_METH_VAR_NAME_80036160fc60677b +L_OBJC_SELECTOR_REFERENCES_91c006d97540f4b5: + .quad L_OBJC_METH_VAR_NAME_91c006d97540f4b5 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_80036160fc60677b + .globl L_OBJC_IMAGE_INFO_91c006d97540f4b5 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_80036160fc60677b: +L_OBJC_IMAGE_INFO_91c006d97540f4b5: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8 -L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8: + .globl L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3 +L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8 + .globl L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_e4e4edcd2d17efb8: - .quad L_OBJC_METH_VAR_NAME_e4e4edcd2d17efb8 +L_OBJC_SELECTOR_REFERENCES_67bf3e41c7e639a3: + .quad L_OBJC_METH_VAR_NAME_67bf3e41c7e639a3 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_e4e4edcd2d17efb8 + .globl L_OBJC_IMAGE_INFO_67bf3e41c7e639a3 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_e4e4edcd2d17efb8: +L_OBJC_IMAGE_INFO_67bf3e41c7e639a3: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_bf9373a91792acd9 -L_OBJC_METH_VAR_NAME_bf9373a91792acd9: + .globl L_OBJC_METH_VAR_NAME_2c2c9a8191012941 +L_OBJC_METH_VAR_NAME_2c2c9a8191012941: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9 + .globl L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_bf9373a91792acd9: - .quad L_OBJC_METH_VAR_NAME_bf9373a91792acd9 +L_OBJC_SELECTOR_REFERENCES_2c2c9a8191012941: + .quad L_OBJC_METH_VAR_NAME_2c2c9a8191012941 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_bf9373a91792acd9 + .globl L_OBJC_IMAGE_INFO_2c2c9a8191012941 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_bf9373a91792acd9: +L_OBJC_IMAGE_INFO_2c2c9a8191012941: .asciz "\000\000\000\000@\000\000" .section __TEXT,__objc_methname,cstring_literals - .globl L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d -L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d: + .globl L_OBJC_METH_VAR_NAME_993d94b40d47ed52 +L_OBJC_METH_VAR_NAME_993d94b40d47ed52: .asciz "performSelector:" .section __DATA,__objc_selrefs,literal_pointers - .globl L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d + .globl L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52 .p2align 3, 0x0 -L_OBJC_SELECTOR_REFERENCES_65f663aa0a6ddc1d: - .quad L_OBJC_METH_VAR_NAME_65f663aa0a6ddc1d +L_OBJC_SELECTOR_REFERENCES_993d94b40d47ed52: + .quad L_OBJC_METH_VAR_NAME_993d94b40d47ed52 .section __DATA,__objc_imageinfo,regular,no_dead_strip - .globl L_OBJC_IMAGE_INFO_65f663aa0a6ddc1d + .globl L_OBJC_IMAGE_INFO_993d94b40d47ed52 .p2align 2, 0x0 -L_OBJC_IMAGE_INFO_65f663aa0a6ddc1d: +L_OBJC_IMAGE_INFO_993d94b40d47ed52: .asciz "\000\000\000\000@\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_static_sel/lib.rs b/crates/test-assembly/crates/test_msg_send_static_sel/lib.rs index 31acd59f9..ef9cf01bb 100644 --- a/crates/test-assembly/crates/test_msg_send_static_sel/lib.rs +++ b/crates/test-assembly/crates/test_msg_send_static_sel/lib.rs @@ -1,8 +1,8 @@ -//! Test how static selectors work in relation to `msg_send!` and `msg_send_id!` +//! Test how static selectors work in relation to `msg_send!`. #![cfg(target_vendor = "apple")] use objc2::rc::Retained; use objc2::runtime::{AnyClass, AnyObject, Sel}; -use objc2::{msg_send, msg_send_id, sel}; +use objc2::{msg_send, sel}; #[no_mangle] unsafe fn handle_with_sel(obj: &AnyObject) -> *mut AnyObject { @@ -11,7 +11,7 @@ unsafe fn handle_with_sel(obj: &AnyObject) -> *mut AnyObject { #[no_mangle] unsafe fn handle_alloc_init(cls: &AnyClass) -> Retained { - msg_send_id![msg_send_id![cls, alloc], init] + msg_send![msg_send![cls, alloc], init] } #[allow(clippy::extra_unused_type_parameters)] diff --git a/crates/test-assembly/crates/test_out_parameters/expected/apple-armv7s.s b/crates/test-assembly/crates/test_out_parameters/expected/apple-armv7s.s index 26f5bf112..70ee97bb3 100644 --- a/crates/test-assembly/crates/test_out_parameters/expected/apple-armv7s.s +++ b/crates/test-assembly/crates/test_out_parameters/expected/apple-armv7s.s @@ -394,7 +394,7 @@ LBB5_2: LBB5_3: str r0, [sp, #8] ldr r2, [sp, #4] - mov r0, #2 + mov r0, #1 str r0, [sp, #16] Ltmp18: mov r0, r5 @@ -431,8 +431,8 @@ LBB5_7: .p2align 2 LJTI5_0: .data_region jt32 - .long LBB5_12-LJTI5_0 .long LBB5_9-LJTI5_0 + .long LBB5_12-LJTI5_0 .end_data_region LBB5_9: Ltmp20: @@ -440,7 +440,7 @@ Ltmp20: str r0, [sp] ldr r0, [sp, #4] ldr r1, [sp, #8] - mov r2, #1 + mov r2, #2 str r2, [sp, #16] Ltmp21: bl SYM(core[CRATE_ID]::ptr::drop_in_place::<(core[CRATE_ID]::option::Option>,)>, 0) @@ -482,10 +482,10 @@ Lttbaseref2: .byte 3 .uleb128 Lcst_end2-Lcst_begin2 Lcst_begin2: + .byte 0 .byte 0 .byte 1 .byte 1 - .byte 0 Lcst_end2: .byte 127 .byte 0 @@ -679,7 +679,7 @@ LBB7_2: LBB7_3: str r0, [sp, #8] ldr r2, [sp, #4] - mov r0, #2 + mov r0, #1 str r0, [sp, #16] Ltmp30: mov r0, r5 @@ -719,8 +719,8 @@ LBB7_8: .p2align 2 LJTI7_0: .data_region jt32 - .long LBB7_13-LJTI7_0 .long LBB7_10-LJTI7_0 + .long LBB7_13-LJTI7_0 .end_data_region LBB7_10: Ltmp32: @@ -728,7 +728,7 @@ Ltmp32: str r0, [sp] ldr r0, [sp, #4] ldr r1, [sp, #8] - mov r2, #1 + mov r2, #2 str r2, [sp, #16] Ltmp33: bl SYM(core[CRATE_ID]::ptr::drop_in_place::<(core[CRATE_ID]::option::Option>,)>, 0) @@ -770,10 +770,10 @@ Lttbaseref4: .byte 3 .uleb128 Lcst_end4-Lcst_begin4 Lcst_begin4: + .byte 0 .byte 0 .byte 1 .byte 1 - .byte 0 Lcst_end4: .byte 127 .byte 0 diff --git a/crates/test-assembly/crates/test_out_parameters/lib.rs b/crates/test-assembly/crates/test_out_parameters/lib.rs index f70e46e23..e15892f06 100644 --- a/crates/test-assembly/crates/test_out_parameters/lib.rs +++ b/crates/test-assembly/crates/test_out_parameters/lib.rs @@ -1,21 +1,21 @@ //! Test that out parameters are handled correctly. -use objc2::__macro_helpers::MsgSend; +use objc2::__macro_helpers::{MsgSend, NoneFamily}; use objc2::rc::Retained; use objc2::runtime::{NSObject, Sel}; #[no_mangle] unsafe fn nonnull_nonnull(obj: &NSObject, sel: Sel, param: &mut Retained) -> usize { - MsgSend::send_message(obj, sel, (param,)) + NoneFamily::send_message(obj, sel, (param,)) } #[no_mangle] unsafe fn null_nonnull(obj: &NSObject, sel: Sel, param: Option<&mut Retained>) -> usize { - MsgSend::send_message(obj, sel, (param,)) + NoneFamily::send_message(obj, sel, (param,)) } #[no_mangle] unsafe fn nonnull_null(obj: &NSObject, sel: Sel, param: &mut Option>) -> usize { - MsgSend::send_message(obj, sel, (param,)) + NoneFamily::send_message(obj, sel, (param,)) } #[no_mangle] @@ -24,7 +24,7 @@ unsafe fn null_null( sel: Sel, param: Option<&mut Option>>, ) -> usize { - MsgSend::send_message(obj, sel, (param,)) + NoneFamily::send_message(obj, sel, (param,)) } #[no_mangle] @@ -34,7 +34,7 @@ unsafe fn two_nonnull_nonnull( param1: &mut Retained, param2: &mut Retained, ) -> usize { - MsgSend::send_message(obj, sel, (param1, param2)) + NoneFamily::send_message(obj, sel, (param1, param2)) } // diff --git a/crates/test-fuzz/fuzz_targets/collection_interior_mut.rs b/crates/test-fuzz/fuzz_targets/collection_interior_mut.rs index bdc242a6b..3ff6a4576 100644 --- a/crates/test-fuzz/fuzz_targets/collection_interior_mut.rs +++ b/crates/test-fuzz/fuzz_targets/collection_interior_mut.rs @@ -12,7 +12,7 @@ use std::hint::black_box; use arbitrary::Arbitrary; use objc2::rc::{autoreleasepool, Retained}; use objc2::runtime::AnyObject; -use objc2::{define_class, msg_send_id, AllocAnyThread, ClassType, DefinedClass, Message}; +use objc2::{define_class, msg_send, AllocAnyThread, ClassType, DefinedClass, Message}; use objc2_foundation::{ CopyingHelper, NSCopying, NSMutableDictionary, NSMutableSet, NSObject, NSObjectProtocol, NSUInteger, NSZone, @@ -90,7 +90,7 @@ impl Key { hash: Cell::new(0), equal_to_mask: Cell::new(0), }); - unsafe { msg_send_id![super(key), init] } + unsafe { msg_send![super(key), init] } } fn validate(&self) { diff --git a/crates/test-ui/ui/define_class_delegate_not_mainthreadonly.rs b/crates/test-ui/ui/define_class_delegate_not_mainthreadonly.rs index 9b2d0309b..2c8643e95 100644 --- a/crates/test-ui/ui/define_class_delegate_not_mainthreadonly.rs +++ b/crates/test-ui/ui/define_class_delegate_not_mainthreadonly.rs @@ -34,7 +34,7 @@ define_class!( extern_methods!( unsafe impl CustomObject { - #[method_id(new)] + #[method(new)] fn new(mtm: MainThreadMarker) -> Retained; } ); diff --git a/crates/test-ui/ui/define_class_invalid_syntax.stderr b/crates/test-ui/ui/define_class_invalid_syntax.stderr index e1afc1f48..d4711aa88 100644 --- a/crates/test-ui/ui/define_class_invalid_syntax.stderr +++ b/crates/test-ui/ui/define_class_invalid_syntax.stderr @@ -11,7 +11,7 @@ error: must specify the desired selector using `#[method(...)]` or `#[method_id( | = note: this error originates in the macro `$crate::__extract_method_attributes_inner` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error: cannot specify the `method`/`method_id` attribute twice +error: cannot specify the `method` attribute twice --> ui/define_class_invalid_syntax.rs | | / define_class!( @@ -24,7 +24,7 @@ error: cannot specify the `method`/`method_id` attribute twice | = note: this error originates in the macro `$crate::__handle_duplicate` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error: cannot specify the `method`/`method_id` attribute twice +error: cannot specify the `method` attribute twice --> ui/define_class_invalid_syntax.rs | | / define_class!( @@ -241,7 +241,7 @@ error: must specify the desired selector using `#[method(...)]` or `#[method_id( | = note: this error originates in the macro `$crate::__extract_method_attributes_inner` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error: cannot specify the `method`/`method_id` attribute twice +error: cannot specify the `method` attribute twice --> ui/define_class_invalid_syntax.rs | | / define_class!( @@ -254,7 +254,7 @@ error: cannot specify the `method`/`method_id` attribute twice | = note: this error originates in the macro `$crate::__handle_duplicate` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error: cannot specify the `method`/`method_id` attribute twice +error: cannot specify the `method` attribute twice --> ui/define_class_invalid_syntax.rs | | / define_class!( diff --git a/crates/test-ui/ui/define_class_invalid_type.stderr b/crates/test-ui/ui/define_class_invalid_type.stderr index f422a457c..70a9934cf 100644 --- a/crates/test-ui/ui/define_class_invalid_type.stderr +++ b/crates/test-ui/ui/define_class_invalid_type.stderr @@ -20,16 +20,7 @@ error[E0277]: the trait bound `Retained: EncodeReturn` is not sati AtomicI8 and $N others = note: required for `Retained` to implement `EncodeReturn` - = note: required for `Retained` to implement `__macro_helpers::convert::return_private::Sealed` -note: required by a bound in `ConvertReturn` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/convert.rs - | - | pub trait ConvertReturn: return_private::Sealed { - | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ConvertReturn` - = note: `ConvertReturn` is a "sealed trait", because to implement it you also need to implement `objc2::__macro_helpers::convert::return_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: - bool - T + = note: required for `Retained` to implement `ConvertReturn<()>` = note: this error originates in the macro `$crate::__define_class_method_out_inner` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Vec<()>: EncodeReturn` is not satisfied @@ -58,11 +49,14 @@ error[E0277]: the trait bound `Vec<()>: EncodeReturn` is not satisfied note: required by a bound in `ConvertReturn` --> $WORKSPACE/crates/objc2/src/__macro_helpers/convert.rs | - | pub trait ConvertReturn: return_private::Sealed { - | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ConvertReturn` + | pub trait ConvertReturn: return_private::Sealed { + | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ConvertReturn` = note: `ConvertReturn` is a "sealed trait", because to implement it you also need to implement `objc2::__macro_helpers::convert::return_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: bool + objc2::rc::Retained + std::option::Option> + objc2::rc::Allocated T = note: this error originates in the macro `$crate::__define_class_method_out_inner` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -164,7 +158,7 @@ error[E0277]: the trait bound `Retained: EncodeReturn` is not sati AtomicI8 and $N others = note: required for `Retained` to implement `EncodeReturn` - = note: required for `Retained` to implement `ConvertReturn` + = note: required for `Retained` to implement `ConvertReturn<()>` = note: this error originates in the macro `$crate::__define_class_register_out` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Retained: Encode` is not satisfied @@ -225,7 +219,7 @@ error[E0277]: the trait bound `Vec<()>: EncodeReturn` is not satisfied AtomicI8 and $N others = note: required for `Vec<()>` to implement `EncodeReturn` - = note: required for `Vec<()>` to implement `ConvertReturn` + = note: required for `Vec<()>` to implement `ConvertReturn<()>` = note: this error originates in the macro `$crate::__define_class_register_out` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Vec<()>: Encode` is not satisfied @@ -408,7 +402,7 @@ error[E0277]: the trait bound `Retained: EncodeReturn` is not sati AtomicI8 and $N others = note: required for `Retained` to implement `EncodeReturn` - = note: required for `Retained` to implement `ConvertReturn` + = note: required for `Retained` to implement `ConvertReturn<()>` = note: this error originates in the macro `$crate::__define_class_method_out_inner` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Vec<()>: EncodeReturn` is not satisfied @@ -433,7 +427,7 @@ error[E0277]: the trait bound `Vec<()>: EncodeReturn` is not satisfied AtomicI8 and $N others = note: required for `Vec<()>` to implement `EncodeReturn` - = note: required for `Vec<()>` to implement `ConvertReturn` + = note: required for `Vec<()>` to implement `ConvertReturn<()>` = note: this error originates in the macro `$crate::__define_class_method_out_inner` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Box: EncodeArgument` is not satisfied diff --git a/crates/test-ui/ui/define_class_invalid_type2.stderr b/crates/test-ui/ui/define_class_invalid_type2.stderr index 6c8e3526e..061a2d38a 100644 --- a/crates/test-ui/ui/define_class_invalid_type2.stderr +++ b/crates/test-ui/ui/define_class_invalid_type2.stderr @@ -1,4 +1,4 @@ -error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Option>` +error[E0271]: type mismatch resolving ` as MaybeOptionRetained>::Inner == CustomObject` --> ui/define_class_invalid_type2.rs | | / define_class!( @@ -7,10 +7,8 @@ error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Inpu | | struct CustomObject; ... | | | ); - | |_^ expected `Option>`, found `Option>` + | |_^ expected `CustomObject`, found `NSObject` | - = note: expected enum `Option>` - found enum `Option>` = note: required for `MethodFamily<3>` to implement `MessageReceiveRetained, Retained>` = note: this error originates in the macro `$crate::__define_class_method_out_inner` which comes from the expansion of the macro `define_class` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/extern_methods_bad_selector.rs b/crates/test-ui/ui/extern_methods_bad_selector.rs index 52550cb49..9db977af1 100644 --- a/crates/test-ui/ui/extern_methods_bad_selector.rs +++ b/crates/test-ui/ui/extern_methods_bad_selector.rs @@ -15,8 +15,8 @@ extern_methods!( extern_methods!( unsafe impl MyObject { - #[method_id()] - fn no_selector_id_self(&self); + #[method()] + fn no_selector_self(&self); } ); diff --git a/crates/test-ui/ui/extern_methods_bad_selector.stderr b/crates/test-ui/ui/extern_methods_bad_selector.stderr index 9fcf4bed6..266b210eb 100644 --- a/crates/test-ui/ui/extern_methods_bad_selector.stderr +++ b/crates/test-ui/ui/extern_methods_bad_selector.stderr @@ -16,13 +16,13 @@ error: number of arguments in function and selector did not match | | / extern_methods!( | | unsafe impl MyObject { - | | #[method_id()] - | | fn no_selector_id_self(&self); + | | #[method()] + | | fn no_selector_self(&self); | | } | | ); | |_^ | - = note: this error originates in the macro `$crate::__method_msg_send_id` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::__method_msg_send` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) error: number of arguments in function and selector did not match --> ui/extern_methods_bad_selector.rs diff --git a/crates/test-ui/ui/extern_methods_deprecated.rs b/crates/test-ui/ui/extern_methods_deprecated.rs new file mode 100644 index 000000000..b217d549e --- /dev/null +++ b/crates/test-ui/ui/extern_methods_deprecated.rs @@ -0,0 +1,19 @@ +//! Test using deprecated `#[method_id(...)]`. +#![deny(warnings)] +use objc2::rc::Retained; +use objc2::runtime::NSObject; +use objc2::{extern_class, extern_methods}; + +extern_class!( + #[unsafe(super(NSObject))] + pub struct MyObject; +); + +extern_methods!( + unsafe impl MyObject { + #[method_id(myMethod:)] + fn my_method(param: i32) -> Retained; + } +); + +fn main() {} diff --git a/crates/test-ui/ui/extern_methods_deprecated.stderr b/crates/test-ui/ui/extern_methods_deprecated.stderr new file mode 100644 index 000000000..3432d3b86 --- /dev/null +++ b/crates/test-ui/ui/extern_methods_deprecated.stderr @@ -0,0 +1,19 @@ +error: use of deprecated function `MyObject::my_method::method_id`: using #[method_id(myMethod:)] inside extern_methods! is deprecated. + Use #[method(myMethod:)] instead + --> ui/extern_methods_deprecated.rs + | + | / extern_methods!( + | | unsafe impl MyObject { + | | #[method_id(myMethod:)] + | | fn my_method(param: i32) -> Retained; + | | } + | | ); + | |_^ + | +note: the lint level is defined here + --> ui/extern_methods_deprecated.rs + | + | #![deny(warnings)] + | ^^^^^^^^ + = note: `#[deny(deprecated)]` implied by `#[deny(warnings)]` + = note: this error originates in the macro `$crate::__extern_methods_method_id_deprecated` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/extern_methods_invalid_method_family.rs b/crates/test-ui/ui/extern_methods_invalid_method_family.rs index 3878cde2a..c96778331 100644 --- a/crates/test-ui/ui/extern_methods_invalid_method_family.rs +++ b/crates/test-ui/ui/extern_methods_invalid_method_family.rs @@ -10,7 +10,7 @@ extern_class!( extern_methods!( unsafe impl MyObject { - #[method_id(noUnsafe)] + #[method(noUnsafe)] #[method_family = none] fn no_unsafe(&self) -> Retained; } @@ -18,7 +18,7 @@ extern_methods!( extern_methods!( unsafe impl MyObject { - #[method_id(unknownFamily)] + #[method(unknownFamily)] #[unsafe(method_family = unknown)] fn unknown_family(&self) -> Retained; } @@ -26,9 +26,10 @@ extern_methods!( extern_methods!( unsafe impl MyObject { - #[method(notOnMethodId)] + #[method(familyTwice)] + #[unsafe(method_family = copy)] #[unsafe(method_family = none)] - fn not_on_method_id(&self); + fn family_twice(&self) -> Retained; } ); diff --git a/crates/test-ui/ui/extern_methods_invalid_method_family.stderr b/crates/test-ui/ui/extern_methods_invalid_method_family.stderr index a347241ff..fa463b5ad 100644 --- a/crates/test-ui/ui/extern_methods_invalid_method_family.stderr +++ b/crates/test-ui/ui/extern_methods_invalid_method_family.stderr @@ -1,15 +1,15 @@ -error: `#[method_family = ...]` is only supported together with `#[method_id(...)]` +error: cannot specify the `method_family` attribute twice --> ui/extern_methods_invalid_method_family.rs | | / extern_methods!( | | unsafe impl MyObject { - | | #[method(notOnMethodId)] - | | #[unsafe(method_family = none)] + | | #[method(familyTwice)] + | | #[unsafe(method_family = copy)] ... | | | ); | |_^ | - = note: this error originates in the macro `$crate::__extern_methods_no_method_family` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::__handle_duplicate` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) error: attribute value must be a literal --> ui/extern_methods_invalid_method_family.rs diff --git a/crates/test-ui/ui/extern_methods_invalid_receiver.rs b/crates/test-ui/ui/extern_methods_invalid_receiver.rs index d80a8966d..078aeb08c 100644 --- a/crates/test-ui/ui/extern_methods_invalid_receiver.rs +++ b/crates/test-ui/ui/extern_methods_invalid_receiver.rs @@ -9,14 +9,14 @@ extern_class!( extern_methods!( unsafe impl MyObject { - #[method_id(initWithMut)] + #[method(initWithMut)] fn init_with_mut(&mut self) -> Option>; } ); extern_methods!( unsafe impl MyObject { - #[method_id(initWithOptionAllocated)] + #[method(initWithOptionAllocated)] fn init_with_option_allocated(this: Option>) -> Option>; } ); diff --git a/crates/test-ui/ui/extern_methods_invalid_receiver.stderr b/crates/test-ui/ui/extern_methods_invalid_receiver.stderr index dc12999df..c9d72a065 100644 --- a/crates/test-ui/ui/extern_methods_invalid_receiver.stderr +++ b/crates/test-ui/ui/extern_methods_invalid_receiver.stderr @@ -1,50 +1,154 @@ -error[E0308]: mismatched types +error[E0277]: the trait bound `&mut MyObject: MessageReceiver` is not satisfied --> ui/extern_methods_invalid_receiver.rs | | / extern_methods!( | | unsafe impl MyObject { - | | #[method_id(initWithMut)] + | | #[method(initWithMut)] | | fn init_with_mut(&mut self) -> Option>; | | } | | ); - | | ^ - | | | - | |_expected `Allocated<_>`, found `&mut MyObject` - | arguments to this function are incorrect - | - = note: expected struct `Allocated<_>` - found mutable reference `&mut MyObject` -note: associated function defined here - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::__rewrite_self_param_inner` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) + | |_^ the trait `MessageReceiver` is not implemented for `&mut MyObject` + | + = help: the following other types implement trait `MessageReceiver`: + &T + &mut AnyObject + *const T + *mut T + NonNull + = note: `MessageReceiver` is implemented for `&MyObject`, but not for `&mut MyObject` + = note: required for `MethodFamily<3>` to implement `RetainSemantics<&mut MyObject, _, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend<&mut MyObject, _>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Retained: Encode` is not satisfied + --> ui/extern_methods_invalid_receiver.rs + | + | / extern_methods!( + | | unsafe impl MyObject { + | | #[method(initWithMut)] + | | fn init_with_mut(&mut self) -> Option>; + | | } + | | ); + | |_^ the trait `Encode` is not implemented for `Retained` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Option>` to implement `Encode` + = note: required for `Option>` to implement `EncodeReturn` + = note: required for `Option>` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics<&mut MyObject, Option>, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend<&mut MyObject, Option>>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Retained: OptionEncode` is not satisfied + --> ui/extern_methods_invalid_receiver.rs + | + | / extern_methods!( + | | unsafe impl MyObject { + | | #[method(initWithMut)] + | | fn init_with_mut(&mut self) -> Option>; + | | } + | | ); + | |_^ the trait `OptionEncode` is not implemented for `Retained` + | + = help: the following other types implement trait `OptionEncode`: + &T + &mut T + NonNull + NonZero + NonZero + NonZero + NonZero + NonZero + and $N others + = note: required for `Option>` to implement `Encode` + = note: required for `Option>` to implement `EncodeReturn` + = note: required for `Option>` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics<&mut MyObject, Option>, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend<&mut MyObject, Option>>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0308]: mismatched types +error[E0277]: the trait bound `Option>: MessageReceiver` is not satisfied --> ui/extern_methods_invalid_receiver.rs | | / extern_methods!( | | unsafe impl MyObject { - | | #[method_id(initWithOptionAllocated)] + | | #[method(initWithOptionAllocated)] | | fn init_with_option_allocated(this: Option>) -> Option>; | | } | | ); - | | ^ - | | | - | |_expected `Allocated<_>`, found `Option>` - | arguments to this function are incorrect - | - = note: expected struct `Allocated<_>` - found enum `Option>` -note: associated function defined here - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^ - = note: this error originates in the macro `$crate::__rewrite_self_param_inner` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) -help: use the `?` operator to extract the `Option>` value, propagating an `Option::None` value to the caller - --> $WORKSPACE/crates/objc2/src/macros/__rewrite_self_param.rs - | - | }? - | + + | |_^ the trait `MessageReceiver` is not implemented for `Option>` + | + = help: the following other types implement trait `MessageReceiver`: + &T + &mut AnyObject + *const T + *mut T + NonNull + = note: required for `MethodFamily<3>` to implement `RetainSemantics>, _, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend>, _>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Retained: Encode` is not satisfied + --> ui/extern_methods_invalid_receiver.rs + | + | / extern_methods!( + | | unsafe impl MyObject { + | | #[method(initWithOptionAllocated)] + | | fn init_with_option_allocated(this: Option>) -> Option>; + | | } + | | ); + | |_^ the trait `Encode` is not implemented for `Retained` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Option>` to implement `Encode` + = note: required for `Option>` to implement `EncodeReturn` + = note: required for `Option>` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics>, Option>, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend>, Option>>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Retained: OptionEncode` is not satisfied + --> ui/extern_methods_invalid_receiver.rs + | + | / extern_methods!( + | | unsafe impl MyObject { + | | #[method(initWithOptionAllocated)] + | | fn init_with_option_allocated(this: Option>) -> Option>; + | | } + | | ); + | |_^ the trait `OptionEncode` is not implemented for `Retained` + | + = help: the following other types implement trait `OptionEncode`: + &T + &mut T + NonNull + NonZero + NonZero + NonZero + NonZero + NonZero + and $N others + = note: required for `Option>` to implement `Encode` + = note: required for `Option>` to implement `EncodeReturn` + = note: required for `Option>` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics>, Option>, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend>, Option>>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/extern_methods_invalid_type.rs b/crates/test-ui/ui/extern_methods_invalid_type.rs index 43a8f99c5..0a9a4b4fd 100644 --- a/crates/test-ui/ui/extern_methods_invalid_type.rs +++ b/crates/test-ui/ui/extern_methods_invalid_type.rs @@ -10,36 +10,15 @@ extern_class!( extern_methods!( unsafe impl MyObject { - #[method(a)] - fn a(&self) -> Retained; + #[method(takesBox:)] + fn takes_box(&self, arg: Box); } ); extern_methods!( unsafe impl MyObject { - #[method_id(b)] - fn b(&self) -> i32; - } -); - -extern_methods!( - unsafe impl MyObject { - #[method(c:)] - fn c(&self, arg: Box); - } -); - -extern_methods!( - unsafe impl MyObject { - #[method(error:)] - fn error(arg: i32) -> Result<(), Retained>; - } -); - -extern_methods!( - unsafe impl MyObject { - #[method_id(error:)] - fn error_id(arg: i32) -> Result, Retained>; + #[method(returnsReferenceToRetained)] + fn returns_reference_to_retained(&self) -> &Retained; } ); diff --git a/crates/test-ui/ui/extern_methods_invalid_type.stderr b/crates/test-ui/ui/extern_methods_invalid_type.stderr index 3a8513219..73e43a0d6 100644 --- a/crates/test-ui/ui/extern_methods_invalid_type.stderr +++ b/crates/test-ui/ui/extern_methods_invalid_type.stderr @@ -1,68 +1,16 @@ -error[E0277]: the trait bound `Retained: ConvertReturn` is not satisfied - --> ui/extern_methods_invalid_type.rs - | - | / extern_methods!( - | | unsafe impl MyObject { - | | #[method(a)] - | | fn a(&self) -> Retained; - | | } - | | ); - | |_^ the trait `Encode` is not implemented for `Retained` - | - = help: the following other types implement trait `Encode`: - &'a T - &'a mut T - *const T - *mut T - AtomicI16 - AtomicI32 - AtomicI64 - AtomicI8 - and $N others - = note: required for `Retained` to implement `EncodeReturn` - = note: required for `Retained` to implement `ConvertReturn` -note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs - | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function -... - | R: ConvertReturn, - | ^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` - = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the trait bound `i32: MaybeUnwrap` is not satisfied - --> ui/extern_methods_invalid_type.rs - | - | / extern_methods!( - | | unsafe impl MyObject { - | | #[method_id(b)] - | | fn b(&self) -> i32; - | | } - | | ); - | |_^ the trait `MaybeUnwrap` is not implemented for `i32` - | - = help: the following other types implement trait `MaybeUnwrap`: - Allocated - Option> - Retained -note: required by a bound in `send_message_retained` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0277]: the trait bound `Box: Encode` is not satisfied --> ui/extern_methods_invalid_type.rs | | / extern_methods!( | | unsafe impl MyObject { - | | #[method(c:)] - | | fn c(&self, arg: Box); + | | #[method(takesBox:)] + | | fn takes_box(&self, arg: Box); | | } | | ); - | |_^ the trait `Encode` is not implemented for `Box` + | | ^ + | | | + | |_the trait `Encode` is not implemented for `Box` + | required by a bound introduced by this call | = help: the following other types implement trait `Encode`: &'a T @@ -78,71 +26,41 @@ error[E0277]: the trait bound `Box: Encode` is not satisfied = note: required for `Box` to implement `ConvertArgument` = note: required for `(Box,)` to implement `ConvertArguments` note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function - | where - | A: ConvertArguments, - | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + | unsafe fn send_message(receiver: Receiver, sel: Sel, args: A) -> Return; + | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `Result<(), Retained>: ConvertReturn` is not satisfied +error[E0277]: the trait bound `Retained: RefEncode` is not satisfied --> ui/extern_methods_invalid_type.rs | | / extern_methods!( | | unsafe impl MyObject { - | | #[method(error:)] - | | fn error(arg: i32) -> Result<(), Retained>; + | | #[method(returnsReferenceToRetained)] + | | fn returns_reference_to_retained(&self) -> &Retained; | | } | | ); - | |_^ the trait `Encode` is not implemented for `Result<(), Retained>` + | |_^ the trait `RefEncode` is not implemented for `Retained` | - = help: the following other types implement trait `Encode`: + = help: the following other types implement trait `RefEncode`: &'a T &'a mut T *const T *mut T + AnyClass + AnyObject + AnyProtocol AtomicI16 - AtomicI32 - AtomicI64 - AtomicI8 and $N others - = note: required for `Result<(), Retained>` to implement `EncodeReturn` - = note: required for `Result<(), Retained>` to implement `ConvertReturn` -note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs - | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function -... - | R: ConvertReturn, - | ^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + = note: required for `&Retained` to implement `Encode` + = note: required for `&Retained` to implement `EncodeReturn` + = note: required for `&Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<6>` to implement `RetainSemantics<&MyObject, &Retained, KindSendMessage>` + = note: required for `MethodFamily<6>` to implement `MsgSend<&MyObject, &Retained>` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `Result, Retained>: MaybeUnwrap` is not satisfied - --> ui/extern_methods_invalid_type.rs - | - | / extern_methods!( - | | unsafe impl MyObject { - | | #[method_id(error:)] - | | fn error_id(arg: i32) -> Result, Retained>; - | | } - | | ); - | |_^ the trait `MaybeUnwrap` is not implemented for `Result, Retained>` - | - = help: the following other types implement trait `MaybeUnwrap`: - Allocated - Option> - Retained -note: required by a bound in `send_message_retained` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the trait bound `MainThreadMarker: ConvertReturn` is not satisfied +error[E0277]: the trait bound `MainThreadMarker: Encode` is not satisfied --> ui/extern_methods_invalid_type.rs | | / extern_methods!( @@ -164,13 +82,7 @@ error[E0277]: the trait bound `MainThreadMarker: ConvertReturn` is not satisfied AtomicI8 and $N others = note: required for `MainThreadMarker` to implement `EncodeReturn` - = note: required for `MainThreadMarker` to implement `ConvertReturn` -note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs - | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function -... - | R: ConvertReturn, - | ^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + = note: required for `MainThreadMarker` to implement `ConvertReturn>` + = note: required for `MethodFamily<6>` to implement `RetainSemantics<&AnyClass, MainThreadMarker, KindSendMessage>` + = note: required for `MethodFamily<6>` to implement `MsgSend<&AnyClass, MainThreadMarker>` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/extern_methods_not_allowed_mutable.rs b/crates/test-ui/ui/extern_methods_not_allowed_mutable.rs index a4e23bde1..4d3957e3d 100644 --- a/crates/test-ui/ui/extern_methods_not_allowed_mutable.rs +++ b/crates/test-ui/ui/extern_methods_not_allowed_mutable.rs @@ -17,8 +17,8 @@ extern_methods!( extern_methods!( unsafe impl MyObject { - #[method_id(testId)] - fn test_id(&mut self) -> Retained; + #[method(testRetained)] + fn test_retained(&mut self) -> Retained; } ); diff --git a/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr b/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr index 68aa81e03..891beb99b 100644 --- a/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr +++ b/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `&mut MyObject: MsgSend` is not satisfied +error[E0277]: the trait bound `&mut MyObject: MessageReceiver` is not satisfied --> ui/extern_methods_not_allowed_mutable.rs | | / extern_methods!( @@ -7,10 +7,7 @@ error[E0277]: the trait bound `&mut MyObject: MsgSend` is not satisfied | | fn test(&mut self); | | } | | ); - | | ^ - | | | - | |_the trait `MessageReceiver` is not implemented for `&mut MyObject` - | required by a bound introduced by this call + | |_^ the trait `MessageReceiver` is not implemented for `&mut MyObject` | = help: the following other types implement trait `MessageReceiver`: &T @@ -19,16 +16,17 @@ error[E0277]: the trait bound `&mut MyObject: MsgSend` is not satisfied *mut T NonNull = note: `MessageReceiver` is implemented for `&MyObject`, but not for `&mut MyObject` - = note: required for `&mut MyObject` to implement `MsgSend` - = note: this error originates in the macro `$crate::__rewrite_self_param_inner` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: required for `MethodFamily<6>` to implement `RetainSemantics<&mut MyObject, _, KindSendMessage>` + = note: required for `MethodFamily<6>` to implement `MsgSend<&mut MyObject, _>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `&mut MyObject: MessageReceiver` is not satisfied --> ui/extern_methods_not_allowed_mutable.rs | | / extern_methods!( | | unsafe impl MyObject { - | | #[method_id(testId)] - | | fn test_id(&mut self) -> Retained; + | | #[method(testRetained)] + | | fn test_retained(&mut self) -> Retained; | | } | | ); | |_^ the trait `MessageReceiver` is not implemented for `&mut MyObject` @@ -40,6 +38,6 @@ error[E0277]: the trait bound `&mut MyObject: MessageReceiver` is not satisfied *mut T NonNull = note: `MessageReceiver` is implemented for `&MyObject`, but not for `&mut MyObject` - = note: required for `&mut MyObject` to implement `MsgSend` - = note: required for `MethodFamily<6>` to implement `MsgSendRetained<&mut MyObject, Option>>` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: required for `MethodFamily<6>` to implement `RetainSemantics<&mut MyObject, _, KindSendMessage>` + = note: required for `MethodFamily<6>` to implement `MsgSend<&mut MyObject, _>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/extern_methods_selector_twice.rs b/crates/test-ui/ui/extern_methods_selector_twice.rs index c4ca62943..898cd89f5 100644 --- a/crates/test-ui/ui/extern_methods_selector_twice.rs +++ b/crates/test-ui/ui/extern_methods_selector_twice.rs @@ -1,4 +1,3 @@ -use objc2::rc::Retained; use objc2::runtime::NSObject; use objc2::{extern_class, extern_methods}; @@ -9,33 +8,9 @@ extern_class!( extern_methods!( unsafe impl MyObject { - #[method(a)] - #[method(a)] - fn a(); - } -); - -extern_methods!( - unsafe impl MyObject { - #[method_id(b)] - #[method_id(b)] - fn b() -> Retained; - } -); - -extern_methods!( - unsafe impl MyObject { - #[method(c)] - #[method_id(c)] - fn c() -> Retained; - } -); - -extern_methods!( - unsafe impl MyObject { - #[method_id(d)] - #[method(d)] - fn d(); + #[method(foo)] + #[method(bar)] + fn selector_twice(); } ); diff --git a/crates/test-ui/ui/extern_methods_selector_twice.stderr b/crates/test-ui/ui/extern_methods_selector_twice.stderr index bb01d0b07..f754c5b62 100644 --- a/crates/test-ui/ui/extern_methods_selector_twice.stderr +++ b/crates/test-ui/ui/extern_methods_selector_twice.stderr @@ -1,49 +1,10 @@ -error: cannot specify the `method`/`method_id` attribute twice +error: cannot specify the `method` attribute twice --> ui/extern_methods_selector_twice.rs | | / extern_methods!( | | unsafe impl MyObject { - | | #[method(a)] - | | #[method(a)] -... | - | | ); - | |_^ - | - = note: this error originates in the macro `$crate::__handle_duplicate` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: cannot specify the `method`/`method_id` attribute twice - --> ui/extern_methods_selector_twice.rs - | - | / extern_methods!( - | | unsafe impl MyObject { - | | #[method_id(b)] - | | #[method_id(b)] -... | - | | ); - | |_^ - | - = note: this error originates in the macro `$crate::__handle_duplicate` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: cannot specify the `method`/`method_id` attribute twice - --> ui/extern_methods_selector_twice.rs - | - | / extern_methods!( - | | unsafe impl MyObject { - | | #[method(c)] - | | #[method_id(c)] -... | - | | ); - | |_^ - | - = note: this error originates in the macro `$crate::__handle_duplicate` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: cannot specify the `method`/`method_id` attribute twice - --> ui/extern_methods_selector_twice.rs - | - | / extern_methods!( - | | unsafe impl MyObject { - | | #[method_id(d)] - | | #[method(d)] + | | #[method(foo)] + | | #[method(bar)] ... | | | ); | |_^ diff --git a/crates/test-ui/ui/extern_methods_variadic.rs b/crates/test-ui/ui/extern_methods_variadic.rs index e31ae4cb5..0cdbd560f 100644 --- a/crates/test-ui/ui/extern_methods_variadic.rs +++ b/crates/test-ui/ui/extern_methods_variadic.rs @@ -21,13 +21,6 @@ extern_methods!( } ); -extern_methods!( - unsafe impl MyObject { - #[method_id(a:)] - fn variadic_id(arg: i32, arg2: ...) -> Retained; - } -); - extern_methods!( unsafe impl MyObject { #[method(a:_)] diff --git a/crates/test-ui/ui/extern_methods_variadic.stderr b/crates/test-ui/ui/extern_methods_variadic.stderr index 88056ae65..f656f7735 100644 --- a/crates/test-ui/ui/extern_methods_variadic.stderr +++ b/crates/test-ui/ui/extern_methods_variadic.stderr @@ -24,19 +24,6 @@ error: variadic methods are not yet supported | = note: this error originates in the macro `$crate::__method_msg_send` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) -error: variadic methods are not yet supported - --> ui/extern_methods_variadic.rs - | - | / extern_methods!( - | | unsafe impl MyObject { - | | #[method_id(a:)] - | | fn variadic_id(arg: i32, arg2: ...) -> Retained; - | | } - | | ); - | |_^ - | - = note: this error originates in the macro `$crate::__method_msg_send_id` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) - error: variadic methods are not yet supported --> ui/extern_methods_variadic.rs | @@ -62,12 +49,6 @@ error: only foreign, `unsafe extern "C"`, or `unsafe extern "C-unwind"` function | fn variadic_instance(&self, arg: i32, ...); | ^^^ -error: only foreign, `unsafe extern "C"`, or `unsafe extern "C-unwind"` functions may have a C-variadic arg - --> ui/extern_methods_variadic.rs - | - | fn variadic_id(arg: i32, arg2: ...) -> Retained; - | ^^^^^^^^^ - error: only foreign, `unsafe extern "C"`, or `unsafe extern "C-unwind"` functions may have a C-variadic arg --> ui/extern_methods_variadic.rs | @@ -104,21 +85,6 @@ error[E0658]: C-variadic functions are unstable = help: add `#![feature(c_variadic)]` to the crate attributes to enable = note: this error originates in the macro `$crate::__extern_methods_rewrite_methods` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0658]: C-variadic functions are unstable - --> ui/extern_methods_variadic.rs - | - | / extern_methods!( - | | unsafe impl MyObject { - | | #[method_id(a:)] - | | fn variadic_id(arg: i32, arg2: ...) -> Retained; - | | } - | | ); - | |_^ - | - = note: see issue #44930 for more information - = help: add `#![feature(c_variadic)]` to the crate attributes to enable - = note: this error originates in the macro `$crate::__extern_methods_rewrite_methods` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) - error[E0658]: C-variadic functions are unstable --> ui/extern_methods_variadic.rs | diff --git a/crates/test-ui/ui/invalid_msg_send.stderr b/crates/test-ui/ui/invalid_msg_send.stderr index dbc0bbd1b..5edf09eb6 100644 --- a/crates/test-ui/ui/invalid_msg_send.stderr +++ b/crates/test-ui/ui/invalid_msg_send.stderr @@ -7,7 +7,7 @@ error: unexpected end of macro invocation note: while trying to match `,` --> $WORKSPACE/crates/objc2/src/macros/mod.rs | - | [$obj:expr, $($selector_and_arguments:tt)+] => { + | [$obj:expr, new $(,)?] => ({ | ^ error: unexpected end of macro invocation @@ -16,11 +16,11 @@ error: unexpected end of macro invocation | let _: () = unsafe { msg_send![obj,] }; | ^ missing tokens in macro arguments | -note: while trying to match meta-variable `$selector_and_arguments:tt` +note: while trying to match `new` --> $WORKSPACE/crates/objc2/src/macros/mod.rs | - | [$obj:expr, $($selector_and_arguments:tt)+] => { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | [$obj:expr, new $(,)?] => ({ + | ^^^ error: no rules expected `)` --> ui/invalid_msg_send.rs diff --git a/crates/test-ui/ui/msg_send_alloc_init_different.rs b/crates/test-ui/ui/msg_send_alloc_init_different.rs index 68bc0c53a..b083644e7 100644 --- a/crates/test-ui/ui/msg_send_alloc_init_different.rs +++ b/crates/test-ui/ui/msg_send_alloc_init_different.rs @@ -1,11 +1,11 @@ //! Ensure that `init` returns the same type as given from `alloc`. use objc2::rc::{Allocated, Retained}; use objc2::runtime::{AnyObject, NSObject}; -use objc2::{class, msg_send_id}; +use objc2::{class, msg_send}; fn main() { let cls = class!(NSObject); - let obj: Allocated = unsafe { msg_send_id![cls, alloc] }; + let obj: Allocated = unsafe { msg_send![cls, alloc] }; - let _: Retained = unsafe { msg_send_id![obj, init] }; + let _: Retained = unsafe { msg_send![obj, init] }; } diff --git a/crates/test-ui/ui/msg_send_alloc_init_different.stderr b/crates/test-ui/ui/msg_send_alloc_init_different.stderr index 64fef5d8f..2cf637f2e 100644 --- a/crates/test-ui/ui/msg_send_alloc_init_different.stderr +++ b/crates/test-ui/ui/msg_send_alloc_init_different.stderr @@ -1,14 +1,37 @@ -error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Option>` +error[E0277]: the trait bound `Allocated: MessageReceiver` is not satisfied --> ui/msg_send_alloc_init_different.rs | - | let _: Retained = unsafe { msg_send_id![obj, init] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `Option>`, found `Option>` + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `Allocated` | - = note: expected enum `Option>` - found enum `Option>` -note: required by a bound in `send_message_retained` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs + = help: the following other types implement trait `MessageReceiver`: + &T + &mut AnyObject + *const T + *mut T + NonNull + = note: required for `MethodFamily<3>` to implement `RetainSemantics, Retained, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Retained: Encode` is not satisfied + --> ui/msg_send_alloc_init_different.rs + | + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` | - | unsafe fn send_message_retained>( - | ^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained` - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics, Retained, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_invalid_error.rs b/crates/test-ui/ui/msg_send_invalid_error.rs index d18069d2b..e6c59dd53 100644 --- a/crates/test-ui/ui/msg_send_invalid_error.rs +++ b/crates/test-ui/ui/msg_send_invalid_error.rs @@ -1,7 +1,7 @@ //! Test that message sending with error handling works correctly. use objc2::rc::{Allocated, Retained}; use objc2::runtime::{AnyObject, NSObject}; -use objc2::{msg_send, msg_send_id, AllocAnyThread, ClassType}; +use objc2::{msg_send, AllocAnyThread, ClassType}; use objc2_foundation::NSString; fn main() { @@ -18,14 +18,11 @@ fn main() { let _: () = unsafe { msg_send![super(obj), g: _] }; let _: () = unsafe { msg_send![super(obj, NSString::class()), h: _] }; - // Basic bad return type for msg_send_id! - let _: () = unsafe { msg_send_id![obj, a: _] }; - // Bad return type from init let _: Result, Retained> = - unsafe { msg_send_id![NSObject::alloc(), initWithError: _] }; + unsafe { msg_send![NSObject::alloc(), initWithError: _] }; // Erroring `alloc` is not supported automatically. let _: Result, Retained> = - unsafe { msg_send_id![NSObject::class(), allocWithError: _] }; + unsafe { msg_send![NSObject::class(), allocWithError: _] }; } diff --git a/crates/test-ui/ui/msg_send_invalid_error.stderr b/crates/test-ui/ui/msg_send_invalid_error.stderr index 6820cab7f..a7625205b 100644 --- a/crates/test-ui/ui/msg_send_invalid_error.stderr +++ b/crates/test-ui/ui/msg_send_invalid_error.stderr @@ -2,36 +2,39 @@ error[E0308]: mismatched types --> ui/msg_send_invalid_error.rs | | let _: () = unsafe { msg_send![obj, a: _] }; - | ^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Result<(), Retained<_>>` + | ^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Result<_, Retained<_>>` | = note: expected unit type `()` - found enum `Result<(), Retained<_>>` + found enum `Result<_, Retained<_>>` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider using `Result::expect` to unwrap the `Result<(), Retained<_>>` value, panicking if the value is a `Result::Err` +help: consider using `Result::expect` to unwrap the `Result<_, Retained<_>>` value, panicking if the value is a `Result::Err` --> $WORKSPACE/crates/objc2/src/macros/mod.rs | | ($crate::__msg_send_helper.expect("REASON")) | +++++++++++++++++ -error[E0308]: mismatched types +error[E0277]: the trait bound `MethodFamily<6>: MsgSendError<&NSString, i32>` is not satisfied --> ui/msg_send_invalid_error.rs | | let _: Result = unsafe { msg_send![obj, b: _] }; - | ^^^^^^^^^^^^^^^^^^^^ expected `Result`, found `Result<(), Retained<_>>` + | ^^^^^^^^^^^^^^^^^^^^ the trait `MsgSendError<&NSString, i32>` is not implemented for `MethodFamily<6>` | - = note: expected enum `Result` - found enum `Result<(), Retained<_>>` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> ui/msg_send_invalid_error.rs | | let _: Result<(), i32> = unsafe { msg_send![obj, c: _] }; - | ^^^^^^^^^^^^^^^^^^^^ expected `Result<(), i32>`, found `Result<(), Retained<_>>` + | ^^^^^^^^^^^^^^^^^^^^ expected `Result<(), i32>`, found `Result<_, Retained<_>>` | = note: expected enum `Result<(), i32>` - found enum `Result<(), Retained<_>>` + found enum `Result<_, Retained<_>>` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider using `Result::expect` to unwrap the `Result<_, Retained<_>>` value, panicking if the value is a `Result::Err` + --> $WORKSPACE/crates/objc2/src/macros/mod.rs + | + | ($crate::__msg_send_helper.expect("REASON")) + | +++++++++++++++++ error[E0277]: the trait bound `i32: ClassType` is not satisfied --> ui/msg_send_invalid_error.rs @@ -50,25 +53,25 @@ error[E0277]: the trait bound `i32: ClassType` is not satisfied NSMutableDictionary and $N others note: required by a bound in `send_message_error` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_message_error(self, sel: Sel, args: A) -> Result<(), Retained> + | unsafe fn send_message_error( | ------------------ required by a bound in this associated function ... - | E: ClassType, - | ^^^^^^^^^ required by this bound in `MsgSend::send_message_error` + | E: ClassType; + | ^^^^^^^^^ required by this bound in `MsgSendError::send_message_error` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> ui/msg_send_invalid_error.rs | | let _: () = unsafe { msg_send![obj, e: obj, f: _] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Result<(), Retained<_>>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Result<_, Retained<_>>` | = note: expected unit type `()` - found enum `Result<(), Retained<_>>` + found enum `Result<_, Retained<_>>` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider using `Result::expect` to unwrap the `Result<(), Retained<_>>` value, panicking if the value is a `Result::Err` +help: consider using `Result::expect` to unwrap the `Result<_, Retained<_>>` value, panicking if the value is a `Result::Err` --> $WORKSPACE/crates/objc2/src/macros/mod.rs | | ($crate::__msg_send_helper.expect("REASON")) @@ -78,12 +81,12 @@ error[E0308]: mismatched types --> ui/msg_send_invalid_error.rs | | let _: () = unsafe { msg_send![super(obj), g: _] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Result<(), Retained<_>>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Result<_, Retained<_>>` | = note: expected unit type `()` - found enum `Result<(), Retained<_>>` + found enum `Result<_, Retained<_>>` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider using `Result::expect` to unwrap the `Result<(), Retained<_>>` value, panicking if the value is a `Result::Err` +help: consider using `Result::expect` to unwrap the `Result<_, Retained<_>>` value, panicking if the value is a `Result::Err` --> $WORKSPACE/crates/objc2/src/macros/mod.rs | | ($crate::__msg_send_helper.expect("REASON")) @@ -93,12 +96,12 @@ error[E0308]: mismatched types --> ui/msg_send_invalid_error.rs | | let _: () = unsafe { msg_send![super(obj, NSString::class()), h: _] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Result<(), Retained<_>>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Result<_, Retained<_>>` | = note: expected unit type `()` - found enum `Result<(), Retained<_>>` + found enum `Result<_, Retained<_>>` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider using `Result::expect` to unwrap the `Result<(), Retained<_>>` value, panicking if the value is a `Result::Err` +help: consider using `Result::expect` to unwrap the `Result<_, Retained<_>>` value, panicking if the value is a `Result::Err` --> $WORKSPACE/crates/objc2/src/macros/mod.rs | | ($crate::__msg_send_helper.expect("REASON")) @@ -107,47 +110,19 @@ help: consider using `Result::expect` to unwrap the `Result<(), Retained<_>>` va error[E0308]: mismatched types --> ui/msg_send_invalid_error.rs | - | let _: () = unsafe { msg_send_id![obj, a: _] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Result, Retained<_>>` - | - = note: expected unit type `()` - found enum `Result, Retained<_>>` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> ui/msg_send_invalid_error.rs - | - | unsafe { msg_send_id![NSObject::alloc(), initWithError: _] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result, ...>`, found `Result, ...>` + | unsafe { msg_send![NSObject::alloc(), initWithError: _] }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result, ...>`, found `Result, ...>` | = note: expected enum `Result, Retained>` found enum `Result, Retained<_>>` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0271]: type mismatch resolving `> as MaybeUnwrap>::Input == Allocated<_>` - --> ui/msg_send_invalid_error.rs - | - | unsafe { msg_send_id![NSObject::class(), allocWithError: _] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Allocated<_>`, found `Option>` - | - = note: expected struct `Allocated<_>` - found enum `Option>` -note: required by a bound in `send_message_retained_error` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained_error( - | --------------------------- required by a bound in this associated function -... - | Option: MaybeUnwrap, - | ^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained_error` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> ui/msg_send_invalid_error.rs | - | unsafe { msg_send_id![NSObject::class(), allocWithError: _] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result, ...>`, found `Result, Retained<_>>` + | unsafe { msg_send![NSObject::class(), allocWithError: _] }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result, ...>`, found `Result<(), Retained<_>>` | = note: expected enum `Result, Retained>` - found enum `Result, Retained<_>>` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + found enum `Result<(), Retained<_>>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_invalid_error3.rs b/crates/test-ui/ui/msg_send_invalid_error3.rs index 11a0ff3d6..d333dae64 100644 --- a/crates/test-ui/ui/msg_send_invalid_error3.rs +++ b/crates/test-ui/ui/msg_send_invalid_error3.rs @@ -1,5 +1,5 @@ -//! Test that `msg_send_id!` with a non-NSError type fails. -use objc2::msg_send_id; +//! Test that `msg_send!` with a non-NSError type fails. +use objc2::msg_send; use objc2::rc::Retained; use objc2::runtime::NSObject; use objc2_foundation::NSString; @@ -7,5 +7,5 @@ use objc2_foundation::NSString; fn main() { let obj = NSObject::new(); let _: Result, Retained> = - unsafe { msg_send_id![&obj, doMoreStuffWithError: _] }; + unsafe { msg_send![&obj, doMoreStuffWithError: _] }; } diff --git a/crates/test-ui/ui/msg_send_invalid_method.rs b/crates/test-ui/ui/msg_send_invalid_method.rs deleted file mode 100644 index af9a26042..000000000 --- a/crates/test-ui/ui/msg_send_invalid_method.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Test invalid msg_send_id methods. -//! -//! The `__msg_send_id_helper!` macro is unfortunately leaked, but I think -//! this is better than having it show up as part of the `msg_send_id!` macro -//! itself! -use objc2::msg_send_id; -use objc2::runtime::NSObject; - -fn main() { - let object: &NSObject; - unsafe { msg_send_id![object, retain] }; - unsafe { msg_send_id![object, release] }; - unsafe { msg_send_id![object, autorelease] }; - unsafe { msg_send_id![object, dealloc] }; -} diff --git a/crates/test-ui/ui/msg_send_invalid_method.stderr b/crates/test-ui/ui/msg_send_invalid_method.stderr deleted file mode 100644 index 4982d16cf..000000000 --- a/crates/test-ui/ui/msg_send_invalid_method.stderr +++ /dev/null @@ -1,31 +0,0 @@ -error: msg_send_id![obj, retain] is not supported. Use `Retained::retain` instead - --> ui/msg_send_invalid_method.rs - | - | unsafe { msg_send_id![object, retain] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: msg_send_id![obj, release] is not supported. Drop an `Retained` instead - --> ui/msg_send_invalid_method.rs - | - | unsafe { msg_send_id![object, release] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: msg_send_id![obj, autorelease] is not supported. Use `Retained::autorelease` - --> ui/msg_send_invalid_method.rs - | - | unsafe { msg_send_id![object, autorelease] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: msg_send_id![obj, dealloc] is not supported. Drop an `Retained` instead - --> ui/msg_send_invalid_method.rs - | - | unsafe { msg_send_id![object, dealloc] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_invalid_receiver.rs b/crates/test-ui/ui/msg_send_invalid_receiver.rs index 1c0702fa0..dd7bdf3ab 100644 --- a/crates/test-ui/ui/msg_send_invalid_receiver.rs +++ b/crates/test-ui/ui/msg_send_invalid_receiver.rs @@ -1,22 +1,22 @@ -//! Test compiler output with invalid msg_send_id receivers. -use objc2::msg_send_id; +//! Test compiler output with invalid msg_send! receivers. +use objc2::msg_send; use objc2::rc::{Allocated, Retained}; use objc2::runtime::{AnyClass, NSObject}; fn main() { let obj: &NSObject; - let _: Allocated = unsafe { msg_send_id![obj, alloc] }; - let _: Retained = unsafe { msg_send_id![obj, init] }; + let _: Allocated = unsafe { msg_send![obj, alloc] }; + let _: Retained = unsafe { msg_send![obj, init] }; let cls: &AnyClass; - let _: Retained = unsafe { msg_send_id![cls, init] }; + let _: Retained = unsafe { msg_send![cls, init] }; let obj: Retained; - let _: Retained = unsafe { msg_send_id![obj, init] }; + let _: Retained = unsafe { msg_send![obj, init] }; let obj: Option>; - let _: Retained = unsafe { msg_send_id![obj, init] }; + let _: Retained = unsafe { msg_send![obj, init] }; let obj: Retained; - let _: Retained = unsafe { msg_send_id![obj, new] }; + let _: Retained = unsafe { msg_send![obj, new] }; let obj: Retained; - let _: Retained = unsafe { msg_send_id![obj, copy] }; + let _: Retained = unsafe { msg_send![obj, copy] }; } diff --git a/crates/test-ui/ui/msg_send_invalid_receiver.stderr b/crates/test-ui/ui/msg_send_invalid_receiver.stderr index 4e311a2af..d25e080cf 100644 --- a/crates/test-ui/ui/msg_send_invalid_receiver.stderr +++ b/crates/test-ui/ui/msg_send_invalid_receiver.stderr @@ -1,93 +1,150 @@ -error[E0308]: mismatched types +error[E0277]: the trait bound `Allocated: Encode` is not satisfied --> ui/msg_send_invalid_receiver.rs | - | let _: Allocated = unsafe { msg_send_id![obj, alloc] }; - | -------------^^^-------- - | | | - | | expected `&AnyClass`, found `&NSObject` - | arguments to this function are incorrect + | let _: Allocated = unsafe { msg_send![obj, alloc] }; + | ^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Allocated` | - = note: expected reference `&AnyClass` - found reference `&NSObject` -note: associated function defined here - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | pub unsafe fn send_message_retained_alloc>>( - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Allocated` to implement `EncodeReturn` + = note: required for `Allocated` to implement `ConvertReturn>` + = note: required for `MethodFamily<7>` to implement `RetainSemantics<&NSObject, Allocated, KindSendMessage>` + = note: required for `MethodFamily<7>` to implement `MsgSend<&NSObject, Allocated>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0308]: mismatched types +error[E0277]: the trait bound `Retained: Encode` is not satisfied --> ui/msg_send_invalid_receiver.rs | - | let _: Retained = unsafe { msg_send_id![obj, init] }; - | -------------^^^------- - | | | - | | expected `Allocated<_>`, found `&NSObject` - | arguments to this function are incorrect - | - = note: expected struct `Allocated<_>` - found reference `&NSObject` -note: associated function defined here - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^ + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics<&NSObject, Retained, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend<&NSObject, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0308]: mismatched types +error[E0277]: the trait bound `Retained: Encode` is not satisfied --> ui/msg_send_invalid_receiver.rs | - | let _: Retained = unsafe { msg_send_id![cls, init] }; - | -------------^^^------- - | | | - | | expected `Allocated<_>`, found `&AnyClass` - | arguments to this function are incorrect + | let _: Retained = unsafe { msg_send![cls, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` | - = note: expected struct `Allocated<_>` - found reference `&AnyClass` -note: associated function defined here - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^ + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics<&AnyClass, Retained, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend<&AnyClass, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0308]: mismatched types +error[E0277]: the trait bound `Retained: MessageReceiver` is not satisfied --> ui/msg_send_invalid_receiver.rs | - | let _: Retained = unsafe { msg_send_id![obj, init] }; - | -------------^^^------- - | | | - | | expected `Allocated<_>`, found `Retained` - | arguments to this function are incorrect + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `Retained` + | + = help: the following other types implement trait `MessageReceiver`: + &T + &mut AnyObject + *const T + *mut T + NonNull + = note: required for `MethodFamily<3>` to implement `RetainSemantics, _, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend, _>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Retained: ConvertReturn>` is not satisfied + --> ui/msg_send_invalid_receiver.rs | - = note: expected struct `Allocated<_>` - found struct `Retained` -note: associated function defined here - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^ + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics, Retained, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0308]: mismatched types +error[E0277]: the trait bound `Option>: MessageReceiver` is not satisfied --> ui/msg_send_invalid_receiver.rs | - | let _: Retained = unsafe { msg_send_id![obj, init] }; - | -------------^^^------- - | | | - | | expected `Allocated<_>`, found `Option>` - | arguments to this function are incorrect + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `Option>` + | + = help: the following other types implement trait `MessageReceiver`: + &T + &mut AnyObject + *const T + *mut T + NonNull + = note: required for `MethodFamily<3>` to implement `RetainSemantics>, _, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend>, _>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Retained: ConvertReturn>` is not satisfied + --> ui/msg_send_invalid_receiver.rs | - = note: expected struct `Allocated<_>` - found enum `Option>` -note: associated function defined here - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^ + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics>, Retained, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend>, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Retained: MessageReceiver` is not satisfied --> ui/msg_send_invalid_receiver.rs | - | let _: Retained = unsafe { msg_send_id![obj, new] }; - | ^^^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `Retained` + | let _: Retained = unsafe { msg_send![obj, new] }; + | ^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `Retained` | = help: the following other types implement trait `MessageReceiver`: &T @@ -95,15 +152,15 @@ error[E0277]: the trait bound `Retained: MessageReceiver` is not satis *const T *mut T NonNull - = note: required for `Retained` to implement `MsgSend` - = note: required for `MethodFamily<1>` to implement `MsgSendRetained, Option>>` - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: required for `MethodFamily<1>` to implement `RetainSemantics, _, KindSendMessage>` + = note: required for `MethodFamily<1>` to implement `MsgSend, _>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Retained: MessageReceiver` is not satisfied --> ui/msg_send_invalid_receiver.rs | - | let _: Retained = unsafe { msg_send_id![obj, copy] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `Retained` + | let _: Retained = unsafe { msg_send![obj, copy] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `Retained` | = help: the following other types implement trait `MessageReceiver`: &T @@ -111,6 +168,6 @@ error[E0277]: the trait bound `Retained: MessageReceiver` is not satis *const T *mut T NonNull - = note: required for `Retained` to implement `MsgSend` - = note: required for `MethodFamily<4>` to implement `MsgSendRetained, Option>>` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: required for `MethodFamily<4>` to implement `RetainSemantics, _, KindSendMessage>` + = note: required for `MethodFamily<4>` to implement `MsgSend, _>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_invalid_return.rs b/crates/test-ui/ui/msg_send_invalid_return.rs index 6f5bdeb37..83455ef16 100644 --- a/crates/test-ui/ui/msg_send_invalid_return.rs +++ b/crates/test-ui/ui/msg_send_invalid_return.rs @@ -1,30 +1,22 @@ -//! Test compiler output with invalid msg_send_id return values. -use objc2::msg_send_id; +//! Test compiler output with invalid msg_send! return values. +use objc2::msg_send; use objc2::rc::{Allocated, Retained}; use objc2::runtime::{AnyClass, AnyObject, NSObject}; fn main() { let cls: &AnyClass; - let _: &AnyObject = unsafe { msg_send_id![cls, new] }; - let _: &AnyObject = unsafe { msg_send_id![cls, alloc] }; - let _: Allocated = unsafe { msg_send_id![cls, alloc] }; - let _: Retained = unsafe { msg_send_id![cls, alloc] }; + let _: Allocated = unsafe { msg_send![cls, alloc] }; + let _: Retained = unsafe { msg_send![cls, alloc] }; // Earlier design worked like this - let _: Option> = unsafe { msg_send_id![cls, alloc] }; + let _: Option> = unsafe { msg_send![cls, alloc] }; // And even earlier design like this - let _: Retained> = unsafe { msg_send_id![cls, alloc] }; + let _: Retained> = unsafe { msg_send![cls, alloc] }; let obj: Allocated; - let _: &AnyObject = unsafe { msg_send_id![obj, init] }; + let _: &AnyObject = unsafe { msg_send![obj, init] }; let obj: Allocated; - let _: Retained = unsafe { msg_send_id![obj, init] }; + let _: Retained = unsafe { msg_send![obj, init] }; let obj: Allocated; - let _: Retained = unsafe { msg_send_id![obj, init] }; - - let obj: &AnyObject; - let _: &AnyObject = unsafe { msg_send_id![obj, copy] }; - - let _: &AnyObject = unsafe { msg_send_id![obj, description] }; - let _: Option<&AnyObject> = unsafe { msg_send_id![obj, description] }; + let _: Retained = unsafe { msg_send![obj, init] }; } diff --git a/crates/test-ui/ui/msg_send_invalid_return.stderr b/crates/test-ui/ui/msg_send_invalid_return.stderr index 5ddc7d234..a9c4d8176 100644 --- a/crates/test-ui/ui/msg_send_invalid_return.stderr +++ b/crates/test-ui/ui/msg_send_invalid_return.stderr @@ -1,172 +1,181 @@ -error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied +error[E0277]: the trait bound `Retained: Encode` is not satisfied --> ui/msg_send_invalid_return.rs | - | let _: &AnyObject = unsafe { msg_send_id![cls, new] }; - | ^^^^^^^^^^^^^^^^^^^^^^ the trait `MaybeUnwrap` is not implemented for `&AnyObject` - | - = help: the following other types implement trait `MaybeUnwrap`: - Allocated - Option> - Retained -note: required by a bound in `send_message_retained` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained` - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied - --> ui/msg_send_invalid_return.rs - | - | let _: &AnyObject = unsafe { msg_send_id![cls, alloc] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MaybeUnwrap` is not implemented for `&AnyObject` - | - = help: the following other types implement trait `MaybeUnwrap`: - Allocated - Option> - Retained -note: required by a bound in `__macro_helpers::msg_send_retained::>::send_message_retained_alloc` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | pub unsafe fn send_message_retained_alloc>>( - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__macro_helpers::msg_send_retained::>::send_message_retained_alloc` - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + | let _: Retained = unsafe { msg_send![cls, alloc] }; + | ^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<7>` to implement `RetainSemantics<&AnyClass, Retained, KindSendMessage>` + = note: required for `MethodFamily<7>` to implement `MsgSend<&AnyClass, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Allocated<_>` +error[E0277]: the trait bound `Allocated: Encode` is not satisfied --> ui/msg_send_invalid_return.rs | - | let _: Retained = unsafe { msg_send_id![cls, alloc] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `Allocated<_>`, found `Option>` - | - = note: expected struct `Allocated<_>` - found enum `Option>` -note: required by a bound in `__macro_helpers::msg_send_retained::>::send_message_retained_alloc` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | pub unsafe fn send_message_retained_alloc>>( - | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `__macro_helpers::msg_send_retained::>::send_message_retained_alloc` - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0277]: the trait bound `Option>: MaybeUnwrap` is not satisfied - --> ui/msg_send_invalid_return.rs - | - | let _: Option> = unsafe { msg_send_id![cls, alloc] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MaybeUnwrap` is not implemented for `Option>` - | - = help: the trait `MaybeUnwrap` is implemented for `Option>` -note: required by a bound in `__macro_helpers::msg_send_retained::>::send_message_retained_alloc` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | pub unsafe fn send_message_retained_alloc>>( - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `__macro_helpers::msg_send_retained::>::send_message_retained_alloc` - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + | let _: Option> = unsafe { msg_send![cls, alloc] }; + | ^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Allocated` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Option>` to implement `Encode` + = note: required for `Option>` to implement `EncodeReturn` + = note: required for `Option>` to implement `ConvertReturn>` + = note: required for `MethodFamily<7>` to implement `RetainSemantics<&AnyClass, Option>, KindSendMessage>` + = note: required for `MethodFamily<7>` to implement `MsgSend<&AnyClass, Option>>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0271]: type mismatch resolving `> as MaybeUnwrap>::Input == Allocated<_>` +error[E0277]: the trait bound `Allocated: OptionEncode` is not satisfied --> ui/msg_send_invalid_return.rs | - | let _: Retained> = unsafe { msg_send_id![cls, alloc] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `Allocated<_>`, found `Option>>` - | - = note: expected struct `Allocated<_>` - found enum `Option>>` -note: required by a bound in `__macro_helpers::msg_send_retained::>::send_message_retained_alloc` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | pub unsafe fn send_message_retained_alloc>>( - | ^^^^^^^^^^^^^^^^^^^^ required by this bound in `__macro_helpers::msg_send_retained::>::send_message_retained_alloc` - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + | let _: Option> = unsafe { msg_send![cls, alloc] }; + | ^^^^^^^^^^^^^^^^^^^^^ the trait `OptionEncode` is not implemented for `Allocated` + | + = help: the following other types implement trait `OptionEncode`: + &T + &mut T + NonNull + NonZero + NonZero + NonZero + NonZero + NonZero + and $N others + = note: required for `Option>` to implement `Encode` + = note: required for `Option>` to implement `EncodeReturn` + = note: required for `Option>` to implement `ConvertReturn>` + = note: required for `MethodFamily<7>` to implement `RetainSemantics<&AnyClass, Option>, KindSendMessage>` + = note: required for `MethodFamily<7>` to implement `MsgSend<&AnyClass, Option>>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied +error[E0277]: the trait bound `Retained>: Encode` is not satisfied --> ui/msg_send_invalid_return.rs | - | let _: &AnyObject = unsafe { msg_send_id![obj, init] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `MaybeUnwrap` is not implemented for `&AnyObject` - | - = help: the following other types implement trait `MaybeUnwrap`: - Allocated - Option> - Retained -note: required by a bound in `send_message_retained` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained` - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + | let _: Retained> = unsafe { msg_send![cls, alloc] }; + | ^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained>` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained>` to implement `EncodeReturn` + = note: required for `Retained>` to implement `ConvertReturn>` + = note: required for `MethodFamily<7>` to implement `RetainSemantics<&AnyClass, Retained>, KindSendMessage>` + = note: required for `MethodFamily<7>` to implement `MsgSend<&AnyClass, Retained>>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Option>` +error[E0277]: the trait bound `Allocated: MessageReceiver` is not satisfied --> ui/msg_send_invalid_return.rs | - | let _: Retained = unsafe { msg_send_id![obj, init] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `Option>`, found `Option>` - | - = note: expected enum `Option>` - found enum `Option>` -note: required by a bound in `send_message_retained` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained` - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + | let _: &AnyObject = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `Allocated` + | + = help: the following other types implement trait `MessageReceiver`: + &T + &mut AnyObject + *const T + *mut T + NonNull + = note: required for `MethodFamily<3>` to implement `RetainSemantics, &AnyObject, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend, &AnyObject>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Option>` +error[E0277]: the trait bound `Allocated: MessageReceiver` is not satisfied --> ui/msg_send_invalid_return.rs | - | let _: Retained = unsafe { msg_send_id![obj, init] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `Option>`, found `Option>` - | - = note: expected enum `Option>` - found enum `Option>` -note: required by a bound in `send_message_retained` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained` - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `Allocated` + | + = help: the following other types implement trait `MessageReceiver`: + &T + &mut AnyObject + *const T + *mut T + NonNull + = note: required for `MethodFamily<3>` to implement `RetainSemantics, Retained, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied +error[E0277]: the trait bound `Retained: Encode` is not satisfied --> ui/msg_send_invalid_return.rs | - | let _: &AnyObject = unsafe { msg_send_id![obj, copy] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `MaybeUnwrap` is not implemented for `&AnyObject` - | - = help: the following other types implement trait `MaybeUnwrap`: - Allocated - Option> - Retained -note: required by a bound in `send_message_retained` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics, Retained, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied +error[E0277]: the trait bound `Allocated: MessageReceiver` is not satisfied --> ui/msg_send_invalid_return.rs | - | let _: &AnyObject = unsafe { msg_send_id![obj, description] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MaybeUnwrap` is not implemented for `&AnyObject` - | - = help: the following other types implement trait `MaybeUnwrap`: - Allocated - Option> - Retained -note: required by a bound in `send_message_retained` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `Allocated` + | + = help: the following other types implement trait `MessageReceiver`: + &T + &mut AnyObject + *const T + *mut T + NonNull + = note: required for `MethodFamily<3>` to implement `RetainSemantics, Retained, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `Option<&AnyObject>: MaybeUnwrap` is not satisfied +error[E0277]: the trait bound `Retained: Encode` is not satisfied --> ui/msg_send_invalid_return.rs | - | let _: Option<&AnyObject> = unsafe { msg_send_id![obj, description] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MaybeUnwrap` is not implemented for `Option<&AnyObject>` - | - = help: the trait `MaybeUnwrap` is implemented for `Option>` -note: required by a bound in `send_message_retained` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs - | - | unsafe fn send_message_retained>( - | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MsgSendRetained::send_message_retained` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + | let _: Retained = unsafe { msg_send![obj, init] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<3>` to implement `RetainSemantics, Retained, KindSendMessage>` + = note: required for `MethodFamily<3>` to implement `MsgSend, Retained>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_missing_comma.rs b/crates/test-ui/ui/msg_send_missing_comma.rs index e545df42f..98778f128 100644 --- a/crates/test-ui/ui/msg_send_missing_comma.rs +++ b/crates/test-ui/ui/msg_send_missing_comma.rs @@ -1,7 +1,6 @@ //! Test msg_send! syntax with missing commas. #![deny(deprecated)] -use objc2::rc::Retained; -use objc2::{msg_send, msg_send_bool, msg_send_id, ClassType}; +use objc2::{msg_send, ClassType}; use objc2_foundation::NSString; fn main() { @@ -10,10 +9,4 @@ fn main() { let _: () = unsafe { msg_send![super(obj), a:obj b:obj] }; let _: () = unsafe { msg_send![super(obj, NSString::class()), a:obj b:obj] }; let _: () = unsafe { msg_send![obj, a:obj b:obj] }; - - unsafe { msg_send_bool![obj, c:obj d:obj] }; - - let _: Retained = unsafe { msg_send_id![super(obj), e:obj f:obj] }; - let _: Retained = unsafe { msg_send_id![super(obj, NSString::class()), e:obj f:obj] }; - let _: Retained = unsafe { msg_send_id![obj, e:obj f:obj] }; } diff --git a/crates/test-ui/ui/msg_send_missing_comma.stderr b/crates/test-ui/ui/msg_send_missing_comma.stderr index 275e4cd56..8f3be2a71 100644 --- a/crates/test-ui/ui/msg_send_missing_comma.stderr +++ b/crates/test-ui/ui/msg_send_missing_comma.stderr @@ -1,29 +1,16 @@ -error: use of deprecated macro `msg_send_bool`: use a normal msg_send! instead, it will perform the conversion for you +error: use of deprecated function `main::__msg_send_missing_comma`: using msg_send! without a comma between arguments is technically not valid macro syntax, and may break in a future version of Rust. You should use the following instead: + msg_send![super(obj), a: obj, b: obj] --> ui/msg_send_missing_comma.rs | - | unsafe { msg_send_bool![obj, c:obj d:obj] }; - | ^^^^^^^^^^^^^ + | let _: () = unsafe { msg_send![super(obj), a:obj b:obj] }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the lint level is defined here --> ui/msg_send_missing_comma.rs | | #![deny(deprecated)] | ^^^^^^^^^^ - -error: use of deprecated macro `objc2::msg_send_bool`: use a normal msg_send! instead, it will perform the conversion for you - --> ui/msg_send_missing_comma.rs - | - | use objc2::{msg_send, msg_send_bool, msg_send_id, ClassType}; - | ^^^^^^^^^^^^^ - -error: use of deprecated function `main::__msg_send_missing_comma`: using msg_send! without a comma between arguments is technically not valid macro syntax, and may break in a future version of Rust. You should use the following instead: - msg_send![super(obj), a: obj, b: obj] - --> ui/msg_send_missing_comma.rs - | - | let _: () = unsafe { msg_send![super(obj), a:obj b:obj] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::__comma_between_args_inner` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `$crate::__comma_between_args_inner` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error: use of deprecated function `main::__msg_send_missing_comma`: using msg_send! without a comma between arguments is technically not valid macro syntax, and may break in a future version of Rust. You should use the following instead: msg_send![super(obj, NSString::class()), a: obj, b: obj] @@ -42,39 +29,3 @@ error: use of deprecated function `main::__msg_send_missing_comma`: using msg_se | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the macro `$crate::__comma_between_args_inner` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: use of deprecated function `main::__msg_send_missing_comma`: using msg_send! without a comma between arguments is technically not valid macro syntax, and may break in a future version of Rust. You should use the following instead: - msg_send![obj, c: obj, d: obj] - --> ui/msg_send_missing_comma.rs - | - | unsafe { msg_send_bool![obj, c:obj d:obj] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::__comma_between_args_inner` which comes from the expansion of the macro `msg_send_bool` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: use of deprecated function `main::__msg_send_missing_comma`: using msg_send_id! without a comma between arguments is technically not valid macro syntax, and may break in a future version of Rust. You should use the following instead: - msg_send_id![super(obj), e: obj, f: obj] - --> ui/msg_send_missing_comma.rs - | - | let _: Retained = unsafe { msg_send_id![super(obj), e:obj f:obj] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::__comma_between_args_inner` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: use of deprecated function `main::__msg_send_missing_comma`: using msg_send_id! without a comma between arguments is technically not valid macro syntax, and may break in a future version of Rust. You should use the following instead: - msg_send_id![super(obj, NSString::class()), e: obj, f: obj] - --> ui/msg_send_missing_comma.rs - | - | let _: Retained = unsafe { msg_send_id![super(obj, NSString::class()), e:obj f:obj] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::__comma_between_args_inner` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: use of deprecated function `main::__msg_send_missing_comma`: using msg_send_id! without a comma between arguments is technically not valid macro syntax, and may break in a future version of Rust. You should use the following instead: - msg_send_id![obj, e: obj, f: obj] - --> ui/msg_send_missing_comma.rs - | - | let _: Retained = unsafe { msg_send_id![obj, e:obj f:obj] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `$crate::__comma_between_args_inner` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_no_return_type.rs b/crates/test-ui/ui/msg_send_no_return_type.rs index 81836d29b..758f6c25c 100644 --- a/crates/test-ui/ui/msg_send_no_return_type.rs +++ b/crates/test-ui/ui/msg_send_no_return_type.rs @@ -1,11 +1,9 @@ //! Test that forgetting to annotate the return type fails //! See https://github.com/SSheldon/rust-objc/issues/62 -use objc2::{class, msg_send, msg_send_id}; +use objc2::{class, msg_send}; fn main() { let cls = class!(NSObject); unsafe { msg_send![cls, new] }; - - unsafe { msg_send_id![cls, new] }; } diff --git a/crates/test-ui/ui/msg_send_no_return_type.stderr b/crates/test-ui/ui/msg_send_no_return_type.stderr index 476b6e636..d54d11948 100644 --- a/crates/test-ui/ui/msg_send_no_return_type.stderr +++ b/crates/test-ui/ui/msg_send_no_return_type.stderr @@ -4,14 +4,14 @@ error[E0283]: type annotations needed | unsafe { msg_send![cls, new] }; | ^^^^^^^^^^^^^^^^^^^ cannot infer type | - = note: cannot satisfy `_: ConvertReturn` - = help: the trait `ConvertReturn` is implemented for `bool` -note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs - | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function -... - | R: ConvertReturn, - | ^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` - = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: multiple `impl`s satisfying `_: ConvertReturn>` found in the `objc2` crate: + - impl ConvertReturn for bool; + - impl ConvertReturn for T + where T: EncodeReturn; + - impl ConvertReturn> for Option> + where T: Message; + - impl ConvertReturn> for Retained + where T: Message; + = note: required for `MethodFamily<1>` to implement `RetainSemantics<&AnyClass, _, KindSendMessage>` + = note: required for `MethodFamily<1>` to implement `MsgSend<&AnyClass, _>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_not_allowed_mutable.rs b/crates/test-ui/ui/msg_send_not_allowed_mutable.rs index 426b58689..2425257c8 100644 --- a/crates/test-ui/ui/msg_send_not_allowed_mutable.rs +++ b/crates/test-ui/ui/msg_send_not_allowed_mutable.rs @@ -1,12 +1,12 @@ -//! Test msg_send! with mutable receivers that are not IsAllowedMutable. +//! Test msg_send! with mutable receivers. +use objc2::msg_send; use objc2::rc::Retained; use objc2::runtime::NSObject; -use objc2::{msg_send, msg_send_id}; fn main() { let obj: &mut NSObject; let _: () = unsafe { msg_send![&mut *obj, test] }; - let _: Retained = unsafe { msg_send_id![obj, test] }; + let _: Retained = unsafe { msg_send![obj, test] }; } diff --git a/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr b/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr index 2fe71c23c..cb578c317 100644 --- a/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr +++ b/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr @@ -1,11 +1,8 @@ -error[E0277]: the trait bound `&mut NSObject: MsgSend` is not satisfied +error[E0277]: the trait bound `&mut NSObject: MessageReceiver` is not satisfied --> ui/msg_send_not_allowed_mutable.rs | | let _: () = unsafe { msg_send![&mut *obj, test] }; - | ----------^^^^^^^^^------- - | | | - | | the trait `MessageReceiver` is not implemented for `&mut NSObject` - | required by a bound introduced by this call + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `&mut NSObject` | = help: the following other types implement trait `MessageReceiver`: &T @@ -14,13 +11,15 @@ error[E0277]: the trait bound `&mut NSObject: MsgSend` is not satisfied *mut T NonNull = note: `MessageReceiver` is implemented for `&NSObject`, but not for `&mut NSObject` - = note: required for `&mut NSObject` to implement `MsgSend` + = note: required for `MethodFamily<6>` to implement `RetainSemantics<&mut NSObject, _, KindSendMessage>` + = note: required for `MethodFamily<6>` to implement `MsgSend<&mut NSObject, _>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `&mut NSObject: MessageReceiver` is not satisfied --> ui/msg_send_not_allowed_mutable.rs | - | let _: Retained = unsafe { msg_send_id![obj, test] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `&mut NSObject` + | let _: Retained = unsafe { msg_send![obj, test] }; + | ^^^^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `&mut NSObject` | = help: the following other types implement trait `MessageReceiver`: &T @@ -29,6 +28,6 @@ error[E0277]: the trait bound `&mut NSObject: MessageReceiver` is not satisfied *mut T NonNull = note: `MessageReceiver` is implemented for `&NSObject`, but not for `&mut NSObject` - = note: required for `&mut NSObject` to implement `MsgSend` - = note: required for `MethodFamily<6>` to implement `MsgSendRetained<&mut NSObject, Option>>` - = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: required for `MethodFamily<6>` to implement `RetainSemantics<&mut NSObject, _, KindSendMessage>` + = note: required for `MethodFamily<6>` to implement `MsgSend<&mut NSObject, _>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_not_encode.stderr b/crates/test-ui/ui/msg_send_not_encode.stderr index d561b9021..f8e741c08 100644 --- a/crates/test-ui/ui/msg_send_not_encode.stderr +++ b/crates/test-ui/ui/msg_send_not_encode.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `Vec: ConvertReturn` is not satisfied +error[E0277]: the trait bound `Vec: Encode` is not satisfied --> ui/msg_send_not_encode.rs | | let _: Vec = msg_send![cls, new]; @@ -15,22 +15,19 @@ error[E0277]: the trait bound `Vec: ConvertReturn` is not satisfied AtomicI8 and $N others = note: required for `Vec` to implement `EncodeReturn` - = note: required for `Vec` to implement `ConvertReturn` -note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs - | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function -... - | R: ConvertReturn, - | ^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` - = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: required for `Vec` to implement `ConvertReturn>` + = note: required for `MethodFamily<1>` to implement `RetainSemantics<&AnyClass, Vec, KindSendMessage>` + = note: required for `MethodFamily<1>` to implement `MsgSend<&AnyClass, Vec>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Vec: Encode` is not satisfied --> ui/msg_send_not_encode.rs | | let _: () = msg_send![cls, newWith: x]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Vec` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `Encode` is not implemented for `Vec` + | required by a bound introduced by this call | = help: the following other types implement trait `Encode`: &'a T @@ -46,20 +43,20 @@ error[E0277]: the trait bound `Vec: Encode` is not satisfied = note: required for `Vec` to implement `ConvertArgument` = note: required for `(Vec,)` to implement `ConvertArguments` note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function - | where - | A: ConvertArguments, - | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + | unsafe fn send_message(receiver: Receiver, sel: Sel, args: A) -> Return; + | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `(): Encode` is not satisfied --> ui/msg_send_not_encode.rs | | let _: () = msg_send![cls, unitAsArgument: ()]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `()` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `Encode` is not implemented for `()` + | required by a bound introduced by this call | = help: the following other types implement trait `Encode`: &'a T @@ -75,11 +72,8 @@ error[E0277]: the trait bound `(): Encode` is not satisfied = note: required for `()` to implement `ConvertArgument` = note: required for `((),)` to implement `ConvertArguments` note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function - | where - | A: ConvertArguments, - | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + | unsafe fn send_message(receiver: Receiver, sel: Sel, args: A) -> Return; + | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_only_message.stderr b/crates/test-ui/ui/msg_send_only_message.stderr index 10a2c79d1..54517fadc 100644 --- a/crates/test-ui/ui/msg_send_only_message.stderr +++ b/crates/test-ui/ui/msg_send_only_message.stderr @@ -1,11 +1,8 @@ -error[E0277]: the trait bound `{integer}: MsgSend` is not satisfied +error[E0277]: the trait bound `{integer}: MessageReceiver` is not satisfied --> ui/msg_send_only_message.rs | | unsafe { msg_send![1, new] }; - | ----------^------ - | | | - | | the trait `MessageReceiver` is not implemented for `{integer}` - | required by a bound introduced by this call + | ^^^^^^^^^^^^^^^^^ the trait `MessageReceiver` is not implemented for `{integer}` | = help: the following other types implement trait `MessageReceiver`: &T @@ -13,4 +10,6 @@ error[E0277]: the trait bound `{integer}: MsgSend` is not satisfied *const T *mut T NonNull - = note: required for `{integer}` to implement `MsgSend` + = note: required for `MethodFamily<1>` to implement `RetainSemantics<{integer}, _, KindSendMessage>` + = note: required for `MethodFamily<1>` to implement `MsgSend<{integer}, _>` + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_special_selectors.rs b/crates/test-ui/ui/msg_send_special_selectors.rs new file mode 100644 index 000000000..68ad5493c --- /dev/null +++ b/crates/test-ui/ui/msg_send_special_selectors.rs @@ -0,0 +1,12 @@ +//! Test special selectors. +use objc2::msg_send; +use objc2::rc::Retained; +use objc2::runtime::NSObject; + +fn main() { + let object: &NSObject; + let _: Retained = unsafe { msg_send![object, retain] }; + let _: Retained = unsafe { msg_send![object, release] }; + let _: Retained = unsafe { msg_send![object, autorelease] }; + let _: Retained = unsafe { msg_send![object, dealloc] }; +} diff --git a/crates/test-ui/ui/msg_send_special_selectors.stderr b/crates/test-ui/ui/msg_send_special_selectors.stderr new file mode 100644 index 000000000..e52cf999d --- /dev/null +++ b/crates/test-ui/ui/msg_send_special_selectors.stderr @@ -0,0 +1,87 @@ +error[E0277]: the trait bound `Retained: Encode` is not satisfied + --> ui/msg_send_special_selectors.rs + | + | let _: Retained = unsafe { msg_send![object, retain] }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<8>` to implement `RetainSemantics<&NSObject, Retained, KindSendMessage>` + = note: required for `MethodFamily<8>` to implement `MsgSend<&NSObject, Retained>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Retained: Encode` is not satisfied + --> ui/msg_send_special_selectors.rs + | + | let _: Retained = unsafe { msg_send![object, release] }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<9>` to implement `RetainSemantics<&NSObject, Retained, KindSendMessage>` + = note: required for `MethodFamily<9>` to implement `MsgSend<&NSObject, Retained>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Retained: Encode` is not satisfied + --> ui/msg_send_special_selectors.rs + | + | let _: Retained = unsafe { msg_send![object, autorelease] }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<10>` to implement `RetainSemantics<&NSObject, Retained, KindSendMessage>` + = note: required for `MethodFamily<10>` to implement `MsgSend<&NSObject, Retained>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: the trait bound `Retained: Encode` is not satisfied + --> ui/msg_send_special_selectors.rs + | + | let _: Retained = unsafe { msg_send![object, dealloc] }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` + | + = help: the following other types implement trait `Encode`: + &'a T + &'a mut T + *const T + *mut T + AtomicI16 + AtomicI32 + AtomicI64 + AtomicI8 + and $N others + = note: required for `Retained` to implement `EncodeReturn` + = note: required for `Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<11>` to implement `RetainSemantics<&NSObject, Retained, KindSendMessage>` + = note: required for `MethodFamily<11>` to implement `MsgSend<&NSObject, Retained>` + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/msg_send_super_not_classtype.stderr b/crates/test-ui/ui/msg_send_super_not_classtype.stderr index dffc69e04..4d24f90df 100644 --- a/crates/test-ui/ui/msg_send_super_not_classtype.stderr +++ b/crates/test-ui/ui/msg_send_super_not_classtype.stderr @@ -11,13 +11,13 @@ error[E0277]: the trait bound `AnyObject: ClassType` is not satisfied NSObject __NSProxy note: required by a bound in `send_super_message_static` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_super_message_static(self, sel: Sel, args: A) -> R + | unsafe fn send_super_message_static( | ------------------------- required by a bound in this associated function - | where +... | Self::Inner: ClassType, - | ^^^^^^^^^ required by this bound in `MsgSend::send_super_message_static` + | ^^^^^^^^^ required by this bound in `MsgSendSuper::send_super_message_static` error[E0277]: the trait bound `AnyObject: ClassType` is not satisfied --> ui/msg_send_super_not_classtype.rs @@ -32,10 +32,10 @@ error[E0277]: the trait bound `AnyObject: ClassType` is not satisfied NSObject __NSProxy note: required by a bound in `send_super_message_static` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_super_message_static(self, sel: Sel, args: A) -> R + | unsafe fn send_super_message_static( | ------------------------- required by a bound in this associated function ... | ::Super: ClassType, - | ^^^^^^^^^ required by this bound in `MsgSend::send_super_message_static` + | ^^^^^^^^^ required by this bound in `MsgSendSuper::send_super_message_static` diff --git a/crates/test-ui/ui/msg_send_underspecified.rs b/crates/test-ui/ui/msg_send_underspecified.rs index 237188e80..0c0dffff2 100644 --- a/crates/test-ui/ui/msg_send_underspecified.rs +++ b/crates/test-ui/ui/msg_send_underspecified.rs @@ -1,8 +1,8 @@ -//! Test compiler output of msg_send_id when ownership is not specified. -use objc2::msg_send_id; +//! Test compiler output of msg_send! when result type is not properly specified. +use objc2::msg_send; use objc2::runtime::NSObject; fn main() { let obj: &NSObject; - let _: &NSObject = &*unsafe { msg_send_id![obj, description] }; + let _: &NSObject = &*unsafe { msg_send![obj, description] }; } diff --git a/crates/test-ui/ui/msg_send_underspecified.stderr b/crates/test-ui/ui/msg_send_underspecified.stderr index c6859b570..b4e8413b8 100644 --- a/crates/test-ui/ui/msg_send_underspecified.stderr +++ b/crates/test-ui/ui/msg_send_underspecified.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed --> ui/msg_send_underspecified.rs | - | let _: &NSObject = &*unsafe { msg_send_id![obj, description] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + | let _: &NSObject = &*unsafe { msg_send![obj, description] }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type diff --git a/crates/test-ui/ui/msg_send_underspecified_error1.rs b/crates/test-ui/ui/msg_send_underspecified_error1.rs index 28cc1ab34..5040d2d94 100644 --- a/crates/test-ui/ui/msg_send_underspecified_error1.rs +++ b/crates/test-ui/ui/msg_send_underspecified_error1.rs @@ -1,9 +1,9 @@ -//! Test underspecified msg_send_id! errors. -use objc2::msg_send_id; +//! Test underspecified msg_send! errors. +use objc2::msg_send; use objc2::rc::Retained; use objc2::runtime::NSObject; fn main() { let obj: &NSObject; - let _: Result, _> = unsafe { msg_send_id![obj, error: _] }; + let _: Result, _> = unsafe { msg_send![obj, error: _] }; } diff --git a/crates/test-ui/ui/msg_send_underspecified_error1.stderr b/crates/test-ui/ui/msg_send_underspecified_error1.stderr index 045fe1b36..161b33fbd 100644 --- a/crates/test-ui/ui/msg_send_underspecified_error1.stderr +++ b/crates/test-ui/ui/msg_send_underspecified_error1.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed --> ui/msg_send_underspecified_error1.rs | - | let _: Result, _> = unsafe { msg_send_id![obj, error: _] }; + | let _: Result, _> = unsafe { msg_send![obj, error: _] }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type diff --git a/crates/test-ui/ui/msg_send_underspecified_error2.rs b/crates/test-ui/ui/msg_send_underspecified_error2.rs index e1d207c74..35740aa17 100644 --- a/crates/test-ui/ui/msg_send_underspecified_error2.rs +++ b/crates/test-ui/ui/msg_send_underspecified_error2.rs @@ -1,9 +1,9 @@ -//! Test underspecified msg_send_id! errors. -use objc2::msg_send_id; +//! Test underspecified msg_send! errors. +use objc2::msg_send; use objc2::rc::Retained; use objc2_foundation::{NSError, NSObject}; fn main() { let obj: &NSObject; - let _: Result<_, Retained> = unsafe { msg_send_id![obj, error: _] }; + let _: Result<_, Retained> = unsafe { msg_send![obj, error: _] }; } diff --git a/crates/test-ui/ui/msg_send_underspecified_error2.stderr b/crates/test-ui/ui/msg_send_underspecified_error2.stderr index 86230ce1a..6da24d54f 100644 --- a/crates/test-ui/ui/msg_send_underspecified_error2.stderr +++ b/crates/test-ui/ui/msg_send_underspecified_error2.stderr @@ -1,5 +1,18 @@ +error[E0283]: type annotations needed + --> ui/msg_send_underspecified_error2.rs + | + | let _: Result<_, Retained> = unsafe { msg_send![obj, error: _] }; + | ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + | + = note: multiple `impl`s satisfying `MethodFamily<6>: MsgSendError<&NSObject, _>` found in the `objc2` crate: + - impl MsgSendError for MethodFamily + where MethodFamily: MsgSend; + - impl MsgSendError> for MethodFamily + where MethodFamily: MsgSend>>; + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0282]: type annotations needed --> ui/msg_send_underspecified_error2.rs | - | let _: Result<_, Retained> = unsafe { msg_send_id![obj, error: _] }; + | let _: Result<_, Retained> = unsafe { msg_send![obj, error: _] }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type diff --git a/crates/test-ui/ui/msg_send_underspecified_error3.rs b/crates/test-ui/ui/msg_send_underspecified_error3.rs index 0dd806ed4..4c4566b59 100644 --- a/crates/test-ui/ui/msg_send_underspecified_error3.rs +++ b/crates/test-ui/ui/msg_send_underspecified_error3.rs @@ -1,8 +1,8 @@ -//! Test underspecified msg_send_id! errors. -use objc2::msg_send_id; +//! Test underspecified msg_send! errors. +use objc2::msg_send; use objc2::runtime::NSObject; fn main() { let obj: &NSObject; - let _: Result<_, _> = unsafe { msg_send_id![obj, error: _] }; + let _: Result<_, _> = unsafe { msg_send![obj, error: _] }; } diff --git a/crates/test-ui/ui/msg_send_underspecified_error3.stderr b/crates/test-ui/ui/msg_send_underspecified_error3.stderr index dadfb21b0..68cbe223b 100644 --- a/crates/test-ui/ui/msg_send_underspecified_error3.stderr +++ b/crates/test-ui/ui/msg_send_underspecified_error3.stderr @@ -1,5 +1,18 @@ +error[E0283]: type annotations needed + --> ui/msg_send_underspecified_error3.rs + | + | let _: Result<_, _> = unsafe { msg_send![obj, error: _] }; + | ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + | + = note: multiple `impl`s satisfying `MethodFamily<6>: MsgSendError<&NSObject, _>` found in the `objc2` crate: + - impl MsgSendError for MethodFamily + where MethodFamily: MsgSend; + - impl MsgSendError> for MethodFamily + where MethodFamily: MsgSend>>; + = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) + error[E0282]: type annotations needed --> ui/msg_send_underspecified_error3.rs | - | let _: Result<_, _> = unsafe { msg_send_id![obj, error: _] }; + | let _: Result<_, _> = unsafe { msg_send![obj, error: _] }; | ^^^^^^^^^^^^ cannot infer type diff --git a/crates/test-ui/ui/msg_send_unwrap.rs b/crates/test-ui/ui/msg_send_unwrap.rs index 900950265..1b678857c 100644 --- a/crates/test-ui/ui/msg_send_unwrap.rs +++ b/crates/test-ui/ui/msg_send_unwrap.rs @@ -1,9 +1,9 @@ -//! Test calling something on return from msg_send_id!. +//! Test calling something on return from `msg_send!`. use objc2::rc::Retained; use objc2::runtime::NSObject; -use objc2::{class, msg_send_id}; +use objc2::{class, msg_send}; fn main() { let cls = class!(NSObject); - let _: Retained = unsafe { msg_send_id![cls, new].unwrap() }; + let _: Retained = unsafe { msg_send![cls, new].unwrap() }; } diff --git a/crates/test-ui/ui/msg_send_unwrap.stderr b/crates/test-ui/ui/msg_send_unwrap.stderr index fcbd3d8c7..b705037fb 100644 --- a/crates/test-ui/ui/msg_send_unwrap.stderr +++ b/crates/test-ui/ui/msg_send_unwrap.stderr @@ -1,7 +1,7 @@ error[E0282]: type annotations needed --> ui/msg_send_unwrap.rs | - | let _: Retained = unsafe { msg_send_id![cls, new].unwrap() }; - | ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + | let _: Retained = unsafe { msg_send![cls, new].unwrap() }; + | ^^^^^^^^^^^^^^^^^^^ cannot infer type | - = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) + = note: this error originates in the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/not_writeback.stderr b/crates/test-ui/ui/not_writeback.stderr index 6bb428858..14dfbc0a7 100644 --- a/crates/test-ui/ui/not_writeback.stderr +++ b/crates/test-ui/ui/not_writeback.stderr @@ -1,4 +1,4 @@ -error[E0277]: the trait bound `&mut Retained: ConvertReturn` is not satisfied +error[E0277]: the trait bound `Retained: RefEncode` is not satisfied --> ui/not_writeback.rs | | let _: &mut Retained = unsafe { msg_send![obj, a] }; @@ -16,22 +16,21 @@ error[E0277]: the trait bound `&mut Retained: ConvertReturn` is not sa and $N others = note: required for `&mut Retained` to implement `Encode` = note: required for `&mut Retained` to implement `EncodeReturn` - = note: required for `&mut Retained` to implement `ConvertReturn` -note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs - | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function -... - | R: ConvertReturn, - | ^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + = note: required for `&mut Retained` to implement `ConvertReturn>` + = note: required for `MethodFamily<6>` to implement `RetainSemantics<*const NSObject, &mut Retained, KindSendMessage>` + = note: 1 redundant requirement hidden + = note: required for `MethodFamily<6>` to implement `RetainSemantics<&Retained, &mut Retained, KindSendMessage>` + = note: required for `MethodFamily<6>` to implement `MsgSend<&Retained, &mut Retained>` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Retained: Encode` is not satisfied --> ui/not_writeback.rs | | let _: () = unsafe { msg_send![obj, a: param] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `Retained` + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `Encode` is not implemented for `Retained` + | required by a bound introduced by this call | = help: the following other types implement trait `Encode`: &'a T @@ -47,20 +46,20 @@ error[E0277]: the trait bound `Retained: Encode` is not satisfied = note: required for `Retained` to implement `ConvertArgument` = note: required for `(Retained,)` to implement `ConvertArguments` note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function - | where - | A: ConvertArguments, - | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + | unsafe fn send_message(receiver: Receiver, sel: Sel, args: A) -> Return; + | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Retained: RefEncode` is not satisfied --> ui/not_writeback.rs | | let _: () = unsafe { msg_send![obj, a: ¶m] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `RefEncode` is not implemented for `Retained` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `RefEncode` is not implemented for `Retained` + | required by a bound introduced by this call | = help: the following other types implement trait `RefEncode`: &'a T @@ -77,20 +76,20 @@ error[E0277]: the trait bound `Retained: RefEncode` is not satisfied = note: required for `&Retained` to implement `ConvertArgument` = note: required for `(&Retained,)` to implement `ConvertArguments` note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function - | where - | A: ConvertArguments, - | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + | unsafe fn send_message(receiver: Receiver, sel: Sel, args: A) -> Return; + | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Retained: RefEncode` is not satisfied --> ui/not_writeback.rs | | let _: () = unsafe { msg_send![obj, a: Some(¶m)] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `RefEncode` is not implemented for `Retained` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `RefEncode` is not implemented for `Retained` + | required by a bound introduced by this call | = help: the following other types implement trait `RefEncode`: &'a T @@ -109,20 +108,20 @@ error[E0277]: the trait bound `Retained: RefEncode` is not satisfied = note: required for `Option<&Retained>` to implement `ConvertArgument` = note: required for `(Option<&Retained>,)` to implement `ConvertArguments` note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function - | where - | A: ConvertArguments, - | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + | unsafe fn send_message(receiver: Receiver, sel: Sel, args: A) -> Return; + | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Retained: RefEncode` is not satisfied --> ui/not_writeback.rs | | let _: () = unsafe { msg_send![obj, a: param] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `RefEncode` is not implemented for `Retained` + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `RefEncode` is not implemented for `Retained` + | required by a bound introduced by this call | = help: the following other types implement trait `RefEncode`: &'a T @@ -139,20 +138,20 @@ error[E0277]: the trait bound `Retained: RefEncode` is not satisfied = note: required for `*mut Retained` to implement `ConvertArgument` = note: required for `(*mut Retained,)` to implement `ConvertArguments` note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function - | where - | A: ConvertArguments, - | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + | unsafe fn send_message(receiver: Receiver, sel: Sel, args: A) -> Return; + | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Retained: RefEncode` is not satisfied --> ui/not_writeback.rs | | let _: () = unsafe { msg_send![obj, a: param] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `RefEncode` is not implemented for `Retained` + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the trait `RefEncode` is not implemented for `Retained` + | required by a bound introduced by this call | = help: the following other types implement trait `RefEncode`: &'a T @@ -170,11 +169,8 @@ error[E0277]: the trait bound `Retained: RefEncode` is not satisfied = note: required for `&mut &mut Retained` to implement `ConvertArgument` = note: required for `(&mut &mut Retained,)` to implement `ConvertArguments` note: required by a bound in `MsgSend::send_message` - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send.rs + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_retained.rs | - | unsafe fn send_message(self, sel: Sel, args: A) -> R - | ------------ required by a bound in this associated function - | where - | A: ConvertArguments, - | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` + | unsafe fn send_message(receiver: Receiver, sel: Sel, args: A) -> Return; + | ^^^^^^^^^^^^^^^^ required by this bound in `MsgSend::send_message` = note: this error originates in the macro `$crate::__msg_send_helper` which comes from the expansion of the macro `msg_send` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/nsarray_not_message.stderr b/crates/test-ui/ui/nsarray_not_message.stderr index 28b08a13c..b4e447933 100644 --- a/crates/test-ui/ui/nsarray_not_message.stderr +++ b/crates/test-ui/ui/nsarray_not_message.stderr @@ -20,7 +20,7 @@ note: required by a bound in `NSArray::::new` | / extern_methods!( | | /// Methods declared on superclass `NSObject` | | unsafe impl NSArray { - | | #[method_id(new)] + | | #[method(new)] | | #[unsafe(method_family = new)] | | pub fn new() -> Retained; | | --- required by a bound in this associated function diff --git a/crates/test-ui/ui/wrong_optional.rs b/crates/test-ui/ui/wrong_optional.rs index 61e705652..a23c33b6a 100644 --- a/crates/test-ui/ui/wrong_optional.rs +++ b/crates/test-ui/ui/wrong_optional.rs @@ -20,7 +20,7 @@ extern_methods!( unsafe impl MyObject { /// Doc comment #[optional] - #[method_id(b)] + #[method(b)] fn b(&self) -> Retained; } ); diff --git a/crates/tests/src/test_foundation_retain_semantics.rs b/crates/tests/src/test_foundation_retain_semantics.rs index 11aebafb4..8c10110e2 100644 --- a/crates/tests/src/test_foundation_retain_semantics.rs +++ b/crates/tests/src/test_foundation_retain_semantics.rs @@ -365,7 +365,7 @@ unsafe impl CopyingHelper for NSCopyingRcTestObject { extern_methods!( unsafe impl NSCopyingRcTestObject { - #[method_id(new)] + #[method(new)] fn new() -> Retained; } ); diff --git a/crates/tests/src/test_object.rs b/crates/tests/src/test_object.rs index d22e2f52d..843bdcdee 100644 --- a/crates/tests/src/test_object.rs +++ b/crates/tests/src/test_object.rs @@ -7,7 +7,7 @@ use objc2::rc::{autoreleasepool, AutoreleasePool, Retained}; use objc2::runtime::{ AnyClass, AnyObject, AnyProtocol, Bool, NSObject, NSObjectProtocol, ProtocolObject, }; -use objc2::{class, extern_protocol, msg_send, msg_send_id, AllocAnyThread, ClassType}; +use objc2::{class, extern_protocol, msg_send, AllocAnyThread, ClassType}; use objc2::{extern_class, sel}; use objc2_foundation::{NSArray, NSException, NSMutableString, NSNumber, NSString}; @@ -25,10 +25,10 @@ extern_protocol!( #[method(b)] fn b() -> c_int; - #[method_id(c)] + #[method(c)] fn c(&self) -> Retained; - #[method_id(d)] + #[method(d)] fn d() -> Retained; #[method(e)] @@ -40,11 +40,11 @@ extern_protocol!( fn f() -> c_int; #[optional] - #[method_id(g)] + #[method(g)] fn g(&self) -> Retained; #[optional] - #[method_id(h)] + #[method(h)] fn h() -> Retained; } ); @@ -90,7 +90,7 @@ static FIX_LINKING: &AnyClass = { impl MyTestObject { fn new() -> Retained { let cls = Self::class(); - unsafe { msg_send_id![cls, new] } + unsafe { msg_send![cls, new] } } #[allow(clippy::needless_lifetimes)] @@ -102,7 +102,7 @@ impl MyTestObject { fn new_autoreleased_retained() -> Retained { let cls = Self::class(); - unsafe { msg_send_id![cls, getAutoreleasedInstance] } + unsafe { msg_send![cls, getAutoreleasedInstance] } } fn add_numbers(a: c_int, b: c_int) -> c_int { diff --git a/framework-crates/objc2-app-kit/examples/delegate.rs b/framework-crates/objc2-app-kit/examples/delegate.rs index 1df9b33c9..53ab8743a 100644 --- a/framework-crates/objc2-app-kit/examples/delegate.rs +++ b/framework-crates/objc2-app-kit/examples/delegate.rs @@ -1,7 +1,7 @@ #![deny(unsafe_op_in_unsafe_fn)] use objc2::rc::Retained; use objc2::runtime::ProtocolObject; -use objc2::{define_class, msg_send_id, DefinedClass, MainThreadMarker, MainThreadOnly}; +use objc2::{define_class, msg_send, DefinedClass, MainThreadMarker, MainThreadOnly}; use objc2_app_kit::{NSApplication, NSApplicationActivationPolicy, NSApplicationDelegate}; use objc2_foundation::{ ns_string, NSCopying, NSNotification, NSObject, NSObjectProtocol, NSString, @@ -58,7 +58,7 @@ impl AppDelegate { id_ivar: NSString::from_str("abc"), maybe_id_ivar: Some(ns_string!("def").copy()), }); - unsafe { msg_send_id![super(this), init] } + unsafe { msg_send![super(this), init] } } } diff --git a/framework-crates/objc2-foundation/examples/speech_synthesis.rs b/framework-crates/objc2-foundation/examples/speech_synthesis.rs index ac26f145f..b882a9f4e 100644 --- a/framework-crates/objc2-foundation/examples/speech_synthesis.rs +++ b/framework-crates/objc2-foundation/examples/speech_synthesis.rs @@ -12,7 +12,7 @@ use std::thread; use std::time::Duration; use objc2::rc::Retained; -use objc2::{extern_class, msg_send, msg_send_id, ClassType}; +use objc2::{extern_class, msg_send, ClassType}; use objc2_foundation::{ns_string, NSObject, NSString}; #[cfg(target_os = "macos")] @@ -35,7 +35,7 @@ mod implementation { impl Synthesizer { // Uses default voice pub(crate) fn new() -> Retained { - unsafe { msg_send_id![Self::class(), new] } + unsafe { msg_send![Self::class(), new] } } fn set_rate(&self, rate: f32) { @@ -110,7 +110,7 @@ mod implementation { impl Synthesizer { pub(crate) fn new() -> Retained { - unsafe { msg_send_id![Self::class(), new] } + unsafe { msg_send![Self::class(), new] } } pub(crate) fn speak(&self, utterance: &Utterance) { @@ -132,7 +132,7 @@ mod implementation { impl Utterance { pub(crate) fn new(string: &NSString) -> Retained { - unsafe { msg_send_id![Self::alloc(), initWithString: string] } + unsafe { msg_send![Self::alloc(), initWithString: string] } } pub(crate) fn set_rate(&self, rate: f32) { diff --git a/framework-crates/objc2-foundation/src/copying.rs b/framework-crates/objc2-foundation/src/copying.rs index 8b2f46cba..534b3e885 100644 --- a/framework-crates/objc2-foundation/src/copying.rs +++ b/framework-crates/objc2-foundation/src/copying.rs @@ -35,7 +35,7 @@ pub unsafe trait CopyingHelper: Message { /// /// The implementation for `NSString` has itself (`NSString`) here, while /// `NSMutableString` instead has `NSString`. - type Result: ?Sized + Message; + type Result: Message; } /// A helper type for implementing [`NSMutableCopying`]. @@ -56,7 +56,7 @@ pub unsafe trait MutableCopyingHelper: Message { /// /// The implementation for `NSString` has `NSMutableString` here, while /// `NSMutableString` has itself (`NSMutableString`). - type Result: ?Sized + Message; + type Result: Message; } // SAFETY: Superclasses are not in general required to implement the same @@ -116,7 +116,7 @@ extern_protocol!( /// Implement `NSCopying` for a custom class. /// /// ``` - /// use objc2::{define_class, msg_send_id, AllocAnyThread, DefinedClass}; + /// use objc2::{define_class, msg_send, AllocAnyThread, DefinedClass}; /// use objc2::rc::Retained; /// use objc2::runtime::NSZone; /// use objc2_foundation::{CopyingHelper, NSCopying, NSObject}; @@ -131,7 +131,7 @@ extern_protocol!( /// fn copyWithZone(&self, _zone: *const NSZone) -> Retained { /// // Create new class, and transfer ivars /// let new = Self::alloc().set_ivars(self.ivars().clone()); - /// unsafe { msg_send_id![super(new), init] } + /// unsafe { msg_send![super(new), init] } /// } /// } /// ); @@ -147,7 +147,8 @@ extern_protocol!( /// /// The output type is the immutable counterpart of the object, which /// is usually `Self`, but e.g. `NSMutableString` returns `NSString`. - #[method_id(copy)] + #[method(copy)] + #[unsafe(method_family = copy)] #[optional] fn copy(&self) -> Retained where @@ -162,7 +163,8 @@ extern_protocol!( /// # Safety /// /// The zone pointer must be valid or NULL. - #[method_id(copyWithZone:)] + #[method(copyWithZone:)] + #[unsafe(method_family = copy)] unsafe fn copyWithZone(&self, zone: *mut NSZone) -> Retained where Self: CopyingHelper; @@ -215,7 +217,8 @@ extern_protocol!( /// /// The output type is the mutable counterpart of the object. E.g. both /// `NSString` and `NSMutableString` return `NSMutableString`. - #[method_id(mutableCopy)] + #[method(mutableCopy)] + #[unsafe(method_family = mutableCopy)] #[optional] fn mutableCopy(&self) -> Retained where @@ -230,7 +233,8 @@ extern_protocol!( /// # Safety /// /// The zone pointer must be valid or NULL. - #[method_id(mutableCopyWithZone:)] + #[method(mutableCopyWithZone:)] + #[unsafe(method_family = mutableCopy)] unsafe fn mutableCopyWithZone(&self, zone: *mut NSZone) -> Retained where Self: MutableCopyingHelper; diff --git a/framework-crates/objc2-foundation/src/data.rs b/framework-crates/objc2-foundation/src/data.rs index d1da3b848..f9d150f03 100644 --- a/framework-crates/objc2-foundation/src/data.rs +++ b/framework-crates/objc2-foundation/src/data.rs @@ -341,7 +341,7 @@ unsafe fn with_vec(obj: objc2::rc::Allocated, bytes: Vec = if cfg!(feature = "gnustep-1-7") { // Can return NULL: // https://github.com/gnustep/libs-base/issues/486 - let desc: Option> = - unsafe { msg_send_id![self, localizedDescription] }; + let desc: Option> = unsafe { msg_send![self, localizedDescription] }; if let Some(desc) = desc { desc } else { - let domain: Retained = unsafe { msg_send_id![self, domain] }; + let domain: Retained = unsafe { msg_send![self, domain] }; // SAFETY: `domain` returns `NSErrorDomain`, which is `NSString`. unsafe { util::display_string(&domain, f)? }; write!(f, " {}", self.code())?; @@ -70,7 +69,7 @@ impl fmt::Display for NSError { return Ok(()); } } else { - unsafe { msg_send_id![self, localizedDescription] } + unsafe { msg_send![self, localizedDescription] } }; // SAFETY: `localizedDescription` returns `NSString`. diff --git a/framework-crates/objc2-foundation/src/exception.rs b/framework-crates/objc2-foundation/src/exception.rs index ab27bec9a..97e5eeaf8 100644 --- a/framework-crates/objc2-foundation/src/exception.rs +++ b/framework-crates/objc2-foundation/src/exception.rs @@ -5,7 +5,7 @@ use core::panic::{RefUnwindSafe, UnwindSafe}; use objc2::exception::Exception; use objc2::rc::Retained; use objc2::runtime::{AnyObject, NSObject, NSObjectProtocol}; -use objc2::{extern_methods, msg_send_id, sel, ClassType}; +use objc2::{extern_methods, msg_send, sel, ClassType}; use crate::{util, NSException}; @@ -39,7 +39,7 @@ impl NSException { use objc2::AllocAnyThread; unsafe { - objc2::msg_send_id![ + objc2::msg_send![ Self::alloc(), initWithName: name, reason: reason, @@ -98,13 +98,13 @@ impl fmt::Debug for NSException { write!(f, "{obj:?}")?; write!(f, " '")?; - let name: Retained = unsafe { msg_send_id![self, name] }; + let name: Retained = unsafe { msg_send![self, name] }; // SAFETY: `name` returns `NSExceptionName`, which is `NSString`. unsafe { util::display_string(&name, f)? }; write!(f, "'")?; write!(f, " reason: ")?; - let reason: Option> = unsafe { msg_send_id![self, reason] }; + let reason: Option> = unsafe { msg_send![self, reason] }; if let Some(reason) = reason { // SAFETY: `reason` returns `NSString`. unsafe { util::display_string(&reason, f)? }; diff --git a/framework-crates/objc2-foundation/src/number.rs b/framework-crates/objc2-foundation/src/number.rs index a8edbf5d3..cea9e8ddc 100644 --- a/framework-crates/objc2-foundation/src/number.rs +++ b/framework-crates/objc2-foundation/src/number.rs @@ -22,7 +22,7 @@ use core::hash; use core::panic::{RefUnwindSafe, UnwindSafe}; use objc2::encode::Encoding; -use objc2::msg_send_id; +use objc2::msg_send; use objc2::rc::Retained; use objc2::runtime::NSObject; @@ -262,7 +262,7 @@ impl Ord for NSNumber { impl fmt::Display for NSNumber { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let string: Retained = unsafe { msg_send_id![self, stringValue] }; + let string: Retained = unsafe { msg_send![self, stringValue] }; // SAFETY: `stringValue` returns `NSString`. unsafe { util::display_string(&string, f) } } diff --git a/framework-crates/objc2-foundation/src/string.rs b/framework-crates/objc2-foundation/src/string.rs index 7df55862d..c6b60a195 100644 --- a/framework-crates/objc2-foundation/src/string.rs +++ b/framework-crates/objc2-foundation/src/string.rs @@ -7,7 +7,7 @@ use core::panic::RefUnwindSafe; use core::panic::UnwindSafe; use core::str; -use objc2::msg_send_id; +use objc2::msg_send; use objc2::rc::{autoreleasepool_leaking, Allocated, AutoreleasePool, Retained}; use objc2::runtime::__nsstring::{nsstring_len, nsstring_to_str, UTF8_ENCODING}; use objc2::{AllocAnyThread, Message}; @@ -128,10 +128,10 @@ impl NSMutableString { unsafe fn init_with_str(obj: Allocated, string: &str) -> Retained { let bytes: *const c_void = string.as_ptr().cast(); - // We use `msg_send_id` instead of the generated method, since that + // We use `msg_send!` instead of the generated method, since that // assumes the encoding is `usize`, whereas GNUStep assumes `i32`. unsafe { - msg_send_id![ + msg_send![ obj, initWithBytes: bytes, length: string.len(), diff --git a/framework-crates/objc2-foundation/src/uuid.rs b/framework-crates/objc2-foundation/src/uuid.rs index cb9aa12ec..985b66cce 100644 --- a/framework-crates/objc2-foundation/src/uuid.rs +++ b/framework-crates/objc2-foundation/src/uuid.rs @@ -4,7 +4,7 @@ use core::panic::{RefUnwindSafe, UnwindSafe}; use objc2::encode::{Encode, Encoding, RefEncode}; use objc2::rc::{Allocated, Retained}; use objc2::runtime::NSObject; -use objc2::{extern_methods, msg_send_id, AllocAnyThread}; +use objc2::{extern_methods, msg_send, AllocAnyThread}; use crate::{util, NSUUID}; @@ -30,7 +30,7 @@ unsafe impl RefEncode for UuidBytes { extern_methods!( unsafe impl NSUUID { - #[method_id(initWithUUIDBytes:)] + #[method(initWithUUIDBytes:)] fn initWithUUIDBytes(this: Allocated, bytes: &UuidBytes) -> Retained; #[method(getUUIDBytes:)] @@ -79,7 +79,7 @@ impl NSUUID { impl fmt::Display for NSUUID { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let string: Retained = unsafe { msg_send_id![self, UUIDString] }; + let string: Retained = unsafe { msg_send![self, UUIDString] }; // SAFETY: `UUIDString` returns `NSString`. unsafe { util::display_string(&string, f) } } @@ -89,7 +89,7 @@ impl fmt::Debug for NSUUID { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // The `uuid` crate does `Debug` and `Display` equally, and so do we. - let string: Retained = unsafe { msg_send_id![self, UUIDString] }; + let string: Retained = unsafe { msg_send![self, UUIDString] }; // SAFETY: `UUIDString` returns `NSString`. unsafe { util::display_string(&string, f) } } diff --git a/framework-crates/objc2-metal/examples/triangle.rs b/framework-crates/objc2-metal/examples/triangle.rs index 47d7b3561..43246a23c 100644 --- a/framework-crates/objc2-metal/examples/triangle.rs +++ b/framework-crates/objc2-metal/examples/triangle.rs @@ -6,7 +6,7 @@ use core::{cell::OnceCell, ptr::NonNull}; use objc2::rc::Retained; use objc2::runtime::ProtocolObject; -use objc2::{define_class, msg_send_id, DefinedClass, MainThreadMarker, MainThreadOnly}; +use objc2::{define_class, msg_send, DefinedClass, MainThreadMarker, MainThreadOnly}; #[cfg(target_os = "macos")] use objc2_app_kit::{ NSApplication, NSApplicationActivationPolicy, NSApplicationDelegate, NSBackingStoreType, @@ -286,7 +286,7 @@ impl Delegate { #[cfg(target_os = "macos")] window: OnceCell::default(), }); - unsafe { msg_send_id![super(this), init] } + unsafe { msg_send![super(this), init] } } } diff --git a/framework-crates/objc2-metal/src/private.rs b/framework-crates/objc2-metal/src/private.rs index cc3c08426..4a5059b8c 100644 --- a/framework-crates/objc2-metal/src/private.rs +++ b/framework-crates/objc2-metal/src/private.rs @@ -11,15 +11,15 @@ use crate::*; use objc2::rc::{Allocated, Retained}; use objc2::runtime::{AnyObject, ProtocolObject}; -use objc2::{extern_methods, msg_send_id, Message}; +use objc2::{extern_methods, msg_send, Message}; pub unsafe trait MTLDevicePrivate: Message { unsafe fn vendorName(&self) -> Retained { - unsafe { msg_send_id![self, vendorName] } + unsafe { msg_send![self, vendorName] } } unsafe fn familyName(&self) -> Retained { - unsafe { msg_send_id![self, familyName] } + unsafe { msg_send![self, familyName] } } } @@ -30,7 +30,7 @@ extern_methods!( #[cfg(feature = "MTLRenderPipeline")] unsafe impl MTLRenderPipelineReflection { #[cfg(feature = "MTLDevice")] - #[method_id(initWithVertexData:fragmentData:serializedVertexDescriptor:device:options:flags:)] + #[method(initWithVertexData:fragmentData:serializedVertexDescriptor:device:options:flags:)] pub unsafe fn initWithVertexData( this: Allocated, vertex_data: *mut c_void, @@ -41,7 +41,7 @@ extern_methods!( flags: u64, ) -> Option>; - #[method_id(newSerializedVertexDataWithFlags:error:_)] + #[method(newSerializedVertexDataWithFlags:error:_)] pub unsafe fn newSerializedVertexDataWithFlags_error( &self, flags: u64, @@ -63,7 +63,7 @@ extern_methods!( extern_methods!( #[cfg(feature = "MTLVertexDescriptor")] unsafe impl MTLVertexDescriptor { - #[method_id(newSerializedDescriptor)] + #[method(newSerializedDescriptor)] pub unsafe fn newSerializedDescriptor(&self) -> Option>; } ); diff --git a/framework-crates/objc2-web-kit/examples/browser.rs b/framework-crates/objc2-web-kit/examples/browser.rs index cf8631668..fc156d2a6 100644 --- a/framework-crates/objc2-web-kit/examples/browser.rs +++ b/framework-crates/objc2-web-kit/examples/browser.rs @@ -4,7 +4,7 @@ use core::cell::OnceCell; use objc2::{ - define_class, msg_send_id, + define_class, msg_send, rc::Retained, runtime::{AnyObject, ProtocolObject, Sel}, sel, DefinedClass, MainThreadMarker, MainThreadOnly, @@ -297,7 +297,7 @@ impl Delegate { fn new(mtm: MainThreadMarker) -> Retained { let this = Self::alloc(mtm); let this = this.set_ivars(Ivars::default()); - unsafe { msg_send_id![super(this), init] } + unsafe { msg_send![super(this), init] } } } diff --git a/framework-crates/objc2-web-kit/src/lib.rs b/framework-crates/objc2-web-kit/src/lib.rs index 7a56d5e25..812528ef6 100644 --- a/framework-crates/objc2-web-kit/src/lib.rs +++ b/framework-crates/objc2-web-kit/src/lib.rs @@ -34,7 +34,7 @@ extern_methods!( #[cfg(feature = "WKNavigationAction")] unsafe impl WKNavigationAction { #[cfg(feature = "WKFrameInfo")] - #[method_id(sourceFrame)] + #[method(sourceFrame)] pub unsafe fn sourceFrame(&self) -> Option>; } ); diff --git a/generated b/generated index 11aab97d4..320b4bc62 160000 --- a/generated +++ b/generated @@ -1 +1 @@ -Subproject commit 11aab97d4e1f980455f13277bf4614fb491c12df +Subproject commit 320b4bc6266f90edbede5b449c2db4c93b4b5539