From b006791714ca51379a57d09bf25fab9cb84c24d0 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 28 Sep 2023 13:37:46 +0200 Subject: [PATCH] Change Allocated in preparation for arbitrary self types --- crates/header-translator/src/method.rs | 2 +- .../icrate/src/additions/Foundation/data.rs | 2 +- .../icrate/src/additions/Foundation/string.rs | 2 +- .../icrate/src/additions/Foundation/thread.rs | 2 +- crates/icrate/src/additions/Metal/private.rs | 2 +- crates/icrate/src/fixes/Foundation/NSUUID.rs | 5 +- crates/icrate/src/generated | 2 +- crates/icrate/tests/mutable_array.rs | 2 +- .../src/__macro_helpers/declare_class.rs | 4 +- .../src/__macro_helpers/method_family.rs | 4 +- .../objc2/src/__macro_helpers/msg_send_id.rs | 81 +++---- crates/objc2/src/macros/extern_methods.rs | 4 +- crates/objc2/src/macros/mod.rs | 13 +- crates/objc2/src/rc/allocated.rs | 78 +++++-- crates/objc2/src/rc/test_object.rs | 2 +- crates/objc2/src/runtime/message_receiver.rs | 7 +- crates/objc2/src/top_level_traits.rs | 2 +- crates/objc2/tests/track_caller.rs | 7 +- .../expected/apple-aarch64.s | 80 ++++--- .../expected/apple-armv7.s | 65 +++--- .../expected/apple-armv7s.s | 65 +++--- .../test_msg_send_error/expected/apple-x86.s | 57 ++--- .../expected/apple-x86_64.s | 47 ++-- .../expected/gnustep-x86.s | 68 +++--- .../expected/gnustep-x86_64.s | 61 ++---- .../crates/test_msg_send_error/lib.rs | 10 +- .../test_msg_send_id/expected/apple-aarch64.s | 78 +++---- .../test_msg_send_id/expected/apple-armv7.s | 58 ++--- .../test_msg_send_id/expected/apple-armv7s.s | 58 ++--- .../test_msg_send_id/expected/apple-x86.s | 78 ++----- .../test_msg_send_id/expected/apple-x86_64.s | 53 ++--- .../test_msg_send_id/expected/gnustep-x86.s | 206 +++++++----------- .../expected/gnustep-x86_64.s | 113 ++++------ .../crates/test_msg_send_id/lib.rs | 14 +- .../ui/declare_class_invalid_type2.stderr | 8 +- .../ui/extern_methods_invalid_receiver.rs | 28 +++ .../ui/extern_methods_invalid_receiver.stderr | 45 ++++ .../test-ui/ui/extern_methods_invalid_type.rs | 4 +- .../ui/extern_methods_invalid_type.stderr | 40 ++-- .../extern_methods_not_allowed_mutable.stderr | 2 +- .../ui/main_thread_only_not_allocable.stderr | 2 +- .../ui/msg_send_id_alloc_init_different.rs | 4 +- .../msg_send_id_alloc_init_different.stderr | 8 +- .../ui/msg_send_id_invalid_receiver.stderr | 24 +- .../test-ui/ui/msg_send_id_invalid_return.rs | 10 +- .../ui/msg_send_id_invalid_return.stderr | 51 +++-- .../ui/msg_send_not_allowed_mutable.stderr | 2 +- .../ui/msg_send_underspecified_error.stderr | 6 +- 48 files changed, 682 insertions(+), 884 deletions(-) create mode 100644 crates/test-ui/ui/extern_methods_invalid_receiver.rs create mode 100644 crates/test-ui/ui/extern_methods_invalid_receiver.stderr diff --git a/crates/header-translator/src/method.rs b/crates/header-translator/src/method.rs index 7a3d97b8e..6aad2fb51 100644 --- a/crates/header-translator/src/method.rs +++ b/crates/header-translator/src/method.rs @@ -686,7 +686,7 @@ impl fmt::Display for Method { // Receiver if let MemoryManagement::IdInit = self.memory_management { - write!(f, "this: Option>, ")?; + write!(f, "this: Allocated, ")?; } else if self.is_class { // Insert nothing; a class method is assumed } else if self.mutating { diff --git a/crates/icrate/src/additions/Foundation/data.rs b/crates/icrate/src/additions/Foundation/data.rs index 717d1355b..8e9292536 100644 --- a/crates/icrate/src/additions/Foundation/data.rs +++ b/crates/icrate/src/additions/Foundation/data.rs @@ -267,7 +267,7 @@ impl IdFromIterator for NSMutableData { } #[cfg(feature = "block")] -unsafe fn with_vec(obj: Option>, bytes: Vec) -> Id { +unsafe fn with_vec(obj: Allocated, bytes: Vec) -> Id { use core::mem::ManuallyDrop; use block2::{Block, ConcreteBlock}; diff --git a/crates/icrate/src/additions/Foundation/string.rs b/crates/icrate/src/additions/Foundation/string.rs index e893348ae..34794bdb6 100644 --- a/crates/icrate/src/additions/Foundation/string.rs +++ b/crates/icrate/src/additions/Foundation/string.rs @@ -144,7 +144,7 @@ impl NSMutableString { } } -unsafe fn init_with_str(obj: Option>, string: &str) -> Id { +unsafe fn init_with_str(obj: Allocated, string: &str) -> Id { let bytes: *const c_void = string.as_ptr().cast(); // We use `msg_send_id` instead of the generated method from `icrate`, // since that assumes the encoding is `usize`, whereas GNUStep assumes diff --git a/crates/icrate/src/additions/Foundation/thread.rs b/crates/icrate/src/additions/Foundation/thread.rs index cea25d217..2cc804cc2 100644 --- a/crates/icrate/src/additions/Foundation/thread.rs +++ b/crates/icrate/src/additions/Foundation/thread.rs @@ -157,7 +157,7 @@ impl MainThreadMarker { /// let obj: Id = unsafe { msg_send_id![obj, init] }; /// ``` #[inline] - pub fn alloc(self) -> Option> { + pub fn alloc(self) -> Allocated { // SAFETY: Same as `ClassType::alloc`, with the addition that since we // take `self: MainThreadMarker`, the `IsAllocableAnyThread` bound is // not required. diff --git a/crates/icrate/src/additions/Metal/private.rs b/crates/icrate/src/additions/Metal/private.rs index fed5db715..b211b9182 100644 --- a/crates/icrate/src/additions/Metal/private.rs +++ b/crates/icrate/src/additions/Metal/private.rs @@ -27,7 +27,7 @@ extern_methods!( #[cfg(feature = "Metal_MTLDevice")] #[method_id(initWithVertexData:fragmentData:serializedVertexDescriptor:device:options:flags:)] pub unsafe fn initWithVertexData( - this: Option>, + this: Allocated, vertex_data: *mut c_void, fragment_data: *mut c_void, vertex_desc: *mut c_void, diff --git a/crates/icrate/src/fixes/Foundation/NSUUID.rs b/crates/icrate/src/fixes/Foundation/NSUUID.rs index c08516fbb..c982c74a3 100644 --- a/crates/icrate/src/fixes/Foundation/NSUUID.rs +++ b/crates/icrate/src/fixes/Foundation/NSUUID.rs @@ -19,10 +19,7 @@ unsafe impl RefEncode for UuidBytes { extern_methods!( unsafe impl Foundation::NSUUID { #[method_id(initWithUUIDBytes:)] - pub(crate) fn initWithUUIDBytes( - this: Option>, - bytes: &UuidBytes, - ) -> Id; + pub(crate) fn initWithUUIDBytes(this: Allocated, bytes: &UuidBytes) -> Id; #[method(getUUIDBytes:)] pub(crate) fn getUUIDBytes(&self, bytes: &mut UuidBytes); diff --git a/crates/icrate/src/generated b/crates/icrate/src/generated index ea169f942..8b603c27e 160000 --- a/crates/icrate/src/generated +++ b/crates/icrate/src/generated @@ -1 +1 @@ -Subproject commit ea169f942ef758aacbdd073883d578ebb59389c5 +Subproject commit 8b603c27ed958b521463533d1ace21df855861a4 diff --git a/crates/icrate/tests/mutable_array.rs b/crates/icrate/tests/mutable_array.rs index 4a326807d..38ccab0c1 100644 --- a/crates/icrate/tests/mutable_array.rs +++ b/crates/icrate/tests/mutable_array.rs @@ -123,7 +123,7 @@ fn test_threaded() { s.spawn(|| { let array = >::alloc(); - assert!(array.is_some()); + let _ = NSMutableArray::init(array); }); }); } diff --git a/crates/objc2/src/__macro_helpers/declare_class.rs b/crates/objc2/src/__macro_helpers/declare_class.rs index 76a384fe6..df96f6b06 100644 --- a/crates/objc2/src/__macro_helpers/declare_class.rs +++ b/crates/objc2/src/__macro_helpers/declare_class.rs @@ -46,7 +46,7 @@ where } // Explicitly left unimplemented for now! -// impl MessageRecieveId>> for Alloc {} +// impl MessageRecieveId> for Alloc {} // Note: `MethodImplementation` allows for `Allocated` as the receiver, so we // restrict it here to only be when the selector is `init`. @@ -56,7 +56,7 @@ where impl MessageRecieveId, Ret> for Init where T: Message, - Ret: MaybeOptionId>, + Ret: MaybeOptionId>>, { #[inline] fn into_return(obj: Ret) -> IdReturnValue { diff --git a/crates/objc2/src/__macro_helpers/method_family.rs b/crates/objc2/src/__macro_helpers/method_family.rs index d01d9d538..1a12994e1 100644 --- a/crates/objc2/src/__macro_helpers/method_family.rs +++ b/crates/objc2/src/__macro_helpers/method_family.rs @@ -13,8 +13,8 @@ /// retainable object pointer type - we ensure this by making /// `message_send_id` return `Id`. /// - `init`: The method must be an instance method and must return an -/// Objective-C pointer type - We ensure this by taking -/// `Option>`, which means it can't be a class method! +/// Objective-C pointer type - We ensure this by taking `Allocated`, +/// which means it can't be a class method! /// /// // TODO: Use an enum instead of u8 here when stable diff --git a/crates/objc2/src/__macro_helpers/msg_send_id.rs b/crates/objc2/src/__macro_helpers/msg_send_id.rs index 16b0c4f3f..5d6698b60 100644 --- a/crates/objc2/src/__macro_helpers/msg_send_id.rs +++ b/crates/objc2/src/__macro_helpers/msg_send_id.rs @@ -19,17 +19,17 @@ pub trait MsgSendId { /// `send_message_id` with that, and return an error if one occurred. #[inline] #[track_caller] - unsafe fn send_message_id_error(obj: T, sel: Sel, args: A) -> Result> + unsafe fn send_message_id_error(obj: T, sel: Sel, args: A) -> Result> where *mut *mut E: Encode, A: TupleExtender<*mut *mut E>, >::PlusOneArgument: ConvertArguments, E: Message, - Option: MaybeUnwrap, + Option: MaybeUnwrap, { let mut err: *mut E = ptr::null_mut(); let args = args.add_argument(&mut err); - let res: Option = unsafe { Self::send_message_id(obj, sel, args) }; + let res: Option = unsafe { Self::send_message_id(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 @@ -66,9 +66,9 @@ unsafe fn encountered_error(err: *mut E) -> Id { unsafe { Id::retain(err) }.expect("error parameter should be set if the method returns NULL") } -impl MsgSendId> for New { +impl MsgSendId>> for New { #[inline] - unsafe fn send_message_id>>( + unsafe fn send_message_id>>>( obj: T, sel: Sel, args: A, @@ -96,18 +96,18 @@ impl MsgSendId<&'_ AnyClass, Allocated> for Alloc { 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, (cls, sel)) + R::maybe_unwrap::(obj, ()) } } -impl MsgSendId>, Id> for Init { +impl MsgSendId, Option>> for Init { #[inline] - unsafe fn send_message_id>>( - obj: Option>, + unsafe fn send_message_id>>>( + obj: Allocated, sel: Sel, args: A, ) -> R { - let ptr = Allocated::option_into_ptr(obj); + 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. @@ -121,9 +121,9 @@ impl MsgSendId>, Id> for Init { } } -impl MsgSendId> for CopyOrMutCopy { +impl MsgSendId>> for CopyOrMutCopy { #[inline] - unsafe fn send_message_id>>( + unsafe fn send_message_id>>>( obj: T, sel: Sel, args: A, @@ -137,9 +137,9 @@ impl MsgSendId> for CopyOrMutCopy { } } -impl MsgSendId> for Other { +impl MsgSendId>> for Other { #[inline] - unsafe fn send_message_id>>( + unsafe fn send_message_id>>>( obj: T, sel: Sel, args: A, @@ -163,11 +163,11 @@ impl MsgSendId> for Other { pub trait MaybeUnwrap { type Input; #[track_caller] - fn maybe_unwrap<'a, F: MsgSendIdFailed<'a>>(obj: Option, args: F::Args) -> Self; + fn maybe_unwrap<'a, F: MsgSendIdFailed<'a>>(obj: Self::Input, args: F::Args) -> Self; } impl MaybeUnwrap for Option> { - type Input = Id; + type Input = Option>; #[inline] fn maybe_unwrap<'a, F: MsgSendIdFailed<'a>>(obj: Option>, _args: F::Args) -> Self { @@ -176,7 +176,7 @@ impl MaybeUnwrap for Option> { } impl MaybeUnwrap for Id { - type Input = Id; + type Input = Option>; #[inline] fn maybe_unwrap<'a, F: MsgSendIdFailed<'a>>(obj: Option>, args: F::Args) -> Self { @@ -187,24 +187,12 @@ impl MaybeUnwrap for Id { } } -impl MaybeUnwrap for Option> { - type Input = Allocated; - - #[inline] - fn maybe_unwrap<'a, F: MsgSendIdFailed<'a>>(obj: Option>, _args: F::Args) -> Self { - obj - } -} - impl MaybeUnwrap for Allocated { type Input = Allocated; #[inline] - fn maybe_unwrap<'a, F: MsgSendIdFailed<'a>>(obj: Option>, args: F::Args) -> Self { - match obj { - Some(obj) => obj, - None => F::failed(args), - } + fn maybe_unwrap<'a, F: MsgSendIdFailed<'a>>(obj: Allocated, _args: F::Args) -> Self { + obj } } @@ -244,15 +232,11 @@ impl<'a> MsgSendIdFailed<'a> for New { } impl<'a> MsgSendIdFailed<'a> for Alloc { - type Args = (&'a AnyClass, Sel); + type Args = (); #[cold] - fn failed((cls, sel): Self::Args) -> ! { - if sel == sel!(alloc) { - panic!("failed allocating {cls}") - } else { - panic!("failed allocating with +[{cls} {sel}]") - } + fn failed(_: Self::Args) -> ! { + unreachable!() } } @@ -385,18 +369,25 @@ mod tests { let mut expected = __ThreadTestData::current(); let cls = __RcTestObject::class(); - let obj: Option> = unsafe { msg_send_id![cls, alloc] }; + let obj: Allocated<__RcTestObject> = unsafe { msg_send_id![cls, alloc] }; expected.alloc += 1; + expected.assert_current(); + // Don't check allocation error let _obj: Id<__RcTestObject> = unsafe { msg_send_id![obj, init] }; expected.init += 1; expected.assert_current(); - let obj: Option> = unsafe { msg_send_id![cls, alloc] }; + let obj: Allocated<__RcTestObject> = unsafe { msg_send_id![cls, alloc] }; expected.alloc += 1; + expected.assert_current(); + // Check allocation error before init - let obj = obj.unwrap(); - let _obj: Id<__RcTestObject> = unsafe { msg_send_id![Some(obj), init] }; + let obj = Allocated::into_ptr(obj); + assert!(!obj.is_null()); + let obj = unsafe { Allocated::new(obj) }; + + let _obj: Id<__RcTestObject> = unsafe { msg_send_id![obj, init] }; expected.init += 1; expected.assert_current(); } @@ -474,7 +465,6 @@ mod tests { } #[test] - #[should_panic = "failed allocating with +[__RcTestObject allocReturningNull]"] fn test_alloc_with_null() { let _obj: Allocated<__RcTestObject> = unsafe { msg_send_id![__RcTestObject::class(), allocReturningNull] }; @@ -483,7 +473,7 @@ mod tests { #[test] #[should_panic = "failed initializing object with -initReturningNull"] fn test_init_with_null() { - let obj: Option> = + let obj: Allocated<__RcTestObject> = unsafe { msg_send_id![__RcTestObject::class(), alloc] }; let _obj: Id<__RcTestObject> = unsafe { msg_send_id![obj, initReturningNull] }; } @@ -492,7 +482,8 @@ mod tests { #[should_panic = "failed allocating object"] #[cfg(not(debug_assertions))] // Does NULL receiver checks fn test_init_with_null_receiver() { - let obj: Option> = None; + let obj: Allocated<__RcTestObject> = + unsafe { msg_send_id![__RcTestObject::class(), allocReturningNull] }; let _obj: Id<__RcTestObject> = unsafe { msg_send_id![obj, init] }; } diff --git a/crates/objc2/src/macros/extern_methods.rs b/crates/objc2/src/macros/extern_methods.rs index 7d9275975..3fe32b354 100644 --- a/crates/objc2/src/macros/extern_methods.rs +++ b/crates/objc2/src/macros/extern_methods.rs @@ -97,7 +97,7 @@ /// #[method_id(initWithVal:)] /// // Arbitary self types are not stable, but we can work around it /// // with the special name `this`. -/// pub fn init(this: Option>, val: usize) -> Id; +/// pub fn init(this: Allocated, val: usize) -> Id; /// } /// /// /// Instance accessor methods. @@ -150,7 +150,7 @@ /// unsafe { msg_send_id![Self::class(), new] } /// } /// -/// pub fn init(this: Option>, val: usize) -> Id { +/// pub fn init(this: Allocated, val: usize) -> Id { /// unsafe { msg_send_id![this, initWithVal: val] } /// } /// } diff --git a/crates/objc2/src/macros/mod.rs b/crates/objc2/src/macros/mod.rs index 49deeaea2..a5adb07a9 100644 --- a/crates/objc2/src/macros/mod.rs +++ b/crates/objc2/src/macros/mod.rs @@ -1081,12 +1081,11 @@ macro_rules! msg_send_bool { /// return type is a generic `Id` or `Option>`. /// /// - The `alloc` family: The receiver must be `&AnyClass`, and the return -/// type is a generic `Allocated` or `Option>`. +/// type is a generic `Allocated`. /// -/// - The `init` family: The receiver must be `Option>` as -/// returned from `alloc`. The receiver is consumed, and a the -/// now-initialized `Id` or `Option>` (with the same `T`) is -/// returned. +/// - The `init` family: The receiver must be `Allocated` as returned from +/// `alloc`. The receiver is consumed, and a the now-initialized `Id` 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 `Id` or @@ -1276,7 +1275,7 @@ macro_rules! __msg_send_id_helper { ($($selector:tt)*) ($($argument:expr,)*) } => ({ - <$crate::__macro_helpers::$retain_semantics as $crate::__macro_helpers::MsgSendId<_, _>>::$fn::<_, _>( + <$crate::__macro_helpers::$retain_semantics as $crate::__macro_helpers::MsgSendId<_, _>>::$fn( $obj, $crate::sel!($($selector)*), ($($argument,)*), @@ -1296,7 +1295,7 @@ macro_rules! __msg_send_id_helper { let result; result = <$crate::__macro_helpers::RetainSemantics<{ $crate::__macro_helpers::retain_semantics(__SELECTOR_DATA) - }> as $crate::__macro_helpers::MsgSendId<_, _>>::$fn::<_, _>( + }> as $crate::__macro_helpers::MsgSendId<_, _>>::$fn( $obj, $crate::__sel_inner!( __SELECTOR_DATA, diff --git a/crates/objc2/src/rc/allocated.rs b/crates/objc2/src/rc/allocated.rs index a992ee16a..a8bc01a4c 100644 --- a/crates/objc2/src/rc/allocated.rs +++ b/crates/objc2/src/rc/allocated.rs @@ -1,18 +1,21 @@ use core::fmt; use core::marker::PhantomData; -use core::mem::{self, ManuallyDrop}; -use core::ptr::NonNull; +use core::mem::ManuallyDrop; -use crate::runtime::objc_release_fast; +use crate::runtime::{objc_release_fast, AnyObject}; use crate::Message; /// A marker type that can be used to indicate that the object has been /// allocated but not initialized. /// +/// TODO. +/// /// The reason we use `Allocated` / `Option>` instead of /// `*mut T` is: /// - To allow releasing allocated objects, e.g. in the face of panics. /// - To safely know the object is valid (albeit uninitialized). +/// +/// Superclass instance variables may or may not have been initialized.... // // Note that there is no way to get something mutable out of `Allocated` // unless you're defining the object. @@ -31,42 +34,56 @@ pub struct Allocated { /// We don't use `Id` here, since that has different auto-trait impls, and /// requires in it's safety contract that the object is initialized (which /// makes it difficult to ensure correctness if such things are split - /// across different files). + /// across different files). Additionally, we want to have fine control + /// over NULL-ness. /// - /// Variance is same as `Id`. - ptr: NonNull, + /// Covariance is correct, same as `Id`. + ptr: *const T, // Intentially not `NonNull`! /// Necessary for dropck, as with `Id`. p: PhantomData, + /// Necessary for auto traits. + p_auto_traits: PhantomData, } // We _could_ probably implement auto traits `Send` and `Sync` here, but to be -// safe, we won't. - -// Explicitly don't implement `Deref`, `Message` nor `RefEncode`! +// safe, we won't for now. +// +// Explicitly don't implement `Deref`, `Message` nor `RefEncode`, though! impl Allocated { /// # Safety /// /// The caller must ensure the given object has +1 retain count, and that /// the object behind the pointer has been allocated (but not yet - /// initialized). + /// initialized), or that the pointer is NULL. #[inline] - pub(crate) unsafe fn new(ptr: *mut T) -> Option { - NonNull::new(ptr).map(|ptr| Self { + pub unsafe fn new(ptr: *mut T) -> Self { + Self { ptr, p: PhantomData, - }) + p_auto_traits: PhantomData, + } } +} +impl Allocated { + /// TODO #[inline] - pub(crate) fn option_into_ptr(this: Option) -> *mut T { - let ptr = this.map(|this| ManuallyDrop::new(this).ptr); + pub fn as_ptr(this: &Self) -> *const T { + this.ptr + } - // Difficult to write this in an ergonomic way with `?Sized`, so we - // hack it with transmute. - // - // SAFETY: `Option>` has the same size as `*mut T`. - unsafe { mem::transmute::>, *mut T>(ptr) } + /// TODO + #[inline] + pub fn as_mut_ptr(this: &mut Self) -> *mut T { + this.ptr as *mut T + } + + /// TODO + #[inline] + pub fn into_ptr(this: Self) -> *mut T { + let this = ManuallyDrop::new(this); + this.ptr as *mut T } } @@ -77,13 +94,30 @@ impl Drop for Allocated { // destructors are written to take into account that the object may // not have been initialized. // + // This is also safe in the case where the object is NULL, + // since `objc_release` allows NULL pointers. + // // Rest is same as `Id`'s `Drop`. - unsafe { objc_release_fast(self.ptr.as_ptr().cast()) }; + unsafe { objc_release_fast(Self::as_mut_ptr(self).cast()) }; } } impl fmt::Pointer for Allocated { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Pointer::fmt(&self.ptr.as_ptr(), f) + fmt::Pointer::fmt(&Self::as_ptr(self), f) + } +} + +#[cfg(test)] +mod tests { + use core::panic::{RefUnwindSafe, UnwindSafe}; + + use static_assertions::assert_not_impl_any; + + use super::*; + + #[test] + fn auto_traits() { + assert_not_impl_any!(Allocated<()>: Send, Sync, UnwindSafe, RefUnwindSafe, Unpin); } } diff --git a/crates/objc2/src/rc/test_object.rs b/crates/objc2/src/rc/test_object.rs index 2faed6de2..aea9c462d 100644 --- a/crates/objc2/src/rc/test_object.rs +++ b/crates/objc2/src/rc/test_object.rs @@ -271,7 +271,7 @@ declare_class!( } None } else { - unsafe { msg_send_id![Some(this), init] } + unsafe { msg_send_id![this, init] } } } diff --git a/crates/objc2/src/runtime/message_receiver.rs b/crates/objc2/src/runtime/message_receiver.rs index bc637cf15..7f5497394 100644 --- a/crates/objc2/src/runtime/message_receiver.rs +++ b/crates/objc2/src/runtime/message_receiver.rs @@ -482,9 +482,11 @@ unsafe impl<'a> MessageReceiver for &'a AnyClass { #[cfg(test)] mod tests { + use core::ptr; + use super::*; use crate::mutability; - use crate::rc::Id; + use crate::rc::{Allocated, Id}; use crate::runtime::NSObject; use crate::test_utils; use crate::{declare_class, msg_send, msg_send_id, ClassType}; @@ -568,7 +570,8 @@ mod tests { assert!(result.is_none()); // This result should not be relied on - let result: Option> = unsafe { msg_send_id![None, init] }; + let obj = unsafe { Allocated::new(ptr::null_mut()) }; + let result: Option> = unsafe { msg_send_id![obj, init] }; assert!(result.is_none()); } diff --git a/crates/objc2/src/top_level_traits.rs b/crates/objc2/src/top_level_traits.rs index 5a5009e0c..8f00b8b22 100644 --- a/crates/objc2/src/top_level_traits.rs +++ b/crates/objc2/src/top_level_traits.rs @@ -287,7 +287,7 @@ pub unsafe trait ClassType: Message { // but `ClassType` is more often already in scope, allowing easier access // to `T::alloc()`. #[inline] - fn alloc() -> Option> + fn alloc() -> Allocated where Self: IsAllocableAnyThread, { diff --git a/crates/objc2/tests/track_caller.rs b/crates/objc2/tests/track_caller.rs index 8c8640ede..303c0863c 100644 --- a/crates/objc2/tests/track_caller.rs +++ b/crates/objc2/tests/track_caller.rs @@ -152,9 +152,10 @@ pub fn test_id_unwrap(checker: &PanicChecker) { let _obj: Id<__RcTestObject> = unsafe { msg_send_id![cls, newReturningNull] }; }); - let msg = "failed allocating with +[__RcTestObject allocReturningNull]"; - checker.assert_panics(msg, line!() + 1, || { - let _obj: Allocated<__RcTestObject> = unsafe { msg_send_id![cls, allocReturningNull] }; + let msg = "failed allocating object"; + checker.assert_panics(msg, line!() + 2, || { + let obj: Allocated<__RcTestObject> = unsafe { msg_send_id![cls, allocReturningNull] }; + let _obj: Id<__RcTestObject> = unsafe { msg_send_id![obj, init] }; }); let msg = "failed initializing object with -initReturningNull"; diff --git a/crates/test-assembly/crates/test_msg_send_error/expected/apple-aarch64.s b/crates/test-assembly/crates/test_msg_send_error/expected/apple-aarch64.s index 0e52c8802..1e6047f04 100644 --- a/crates/test-assembly/crates/test_msg_send_error/expected/apple-aarch64.s +++ b/crates/test-assembly/crates/test_msg_send_error/expected/apple-aarch64.s @@ -96,30 +96,19 @@ Lloh7: .globl _error_alloc .p2align 2 _error_alloc: - sub sp, sp, #32 - stp x29, x30, [sp, #16] - add x29, sp, #16 - str xzr, [sp, #8] - add x2, sp, #8 - bl _objc_msgSend - cbz x0, LBB4_2 - mov x1, x0 - mov x0, #0 - ldp x29, x30, [sp, #16] - add sp, sp, #32 - ret -LBB4_2: - ldr x0, [sp, #8] + stp x29, x30, [sp, #-16]! + mov x29, sp Lloh8: - adrp x1, l_anon.[ID].5@PAGE + adrp x0, l_anon.[ID].5@PAGE Lloh9: - add x1, x1, l_anon.[ID].5@PAGEOFF - bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) - mov x1, x0 - mov w0, #1 - ldp x29, x30, [sp, #16] - add sp, sp, #32 - ret + add x0, x0, l_anon.[ID].5@PAGEOFF +Lloh10: + adrp x2, l_anon.[ID].6@PAGE +Lloh11: + add x2, x2, l_anon.[ID].6@PAGEOFF + mov w1, #15 + bl SYM(core::panicking::panic::GENERATED_ID, 0) + .loh AdrpAdd Lloh10, Lloh11 .loh AdrpAdd Lloh8, Lloh9 .globl _error_init @@ -139,17 +128,17 @@ _error_init: ret LBB5_2: ldr x0, [sp, #8] -Lloh10: - adrp x1, l_anon.[ID].6@PAGE -Lloh11: - add x1, x1, l_anon.[ID].6@PAGEOFF +Lloh12: + adrp x1, l_anon.[ID].7@PAGE +Lloh13: + add x1, x1, l_anon.[ID].7@PAGEOFF bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov x1, x0 mov w0, #1 ldp x29, x30, [sp, #16] add sp, sp, #32 ret - .loh AdrpAdd Lloh10, Lloh11 + .loh AdrpAdd Lloh12, Lloh13 .globl _error_copy .p2align 2 @@ -168,17 +157,17 @@ _error_copy: ret LBB6_2: ldr x0, [sp, #8] -Lloh12: - adrp x1, l_anon.[ID].7@PAGE -Lloh13: - add x1, x1, l_anon.[ID].7@PAGEOFF +Lloh14: + adrp x1, l_anon.[ID].8@PAGE +Lloh15: + add x1, x1, l_anon.[ID].8@PAGEOFF bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov x1, x0 mov w0, #1 ldp x29, x30, [sp, #16] add sp, sp, #32 ret - .loh AdrpAdd Lloh12, Lloh13 + .loh AdrpAdd Lloh14, Lloh15 .globl _error_autoreleased .p2align 2 @@ -201,17 +190,17 @@ _error_autoreleased: ret LBB7_2: ldr x0, [sp, #8] -Lloh14: - adrp x1, l_anon.[ID].8@PAGE -Lloh15: - add x1, x1, l_anon.[ID].8@PAGEOFF +Lloh16: + adrp x1, l_anon.[ID].9@PAGE +Lloh17: + add x1, x1, l_anon.[ID].9@PAGEOFF bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov x1, x0 mov w0, #1 ldp x29, x30, [sp, #16] add sp, sp, #32 ret - .loh AdrpAdd Lloh14, Lloh15 + .loh AdrpAdd Lloh16, Lloh17 .section __TEXT,__const l_anon.[ID].0: @@ -234,24 +223,29 @@ l_anon.[ID].4: .quad l_anon.[ID].2 .asciz "6\000\000\000\000\000\000\000\017\000\000\000\005\000\000" - .p2align 3, 0x0 + .section __TEXT,__const l_anon.[ID].5: - .quad l_anon.[ID].2 - .asciz "6\000\000\000\000\000\000\000\024\000\000\000\005\000\000" + .ascii "not implemented" + .section __DATA,__const .p2align 3, 0x0 l_anon.[ID].6: .quad l_anon.[ID].2 - .asciz "6\000\000\000\000\000\000\000\031\000\000\000\005\000\000" + .asciz "6\000\000\000\000\000\000\000\026\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].7: .quad l_anon.[ID].2 - .asciz "6\000\000\000\000\000\000\000\036\000\000\000\005\000\000" + .asciz "6\000\000\000\000\000\000\000\033\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].8: .quad l_anon.[ID].2 - .asciz "6\000\000\000\000\000\000\000#\000\000\000\005\000\000" + .asciz "6\000\000\000\000\000\000\000 \000\000\000\005\000\000" + + .p2align 3, 0x0 +l_anon.[ID].9: + .quad l_anon.[ID].2 + .asciz "6\000\000\000\000\000\000\000%\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_error/expected/apple-armv7.s b/crates/test-assembly/crates/test_msg_send_error/expected/apple-armv7.s index 99e97b936..5b64a13f1 100644 --- a/crates/test-assembly/crates/test_msg_send_error/expected/apple-armv7.s +++ b/crates/test-assembly/crates/test_msg_send_error/expected/apple-armv7.s @@ -98,31 +98,19 @@ LPC3_0: .p2align 2 .code 32 _error_alloc: - push {r4, r7, lr} - add r7, sp, #4 - sub sp, sp, #4 - mov r4, #0 - mov r2, sp - str r4, [sp] - bl _objc_msgSend - mov r1, r0 - cmp r0, #0 - beq LBB4_2 - mov r0, r4 - sub sp, r7, #4 - pop {r4, r7, pc} -LBB4_2: - ldr r0, [sp] - movw r1, :lower16:(l_anon.[ID].5-(LPC4_0+8)) - movt r1, :upper16:(l_anon.[ID].5-(LPC4_0+8)) + push {r7, lr} + mov r7, sp + movw r0, :lower16:(l_anon.[ID].5-(LPC4_0+8)) + mov r1, #15 + movt r0, :upper16:(l_anon.[ID].5-(LPC4_0+8)) + movw r2, :lower16:(l_anon.[ID].6-(LPC4_1+8)) + movt r2, :upper16:(l_anon.[ID].6-(LPC4_1+8)) LPC4_0: - add r1, pc, r1 - bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) - mov r1, r0 - mov r4, #1 - mov r0, r4 - sub sp, r7, #4 - pop {r4, r7, pc} + add r0, pc, r0 +LPC4_1: + add r2, pc, r2 + mov lr, pc + b SYM(core::panicking::panic::GENERATED_ID, 0) .globl _error_init .p2align 2 @@ -143,8 +131,8 @@ _error_init: pop {r4, r7, pc} LBB5_2: ldr r0, [sp] - movw r1, :lower16:(l_anon.[ID].6-(LPC5_0+8)) - movt r1, :upper16:(l_anon.[ID].6-(LPC5_0+8)) + movw r1, :lower16:(l_anon.[ID].7-(LPC5_0+8)) + movt r1, :upper16:(l_anon.[ID].7-(LPC5_0+8)) LPC5_0: add r1, pc, r1 bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) @@ -173,8 +161,8 @@ _error_copy: pop {r4, r7, pc} LBB6_2: ldr r0, [sp] - movw r1, :lower16:(l_anon.[ID].7-(LPC6_0+8)) - movt r1, :upper16:(l_anon.[ID].7-(LPC6_0+8)) + movw r1, :lower16:(l_anon.[ID].8-(LPC6_0+8)) + movt r1, :upper16:(l_anon.[ID].8-(LPC6_0+8)) LPC6_0: add r1, pc, r1 bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) @@ -207,8 +195,8 @@ _error_autoreleased: pop {r4, r7, pc} LBB7_2: ldr r0, [sp] - movw r1, :lower16:(l_anon.[ID].8-(LPC7_0+8)) - movt r1, :upper16:(l_anon.[ID].8-(LPC7_0+8)) + movw r1, :lower16:(l_anon.[ID].9-(LPC7_0+8)) + movt r1, :upper16:(l_anon.[ID].9-(LPC7_0+8)) LPC7_0: add r1, pc, r1 bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) @@ -239,24 +227,29 @@ l_anon.[ID].4: .long l_anon.[ID].2 .asciz "6\000\000\000\017\000\000\000\005\000\000" - .p2align 2, 0x0 + .section __TEXT,__const l_anon.[ID].5: - .long l_anon.[ID].2 - .asciz "6\000\000\000\024\000\000\000\005\000\000" + .ascii "not implemented" + .section __DATA,__const .p2align 2, 0x0 l_anon.[ID].6: .long l_anon.[ID].2 - .asciz "6\000\000\000\031\000\000\000\005\000\000" + .asciz "6\000\000\000\026\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].7: .long l_anon.[ID].2 - .asciz "6\000\000\000\036\000\000\000\005\000\000" + .asciz "6\000\000\000\033\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].8: .long l_anon.[ID].2 - .asciz "6\000\000\000#\000\000\000\005\000\000" + .asciz "6\000\000\000 \000\000\000\005\000\000" + + .p2align 2, 0x0 +l_anon.[ID].9: + .long l_anon.[ID].2 + .asciz "6\000\000\000%\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_error/expected/apple-armv7s.s b/crates/test-assembly/crates/test_msg_send_error/expected/apple-armv7s.s index 2b29199f2..7fdb9c6b2 100644 --- a/crates/test-assembly/crates/test_msg_send_error/expected/apple-armv7s.s +++ b/crates/test-assembly/crates/test_msg_send_error/expected/apple-armv7s.s @@ -98,31 +98,19 @@ LPC3_0: .p2align 2 .code 32 _error_alloc: - push {r4, r7, lr} - add r7, sp, #4 - sub sp, sp, #4 - mov r4, #0 - mov r2, sp - str r4, [sp] - bl _objc_msgSend - mov r1, r0 - cmp r0, #0 - beq LBB4_2 - mov r0, r4 - sub sp, r7, #4 - pop {r4, r7, pc} -LBB4_2: - movw r1, :lower16:(l_anon.[ID].5-(LPC4_0+8)) - movt r1, :upper16:(l_anon.[ID].5-(LPC4_0+8)) - ldr r0, [sp] + push {r7, lr} + mov r7, sp + movw r0, :lower16:(l_anon.[ID].5-(LPC4_0+8)) + mov r1, #15 + movt r0, :upper16:(l_anon.[ID].5-(LPC4_0+8)) + movw r2, :lower16:(l_anon.[ID].6-(LPC4_1+8)) + movt r2, :upper16:(l_anon.[ID].6-(LPC4_1+8)) LPC4_0: - add r1, pc, r1 - bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) - mov r1, r0 - mov r4, #1 - mov r0, r4 - sub sp, r7, #4 - pop {r4, r7, pc} + add r0, pc, r0 +LPC4_1: + add r2, pc, r2 + mov lr, pc + b SYM(core::panicking::panic::GENERATED_ID, 0) .globl _error_init .p2align 2 @@ -142,8 +130,8 @@ _error_init: sub sp, r7, #4 pop {r4, r7, pc} LBB5_2: - movw r1, :lower16:(l_anon.[ID].6-(LPC5_0+8)) - movt r1, :upper16:(l_anon.[ID].6-(LPC5_0+8)) + movw r1, :lower16:(l_anon.[ID].7-(LPC5_0+8)) + movt r1, :upper16:(l_anon.[ID].7-(LPC5_0+8)) ldr r0, [sp] LPC5_0: add r1, pc, r1 @@ -172,8 +160,8 @@ _error_copy: sub sp, r7, #4 pop {r4, r7, pc} LBB6_2: - movw r1, :lower16:(l_anon.[ID].7-(LPC6_0+8)) - movt r1, :upper16:(l_anon.[ID].7-(LPC6_0+8)) + movw r1, :lower16:(l_anon.[ID].8-(LPC6_0+8)) + movt r1, :upper16:(l_anon.[ID].8-(LPC6_0+8)) ldr r0, [sp] LPC6_0: add r1, pc, r1 @@ -206,8 +194,8 @@ _error_autoreleased: sub sp, r7, #4 pop {r4, r7, pc} LBB7_2: - movw r1, :lower16:(l_anon.[ID].8-(LPC7_0+8)) - movt r1, :upper16:(l_anon.[ID].8-(LPC7_0+8)) + movw r1, :lower16:(l_anon.[ID].9-(LPC7_0+8)) + movt r1, :upper16:(l_anon.[ID].9-(LPC7_0+8)) ldr r0, [sp] LPC7_0: add r1, pc, r1 @@ -239,24 +227,29 @@ l_anon.[ID].4: .long l_anon.[ID].2 .asciz "6\000\000\000\017\000\000\000\005\000\000" - .p2align 2, 0x0 + .section __TEXT,__const l_anon.[ID].5: - .long l_anon.[ID].2 - .asciz "6\000\000\000\024\000\000\000\005\000\000" + .ascii "not implemented" + .section __DATA,__const .p2align 2, 0x0 l_anon.[ID].6: .long l_anon.[ID].2 - .asciz "6\000\000\000\031\000\000\000\005\000\000" + .asciz "6\000\000\000\026\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].7: .long l_anon.[ID].2 - .asciz "6\000\000\000\036\000\000\000\005\000\000" + .asciz "6\000\000\000\033\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].8: .long l_anon.[ID].2 - .asciz "6\000\000\000#\000\000\000\005\000\000" + .asciz "6\000\000\000 \000\000\000\005\000\000" + + .p2align 2, 0x0 +l_anon.[ID].9: + .long l_anon.[ID].2 + .asciz "6\000\000\000%\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_error/expected/apple-x86.s b/crates/test-assembly/crates/test_msg_send_error/expected/apple-x86.s index 22b58b61b..0ba598619 100644 --- a/crates/test-assembly/crates/test_msg_send_error/expected/apple-x86.s +++ b/crates/test-assembly/crates/test_msg_send_error/expected/apple-x86.s @@ -134,39 +134,17 @@ LBB3_2: _error_alloc: push ebp mov ebp, esp - push esi - push eax + sub esp, 8 call L4$pb L4$pb: - pop esi - mov eax, dword ptr [ebp + 8] - mov ecx, dword ptr [ebp + 12] - mov dword ptr [ebp - 8], 0 + pop eax sub esp, 4 - lea edx, [ebp - 8] - push edx + lea ecx, [eax + l_anon.[ID].6-L4$pb] + lea eax, [eax + l_anon.[ID].5-L4$pb] push ecx + push 15 push eax - call _objc_msgSend - add esp, 16 - test eax, eax - je LBB4_2 - mov edx, eax - xor eax, eax - add esp, 4 - pop esi - pop ebp - ret -LBB4_2: - mov ecx, dword ptr [ebp - 8] - lea edx, [esi + l_anon.[ID].5-L4$pb] - call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) - mov edx, eax - mov eax, 1 - add esp, 4 - pop esi - pop ebp - ret + call SYM(core::panicking::panic::GENERATED_ID, 0) .globl _error_init .p2align 4, 0x90 @@ -198,7 +176,7 @@ L5$pb: ret LBB5_2: mov ecx, dword ptr [ebp - 8] - lea edx, [esi + l_anon.[ID].6-L5$pb] + lea edx, [esi + l_anon.[ID].7-L5$pb] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov edx, eax mov eax, 1 @@ -237,7 +215,7 @@ L6$pb: ret LBB6_2: mov ecx, dword ptr [ebp - 8] - lea edx, [esi + l_anon.[ID].7-L6$pb] + lea edx, [esi + l_anon.[ID].8-L6$pb] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov edx, eax mov eax, 1 @@ -285,7 +263,7 @@ L7$pb: ret LBB7_2: mov ecx, dword ptr [ebp - 8] - lea edx, [esi + l_anon.[ID].8-L7$pb] + lea edx, [esi + l_anon.[ID].9-L7$pb] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov edx, eax mov eax, 1 @@ -315,24 +293,29 @@ l_anon.[ID].4: .long l_anon.[ID].2 .asciz "6\000\000\000\017\000\000\000\005\000\000" - .p2align 2, 0x0 + .section __TEXT,__const l_anon.[ID].5: - .long l_anon.[ID].2 - .asciz "6\000\000\000\024\000\000\000\005\000\000" + .ascii "not implemented" + .section __DATA,__const .p2align 2, 0x0 l_anon.[ID].6: .long l_anon.[ID].2 - .asciz "6\000\000\000\031\000\000\000\005\000\000" + .asciz "6\000\000\000\026\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].7: .long l_anon.[ID].2 - .asciz "6\000\000\000\036\000\000\000\005\000\000" + .asciz "6\000\000\000\033\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].8: .long l_anon.[ID].2 - .asciz "6\000\000\000#\000\000\000\005\000\000" + .asciz "6\000\000\000 \000\000\000\005\000\000" + + .p2align 2, 0x0 +l_anon.[ID].9: + .long l_anon.[ID].2 + .asciz "6\000\000\000%\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_error/expected/apple-x86_64.s b/crates/test-assembly/crates/test_msg_send_error/expected/apple-x86_64.s index 3a83ab0c8..4c5ab6660 100644 --- a/crates/test-assembly/crates/test_msg_send_error/expected/apple-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_error/expected/apple-x86_64.s @@ -88,26 +88,10 @@ LBB3_2: _error_alloc: push rbp mov rbp, rsp - sub rsp, 16 - mov qword ptr [rbp - 8], 0 - lea rdx, [rbp - 8] - call _objc_msgSend - test rax, rax - je LBB4_2 - mov rdx, rax - xor eax, eax - add rsp, 16 - pop rbp - ret -LBB4_2: - mov rdi, qword ptr [rbp - 8] - lea rsi, [rip + l_anon.[ID].5] - call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) - mov rdx, rax - mov eax, 1 - add rsp, 16 - pop rbp - ret + lea rdi, [rip + l_anon.[ID].5] + lea rdx, [rip + l_anon.[ID].6] + mov esi, 15 + call SYM(core::panicking::panic::GENERATED_ID, 0) .globl _error_init .p2align 4, 0x90 @@ -127,7 +111,7 @@ _error_init: ret LBB5_2: mov rdi, qword ptr [rbp - 8] - lea rsi, [rip + l_anon.[ID].6] + lea rsi, [rip + l_anon.[ID].7] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov rdx, rax mov eax, 1 @@ -153,7 +137,7 @@ _error_copy: ret LBB6_2: mov rdi, qword ptr [rbp - 8] - lea rsi, [rip + l_anon.[ID].7] + lea rsi, [rip + l_anon.[ID].8] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov rdx, rax mov eax, 1 @@ -186,7 +170,7 @@ _error_autoreleased: ret LBB7_2: mov rdi, qword ptr [rbp - 8] - lea rsi, [rip + l_anon.[ID].8] + lea rsi, [rip + l_anon.[ID].9] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov rdx, rax mov eax, 1 @@ -215,24 +199,29 @@ l_anon.[ID].4: .quad l_anon.[ID].2 .asciz "6\000\000\000\000\000\000\000\017\000\000\000\005\000\000" - .p2align 3, 0x0 + .section __TEXT,__const l_anon.[ID].5: - .quad l_anon.[ID].2 - .asciz "6\000\000\000\000\000\000\000\024\000\000\000\005\000\000" + .ascii "not implemented" + .section __DATA,__const .p2align 3, 0x0 l_anon.[ID].6: .quad l_anon.[ID].2 - .asciz "6\000\000\000\000\000\000\000\031\000\000\000\005\000\000" + .asciz "6\000\000\000\000\000\000\000\026\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].7: .quad l_anon.[ID].2 - .asciz "6\000\000\000\000\000\000\000\036\000\000\000\005\000\000" + .asciz "6\000\000\000\000\000\000\000\033\000\000\000\005\000\000" .p2align 3, 0x0 l_anon.[ID].8: .quad l_anon.[ID].2 - .asciz "6\000\000\000\000\000\000\000#\000\000\000\005\000\000" + .asciz "6\000\000\000\000\000\000\000 \000\000\000\005\000\000" + + .p2align 3, 0x0 +l_anon.[ID].9: + .quad l_anon.[ID].2 + .asciz "6\000\000\000\000\000\000\000%\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_error/expected/gnustep-x86.s b/crates/test-assembly/crates/test_msg_send_error/expected/gnustep-x86.s index 477d92eab..d670ccb8a 100644 --- a/crates/test-assembly/crates/test_msg_send_error/expected/gnustep-x86.s +++ b/crates/test-assembly/crates/test_msg_send_error/expected/gnustep-x86.s @@ -171,45 +171,21 @@ error_new: .type error_alloc,@function error_alloc: push ebx - push edi - push esi - sub esp, 16 - mov esi, dword ptr [esp + 32] - mov edi, dword ptr [esp + 36] + sub esp, 8 call .L4$pb .L4$pb: pop ebx - mov dword ptr [esp + 12], 0 .Ltmp4: add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp4-.L4$pb) - sub esp, 8 - push edi - push esi - call objc_msg_lookup@PLT - add esp, 12 - lea ecx, [esp + 16] + sub esp, 4 + lea eax, [ebx + .Lanon.[ID].6@GOTOFF] + lea ecx, [ebx + .Lanon.[ID].5@GOTOFF] + push eax + push 15 push ecx - push edi - push esi - call eax - add esp, 16 - test eax, eax - je .LBB4_2 - mov edx, eax - xor eax, eax -.LBB4_3: + call SYM(core::panicking::panic::GENERATED_ID, 0)@PLT add esp, 16 - pop esi - pop edi - pop ebx - ret -.LBB4_2: - mov ecx, dword ptr [esp + 12] - lea edx, [ebx + .Lanon.[ID].5@GOTOFF] - call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) - mov edx, eax - mov eax, 1 - jmp .LBB4_3 + ud2 .Lfunc_end4: .size error_alloc, .Lfunc_end4-error_alloc @@ -259,7 +235,7 @@ error_init: .LBB5_4: mov ecx, dword ptr [esp + 12] .LBB5_5: - lea edx, [ebx + .Lanon.[ID].6@GOTOFF] + lea edx, [ebx + .Lanon.[ID].7@GOTOFF] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov edx, eax mov eax, 1 @@ -307,7 +283,7 @@ error_copy: ret .LBB6_2: mov ecx, dword ptr [esp + 12] - lea edx, [ebx + .Lanon.[ID].7@GOTOFF] + lea edx, [ebx + .Lanon.[ID].8@GOTOFF] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov edx, eax mov eax, 1 @@ -358,7 +334,7 @@ error_autoreleased: ret .LBB7_2: mov ecx, dword ptr [esp + 12] - lea edx, [ebx + .Lanon.[ID].8@GOTOFF] + lea edx, [ebx + .Lanon.[ID].9@GOTOFF] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov edx, eax mov eax, 1 @@ -401,19 +377,17 @@ error_autoreleased: .size .Lanon.[ID].4, 16 .type .Lanon.[ID].5,@object - .section .data.rel.ro..Lanon.[ID].5,"aw",@progbits - .p2align 2, 0x0 + .section .rodata..Lanon.[ID].5,"a",@progbits .Lanon.[ID].5: - .long .Lanon.[ID].2 - .asciz "6\000\000\000\024\000\000\000\005\000\000" - .size .Lanon.[ID].5, 16 + .ascii "not implemented" + .size .Lanon.[ID].5, 15 .type .Lanon.[ID].6,@object .section .data.rel.ro..Lanon.[ID].6,"aw",@progbits .p2align 2, 0x0 .Lanon.[ID].6: .long .Lanon.[ID].2 - .asciz "6\000\000\000\031\000\000\000\005\000\000" + .asciz "6\000\000\000\026\000\000\000\005\000\000" .size .Lanon.[ID].6, 16 .type .Lanon.[ID].7,@object @@ -421,7 +395,7 @@ error_autoreleased: .p2align 2, 0x0 .Lanon.[ID].7: .long .Lanon.[ID].2 - .asciz "6\000\000\000\036\000\000\000\005\000\000" + .asciz "6\000\000\000\033\000\000\000\005\000\000" .size .Lanon.[ID].7, 16 .type .Lanon.[ID].8,@object @@ -429,7 +403,15 @@ error_autoreleased: .p2align 2, 0x0 .Lanon.[ID].8: .long .Lanon.[ID].2 - .asciz "6\000\000\000#\000\000\000\005\000\000" + .asciz "6\000\000\000 \000\000\000\005\000\000" .size .Lanon.[ID].8, 16 + .type .Lanon.[ID].9,@object + .section .data.rel.ro..Lanon.[ID].9,"aw",@progbits + .p2align 2, 0x0 +.Lanon.[ID].9: + .long .Lanon.[ID].2 + .asciz "6\000\000\000%\000\000\000\005\000\000" + .size .Lanon.[ID].9, 16 + .section ".note.GNU-stack","",@progbits diff --git a/crates/test-assembly/crates/test_msg_send_error/expected/gnustep-x86_64.s b/crates/test-assembly/crates/test_msg_send_error/expected/gnustep-x86_64.s index 06fd47f8d..9c90e678d 100644 --- a/crates/test-assembly/crates/test_msg_send_error/expected/gnustep-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_error/expected/gnustep-x86_64.s @@ -116,35 +116,12 @@ error_new: .p2align 4, 0x90 .type error_alloc,@function error_alloc: - push r14 - push rbx push rax - mov rbx, rsi - mov r14, rdi - mov qword ptr [rsp], 0 - call qword ptr [rip + objc_msg_lookup@GOTPCREL] - mov rdx, rsp - mov rdi, r14 - mov rsi, rbx - call rax - test rax, rax - je .LBB4_2 - mov rdx, rax - xor eax, eax - add rsp, 8 - pop rbx - pop r14 - ret -.LBB4_2: - mov rdi, qword ptr [rsp] - lea rsi, [rip + .Lanon.[ID].5] - call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) - mov rdx, rax - mov eax, 1 - add rsp, 8 - pop rbx - pop r14 - ret + lea rdi, [rip + .Lanon.[ID].5] + lea rdx, [rip + .Lanon.[ID].6] + mov esi, 15 + call qword ptr [rip + SYM(core::panicking::panic::GENERATED_ID, 0)@GOTPCREL] + ud2 .Lfunc_end4: .size error_alloc, .Lfunc_end4-error_alloc @@ -180,7 +157,7 @@ error_init: .LBB5_4: mov rdi, qword ptr [rsp] .LBB5_5: - lea rsi, [rip + .Lanon.[ID].6] + lea rsi, [rip + .Lanon.[ID].7] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov rdx, rax mov eax, 1 @@ -217,7 +194,7 @@ error_copy: ret .LBB6_2: mov rdi, qword ptr [rsp] - lea rsi, [rip + .Lanon.[ID].7] + lea rsi, [rip + .Lanon.[ID].8] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov rdx, rax mov eax, 1 @@ -256,7 +233,7 @@ error_autoreleased: ret .LBB7_2: mov rdi, qword ptr [rsp] - lea rsi, [rip + .Lanon.[ID].8] + lea rsi, [rip + .Lanon.[ID].9] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_id::encountered_error::, 0) mov rdx, rax mov eax, 1 @@ -302,19 +279,17 @@ error_autoreleased: .size .Lanon.[ID].4, 24 .type .Lanon.[ID].5,@object - .section .data.rel.ro..Lanon.[ID].5,"aw",@progbits - .p2align 3, 0x0 + .section .rodata..Lanon.[ID].5,"a",@progbits .Lanon.[ID].5: - .quad .Lanon.[ID].2 - .asciz "6\000\000\000\000\000\000\000\024\000\000\000\005\000\000" - .size .Lanon.[ID].5, 24 + .ascii "not implemented" + .size .Lanon.[ID].5, 15 .type .Lanon.[ID].6,@object .section .data.rel.ro..Lanon.[ID].6,"aw",@progbits .p2align 3, 0x0 .Lanon.[ID].6: .quad .Lanon.[ID].2 - .asciz "6\000\000\000\000\000\000\000\031\000\000\000\005\000\000" + .asciz "6\000\000\000\000\000\000\000\026\000\000\000\005\000\000" .size .Lanon.[ID].6, 24 .type .Lanon.[ID].7,@object @@ -322,7 +297,7 @@ error_autoreleased: .p2align 3, 0x0 .Lanon.[ID].7: .quad .Lanon.[ID].2 - .asciz "6\000\000\000\000\000\000\000\036\000\000\000\005\000\000" + .asciz "6\000\000\000\000\000\000\000\033\000\000\000\005\000\000" .size .Lanon.[ID].7, 24 .type .Lanon.[ID].8,@object @@ -330,7 +305,15 @@ error_autoreleased: .p2align 3, 0x0 .Lanon.[ID].8: .quad .Lanon.[ID].2 - .asciz "6\000\000\000\000\000\000\000#\000\000\000\005\000\000" + .asciz "6\000\000\000\000\000\000\000 \000\000\000\005\000\000" .size .Lanon.[ID].8, 24 + .type .Lanon.[ID].9,@object + .section .data.rel.ro..Lanon.[ID].9,"aw",@progbits + .p2align 3, 0x0 +.Lanon.[ID].9: + .quad .Lanon.[ID].2 + .asciz "6\000\000\000\000\000\000\000%\000\000\000\005\000\000" + .size .Lanon.[ID].9, 24 + .section ".note.GNU-stack","",@progbits 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 ec9e35e4e..7fe47e833 100644 --- a/crates/test-assembly/crates/test_msg_send_error/lib.rs +++ b/crates/test-assembly/crates/test_msg_send_error/lib.rs @@ -1,5 +1,5 @@ //! Test that error parameters are handled correctly. -use objc2::__macro_helpers::{Alloc, CopyOrMutCopy, Init, MsgSend, MsgSendId, New, Other}; +use objc2::__macro_helpers::{CopyOrMutCopy, Init, MsgSend, MsgSendId, New, Other}; use objc2::rc::{Allocated, Id}; use objc2::runtime::{AnyClass, AnyObject, Sel}; @@ -16,12 +16,14 @@ unsafe fn error_new(cls: &AnyClass, sel: Sel) -> Result> { } #[no_mangle] -unsafe fn error_alloc(cls: &AnyClass, sel: Sel) -> Result> { - Alloc::send_message_id_error(cls, sel, ()) +unsafe fn error_alloc(_cls: &AnyClass, _sel: Sel) -> Result> { + // Alloc::send_message_id_error(cls, sel, ()) + // Note: Erroring allocation methods are not currently supported + unimplemented!() } #[no_mangle] -unsafe fn error_init(obj: Option>, sel: Sel) -> Result> { +unsafe fn error_init(obj: Allocated, sel: Sel) -> Result> { Init::send_message_id_error(obj, sel, ()) } diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/apple-aarch64.s b/crates/test-assembly/crates/test_msg_send_id/expected/apple-aarch64.s index 01f0ebb2d..27b038abb 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/apple-aarch64.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/apple-aarch64.s @@ -32,29 +32,6 @@ Lloh1: _handle_alloc: b _objc_msgSend - .globl _handle_alloc_fallible - .p2align 2 -_handle_alloc_fallible: - stp x20, x19, [sp, #-32]! - stp x29, x30, [sp, #16] - add x29, sp, #16 - mov x19, x1 - mov x20, x0 - bl _objc_msgSend - cbz x0, LBB3_2 - ldp x29, x30, [sp, #16] - ldp x20, x19, [sp], #32 - ret -LBB3_2: -Lloh2: - adrp x2, l_anon.[ID].2@PAGE -Lloh3: - add x2, x2, l_anon.[ID].2@PAGEOFF - mov x0, x20 - mov x1, x19 - bl SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) - .loh AdrpAdd Lloh2, Lloh3 - .globl _handle_init .p2align 2 _handle_init: @@ -69,19 +46,19 @@ _handle_init_fallible: mov x19, x1 mov x20, x0 bl _objc_msgSend - cbz x0, LBB5_2 + cbz x0, LBB4_2 ldp x29, x30, [sp, #16] ldp x20, x19, [sp], #32 ret -LBB5_2: -Lloh4: - adrp x2, l_anon.[ID].3@PAGE -Lloh5: - add x2, x2, l_anon.[ID].3@PAGEOFF +LBB4_2: +Lloh2: + adrp x2, l_anon.[ID].2@PAGE +Lloh3: + add x2, x2, l_anon.[ID].2@PAGEOFF mov x0, x20 mov x1, x19 bl SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) - .loh AdrpAdd Lloh4, Lloh5 + .loh AdrpAdd Lloh2, Lloh3 .globl _handle_alloc_init .p2align 2 @@ -130,16 +107,16 @@ _handle_copy_fallible: stp x29, x30, [sp, #-16]! mov x29, sp bl _objc_msgSend - cbz x0, LBB10_2 + cbz x0, LBB9_2 ldp x29, x30, [sp], #16 ret -LBB10_2: -Lloh6: - adrp x0, l_anon.[ID].4@PAGE -Lloh7: - add x0, x0, l_anon.[ID].4@PAGEOFF +LBB9_2: +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_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) - .loh AdrpAdd Lloh6, Lloh7 + .loh AdrpAdd Lloh4, Lloh5 .globl _handle_autoreleased .p2align 2 @@ -166,19 +143,19 @@ _handle_autoreleased_fallible: mov x29, x29 ; InlineAsm End bl _objc_retainAutoreleasedReturnValue - cbz x0, LBB12_2 + cbz x0, LBB11_2 ldp x29, x30, [sp, #16] ldp x20, x19, [sp], #32 ret -LBB12_2: -Lloh8: - adrp x2, l_anon.[ID].5@PAGE -Lloh9: - add x2, x2, l_anon.[ID].5@PAGEOFF +LBB11_2: +Lloh6: + adrp x2, l_anon.[ID].4@PAGE +Lloh7: + add x2, x2, l_anon.[ID].4@PAGEOFF mov x0, x20 mov x1, x19 bl SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) - .loh AdrpAdd Lloh8, Lloh9 + .loh AdrpAdd Lloh6, Lloh7 .globl _handle_with_out_param .p2align 2 @@ -212,26 +189,21 @@ l_anon.[ID].0: .p2align 3, 0x0 l_anon.[ID].1: .quad l_anon.[ID].0 - .asciz "3\000\000\000\000\000\000\000\r\000\000\000\005\000\000" + .asciz "3\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 "3\000\000\000\000\000\000\000\027\000\000\000\005\000\000" + .asciz "3\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 "3\000\000\000\000\000\000\000!\000\000\000\005\000\000" + .asciz "3\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 "3\000\000\000\000\000\000\000>\000\000\000\005\000\000" - - .p2align 3, 0x0 -l_anon.[ID].5: - .quad l_anon.[ID].0 - .asciz "3\000\000\000\000\000\000\000H\000\000\000\005\000\000" + .asciz "3\000\000\000\000\000\000\000D\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7.s b/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7.s index bc453aff0..aebaf194d 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7.s @@ -33,27 +33,6 @@ LPC1_0: _handle_alloc: b _objc_msgSend - .globl _handle_alloc_fallible - .p2align 2 - .code 32 -_handle_alloc_fallible: - push {r4, r5, r7, lr} - add r7, sp, #8 - mov r4, r1 - mov r5, r0 - bl _objc_msgSend - cmp r0, #0 - popne {r4, r5, r7, pc} -LBB3_1: - movw r2, :lower16:(l_anon.[ID].2-(LPC3_0+8)) - mov r0, r5 - movt r2, :upper16:(l_anon.[ID].2-(LPC3_0+8)) - mov r1, r4 -LPC3_0: - add r2, pc, r2 - mov lr, pc - b SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) - .globl _handle_init .p2align 2 .code 32 @@ -71,12 +50,12 @@ _handle_init_fallible: bl _objc_msgSend cmp r0, #0 popne {r4, r5, r7, pc} -LBB5_1: - movw r2, :lower16:(l_anon.[ID].3-(LPC5_0+8)) +LBB4_1: + movw r2, :lower16:(l_anon.[ID].2-(LPC4_0+8)) mov r0, r5 - movt r2, :upper16:(l_anon.[ID].3-(LPC5_0+8)) + movt r2, :upper16:(l_anon.[ID].2-(LPC4_0+8)) mov r1, r4 -LPC5_0: +LPC4_0: add r2, pc, r2 mov lr, pc b SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) @@ -131,10 +110,10 @@ _handle_copy_fallible: bl _objc_msgSend cmp r0, #0 popne {r7, pc} -LBB10_1: - movw r0, :lower16:(l_anon.[ID].4-(LPC10_0+8)) - movt r0, :upper16:(l_anon.[ID].4-(LPC10_0+8)) -LPC10_0: +LBB9_1: + movw r0, :lower16:(l_anon.[ID].3-(LPC9_0+8)) + movt r0, :upper16:(l_anon.[ID].3-(LPC9_0+8)) +LPC9_0: add r0, pc, r0 mov lr, pc b SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) @@ -167,12 +146,12 @@ _handle_autoreleased_fallible: bl _objc_retainAutoreleasedReturnValue cmp r0, #0 popne {r4, r5, r7, pc} -LBB12_1: - movw r2, :lower16:(l_anon.[ID].5-(LPC12_0+8)) +LBB11_1: + movw r2, :lower16:(l_anon.[ID].4-(LPC11_0+8)) mov r0, r5 - movt r2, :upper16:(l_anon.[ID].5-(LPC12_0+8)) + movt r2, :upper16:(l_anon.[ID].4-(LPC11_0+8)) mov r1, r4 -LPC12_0: +LPC11_0: add r2, pc, r2 mov lr, pc b SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) @@ -206,26 +185,21 @@ l_anon.[ID].0: .p2align 2, 0x0 l_anon.[ID].1: .long l_anon.[ID].0 - .asciz "3\000\000\000\r\000\000\000\005\000\000" + .asciz "3\000\000\000\017\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].2: .long l_anon.[ID].0 - .asciz "3\000\000\000\027\000\000\000\005\000\000" + .asciz "3\000\000\000\036\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].3: .long l_anon.[ID].0 - .asciz "3\000\000\000!\000\000\000\005\000\000" + .asciz "3\000\000\000:\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].4: .long l_anon.[ID].0 - .asciz "3\000\000\000>\000\000\000\005\000\000" - - .p2align 2, 0x0 -l_anon.[ID].5: - .long l_anon.[ID].0 - .asciz "3\000\000\000H\000\000\000\005\000\000" + .asciz "3\000\000\000D\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7s.s b/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7s.s index 87e298aa0..f90814f61 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7s.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/apple-armv7s.s @@ -39,27 +39,6 @@ _handle_alloc: bl _objc_msgSend pop {r7, pc} - .globl _handle_alloc_fallible - .p2align 2 - .code 32 -_handle_alloc_fallible: - push {r4, r5, r7, lr} - add r7, sp, #8 - mov r4, r1 - mov r5, r0 - bl _objc_msgSend - cmp r0, #0 - popne {r4, r5, r7, pc} -LBB3_1: - movw r2, :lower16:(l_anon.[ID].2-(LPC3_0+8)) - mov r0, r5 - movt r2, :upper16:(l_anon.[ID].2-(LPC3_0+8)) - mov r1, r4 -LPC3_0: - add r2, pc, r2 - mov lr, pc - b SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) - .globl _handle_init .p2align 2 .code 32 @@ -80,12 +59,12 @@ _handle_init_fallible: bl _objc_msgSend cmp r0, #0 popne {r4, r5, r7, pc} -LBB5_1: - movw r2, :lower16:(l_anon.[ID].3-(LPC5_0+8)) +LBB4_1: + movw r2, :lower16:(l_anon.[ID].2-(LPC4_0+8)) mov r0, r5 - movt r2, :upper16:(l_anon.[ID].3-(LPC5_0+8)) + movt r2, :upper16:(l_anon.[ID].2-(LPC4_0+8)) mov r1, r4 -LPC5_0: +LPC4_0: add r2, pc, r2 mov lr, pc b SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) @@ -143,10 +122,10 @@ _handle_copy_fallible: bl _objc_msgSend cmp r0, #0 popne {r7, pc} -LBB10_1: - movw r0, :lower16:(l_anon.[ID].4-(LPC10_0+8)) - movt r0, :upper16:(l_anon.[ID].4-(LPC10_0+8)) -LPC10_0: +LBB9_1: + movw r0, :lower16:(l_anon.[ID].3-(LPC9_0+8)) + movt r0, :upper16:(l_anon.[ID].3-(LPC9_0+8)) +LPC9_0: add r0, pc, r0 mov lr, pc b SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) @@ -179,12 +158,12 @@ _handle_autoreleased_fallible: bl _objc_retainAutoreleasedReturnValue cmp r0, #0 popne {r4, r5, r7, pc} -LBB12_1: - movw r2, :lower16:(l_anon.[ID].5-(LPC12_0+8)) +LBB11_1: + movw r2, :lower16:(l_anon.[ID].4-(LPC11_0+8)) mov r0, r5 - movt r2, :upper16:(l_anon.[ID].5-(LPC12_0+8)) + movt r2, :upper16:(l_anon.[ID].4-(LPC11_0+8)) mov r1, r4 -LPC12_0: +LPC11_0: add r2, pc, r2 mov lr, pc b SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) @@ -218,26 +197,21 @@ l_anon.[ID].0: .p2align 2, 0x0 l_anon.[ID].1: .long l_anon.[ID].0 - .asciz "3\000\000\000\r\000\000\000\005\000\000" + .asciz "3\000\000\000\017\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].2: .long l_anon.[ID].0 - .asciz "3\000\000\000\027\000\000\000\005\000\000" + .asciz "3\000\000\000\036\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].3: .long l_anon.[ID].0 - .asciz "3\000\000\000!\000\000\000\005\000\000" + .asciz "3\000\000\000:\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].4: .long l_anon.[ID].0 - .asciz "3\000\000\000>\000\000\000\005\000\000" - - .p2align 2, 0x0 -l_anon.[ID].5: - .long l_anon.[ID].0 - .asciz "3\000\000\000H\000\000\000\005\000\000" + .asciz "3\000\000\000D\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86.s b/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86.s index a8ee64cf9..c4f0853af 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86.s @@ -51,41 +51,6 @@ _handle_alloc: pop ebp jmp _objc_msgSend - .globl _handle_alloc_fallible - .p2align 4, 0x90 -_handle_alloc_fallible: - push ebp - mov ebp, esp - push ebx - push edi - push esi - sub esp, 12 - call L3$pb -L3$pb: - pop ebx - mov edi, dword ptr [ebp + 12] - mov esi, dword ptr [ebp + 8] - sub esp, 8 - push edi - push esi - call _objc_msgSend - add esp, 16 - test eax, eax - je LBB3_2 - add esp, 12 - pop esi - pop edi - pop ebx - pop ebp - ret -LBB3_2: - sub esp, 4 - lea eax, [ebx + l_anon.[ID].2-L3$pb] - push eax - push edi - push esi - call SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) - .globl _handle_init .p2align 4, 0x90 _handle_init: @@ -103,8 +68,8 @@ _handle_init_fallible: push edi push esi sub esp, 12 - call L5$pb -L5$pb: + call L4$pb +L4$pb: pop ebx mov edi, dword ptr [ebp + 12] mov esi, dword ptr [ebp + 8] @@ -114,16 +79,16 @@ L5$pb: call _objc_msgSend add esp, 16 test eax, eax - je LBB5_2 + je LBB4_2 add esp, 12 pop esi pop edi pop ebx pop ebp ret -LBB5_2: +LBB4_2: sub esp, 4 - lea eax, [ebx + l_anon.[ID].3-L5$pb] + lea eax, [ebx + l_anon.[ID].2-L4$pb] push eax push edi push esi @@ -205,8 +170,8 @@ _handle_copy_fallible: mov ebp, esp push esi sub esp, 20 - call L10$pb -L10$pb: + call L9$pb +L9$pb: pop esi mov eax, dword ptr [ebp + 8] mov ecx, dword ptr [ebp + 12] @@ -214,13 +179,13 @@ L10$pb: mov dword ptr [esp], eax call _objc_msgSend test eax, eax - je LBB10_2 + je LBB9_2 add esp, 20 pop esi pop ebp ret -LBB10_2: - lea eax, [esi + l_anon.[ID].4-L10$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_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) @@ -255,8 +220,8 @@ _handle_autoreleased_fallible: push edi push esi sub esp, 12 - call L12$pb -L12$pb: + call L11$pb +L11$pb: pop ebx mov edi, dword ptr [ebp + 12] mov esi, dword ptr [ebp + 8] @@ -275,16 +240,16 @@ L12$pb: call _objc_retainAutoreleasedReturnValue add esp, 16 test eax, eax - je LBB12_2 + je LBB11_2 add esp, 12 pop esi pop edi pop ebx pop ebp ret -LBB12_2: +LBB11_2: sub esp, 4 - lea eax, [ebx + l_anon.[ID].5-L12$pb] + lea eax, [ebx + l_anon.[ID].4-L11$pb] push eax push edi push esi @@ -335,26 +300,21 @@ l_anon.[ID].0: .p2align 2, 0x0 l_anon.[ID].1: .long l_anon.[ID].0 - .asciz "3\000\000\000\r\000\000\000\005\000\000" + .asciz "3\000\000\000\017\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].2: .long l_anon.[ID].0 - .asciz "3\000\000\000\027\000\000\000\005\000\000" + .asciz "3\000\000\000\036\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].3: .long l_anon.[ID].0 - .asciz "3\000\000\000!\000\000\000\005\000\000" + .asciz "3\000\000\000:\000\000\000\005\000\000" .p2align 2, 0x0 l_anon.[ID].4: .long l_anon.[ID].0 - .asciz "3\000\000\000>\000\000\000\005\000\000" - - .p2align 2, 0x0 -l_anon.[ID].5: - .long l_anon.[ID].0 - .asciz "3\000\000\000H\000\000\000\005\000\000" + .asciz "3\000\000\000D\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86_64.s b/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86_64.s index 44dd82358..a7d4e28a3 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/apple-x86_64.s @@ -38,28 +38,6 @@ _handle_alloc: pop rbp jmp _objc_msgSend - .globl _handle_alloc_fallible - .p2align 4, 0x90 -_handle_alloc_fallible: - push rbp - mov rbp, rsp - push r14 - push rbx - mov rbx, rsi - mov r14, rdi - call _objc_msgSend - test rax, rax - je LBB3_2 - pop rbx - pop r14 - pop rbp - ret -LBB3_2: - lea rdx, [rip + l_anon.[ID].2] - mov rdi, r14 - mov rsi, rbx - call SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) - .globl _handle_init .p2align 4, 0x90 _handle_init: @@ -79,13 +57,13 @@ _handle_init_fallible: mov r14, rdi call _objc_msgSend test rax, rax - je LBB5_2 + je LBB4_2 pop rbx pop r14 pop rbp ret -LBB5_2: - lea rdx, [rip + l_anon.[ID].3] +LBB4_2: + lea rdx, [rip + l_anon.[ID].2] mov rdi, r14 mov rsi, rbx call SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) @@ -149,11 +127,11 @@ _handle_copy_fallible: mov rbp, rsp call _objc_msgSend test rax, rax - je LBB10_2 + je LBB9_2 pop rbp ret -LBB10_2: - lea rdi, [rip + l_anon.[ID].4] +LBB9_2: + lea rdi, [rip + l_anon.[ID].3] call SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) .globl _handle_autoreleased @@ -190,13 +168,13 @@ _handle_autoreleased_fallible: ## InlineAsm End test rax, rax - je LBB12_2 + je LBB11_2 pop rbx pop r14 pop rbp ret -LBB12_2: - lea rdx, [rip + l_anon.[ID].5] +LBB11_2: + lea rdx, [rip + l_anon.[ID].4] mov rdi, r14 mov rsi, rbx call SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0) @@ -240,26 +218,21 @@ l_anon.[ID].0: .p2align 3, 0x0 l_anon.[ID].1: .quad l_anon.[ID].0 - .asciz "3\000\000\000\000\000\000\000\r\000\000\000\005\000\000" + .asciz "3\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 "3\000\000\000\000\000\000\000\027\000\000\000\005\000\000" + .asciz "3\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 "3\000\000\000\000\000\000\000!\000\000\000\005\000\000" + .asciz "3\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 "3\000\000\000\000\000\000\000>\000\000\000\005\000\000" - - .p2align 3, 0x0 -l_anon.[ID].5: - .quad l_anon.[ID].0 - .asciz "3\000\000\000\000\000\000\000H\000\000\000\005\000\000" + .asciz "3\000\000\000\000\000\000\000D\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86.s b/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86.s index 72c27a5e9..1d28e4a11 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86.s @@ -104,48 +104,6 @@ handle_alloc: .Lfunc_end2: .size handle_alloc, .Lfunc_end2-handle_alloc - .section .text.handle_alloc_fallible,"ax",@progbits - .globl handle_alloc_fallible - .p2align 4, 0x90 - .type handle_alloc_fallible,@function -handle_alloc_fallible: - push ebx - push edi - push esi - mov edi, dword ptr [esp + 20] - mov esi, dword ptr [esp + 16] - call .L3$pb -.L3$pb: - pop ebx -.Ltmp3: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp3-.L3$pb) - sub esp, 8 - push edi - push esi - call objc_msg_lookup@PLT - add esp, 8 - push edi - push esi - call eax - add esp, 16 - test eax, eax - je .LBB3_1 - pop esi - pop edi - pop ebx - ret -.LBB3_1: - sub esp, 4 - lea eax, [ebx + .Lanon.[ID].2@GOTOFF] - push eax - push edi - push esi - call SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@PLT - add esp, 16 - ud2 -.Lfunc_end3: - .size handle_alloc_fallible, .Lfunc_end3-handle_alloc_fallible - .section .text.handle_init,"ax",@progbits .globl handle_init .p2align 4, 0x90 @@ -155,13 +113,13 @@ handle_init: push edi push esi mov esi, dword ptr [esp + 16] - call .L4$pb -.L4$pb: + call .L3$pb +.L3$pb: pop ebx -.Ltmp4: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp4-.L4$pb) +.Ltmp3: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp3-.L3$pb) test esi, esi - je .LBB4_2 + je .LBB3_2 mov edi, dword ptr [esp + 20] sub esp, 8 push edi @@ -176,14 +134,14 @@ handle_init: pop edi pop ebx ret -.LBB4_2: +.LBB3_2: xor eax, eax pop esi pop edi pop ebx ret -.Lfunc_end4: - .size handle_init, .Lfunc_end4-handle_init +.Lfunc_end3: + .size handle_init, .Lfunc_end3-handle_init .section .text.handle_init_fallible,"ax",@progbits .globl handle_init_fallible @@ -195,13 +153,13 @@ handle_init_fallible: push esi mov esi, dword ptr [esp + 16] mov edi, dword ptr [esp + 20] - call .L5$pb -.L5$pb: + call .L4$pb +.L4$pb: pop ebx -.Ltmp5: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp5-.L5$pb) +.Ltmp4: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp4-.L4$pb) test esi, esi - je .LBB5_2 + je .LBB4_2 sub esp, 8 push edi push esi @@ -212,22 +170,22 @@ handle_init_fallible: call eax add esp, 16 test eax, eax - je .LBB5_2 + je .LBB4_2 pop esi pop edi pop ebx ret -.LBB5_2: +.LBB4_2: sub esp, 4 - lea eax, [ebx + .Lanon.[ID].3@GOTOFF] + lea eax, [ebx + .Lanon.[ID].2@GOTOFF] push eax push edi push esi call SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@PLT add esp, 16 ud2 -.Lfunc_end5: - .size handle_init_fallible, .Lfunc_end5-handle_init_fallible +.Lfunc_end4: + .size handle_init_fallible, .Lfunc_end4-handle_init_fallible .section .text.handle_alloc_init,"ax",@progbits .globl handle_alloc_init @@ -239,11 +197,11 @@ handle_alloc_init: push esi mov esi, dword ptr [esp + 16] mov edi, dword ptr [esp + 20] - call .L6$pb -.L6$pb: + call .L5$pb +.L5$pb: pop ebx -.Ltmp6: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp6-.L6$pb) +.Ltmp5: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp5-.L5$pb) sub esp, 8 push edi push esi @@ -254,7 +212,7 @@ handle_alloc_init: call eax add esp, 16 test eax, eax - je .LBB6_2 + je .LBB5_2 mov edi, dword ptr [esp + 24] mov esi, eax sub esp, 8 @@ -270,14 +228,14 @@ handle_alloc_init: pop edi pop ebx ret -.LBB6_2: +.LBB5_2: xor eax, eax pop esi pop edi pop ebx ret -.Lfunc_end6: - .size handle_alloc_init, .Lfunc_end6-handle_alloc_init +.Lfunc_end5: + .size handle_alloc_init, .Lfunc_end5-handle_alloc_init .section .text.handle_alloc_release,"ax",@progbits .globl handle_alloc_release @@ -290,11 +248,11 @@ handle_alloc_release: sub esp, 16 mov esi, dword ptr [esp + 32] mov edi, dword ptr [esp + 36] - call .L7$pb -.L7$pb: + call .L6$pb +.L6$pb: pop ebx -.Ltmp7: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp7-.L7$pb) +.Ltmp6: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp6-.L6$pb) mov dword ptr [esp + 4], edi mov dword ptr [esp], esi call objc_msg_lookup@PLT @@ -308,8 +266,8 @@ handle_alloc_release: pop edi pop ebx ret -.Lfunc_end7: - .size handle_alloc_release, .Lfunc_end7-handle_alloc_release +.Lfunc_end6: + .size handle_alloc_release, .Lfunc_end6-handle_alloc_release .section .text.handle_alloc_init_release,"ax",@progbits .globl handle_alloc_init_release @@ -324,11 +282,11 @@ handle_alloc_init_release: mov esi, dword ptr [esp + 32] mov ebp, dword ptr [esp + 36] mov edi, dword ptr [esp + 40] - call .L8$pb -.L8$pb: + call .L7$pb +.L7$pb: pop ebx -.Ltmp8: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp8-.L8$pb) +.Ltmp7: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp7-.L7$pb) mov dword ptr [esp + 4], ebp mov dword ptr [esp], esi call objc_msg_lookup@PLT @@ -350,8 +308,8 @@ handle_alloc_init_release: pop ebx pop ebp ret -.Lfunc_end8: - .size handle_alloc_init_release, .Lfunc_end8-handle_alloc_init_release +.Lfunc_end7: + .size handle_alloc_init_release, .Lfunc_end7-handle_alloc_init_release .section .text.handle_copy,"ax",@progbits .globl handle_copy @@ -363,11 +321,11 @@ handle_copy: push esi mov esi, dword ptr [esp + 16] mov edi, dword ptr [esp + 20] - call .L9$pb -.L9$pb: + call .L8$pb +.L8$pb: pop ebx -.Ltmp9: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp9-.L9$pb) +.Ltmp8: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp8-.L8$pb) sub esp, 8 push edi push esi @@ -381,8 +339,8 @@ handle_copy: pop edi pop ebx ret -.Lfunc_end9: - .size handle_copy, .Lfunc_end9-handle_copy +.Lfunc_end8: + .size handle_copy, .Lfunc_end8-handle_copy .section .text.handle_copy_fallible,"ax",@progbits .globl handle_copy_fallible @@ -395,11 +353,11 @@ handle_copy_fallible: sub esp, 16 mov esi, dword ptr [esp + 32] mov edi, dword ptr [esp + 36] - call .L10$pb -.L10$pb: + call .L9$pb +.L9$pb: pop ebx -.Ltmp10: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp10-.L10$pb) +.Ltmp9: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp9-.L9$pb) mov dword ptr [esp + 4], edi mov dword ptr [esp], esi call objc_msg_lookup@PLT @@ -407,19 +365,19 @@ handle_copy_fallible: mov dword ptr [esp], esi call eax test eax, eax - je .LBB10_1 + je .LBB9_1 add esp, 16 pop esi pop edi pop ebx ret -.LBB10_1: - lea eax, [ebx + .Lanon.[ID].4@GOTOFF] +.LBB9_1: + lea eax, [ebx + .Lanon.[ID].3@GOTOFF] mov dword ptr [esp], eax call SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@PLT ud2 -.Lfunc_end10: - .size handle_copy_fallible, .Lfunc_end10-handle_copy_fallible +.Lfunc_end9: + .size handle_copy_fallible, .Lfunc_end9-handle_copy_fallible .section .text.handle_autoreleased,"ax",@progbits .globl handle_autoreleased @@ -432,11 +390,11 @@ handle_autoreleased: sub esp, 16 mov esi, dword ptr [esp + 32] mov edi, dword ptr [esp + 36] - call .L11$pb -.L11$pb: + call .L10$pb +.L10$pb: pop ebx -.Ltmp11: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp11-.L11$pb) +.Ltmp10: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp10-.L10$pb) mov dword ptr [esp + 4], edi mov dword ptr [esp], esi call objc_msg_lookup@PLT @@ -450,8 +408,8 @@ handle_autoreleased: pop edi pop ebx ret -.Lfunc_end11: - .size handle_autoreleased, .Lfunc_end11-handle_autoreleased +.Lfunc_end10: + .size handle_autoreleased, .Lfunc_end10-handle_autoreleased .section .text.handle_autoreleased_fallible,"ax",@progbits .globl handle_autoreleased_fallible @@ -463,11 +421,11 @@ handle_autoreleased_fallible: push esi mov edi, dword ptr [esp + 20] mov esi, dword ptr [esp + 16] - call .L12$pb -.L12$pb: + call .L11$pb +.L11$pb: pop ebx -.Ltmp12: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp12-.L12$pb) +.Ltmp11: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp11-.L11$pb) sub esp, 8 push edi push esi @@ -481,22 +439,22 @@ handle_autoreleased_fallible: call objc_retainAutoreleasedReturnValue@PLT add esp, 16 test eax, eax - je .LBB12_1 + je .LBB11_1 pop esi pop edi pop ebx ret -.LBB12_1: +.LBB11_1: sub esp, 4 - lea eax, [ebx + .Lanon.[ID].5@GOTOFF] + lea eax, [ebx + .Lanon.[ID].4@GOTOFF] push eax push edi push esi call SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@PLT add esp, 16 ud2 -.Lfunc_end12: - .size handle_autoreleased_fallible, .Lfunc_end12-handle_autoreleased_fallible +.Lfunc_end11: + .size handle_autoreleased_fallible, .Lfunc_end11-handle_autoreleased_fallible .section .text.handle_with_out_param,"ax",@progbits .globl handle_with_out_param @@ -511,11 +469,11 @@ handle_with_out_param: mov ebp, dword ptr [esp + 40] mov eax, dword ptr [esp + 32] mov esi, dword ptr [esp + 36] - call .L13$pb -.L13$pb: + call .L12$pb +.L12$pb: pop ebx -.Ltmp13: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp13-.L13$pb) +.Ltmp12: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp12-.L12$pb) mov edi, dword ptr [ebp] mov dword ptr [esp + 4], esi mov dword ptr [esp], eax @@ -539,8 +497,8 @@ handle_with_out_param: pop ebx pop ebp ret -.Lfunc_end13: - .size handle_with_out_param, .Lfunc_end13-handle_with_out_param +.Lfunc_end12: + .size handle_with_out_param, .Lfunc_end12-handle_with_out_param .type .Lanon.[ID].0,@object .section .rodata..Lanon.[ID].0,"a",@progbits @@ -553,7 +511,7 @@ handle_with_out_param: .p2align 2, 0x0 .Lanon.[ID].1: .long .Lanon.[ID].0 - .asciz "3\000\000\000\r\000\000\000\005\000\000" + .asciz "3\000\000\000\017\000\000\000\005\000\000" .size .Lanon.[ID].1, 16 .type .Lanon.[ID].2,@object @@ -561,7 +519,7 @@ handle_with_out_param: .p2align 2, 0x0 .Lanon.[ID].2: .long .Lanon.[ID].0 - .asciz "3\000\000\000\027\000\000\000\005\000\000" + .asciz "3\000\000\000\036\000\000\000\005\000\000" .size .Lanon.[ID].2, 16 .type .Lanon.[ID].3,@object @@ -569,7 +527,7 @@ handle_with_out_param: .p2align 2, 0x0 .Lanon.[ID].3: .long .Lanon.[ID].0 - .asciz "3\000\000\000!\000\000\000\005\000\000" + .asciz "3\000\000\000:\000\000\000\005\000\000" .size .Lanon.[ID].3, 16 .type .Lanon.[ID].4,@object @@ -577,15 +535,7 @@ handle_with_out_param: .p2align 2, 0x0 .Lanon.[ID].4: .long .Lanon.[ID].0 - .asciz "3\000\000\000>\000\000\000\005\000\000" + .asciz "3\000\000\000D\000\000\000\005\000\000" .size .Lanon.[ID].4, 16 - .type .Lanon.[ID].5,@object - .section .data.rel.ro..Lanon.[ID].5,"aw",@progbits - .p2align 2, 0x0 -.Lanon.[ID].5: - .long .Lanon.[ID].0 - .asciz "3\000\000\000H\000\000\000\005\000\000" - .size .Lanon.[ID].5, 16 - .section ".note.GNU-stack","",@progbits diff --git a/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86_64.s b/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86_64.s index d1b75f706..872af810e 100644 --- a/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_id/expected/gnustep-x86_64.s @@ -69,42 +69,13 @@ handle_alloc: .Lfunc_end2: .size handle_alloc, .Lfunc_end2-handle_alloc - .section .text.handle_alloc_fallible,"ax",@progbits - .globl handle_alloc_fallible - .p2align 4, 0x90 - .type handle_alloc_fallible,@function -handle_alloc_fallible: - push r14 - push rbx - push rax - mov rbx, rsi - mov r14, rdi - call qword ptr [rip + objc_msg_lookup@GOTPCREL] - mov rdi, r14 - mov rsi, rbx - call rax - test rax, rax - je .LBB3_1 - add rsp, 8 - pop rbx - pop r14 - ret -.LBB3_1: - lea rdx, [rip + .Lanon.[ID].2] - mov rdi, r14 - mov rsi, rbx - call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@GOTPCREL] - ud2 -.Lfunc_end3: - .size handle_alloc_fallible, .Lfunc_end3-handle_alloc_fallible - .section .text.handle_init,"ax",@progbits .globl handle_init .p2align 4, 0x90 .type handle_init,@function handle_init: test rdi, rdi - je .LBB4_1 + je .LBB3_1 push r14 push rbx push rax @@ -117,11 +88,11 @@ handle_init: pop rbx pop r14 jmp rax -.LBB4_1: +.LBB3_1: xor eax, eax ret -.Lfunc_end4: - .size handle_init, .Lfunc_end4-handle_init +.Lfunc_end3: + .size handle_init, .Lfunc_end3-handle_init .section .text.handle_init_fallible,"ax",@progbits .globl handle_init_fallible @@ -134,7 +105,7 @@ handle_init_fallible: mov rbx, rsi mov r14, rdi test rdi, rdi - je .LBB5_2 + je .LBB4_2 mov rdi, r14 mov rsi, rbx call qword ptr [rip + objc_msg_lookup@GOTPCREL] @@ -142,19 +113,19 @@ handle_init_fallible: mov rsi, rbx call rax test rax, rax - je .LBB5_2 + je .LBB4_2 add rsp, 8 pop rbx pop r14 ret -.LBB5_2: - lea rdx, [rip + .Lanon.[ID].3] +.LBB4_2: + lea rdx, [rip + .Lanon.[ID].2] mov rdi, r14 mov rsi, rbx call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@GOTPCREL] ud2 -.Lfunc_end5: - .size handle_init_fallible, .Lfunc_end5-handle_init_fallible +.Lfunc_end4: + .size handle_init_fallible, .Lfunc_end4-handle_init_fallible .section .text.handle_alloc_init,"ax",@progbits .globl handle_alloc_init @@ -172,7 +143,7 @@ handle_alloc_init: mov rsi, r14 call rax test rax, rax - je .LBB6_1 + je .LBB5_1 mov r14, rax mov rdi, rax mov rsi, rbx @@ -183,14 +154,14 @@ handle_alloc_init: pop r14 pop r15 jmp rax -.LBB6_1: +.LBB5_1: xor eax, eax pop rbx pop r14 pop r15 ret -.Lfunc_end6: - .size handle_alloc_init, .Lfunc_end6-handle_alloc_init +.Lfunc_end5: + .size handle_alloc_init, .Lfunc_end5-handle_alloc_init .section .text.handle_alloc_release,"ax",@progbits .globl handle_alloc_release @@ -211,8 +182,8 @@ handle_alloc_release: pop rbx pop r14 jmp qword ptr [rip + objc_release@GOTPCREL] -.Lfunc_end7: - .size handle_alloc_release, .Lfunc_end7-handle_alloc_release +.Lfunc_end6: + .size handle_alloc_release, .Lfunc_end6-handle_alloc_release .section .text.handle_alloc_init_release,"ax",@progbits .globl handle_alloc_init_release @@ -246,8 +217,8 @@ handle_alloc_init_release: pop r14 pop r15 jmp qword ptr [rip + objc_release@GOTPCREL] -.Lfunc_end8: - .size handle_alloc_init_release, .Lfunc_end8-handle_alloc_init_release +.Lfunc_end7: + .size handle_alloc_init_release, .Lfunc_end7-handle_alloc_init_release .section .text.handle_copy,"ax",@progbits .globl handle_copy @@ -266,8 +237,8 @@ handle_copy: pop rbx pop r14 jmp rax -.Lfunc_end9: - .size handle_copy, .Lfunc_end9-handle_copy +.Lfunc_end8: + .size handle_copy, .Lfunc_end8-handle_copy .section .text.handle_copy_fallible,"ax",@progbits .globl handle_copy_fallible @@ -284,17 +255,17 @@ handle_copy_fallible: mov rsi, rbx call rax test rax, rax - je .LBB10_1 + je .LBB9_1 add rsp, 8 pop rbx pop r14 ret -.LBB10_1: - lea rdi, [rip + .Lanon.[ID].4] +.LBB9_1: + lea rdi, [rip + .Lanon.[ID].3] call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@GOTPCREL] ud2 -.Lfunc_end10: - .size handle_copy_fallible, .Lfunc_end10-handle_copy_fallible +.Lfunc_end9: + .size handle_copy_fallible, .Lfunc_end9-handle_copy_fallible .section .text.handle_autoreleased,"ax",@progbits .globl handle_autoreleased @@ -315,8 +286,8 @@ handle_autoreleased: pop rbx pop r14 jmp qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] -.Lfunc_end11: - .size handle_autoreleased, .Lfunc_end11-handle_autoreleased +.Lfunc_end10: + .size handle_autoreleased, .Lfunc_end10-handle_autoreleased .section .text.handle_autoreleased_fallible,"ax",@progbits .globl handle_autoreleased_fallible @@ -335,19 +306,19 @@ handle_autoreleased_fallible: mov rdi, rax call qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] test rax, rax - je .LBB12_1 + je .LBB11_1 add rsp, 8 pop rbx pop r14 ret -.LBB12_1: - lea rdx, [rip + .Lanon.[ID].5] +.LBB11_1: + lea rdx, [rip + .Lanon.[ID].4] mov rdi, r14 mov rsi, rbx call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_id::MsgSendIdFailed>::failed::GENERATED_ID, 0)@GOTPCREL] ud2 -.Lfunc_end12: - .size handle_autoreleased_fallible, .Lfunc_end12-handle_autoreleased_fallible +.Lfunc_end11: + .size handle_autoreleased_fallible, .Lfunc_end11-handle_autoreleased_fallible .section .text.handle_with_out_param,"ax",@progbits .globl handle_with_out_param @@ -380,8 +351,8 @@ handle_with_out_param: pop r14 pop r15 jmp qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] -.Lfunc_end13: - .size handle_with_out_param, .Lfunc_end13-handle_with_out_param +.Lfunc_end12: + .size handle_with_out_param, .Lfunc_end12-handle_with_out_param .type .Lanon.[ID].0,@object .section .rodata..Lanon.[ID].0,"a",@progbits @@ -394,7 +365,7 @@ handle_with_out_param: .p2align 3, 0x0 .Lanon.[ID].1: .quad .Lanon.[ID].0 - .asciz "3\000\000\000\000\000\000\000\r\000\000\000\005\000\000" + .asciz "3\000\000\000\000\000\000\000\017\000\000\000\005\000\000" .size .Lanon.[ID].1, 24 .type .Lanon.[ID].2,@object @@ -402,7 +373,7 @@ handle_with_out_param: .p2align 3, 0x0 .Lanon.[ID].2: .quad .Lanon.[ID].0 - .asciz "3\000\000\000\000\000\000\000\027\000\000\000\005\000\000" + .asciz "3\000\000\000\000\000\000\000\036\000\000\000\005\000\000" .size .Lanon.[ID].2, 24 .type .Lanon.[ID].3,@object @@ -410,7 +381,7 @@ handle_with_out_param: .p2align 3, 0x0 .Lanon.[ID].3: .quad .Lanon.[ID].0 - .asciz "3\000\000\000\000\000\000\000!\000\000\000\005\000\000" + .asciz "3\000\000\000\000\000\000\000:\000\000\000\005\000\000" .size .Lanon.[ID].3, 24 .type .Lanon.[ID].4,@object @@ -418,15 +389,7 @@ handle_with_out_param: .p2align 3, 0x0 .Lanon.[ID].4: .quad .Lanon.[ID].0 - .asciz "3\000\000\000\000\000\000\000>\000\000\000\005\000\000" + .asciz "3\000\000\000\000\000\000\000D\000\000\000\005\000\000" .size .Lanon.[ID].4, 24 - .type .Lanon.[ID].5,@object - .section .data.rel.ro..Lanon.[ID].5,"aw",@progbits - .p2align 3, 0x0 -.Lanon.[ID].5: - .quad .Lanon.[ID].0 - .asciz "3\000\000\000\000\000\000\000H\000\000\000\005\000\000" - .size .Lanon.[ID].5, 24 - .section ".note.GNU-stack","",@progbits diff --git a/crates/test-assembly/crates/test_msg_send_id/lib.rs b/crates/test-assembly/crates/test_msg_send_id/lib.rs index 1a4a3b6e1..555bc13df 100644 --- a/crates/test-assembly/crates/test_msg_send_id/lib.rs +++ b/crates/test-assembly/crates/test_msg_send_id/lib.rs @@ -14,22 +14,17 @@ unsafe fn handle_new_fallible(cls: &AnyClass, sel: Sel) -> Id { } #[no_mangle] -unsafe fn handle_alloc(cls: &AnyClass, sel: Sel) -> Option> { +unsafe fn handle_alloc(cls: &AnyClass, sel: Sel) -> Allocated { Alloc::send_message_id(cls, sel, ()) } #[no_mangle] -unsafe fn handle_alloc_fallible(cls: &AnyClass, sel: Sel) -> Allocated { - Alloc::send_message_id(cls, sel, ()) -} - -#[no_mangle] -unsafe fn handle_init(obj: Option>, sel: Sel) -> Option> { +unsafe fn handle_init(obj: Allocated, sel: Sel) -> Option> { Init::send_message_id(obj, sel, ()) } #[no_mangle] -unsafe fn handle_init_fallible(obj: Option>, sel: Sel) -> Id { +unsafe fn handle_init_fallible(obj: Allocated, sel: Sel) -> Id { Init::send_message_id(obj, sel, ()) } @@ -41,8 +36,7 @@ unsafe fn handle_alloc_init(cls: &AnyClass, sel1: Sel, sel2: Sel) -> Option> = Alloc::send_message_id(cls, sel, ()); - let _obj = obj.unwrap_unchecked(); + let _obj: Allocated = Alloc::send_message_id(cls, sel, ()); } #[no_mangle] diff --git a/crates/test-ui/ui/declare_class_invalid_type2.stderr b/crates/test-ui/ui/declare_class_invalid_type2.stderr index 1b7ba47f2..8aaaff567 100644 --- a/crates/test-ui/ui/declare_class_invalid_type2.stderr +++ b/crates/test-ui/ui/declare_class_invalid_type2.stderr @@ -1,11 +1,11 @@ -error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Id` +error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Option>` --> ui/declare_class_invalid_type2.rs | | fn test_init_not_same_generics(this: Allocated) -> Id { - | ^^^^^^^^^^^^^^^ expected `Id`, found `Id` + | ^^^^^^^^^^^^^^^ expected `Option>`, found `Option>` | - = note: expected struct `Id` - found struct `Id` + = note: expected enum `Option>` + found enum `Option>` = note: required for `RetainSemantics<3>` to implement `MessageRecieveId, Id>` error[E0277]: the trait bound `i32: MaybeOptionId` is not satisfied diff --git a/crates/test-ui/ui/extern_methods_invalid_receiver.rs b/crates/test-ui/ui/extern_methods_invalid_receiver.rs new file mode 100644 index 000000000..df29eaf49 --- /dev/null +++ b/crates/test-ui/ui/extern_methods_invalid_receiver.rs @@ -0,0 +1,28 @@ +use objc2::rc::{Allocated, Id}; +use objc2::runtime::NSObject; +use objc2::{extern_class, extern_methods, mutability, ClassType}; + +extern_class!( + pub struct MyObject; + + unsafe impl ClassType for MyObject { + type Super = NSObject; + type Mutability = mutability::InteriorMutable; + } +); + +extern_methods!( + unsafe impl MyObject { + #[method_id(initWithMut)] + fn init_with_mut(&mut self) -> Option>; + } +); + +extern_methods!( + unsafe impl MyObject { + #[method_id(initWithOptionAllocated)] + fn init_with_option_allocated(this: Option>) -> Option>; + } +); + +fn main() {} diff --git a/crates/test-ui/ui/extern_methods_invalid_receiver.stderr b/crates/test-ui/ui/extern_methods_invalid_receiver.stderr new file mode 100644 index 000000000..41c2b6814 --- /dev/null +++ b/crates/test-ui/ui/extern_methods_invalid_receiver.stderr @@ -0,0 +1,45 @@ +error[E0308]: mismatched types + --> ui/extern_methods_invalid_receiver.rs + | + | / extern_methods!( + | | unsafe impl MyObject { + | | #[method_id(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_id.rs + | + | unsafe fn send_message_id>( + | ^^^^^^^^^^^^^^^ + = 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) + +error[E0308]: mismatched types + --> ui/extern_methods_invalid_receiver.rs + | + | / extern_methods!( + | | unsafe impl MyObject { + | | #[method_id(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_id.rs + | + | unsafe fn send_message_id>( + | ^^^^^^^^^^^^^^^ + = 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) diff --git a/crates/test-ui/ui/extern_methods_invalid_type.rs b/crates/test-ui/ui/extern_methods_invalid_type.rs index 70ea5a87f..ee7f3e28d 100644 --- a/crates/test-ui/ui/extern_methods_invalid_type.rs +++ b/crates/test-ui/ui/extern_methods_invalid_type.rs @@ -28,8 +28,8 @@ extern_methods!( extern_methods!( unsafe impl MyObject { - #[method_id(init)] - fn init(&mut self) -> Option>; + #[method(c:)] + fn c(&self, arg: Box); } ); diff --git a/crates/test-ui/ui/extern_methods_invalid_type.stderr b/crates/test-ui/ui/extern_methods_invalid_type.stderr index a09cc2396..0c6c8b082 100644 --- a/crates/test-ui/ui/extern_methods_invalid_type.stderr +++ b/crates/test-ui/ui/extern_methods_invalid_type.stderr @@ -46,7 +46,6 @@ error[E0277]: the trait bound `i32: MaybeUnwrap` is not satisfied Id Allocated Option> - Option> note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -54,28 +53,42 @@ note: required by a bound in `send_message_id` | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MsgSendId::send_message_id` = 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[E0308]: mismatched types +error[E0277]: the trait bound `Box: Encode` is not satisfied --> ui/extern_methods_invalid_type.rs | | / extern_methods!( | | unsafe impl MyObject { - | | #[method_id(init)] - | | fn init(&mut self) -> Option>; + | | #[method(c:)] + | | fn c(&self, arg: Box); | | } | | ); | | ^ | | | - | |_expected `Option>`, found `&mut MyObject` - | arguments to this function are incorrect + | |_the trait `Encode` is not implemented for `Box` + | required by a bound introduced by this call | - = note: expected enum `Option>` - found mutable reference `&mut MyObject` -note: associated function defined here - --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs + = help: the following other types implement trait `Encode`: + isize + i8 + i16 + i32 + i64 + usize + u8 + u16 + and $N others + = note: required for `Box` to implement `EncodeArgument` + = 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 | - | unsafe fn send_message_id>( - | ^^^^^^^^^^^^^^^ - = 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) + | 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` + = 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<(), Id>: Encode` is not satisfied --> ui/extern_methods_invalid_type.rs @@ -125,7 +138,6 @@ error[E0277]: the trait bound `Result, Id>: MaybeUnwrap` Id Allocated Option> - Option> note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | 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 bf633f9ae..416711baf 100644 --- a/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr +++ b/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr @@ -44,5 +44,5 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM = note: required for `MyObject` to implement `IsAllowedMutable` = note: required for `&mut MyObject` to implement `MessageReceiver` = note: required for `&mut MyObject` to implement `MsgSend` - = note: required for `RetainSemantics<5>` to implement `MsgSendId<&mut MyObject, Id<_>>` + = note: required for `RetainSemantics<5>` to implement `MsgSendId<&mut MyObject, Option>>` = 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) diff --git a/crates/test-ui/ui/main_thread_only_not_allocable.stderr b/crates/test-ui/ui/main_thread_only_not_allocable.stderr index d3eb4ed3b..38678c297 100644 --- a/crates/test-ui/ui/main_thread_only_not_allocable.stderr +++ b/crates/test-ui/ui/main_thread_only_not_allocable.stderr @@ -15,7 +15,7 @@ error[E0277]: the trait bound `MainThreadOnly: mutability::MutabilityIsAllocable note: required by a bound in `objc2::ClassType::alloc` --> $WORKSPACE/crates/objc2/src/top_level_traits.rs | - | fn alloc() -> Option> + | fn alloc() -> Allocated | ----- required by a bound in this associated function | where | Self: IsAllocableAnyThread, diff --git a/crates/test-ui/ui/msg_send_id_alloc_init_different.rs b/crates/test-ui/ui/msg_send_id_alloc_init_different.rs index d6c22e188..e6f68e5d5 100644 --- a/crates/test-ui/ui/msg_send_id_alloc_init_different.rs +++ b/crates/test-ui/ui/msg_send_id_alloc_init_different.rs @@ -1,11 +1,11 @@ //! Ensure that `init` returns the same type as given from `alloc`. use objc2::rc::{Allocated, Id}; -use objc2::runtime::{NSObject, AnyObject}; +use objc2::runtime::{AnyObject, NSObject}; use objc2::{class, msg_send_id}; fn main() { let cls = class!(NSObject); - let obj: Option> = unsafe { msg_send_id![cls, alloc] }; + let obj: Allocated = unsafe { msg_send_id![cls, alloc] }; let _: Id = unsafe { msg_send_id![obj, init] }; } diff --git a/crates/test-ui/ui/msg_send_id_alloc_init_different.stderr b/crates/test-ui/ui/msg_send_id_alloc_init_different.stderr index 16216c0f1..206188b1c 100644 --- a/crates/test-ui/ui/msg_send_id_alloc_init_different.stderr +++ b/crates/test-ui/ui/msg_send_id_alloc_init_different.stderr @@ -1,11 +1,11 @@ -error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Id` +error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Option>` --> ui/msg_send_id_alloc_init_different.rs | | let _: Id = unsafe { msg_send_id![obj, init] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `Id`, found `Id` + | ^^^^^^^^^^^^^^^^^^^^^^^ expected `Option>`, found `Option>` | - = note: expected struct `Id` - found struct `Id` + = note: expected enum `Option>` + found enum `Option>` note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | diff --git a/crates/test-ui/ui/msg_send_id_invalid_receiver.stderr b/crates/test-ui/ui/msg_send_id_invalid_receiver.stderr index 41e10c0b9..56bf38f65 100644 --- a/crates/test-ui/ui/msg_send_id_invalid_receiver.stderr +++ b/crates/test-ui/ui/msg_send_id_invalid_receiver.stderr @@ -21,10 +21,10 @@ error[E0308]: mismatched types | let _: Id = unsafe { msg_send_id![obj, init] }; | -------------^^^------- | | | - | | expected `Option>`, found `&NSObject` + | | expected `Allocated<_>`, found `&NSObject` | arguments to this function are incorrect | - = note: expected enum `Option>` + = note: expected struct `Allocated<_>` found reference `&NSObject` note: associated function defined here --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs @@ -38,10 +38,10 @@ error[E0308]: mismatched types | let _: Id = unsafe { msg_send_id![cls, init] }; | -------------^^^------- | | | - | | expected `Option>`, found `&AnyClass` + | | expected `Allocated<_>`, found `&AnyClass` | arguments to this function are incorrect | - = note: expected enum `Option>` + = note: expected struct `Allocated<_>` found reference `&AnyClass` note: associated function defined here --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs @@ -55,11 +55,11 @@ error[E0308]: mismatched types | let _: Id = unsafe { msg_send_id![obj, init] }; | -------------^^^------- | | | - | | expected `Option>`, found `Id` + | | expected `Allocated<_>`, found `Id` | arguments to this function are incorrect | - = note: expected enum `Option>` - found struct `Id` + = note: expected struct `Allocated<_>` + found struct `Id` note: associated function defined here --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -72,11 +72,11 @@ error[E0308]: mismatched types | let _: Id = unsafe { msg_send_id![obj, init] }; | -------------^^^------- | | | - | | expected `Option>`, found `Option>` + | | expected `Allocated<_>`, found `Option>` | arguments to this function are incorrect | - = note: expected enum `Option>` - found enum `Option>` + = note: expected struct `Allocated<_>` + found enum `Option>` note: associated function defined here --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -93,7 +93,7 @@ error[E0277]: the trait bound `Id: MsgSend` is not satisfied | required by a bound introduced by this call | = note: required for `Id` to implement `MsgSend` - = note: required for `RetainSemantics<1>` to implement `MsgSendId, Id<_>>` + = note: required for `RetainSemantics<1>` to implement `MsgSendId, Option>>` help: consider borrowing here | 19 | let _: Id = unsafe { msg_send_id![&obj, new] }; @@ -109,7 +109,7 @@ error[E0277]: the trait bound `Id: MsgSend` is not satisfied | required by a bound introduced by this call | = note: required for `Id` to implement `MsgSend` - = note: required for `RetainSemantics<4>` to implement `MsgSendId, Id<_>>` + = note: required for `RetainSemantics<4>` to implement `MsgSendId, Option>>` help: consider borrowing here | 21 | let _: Id = unsafe { msg_send_id![&obj, copy] }; diff --git a/crates/test-ui/ui/msg_send_id_invalid_return.rs b/crates/test-ui/ui/msg_send_id_invalid_return.rs index 9009ac961..71e1f7b8f 100644 --- a/crates/test-ui/ui/msg_send_id_invalid_return.rs +++ b/crates/test-ui/ui/msg_send_id_invalid_return.rs @@ -1,7 +1,7 @@ //! Test compiler output with invalid msg_send_id return values. use objc2::msg_send_id; use objc2::rc::{Allocated, Id}; -use objc2::runtime::{AnyClass, NSObject, AnyObject}; +use objc2::runtime::{AnyClass, AnyObject, NSObject}; fn main() { let cls: &AnyClass; @@ -13,13 +13,15 @@ fn main() { let _: Allocated = unsafe { msg_send_id![cls, alloc] }; let _: Id = unsafe { msg_send_id![cls, alloc] }; // Earlier design worked like this + let _: Option> = unsafe { msg_send_id![cls, alloc] }; + // And even earlier design like this let _: Id> = unsafe { msg_send_id![cls, alloc] }; - let obj: Option>; + let obj: Allocated; let _: &AnyObject = unsafe { msg_send_id![obj, init] }; - let obj: Option>; + let obj: Allocated; let _: Id = unsafe { msg_send_id![obj, init] }; - let obj: Option>; + let obj: Allocated; let _: Id = unsafe { msg_send_id![obj, init] }; let obj: &AnyObject; diff --git a/crates/test-ui/ui/msg_send_id_invalid_return.stderr b/crates/test-ui/ui/msg_send_id_invalid_return.stderr index cd2d42914..b182371c8 100644 --- a/crates/test-ui/ui/msg_send_id_invalid_return.stderr +++ b/crates/test-ui/ui/msg_send_id_invalid_return.stderr @@ -8,7 +8,6 @@ error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied Id Allocated Option> - Option> note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -32,7 +31,7 @@ error[E0277]: the trait bound `AnyClass: Message` is not satisfied __RcTestObject NSObject __NSProxy - = note: required for `RetainSemantics<1>` to implement `MsgSendId<&AnyClass, Id>` + = note: required for `RetainSemantics<1>` to implement `MsgSendId<&AnyClass, Option>>` error[E0277]: the trait bound `AnyClass: Message` is not satisfied --> ui/msg_send_id_invalid_return.rs @@ -50,7 +49,7 @@ error[E0277]: the trait bound `AnyClass: Message` is not satisfied __RcTestObject NSObject __NSProxy - = note: required for `RetainSemantics<1>` to implement `MsgSendId<&AnyClass, Id>` + = note: required for `RetainSemantics<1>` to implement `MsgSendId<&AnyClass, Option>>` error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied --> ui/msg_send_id_invalid_return.rs @@ -62,7 +61,6 @@ error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied Id Allocated Option> - Option> note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -92,10 +90,10 @@ error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == --> ui/msg_send_id_invalid_return.rs | | let _: Id = unsafe { msg_send_id![cls, alloc] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `Allocated<_>`, found `Id` + | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `Allocated<_>`, found `Option>` | = note: expected struct `Allocated<_>` - found struct `Id` + found enum `Option>` note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -103,14 +101,28 @@ note: required by a bound in `send_message_id` | ^^^^^^^^^ required by this bound in `MsgSendId::send_message_id` = 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_id_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 `send_message_id` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs + | + | unsafe fn send_message_id>( + | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MsgSendId::send_message_id` + = note: this error originates in 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_id_invalid_return.rs | | let _: Id> = unsafe { msg_send_id![cls, alloc] }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `Allocated<_>`, found `Id>` + | ^^^^^^^^^^^^^^^^^^^^^^^^ expected `Allocated<_>`, found `Option>>` | = note: expected struct `Allocated<_>` - found struct `Id>` + found enum `Option>>` note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -128,7 +140,6 @@ error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied Id Allocated Option> - Option> note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -136,14 +147,14 @@ note: required by a bound in `send_message_id` | ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `MsgSendId::send_message_id` = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Id` +error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Option>` --> ui/msg_send_id_invalid_return.rs | | let _: Id = unsafe { msg_send_id![obj, init] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `Id`, found `Id` + | ^^^^^^^^^^^^^^^^^^^^^^^ expected `Option>`, found `Option>` | - = note: expected struct `Id` - found struct `Id` + = note: expected enum `Option>` + found enum `Option>` note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -151,14 +162,14 @@ note: required by a bound in `send_message_id` | ^^^^^^^^^ required by this bound in `MsgSendId::send_message_id` = note: this error originates in the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Id` +error[E0271]: type mismatch resolving ` as MaybeUnwrap>::Input == Option>` --> ui/msg_send_id_invalid_return.rs | | let _: Id = unsafe { msg_send_id![obj, init] }; - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `Id`, found `Id` + | ^^^^^^^^^^^^^^^^^^^^^^^ expected `Option>`, found `Option>` | - = note: expected struct `Id` - found struct `Id` + = note: expected enum `Option>` + found enum `Option>` note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -176,7 +187,6 @@ error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied Id Allocated Option> - Option> note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -194,7 +204,6 @@ error[E0277]: the trait bound `&AnyObject: MaybeUnwrap` is not satisfied Id Allocated Option> - Option> note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | @@ -208,9 +217,7 @@ error[E0277]: the trait bound `Option<&AnyObject>: MaybeUnwrap` is not satisfied | let _: Option<&AnyObject> = unsafe { msg_send_id![obj, description] }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MaybeUnwrap` is not implemented for `Option<&AnyObject>` | - = help: the following other types implement trait `MaybeUnwrap`: - Option> - Option> + = help: the trait `MaybeUnwrap` is implemented for `Option>` note: required by a bound in `send_message_id` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | 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 a1967aefc..375d6b028 100644 --- a/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr +++ b/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr @@ -33,4 +33,4 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM = note: required for `NSThread` to implement `IsAllowedMutable` = note: required for `&mut NSThread` to implement `MessageReceiver` = note: required for `&mut NSThread` to implement `MsgSend` - = note: required for `RetainSemantics<5>` to implement `MsgSendId<&mut NSThread, Id<_>>` + = note: required for `RetainSemantics<5>` to implement `MsgSendId<&mut NSThread, Option>>` diff --git a/crates/test-ui/ui/msg_send_underspecified_error.stderr b/crates/test-ui/ui/msg_send_underspecified_error.stderr index bb29be681..5a3195617 100644 --- a/crates/test-ui/ui/msg_send_underspecified_error.stderr +++ b/crates/test-ui/ui/msg_send_underspecified_error.stderr @@ -39,7 +39,7 @@ error[E0283]: type annotations needed note: required by a bound in `send_message_id_error` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | - | unsafe fn send_message_id_error(obj: T, sel: Sel, args: A) -> Result> + | unsafe fn send_message_id_error(obj: T, sel: Sel, args: A) -> Result> | --------------------- required by a bound in this associated function | where | *mut *mut E: Encode, @@ -60,7 +60,7 @@ error[E0283]: type annotations needed note: required by a bound in `send_message_id_error` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | - | unsafe fn send_message_id_error(obj: T, sel: Sel, args: A) -> Result> + | unsafe fn send_message_id_error(obj: T, sel: Sel, args: A) -> Result> | --------------------- required by a bound in this associated function | where | *mut *mut E: Encode, @@ -81,7 +81,7 @@ error[E0283]: type annotations needed note: required by a bound in `send_message_id_error` --> $WORKSPACE/crates/objc2/src/__macro_helpers/msg_send_id.rs | - | unsafe fn send_message_id_error(obj: T, sel: Sel, args: A) -> Result> + | unsafe fn send_message_id_error(obj: T, sel: Sel, args: A) -> Result> | --------------------- required by a bound in this associated function | where | *mut *mut E: Encode,