From 96f4d52b996d733669ad006bc0672f825b42ac7f Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 3 Oct 2023 01:19:52 +0200 Subject: [PATCH] Restrict `this` parameters to `Self`-like types Also refactor declare class internals slightly --- crates/objc2/CHANGELOG.md | 2 + .../src/__macro_helpers/declare_class.rs | 245 ++++++++- crates/objc2/src/__macro_helpers/mod.rs | 193 +------- crates/objc2/src/macros/__field_helpers.rs | 8 +- crates/objc2/src/macros/declare_class.rs | 17 +- .../expected/apple-aarch64.s | 465 ++++++++---------- .../test_declare_class/expected/apple-armv7.s | 358 ++++++-------- .../expected/apple-armv7s.s | 369 ++++++-------- .../expected/apple-old-x86.s | 284 +++++------ .../test_declare_class/expected/apple-x86.s | 284 +++++------ .../expected/apple-x86_64.s | 198 +++----- .../ui/declare_class_invalid_receiver.rs | 5 + .../ui/declare_class_invalid_receiver.stderr | 116 +++-- .../declare_class_mut_self_not_mutable.stderr | 30 +- 14 files changed, 1209 insertions(+), 1365 deletions(-) diff --git a/crates/objc2/CHANGELOG.md b/crates/objc2/CHANGELOG.md index 26211ea27..b429aa3f0 100644 --- a/crates/objc2/CHANGELOG.md +++ b/crates/objc2/CHANGELOG.md @@ -101,6 +101,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). let ivar = cls.instance_variable("number").unwrap(); let number = unsafe { *ivar.load::(&obj) }; ``` +* Disallow the ability to use non-`Self`-like types as the receiver in + `declare_class!`. ### Removed * **BREAKING**: Removed `ProtocolType` implementation for `NSObject`. diff --git a/crates/objc2/src/__macro_helpers/declare_class.rs b/crates/objc2/src/__macro_helpers/declare_class.rs index df96f6b06..c98e8a99b 100644 --- a/crates/objc2/src/__macro_helpers/declare_class.rs +++ b/crates/objc2/src/__macro_helpers/declare_class.rs @@ -1,9 +1,20 @@ +#[cfg(all(debug_assertions, feature = "verify"))] +use alloc::vec::Vec; +use core::marker::PhantomData; +#[cfg(all(debug_assertions, feature = "verify"))] +use std::collections::HashSet; + +#[cfg(all(debug_assertions, feature = "verify"))] +use crate::runtime::{AnyProtocol, MethodDescription}; + use objc2_encode::Encoding; +use crate::declare::{ClassBuilder, IvarType}; use crate::encode::Encode; use crate::rc::{Allocated, Id}; +use crate::runtime::{AnyClass, MethodImplementation, Sel}; use crate::runtime::{AnyObject, MessageReceiver}; -use crate::{ClassType, Message}; +use crate::{ClassType, Message, ProtocolType}; use super::{CopyOrMutCopy, Init, MaybeUnwrap, New, Other}; use crate::mutability; @@ -52,7 +63,7 @@ where // restrict it here to only be when the selector is `init`. // // Additionally, the receiver and return type must have the same generic -// generic parameter `T`. +// parameter `T`. impl MessageRecieveId, Ret> for Init where T: Message, @@ -190,3 +201,233 @@ where { // Noop } + +#[derive(Debug)] +pub struct ClassBuilderHelper { + builder: ClassBuilder, + p: PhantomData, +} + +#[track_caller] +fn failed_declaring_class(name: &str) -> ! { + panic!("could not create new class {name}. Perhaps a class with that name already exists?") +} + +impl ClassBuilderHelper { + #[inline] + #[track_caller] + pub fn new() -> Self + where + T::Super: ClassType, + { + let builder = match ClassBuilder::new(T::NAME, ::class()) { + Some(builder) => builder, + None => failed_declaring_class(T::NAME), + }; + + Self { + builder, + p: PhantomData, + } + } + + #[inline] + pub fn add_protocol_methods

(&mut self) -> ClassProtocolMethodsBuilder<'_, T> + where + P: ?Sized + ProtocolType, + { + let protocol = P::protocol(); + + if let Some(protocol) = protocol { + self.builder.add_protocol(protocol); + } + + #[cfg(all(debug_assertions, feature = "verify"))] + { + ClassProtocolMethodsBuilder { + builder: self, + protocol, + required_instance_methods: protocol + .map(|p| p.method_descriptions(true)) + .unwrap_or_default(), + optional_instance_methods: protocol + .map(|p| p.method_descriptions(false)) + .unwrap_or_default(), + registered_instance_methods: HashSet::new(), + required_class_methods: protocol + .map(|p| p.class_method_descriptions(true)) + .unwrap_or_default(), + optional_class_methods: protocol + .map(|p| p.class_method_descriptions(false)) + .unwrap_or_default(), + registered_class_methods: HashSet::new(), + } + } + + #[cfg(not(all(debug_assertions, feature = "verify")))] + { + ClassProtocolMethodsBuilder { builder: self } + } + } + + // Extra: Restrict to callee `T` + #[inline] + pub unsafe fn add_method(&mut self, sel: Sel, func: F) + where + F: MethodImplementation, + { + unsafe { self.builder.add_method(sel, func) } + } + + #[inline] + pub unsafe fn add_class_method(&mut self, sel: Sel, func: F) + where + F: MethodImplementation, + { + unsafe { self.builder.add_class_method(sel, func) } + } + + #[inline] + pub fn add_static_ivar(&mut self) { + self.builder.add_static_ivar::() + } + + #[inline] + pub fn register(self) -> &'static AnyClass { + self.builder.register() + } +} + +/// Helper for ensuring that: +/// - Only methods on the protocol are overriden. +/// - TODO: The methods have the correct signature. +/// - All required methods are overridden. +#[derive(Debug)] +pub struct ClassProtocolMethodsBuilder<'a, T: ?Sized> { + builder: &'a mut ClassBuilderHelper, + #[cfg(all(debug_assertions, feature = "verify"))] + protocol: Option<&'static AnyProtocol>, + #[cfg(all(debug_assertions, feature = "verify"))] + required_instance_methods: Vec, + #[cfg(all(debug_assertions, feature = "verify"))] + optional_instance_methods: Vec, + #[cfg(all(debug_assertions, feature = "verify"))] + registered_instance_methods: HashSet, + #[cfg(all(debug_assertions, feature = "verify"))] + required_class_methods: Vec, + #[cfg(all(debug_assertions, feature = "verify"))] + optional_class_methods: Vec, + #[cfg(all(debug_assertions, feature = "verify"))] + registered_class_methods: HashSet, +} + +impl ClassProtocolMethodsBuilder<'_, T> { + #[inline] + pub unsafe fn add_method(&mut self, sel: Sel, func: F) + where + F: MethodImplementation, + { + #[cfg(all(debug_assertions, feature = "verify"))] + if let Some(protocol) = self.protocol { + let _types = self + .required_instance_methods + .iter() + .chain(&self.optional_instance_methods) + .find(|desc| desc.sel == sel) + .map(|desc| desc.types) + .unwrap_or_else(|| { + panic!( + "failed overriding protocol method -[{protocol} {sel}]: method not found" + ) + }); + } + + // SAFETY: Checked by caller + unsafe { self.builder.add_method(sel, func) }; + + #[cfg(all(debug_assertions, feature = "verify"))] + if !self.registered_instance_methods.insert(sel) { + unreachable!("already added") + } + } + + #[inline] + pub unsafe fn add_class_method(&mut self, sel: Sel, func: F) + where + F: MethodImplementation, + { + #[cfg(all(debug_assertions, feature = "verify"))] + if let Some(protocol) = self.protocol { + let _types = self + .required_class_methods + .iter() + .chain(&self.optional_class_methods) + .find(|desc| desc.sel == sel) + .map(|desc| desc.types) + .unwrap_or_else(|| { + panic!( + "failed overriding protocol method +[{protocol} {sel}]: method not found" + ) + }); + } + + // SAFETY: Checked by caller + unsafe { self.builder.add_class_method(sel, func) }; + + #[cfg(all(debug_assertions, feature = "verify"))] + if !self.registered_class_methods.insert(sel) { + unreachable!("already added") + } + } + + #[cfg(all(debug_assertions, feature = "verify"))] + pub fn finish(self) { + let superclass = self.builder.builder.superclass(); + + if let Some(protocol) = self.protocol { + for desc in &self.required_instance_methods { + if self.registered_instance_methods.contains(&desc.sel) { + continue; + } + + // TODO: Don't do this when `NS_PROTOCOL_REQUIRES_EXPLICIT_IMPLEMENTATION` + if superclass + .and_then(|superclass| superclass.instance_method(desc.sel)) + .is_some() + { + continue; + } + + panic!( + "must implement required protocol method -[{protocol} {}]", + desc.sel + ) + } + } + + if let Some(protocol) = self.protocol { + for desc in &self.required_class_methods { + if self.registered_class_methods.contains(&desc.sel) { + continue; + } + + // TODO: Don't do this when `NS_PROTOCOL_REQUIRES_EXPLICIT_IMPLEMENTATION` + if superclass + .and_then(|superclass| superclass.class_method(desc.sel)) + .is_some() + { + continue; + } + + panic!( + "must implement required protocol method +[{protocol} {}]", + desc.sel + ); + } + } + } + + #[inline] + #[cfg(not(all(debug_assertions, feature = "verify")))] + pub fn finish(self) {} +} diff --git a/crates/objc2/src/__macro_helpers/mod.rs b/crates/objc2/src/__macro_helpers/mod.rs index e1646649f..b7cffdbf7 100644 --- a/crates/objc2/src/__macro_helpers/mod.rs +++ b/crates/objc2/src/__macro_helpers/mod.rs @@ -1,14 +1,3 @@ -#[cfg(all(debug_assertions, feature = "verify"))] -use alloc::vec::Vec; -#[cfg(all(debug_assertions, feature = "verify"))] -use std::collections::HashSet; - -use crate::declare::ClassBuilder; -#[cfg(all(debug_assertions, feature = "verify"))] -use crate::runtime::MethodDescription; -use crate::runtime::{AnyClass, AnyProtocol, MethodImplementation, Sel}; -use crate::Message; - pub use core::borrow::{Borrow, BorrowMut}; pub use core::cell::UnsafeCell; pub use core::convert::{AsMut, AsRef}; @@ -35,8 +24,9 @@ pub use self::cache::{CachedClass, CachedSel}; pub use self::common_selectors::{alloc_sel, dealloc_sel, init_sel, new_sel}; pub use self::convert::{ConvertArgument, ConvertArguments, ConvertReturn, TupleExtender}; pub use self::declare_class::{ - assert_mutability_matches_superclass_mutability, IdReturnValue, MaybeOptionId, - MessageRecieveId, ValidSubclassMutability, + assert_mutability_matches_superclass_mutability, ClassBuilderHelper, + ClassProtocolMethodsBuilder, IdReturnValue, MaybeOptionId, MessageRecieveId, + ValidSubclassMutability, }; pub use self::method_family::{ retain_semantics, Alloc, CopyOrMutCopy, Init, New, Other, RetainSemantics, @@ -74,183 +64,6 @@ impl ModuleInfo { } } -impl ClassBuilder { - #[doc(hidden)] - pub fn __add_protocol_methods<'a, 'b>( - &'a mut self, - protocol: Option<&'b AnyProtocol>, - ) -> ClassProtocolMethodsBuilder<'a, 'b> { - if let Some(protocol) = protocol { - self.add_protocol(protocol); - } - - #[cfg(all(debug_assertions, feature = "verify"))] - { - ClassProtocolMethodsBuilder { - builder: self, - protocol, - required_instance_methods: protocol - .map(|p| p.method_descriptions(true)) - .unwrap_or_default(), - optional_instance_methods: protocol - .map(|p| p.method_descriptions(false)) - .unwrap_or_default(), - registered_instance_methods: HashSet::new(), - required_class_methods: protocol - .map(|p| p.class_method_descriptions(true)) - .unwrap_or_default(), - optional_class_methods: protocol - .map(|p| p.class_method_descriptions(false)) - .unwrap_or_default(), - registered_class_methods: HashSet::new(), - } - } - - #[cfg(not(all(debug_assertions, feature = "verify")))] - { - ClassProtocolMethodsBuilder { - builder: self, - protocol, - } - } - } -} - -/// Helper for ensuring that: -/// - Only methods on the protocol are overriden. -/// - TODO: The methods have the correct signature. -/// - All required methods are overridden. -#[derive(Debug)] -pub struct ClassProtocolMethodsBuilder<'a, 'b> { - builder: &'a mut ClassBuilder, - #[allow(unused)] - protocol: Option<&'b AnyProtocol>, - #[cfg(all(debug_assertions, feature = "verify"))] - required_instance_methods: Vec, - #[cfg(all(debug_assertions, feature = "verify"))] - optional_instance_methods: Vec, - #[cfg(all(debug_assertions, feature = "verify"))] - registered_instance_methods: HashSet, - #[cfg(all(debug_assertions, feature = "verify"))] - required_class_methods: Vec, - #[cfg(all(debug_assertions, feature = "verify"))] - optional_class_methods: Vec, - #[cfg(all(debug_assertions, feature = "verify"))] - registered_class_methods: HashSet, -} - -impl ClassProtocolMethodsBuilder<'_, '_> { - #[inline] - pub unsafe fn add_method(&mut self, sel: Sel, func: F) - where - T: Message + ?Sized, - F: MethodImplementation, - { - #[cfg(all(debug_assertions, feature = "verify"))] - if let Some(protocol) = self.protocol { - let _types = self - .required_instance_methods - .iter() - .chain(&self.optional_instance_methods) - .find(|desc| desc.sel == sel) - .map(|desc| desc.types) - .unwrap_or_else(|| { - panic!( - "failed overriding protocol method -[{protocol} {sel}]: method not found" - ) - }); - } - - // SAFETY: Checked by caller - unsafe { self.builder.add_method(sel, func) }; - - #[cfg(all(debug_assertions, feature = "verify"))] - if !self.registered_instance_methods.insert(sel) { - unreachable!("already added") - } - } - - #[inline] - pub unsafe fn add_class_method(&mut self, sel: Sel, func: F) - where - F: MethodImplementation, - { - #[cfg(all(debug_assertions, feature = "verify"))] - if let Some(protocol) = self.protocol { - let _types = self - .required_class_methods - .iter() - .chain(&self.optional_class_methods) - .find(|desc| desc.sel == sel) - .map(|desc| desc.types) - .unwrap_or_else(|| { - panic!( - "failed overriding protocol method +[{protocol} {sel}]: method not found" - ) - }); - } - - // SAFETY: Checked by caller - unsafe { self.builder.add_class_method(sel, func) }; - - #[cfg(all(debug_assertions, feature = "verify"))] - if !self.registered_class_methods.insert(sel) { - unreachable!("already added") - } - } - - #[cfg(all(debug_assertions, feature = "verify"))] - pub fn __finish(self) { - let superclass = self.builder.superclass(); - - if let Some(protocol) = self.protocol { - for desc in &self.required_instance_methods { - if self.registered_instance_methods.contains(&desc.sel) { - continue; - } - - // TODO: Don't do this when `NS_PROTOCOL_REQUIRES_EXPLICIT_IMPLEMENTATION` - if superclass - .and_then(|superclass| superclass.instance_method(desc.sel)) - .is_some() - { - continue; - } - - panic!( - "must implement required protocol method -[{protocol} {}]", - desc.sel - ) - } - } - - if let Some(protocol) = self.protocol { - for desc in &self.required_class_methods { - if self.registered_class_methods.contains(&desc.sel) { - continue; - } - - // TODO: Don't do this when `NS_PROTOCOL_REQUIRES_EXPLICIT_IMPLEMENTATION` - if superclass - .and_then(|superclass| superclass.class_method(desc.sel)) - .is_some() - { - continue; - } - - panic!( - "must implement required protocol method +[{protocol} {}]", - desc.sel - ); - } - } - } - - #[inline] - #[cfg(not(all(debug_assertions, feature = "verify")))] - pub fn __finish(self) {} -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/objc2/src/macros/__field_helpers.rs b/crates/objc2/src/macros/__field_helpers.rs index 3a18a3b82..b545f17c6 100644 --- a/crates/objc2/src/macros/__field_helpers.rs +++ b/crates/objc2/src/macros/__field_helpers.rs @@ -100,7 +100,9 @@ macro_rules! __parse_fields { "no need to specify an ivar module when the type has no ivars" ); - pub(super) fn __objc2_declare_ivars(__objc2_builder: &mut $crate::declare::ClassBuilder) {} + pub(super) fn __objc2_declare_ivars( + __objc2_builder: &mut $crate::__macro_helpers::ClassBuilderHelper, + ) {} } $out_macro! { @@ -125,7 +127,9 @@ macro_rules! __parse_fields { $($ivar_output)+ - pub(super) fn __objc2_declare_ivars(__objc2_builder: &mut $crate::declare::ClassBuilder) { + pub(super) fn __objc2_declare_ivars( + __objc2_builder: &mut $crate::__macro_helpers::ClassBuilderHelper, + ) { // Ivars $( __objc2_builder.add_static_ivar::<$ivar_type_name>(); diff --git a/crates/objc2/src/macros/declare_class.rs b/crates/objc2/src/macros/declare_class.rs index 44aa7b3c6..2b710477c 100644 --- a/crates/objc2/src/macros/declare_class.rs +++ b/crates/objc2/src/macros/declare_class.rs @@ -555,16 +555,7 @@ macro_rules! __declare_class_inner { static REGISTER_CLASS: $crate::__macro_helpers::Once = $crate::__macro_helpers::Once::new(); REGISTER_CLASS.call_once(|| { - let __objc2_superclass = <$superclass as $crate::ClassType>::class(); - let mut __objc2_builder = $crate::declare::ClassBuilder::new( - ::NAME, - __objc2_superclass, - ).unwrap_or_else(|| { - $crate::__macro_helpers::panic!( - "could not create new class {}. Perhaps a class with that name already exists?", - ::NAME, - ) - }); + let mut __objc2_builder = $crate::__macro_helpers::ClassBuilderHelper::::new(); $($ivar_helper_module::__objc2_declare_ivars(&mut __objc2_builder);)? @@ -783,9 +774,7 @@ macro_rules! __declare_class_register_impls { // Implement protocol #[allow(unused_mut)] - let mut __objc2_protocol_builder = $builder.__add_protocol_methods( - ::protocol() - ); + let mut __objc2_protocol_builder = $builder.add_protocol_methods::(); // In case the user's function is marked `deprecated` #[allow(deprecated)] @@ -801,7 +790,7 @@ macro_rules! __declare_class_register_impls { } // Finished declaring protocol; get error message if any - __objc2_protocol_builder.__finish(); + __objc2_protocol_builder.finish(); } $crate::__declare_class_register_impls! { diff --git a/crates/test-assembly/crates/test_declare_class/expected/apple-aarch64.s b/crates/test-assembly/crates/test_declare_class/expected/apple-aarch64.s index 00cce80b9..8bb3a2e77 100644 --- a/crates/test-assembly/crates/test_declare_class/expected/apple-aarch64.s +++ b/crates/test-assembly/crates/test_declare_class/expected/apple-aarch64.s @@ -5,15 +5,15 @@ SYM(core[CRATE_ID]::ptr::drop_in_place::<::call .p2align 2 SYM(::call_once::<::class::{closure#0}>::{closure#0}, 0): - sub sp, sp, #112 - stp x22, x21, [sp, #64] - stp x20, x19, [sp, #80] - stp x29, x30, [sp, #96] - add x29, sp, #96 + sub sp, sp, #64 + stp x22, x21, [sp, #16] + stp x20, x19, [sp, #32] + stp x29, x30, [sp, #48] + add x29, sp, #48 ldr x8, [x0] ldrb w9, [x8] strb wzr, [x8] - cbz w9, LBB1_3 + cbz w9, LBB1_5 Lloh0: adrp x8, L_OBJC_CLASSLIST_REFERENCES_$_NSObject@GOTPAGE Lloh1: @@ -21,35 +21,35 @@ Lloh1: Lloh2: ldr x2, [x8] Lloh3: - adrp x0, l_anon.[ID].16@PAGE + adrp x0, l_anon.[ID].11@PAGE Lloh4: - add x0, x0, l_anon.[ID].16@PAGEOFF + add x0, x0, l_anon.[ID].11@PAGEOFF mov w1, #15 bl SYM(objc2::declare::ClassBuilder::new::GENERATED_ID, 0) - cbz x0, LBB1_4 - str x0, [sp] + cbz x0, LBB1_6 + str x0, [sp, #8] Lloh5: - adrp x1, l_anon.[ID].11@PAGE + adrp x1, l_anon.[ID].12@PAGE Lloh6: - add x1, x1, l_anon.[ID].11@PAGEOFF + add x1, x1, l_anon.[ID].12@PAGEOFF Lloh7: - adrp x5, l_anon.[ID].14@PAGE + adrp x5, l_anon.[ID].15@PAGE Lloh8: - add x5, x5, l_anon.[ID].14@PAGEOFF - mov x0, sp + add x5, x5, l_anon.[ID].15@PAGEOFF + add x0, sp, #8 mov w2, #4 mov w3, #1 mov w4, #0 bl SYM(objc2::declare::ClassBuilder::add_ivar_inner_mono::GENERATED_ID, 0) Lloh9: - adrp x1, l_anon.[ID].12@PAGE + adrp x1, l_anon.[ID].13@PAGE Lloh10: - add x1, x1, l_anon.[ID].12@PAGEOFF + add x1, x1, l_anon.[ID].13@PAGEOFF Lloh11: adrp x19, l_anon.[ID].2@PAGE Lloh12: add x19, x19, l_anon.[ID].2@PAGEOFF - mov x0, sp + add x0, sp, #8 mov w2, #4 mov w3, #8 mov w4, #3 @@ -73,7 +73,7 @@ Lloh20: adrp x5, SYM(::class::{closure#0}::__objc2_dealloc, 0)@PAGE Lloh21: add x5, x5, SYM(::class::{closure#0}::__objc2_dealloc, 0)@PAGEOFF - mov x0, sp + add x0, sp, #8 mov x2, x20 mov x3, #0 mov x4, x21 @@ -88,7 +88,7 @@ Lloh25: adrp x5, _init@PAGE Lloh26: add x5, x5, _init@PAGEOFF - mov x0, sp + add x0, sp, #8 mov x2, x20 mov x3, #0 mov x4, x19 @@ -101,7 +101,7 @@ Lloh29: adrp x5, _class_method@PAGE Lloh30: add x5, x5, _class_method@PAGEOFF - mov x0, sp + add x0, sp, #8 mov x2, x20 mov x3, #0 mov x4, x21 @@ -114,7 +114,7 @@ Lloh33: adrp x5, _method@PAGE Lloh34: add x5, x5, _method@PAGEOFF - mov x0, sp + add x0, sp, #8 mov x2, x20 mov x3, #0 mov x4, x21 @@ -131,7 +131,7 @@ Lloh39: adrp x5, _method_bool@PAGE Lloh40: add x5, x5, _method_bool@PAGEOFF - mov x0, sp + add x0, sp, #8 mov x2, x21 mov w3, #1 mov x4, x21 @@ -144,7 +144,7 @@ Lloh43: adrp x5, _method_id@PAGE Lloh44: add x5, x5, _method_id@PAGEOFF - mov x0, sp + add x0, sp, #8 mov x2, x20 mov x3, #0 mov x4, x19 @@ -157,7 +157,7 @@ Lloh47: adrp x5, _method_id_with_param@PAGE Lloh48: add x5, x5, _method_id_with_param@PAGEOFF - mov x0, sp + add x0, sp, #8 mov x2, x21 mov w3, #1 mov x4, x19 @@ -168,9 +168,11 @@ Lloh50: add x0, x0, l_anon.[ID].17@PAGEOFF mov w1, #9 bl SYM(objc2::runtime::AnyProtocol::get::GENERATED_ID, 0) + cbz x0, LBB1_4 mov x1, x0 - mov x0, sp - bl SYM(objc2::__macro_helpers::::__add_protocol_methods::GENERATED_ID, 0) + add x0, sp, #8 + bl SYM(objc2::declare::ClassBuilder::add_protocol::GENERATED_ID, 0) +LBB1_4: Lloh51: adrp x8, L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166@PAGE Lloh52: @@ -180,61 +182,47 @@ Lloh53: Lloh54: add x2, x2, l_anon.[ID].7@PAGEOFF Lloh55: - adrp x5, _copyWithZone@PAGE + adrp x4, l_anon.[ID].2@PAGE Lloh56: + add x4, x4, l_anon.[ID].2@PAGEOFF +Lloh57: + adrp x5, _copyWithZone@PAGE +Lloh58: add x5, x5, _copyWithZone@PAGEOFF + add x0, sp, #8 mov w3, #1 - mov x4, x19 bl SYM(objc2::declare::ClassBuilder::add_method_inner::GENERATED_ID, 0) - ldr x0, [sp] + ldr x0, [sp, #8] bl SYM(objc2::declare::ClassBuilder::register::GENERATED_ID, 0) - ldp x29, x30, [sp, #96] - ldp x20, x19, [sp, #80] - ldp x22, x21, [sp, #64] - add sp, sp, #112 + ldp x29, x30, [sp, #48] + ldp x20, x19, [sp, #32] + ldp x22, x21, [sp, #16] + add sp, sp, #64 ret -LBB1_3: -Lloh57: +LBB1_5: +Lloh59: adrp x0, l_anon.[ID].8@PAGE -Lloh58: +Lloh60: add x0, x0, l_anon.[ID].8@PAGEOFF -Lloh59: +Lloh61: adrp x2, l_anon.[ID].10@PAGE -Lloh60: +Lloh62: add x2, x2, l_anon.[ID].10@PAGEOFF mov w1, #43 bl SYM(core::panicking::panic::GENERATED_ID, 0) -LBB1_4: -Lloh61: - adrp x8, l_anon.[ID].21@PAGE -Lloh62: - add x8, x8, l_anon.[ID].21@PAGEOFF +LBB1_6: Lloh63: - adrp x9, SYM(<&str as core[CRATE_ID]::fmt::Display>::fmt, 0)@PAGE + adrp x0, l_anon.[ID].11@PAGE Lloh64: - add x9, x9, SYM(<&str as core[CRATE_ID]::fmt::Display>::fmt, 0)@PAGEOFF - stp x8, x9, [sp, #48] + add x0, x0, l_anon.[ID].11@PAGEOFF Lloh65: - adrp x8, l_anon.[ID].20@PAGE + adrp x2, l_anon.[ID].16@PAGE Lloh66: - add x8, x8, l_anon.[ID].20@PAGEOFF - mov w9, #2 - stp x8, x9, [sp] - add x8, sp, #48 - mov w9, #1 - str x8, [sp, #16] - stp x9, xzr, [sp, #24] -Lloh67: - adrp x1, l_anon.[ID].15@PAGE -Lloh68: - add x1, x1, l_anon.[ID].15@PAGEOFF - mov x0, sp - bl SYM(core::panicking::panic_fmt::GENERATED_ID, 0) + add x2, x2, l_anon.[ID].16@PAGEOFF + mov w1, #15 + bl SYM(objc2::__macro_helpers::declare_class::failed_declaring_class::GENERATED_ID, 0) .loh AdrpAdd Lloh3, Lloh4 .loh AdrpLdrGotLdr Lloh0, Lloh1, Lloh2 - .loh AdrpAdd Lloh55, Lloh56 - .loh AdrpAdd Lloh53, Lloh54 - .loh AdrpLdr Lloh51, Lloh52 .loh AdrpAdd Lloh49, Lloh50 .loh AdrpAdd Lloh47, Lloh48 .loh AdrpLdr Lloh45, Lloh46 @@ -257,12 +245,14 @@ Lloh68: .loh AdrpAdd Lloh9, Lloh10 .loh AdrpAdd Lloh7, Lloh8 .loh AdrpAdd Lloh5, Lloh6 - .loh AdrpAdd Lloh59, Lloh60 .loh AdrpAdd Lloh57, Lloh58 - .loh AdrpAdd Lloh67, Lloh68 + .loh AdrpAdd Lloh55, Lloh56 + .loh AdrpAdd Lloh53, Lloh54 + .loh AdrpLdr Lloh51, Lloh52 + .loh AdrpAdd Lloh61, Lloh62 + .loh AdrpAdd Lloh59, Lloh60 .loh AdrpAdd Lloh65, Lloh66 .loh AdrpAdd Lloh63, Lloh64 - .loh AdrpAdd Lloh61, Lloh62 .p2align 2 SYM(<::call_once<::class::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0): @@ -277,83 +267,76 @@ SYM(<::call_once<::fmt, 0): - mov x2, x1 - ldp x8, x1, [x0] - mov x0, x8 - b SYM(::fmt::GENERATED_ID, 0) - .globl _get_class .p2align 2 _get_class: sub sp, sp, #32 stp x29, x30, [sp, #16] add x29, sp, #16 -Lloh69: +Lloh67: adrp x8, SYM(::class::REGISTER_CLASS, 0)@PAGE -Lloh70: +Lloh68: add x8, x8, SYM(::class::REGISTER_CLASS, 0)@PAGEOFF ldapr x8, [x8] cmp x8, #3 - b.ne LBB4_3 -Lloh71: - adrp x0, l_anon.[ID].16@PAGE -Lloh72: - add x0, x0, l_anon.[ID].16@PAGEOFF + b.ne LBB3_3 +Lloh69: + adrp x0, l_anon.[ID].11@PAGE +Lloh70: + add x0, x0, l_anon.[ID].11@PAGEOFF mov w1, #15 bl SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) - cbz x0, LBB4_4 -LBB4_2: + cbz x0, LBB3_4 +LBB3_2: ldp x29, x30, [sp, #16] add sp, sp, #32 ret -LBB4_3: +LBB3_3: mov w8, #1 strb w8, [sp, #7] add x8, sp, #7 str x8, [sp, #8] -Lloh73: +Lloh71: adrp x0, SYM(::class::REGISTER_CLASS, 0)@PAGE -Lloh74: +Lloh72: add x0, x0, SYM(::class::REGISTER_CLASS, 0)@PAGEOFF -Lloh75: +Lloh73: adrp x3, l_anon.[ID].0@PAGE -Lloh76: +Lloh74: add x3, x3, l_anon.[ID].0@PAGEOFF -Lloh77: - adrp x4, l_anon.[ID].15@PAGE -Lloh78: - add x4, x4, l_anon.[ID].15@PAGEOFF +Lloh75: + adrp x4, l_anon.[ID].16@PAGE +Lloh76: + add x4, x4, l_anon.[ID].16@PAGEOFF add x2, sp, #8 mov w1, #0 bl SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) -Lloh79: - adrp x0, l_anon.[ID].16@PAGE -Lloh80: - add x0, x0, l_anon.[ID].16@PAGEOFF +Lloh77: + adrp x0, l_anon.[ID].11@PAGE +Lloh78: + add x0, x0, l_anon.[ID].11@PAGEOFF mov w1, #15 bl SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) - cbnz x0, LBB4_2 -LBB4_4: -Lloh81: + cbnz x0, LBB3_2 +LBB3_4: +Lloh79: adrp x0, l_anon.[ID].8@PAGE -Lloh82: +Lloh80: add x0, x0, l_anon.[ID].8@PAGEOFF -Lloh83: - adrp x2, l_anon.[ID].15@PAGE -Lloh84: - add x2, x2, l_anon.[ID].15@PAGEOFF +Lloh81: + adrp x2, l_anon.[ID].16@PAGE +Lloh82: + add x2, x2, l_anon.[ID].16@PAGEOFF mov w1, #43 bl SYM(core::panicking::panic::GENERATED_ID, 0) + .loh AdrpAdd Lloh67, Lloh68 .loh AdrpAdd Lloh69, Lloh70 - .loh AdrpAdd Lloh71, Lloh72 - .loh AdrpAdd Lloh79, Lloh80 .loh AdrpAdd Lloh77, Lloh78 .loh AdrpAdd Lloh75, Lloh76 .loh AdrpAdd Lloh73, Lloh74 - .loh AdrpAdd Lloh83, Lloh84 + .loh AdrpAdd Lloh71, Lloh72 .loh AdrpAdd Lloh81, Lloh82 + .loh AdrpAdd Lloh79, Lloh80 .globl _get_obj .p2align 2 @@ -361,18 +344,18 @@ _get_obj: stp x20, x19, [sp, #-32]! stp x29, x30, [sp, #16] add x29, sp, #16 -Lloh85: +Lloh83: adrp x8, L_OBJC_SELECTOR_REFERENCES_new@GOTPAGE -Lloh86: +Lloh84: ldr x8, [x8, L_OBJC_SELECTOR_REFERENCES_new@GOTPAGEOFF] -Lloh87: +Lloh85: ldr x19, [x8] bl _get_class mov x1, x19 ldp x29, x30, [sp, #16] ldp x20, x19, [sp], #32 b _objc_msgSend - .loh AdrpLdrGotLdr Lloh85, Lloh86, Lloh87 + .loh AdrpLdrGotLdr Lloh83, Lloh84, Lloh85 .globl _access_ivars .p2align 2 @@ -383,18 +366,18 @@ _access_ivars: add x29, sp, #32 bl _get_obj mov x19, x0 -Lloh88: - adrp x1, l_anon.[ID].11@PAGE -Lloh89: - add x1, x1, l_anon.[ID].11@PAGEOFF +Lloh86: + adrp x1, l_anon.[ID].12@PAGE +Lloh87: + add x1, x1, l_anon.[ID].12@PAGEOFF mov w2, #4 bl SYM(objc2::runtime::AnyObject::lookup_instance_variable_dynamically::GENERATED_ID, 0) bl _ivar_getOffset ldrb w20, [x19, x0] -Lloh90: - adrp x1, l_anon.[ID].12@PAGE -Lloh91: - add x1, x1, l_anon.[ID].12@PAGEOFF +Lloh88: + adrp x1, l_anon.[ID].13@PAGE +Lloh89: + add x1, x1, l_anon.[ID].13@PAGEOFF mov x0, x19 mov w2, #4 bl SYM(objc2::runtime::AnyObject::lookup_instance_variable_dynamically::GENERATED_ID, 0) @@ -408,8 +391,8 @@ Lloh91: ldp x20, x19, [sp, #16] ldp x22, x21, [sp], #48 ret - .loh AdrpAdd Lloh90, Lloh91 .loh AdrpAdd Lloh88, Lloh89 + .loh AdrpAdd Lloh86, Lloh87 .globl SYM(::class, 0) .p2align 2 @@ -417,70 +400,70 @@ SYM(::class::REGISTER_CLASS, 0)@PAGE -Lloh93: +Lloh91: add x8, x8, SYM(::class::REGISTER_CLASS, 0)@PAGEOFF ldapr x8, [x8] cmp x8, #3 - b.ne LBB7_3 -Lloh94: - adrp x0, l_anon.[ID].16@PAGE -Lloh95: - add x0, x0, l_anon.[ID].16@PAGEOFF + b.ne LBB6_3 +Lloh92: + adrp x0, l_anon.[ID].11@PAGE +Lloh93: + add x0, x0, l_anon.[ID].11@PAGEOFF mov w1, #15 bl SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) - cbz x0, LBB7_4 -LBB7_2: + cbz x0, LBB6_4 +LBB6_2: ldp x29, x30, [sp, #16] add sp, sp, #32 ret -LBB7_3: +LBB6_3: mov w8, #1 strb w8, [sp, #7] add x8, sp, #7 str x8, [sp, #8] -Lloh96: +Lloh94: adrp x0, SYM(::class::REGISTER_CLASS, 0)@PAGE -Lloh97: +Lloh95: add x0, x0, SYM(::class::REGISTER_CLASS, 0)@PAGEOFF -Lloh98: +Lloh96: adrp x3, l_anon.[ID].0@PAGE -Lloh99: +Lloh97: add x3, x3, l_anon.[ID].0@PAGEOFF -Lloh100: - adrp x4, l_anon.[ID].15@PAGE -Lloh101: - add x4, x4, l_anon.[ID].15@PAGEOFF +Lloh98: + adrp x4, l_anon.[ID].16@PAGE +Lloh99: + add x4, x4, l_anon.[ID].16@PAGEOFF add x2, sp, #8 mov w1, #0 bl SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) -Lloh102: - adrp x0, l_anon.[ID].16@PAGE -Lloh103: - add x0, x0, l_anon.[ID].16@PAGEOFF +Lloh100: + adrp x0, l_anon.[ID].11@PAGE +Lloh101: + add x0, x0, l_anon.[ID].11@PAGEOFF mov w1, #15 bl SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) - cbnz x0, LBB7_2 -LBB7_4: -Lloh104: + cbnz x0, LBB6_2 +LBB6_4: +Lloh102: adrp x0, l_anon.[ID].8@PAGE -Lloh105: +Lloh103: add x0, x0, l_anon.[ID].8@PAGEOFF -Lloh106: - adrp x2, l_anon.[ID].15@PAGE -Lloh107: - add x2, x2, l_anon.[ID].15@PAGEOFF +Lloh104: + adrp x2, l_anon.[ID].16@PAGE +Lloh105: + add x2, x2, l_anon.[ID].16@PAGEOFF mov w1, #43 bl SYM(core::panicking::panic::GENERATED_ID, 0) + .loh AdrpAdd Lloh90, Lloh91 .loh AdrpAdd Lloh92, Lloh93 - .loh AdrpAdd Lloh94, Lloh95 - .loh AdrpAdd Lloh102, Lloh103 .loh AdrpAdd Lloh100, Lloh101 .loh AdrpAdd Lloh98, Lloh99 .loh AdrpAdd Lloh96, Lloh97 - .loh AdrpAdd Lloh106, Lloh107 + .loh AdrpAdd Lloh94, Lloh95 .loh AdrpAdd Lloh104, Lloh105 + .loh AdrpAdd Lloh102, Lloh103 .p2align 2 SYM(::class::{closure#0}::__objc2_dealloc, 0): @@ -490,22 +473,22 @@ SYM(::class::REGISTER_CLASS, 0),8,3 + .section __TEXT,__const l_anon.[ID].17: .ascii "NSCopying" -l_anon.[ID].18: - .ascii "could not create new class " - -l_anon.[ID].19: - .ascii ". Perhaps a class with that name already exists?" - - .section __DATA,__const - .p2align 3, 0x0 -l_anon.[ID].20: - .quad l_anon.[ID].18 - .asciz "\033\000\000\000\000\000\000" - .quad l_anon.[ID].19 - .asciz "0\000\000\000\000\000\000" - - .p2align 3, 0x0 -l_anon.[ID].21: - .quad l_anon.[ID].16 - .asciz "\017\000\000\000\000\000\000" - .section __TEXT,__objc_methname,cstring_literals .globl L_OBJC_METH_VAR_NAME_d874ee9262978be2 L_OBJC_METH_VAR_NAME_d874ee9262978be2: diff --git a/crates/test-assembly/crates/test_declare_class/expected/apple-armv7.s b/crates/test-assembly/crates/test_declare_class/expected/apple-armv7.s index 75852a803..fe42bf1e7 100644 --- a/crates/test-assembly/crates/test_declare_class/expected/apple-armv7.s +++ b/crates/test-assembly/crates/test_declare_class/expected/apple-armv7.s @@ -11,31 +11,31 @@ SYM(::call_once::<::__add_protocol_methods::GENERATED_ID, 0) - movw r2, :lower16:(l_anon.[ID].7-(LPC1_24+8)) + add r0, sp, #8 + bl SYM(objc2::declare::ClassBuilder::add_protocol::GENERATED_ID, 0) +LBB1_4: + movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166-(LPC1_24+8)) + add r0, sp, #8 + movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166-(LPC1_24+8)) mov r3, #1 - movt r2, :upper16:(l_anon.[ID].7-(LPC1_24+8)) - movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166-(LPC1_25+8)) - movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166-(LPC1_25+8)) LPC1_24: - add r2, pc, r2 -LPC1_25: ldr r1, [pc, r1] + movw r2, :lower16:(l_anon.[ID].7-(LPC1_25+8)) + movt r2, :upper16:(l_anon.[ID].7-(LPC1_25+8)) movw r9, :lower16:(_copyWithZone-(LPC1_26+8)) movt r9, :upper16:(_copyWithZone-(LPC1_26+8)) +LPC1_25: + add r2, pc, r2 LPC1_26: add r9, pc, r9 strd r8, r9, [sp] @@ -196,7 +200,7 @@ LPC1_26: sub sp, r7, #20 pop {r8, r10, r11} pop {r4, r5, r7, pc} -LBB1_3: +LBB1_5: movw r0, :lower16:(l_anon.[ID].8-(LPC1_27+8)) mov r1, #43 movt r0, :upper16:(l_anon.[ID].8-(LPC1_27+8)) @@ -208,37 +212,18 @@ LPC1_28: add r2, pc, r2 mov lr, pc b SYM(core::panicking::panic::GENERATED_ID, 0) -LBB1_4: - movw r0, :lower16:(l_anon.[ID].20-(LPC1_29+8)) - mov r5, #0 - movt r0, :upper16:(l_anon.[ID].20-(LPC1_29+8)) - movw r2, :lower16:(SYM(<&str as core[CRATE_ID]::fmt::Display>::fmt, 0)-(LPC1_30+8)) - movt r2, :upper16:(SYM(<&str as core[CRATE_ID]::fmt::Display>::fmt, 0)-(LPC1_30+8)) - movw r3, :lower16:(l_anon.[ID].21-(LPC1_31+8)) - movt r3, :upper16:(l_anon.[ID].21-(LPC1_31+8)) - movw r1, :lower16:(l_anon.[ID].15-(LPC1_32+8)) +LBB1_6: + movw r0, :lower16:(l_anon.[ID].11-(LPC1_29+8)) + mov r1, #15 + movt r0, :upper16:(l_anon.[ID].11-(LPC1_29+8)) + movw r2, :lower16:(l_anon.[ID].16-(LPC1_30+8)) + movt r2, :upper16:(l_anon.[ID].16-(LPC1_30+8)) LPC1_29: add r0, pc, r0 - movt r1, :upper16:(l_anon.[ID].15-(LPC1_32+8)) - str r0, [sp, #8] - mov r0, #1 - str r0, [sp, #20] - sub r0, r7, #28 - str r0, [sp, #16] -LPC1_32: - add r1, pc, r1 - add r0, sp, #8 - str r5, [sp, #24] - mov r5, #2 LPC1_30: add r2, pc, r2 -LPC1_31: - add r3, pc, r3 - str r5, [sp, #12] - str r2, [r7, #-24] - str r3, [r7, #-28] mov lr, pc - b SYM(core::panicking::panic_fmt::GENERATED_ID, 0) + b SYM(objc2::__macro_helpers::declare_class::failed_declaring_class::GENERATED_ID, 0) .p2align 2 .code 32 @@ -253,13 +238,6 @@ SYM(<::call_once<::fmt, 0): - mov r2, r1 - ldrd r0, r1, [r0] - b SYM(::fmt::GENERATED_ID, 0) - .globl _get_class .p2align 2 .code 32 @@ -267,58 +245,58 @@ _get_class: push {r7, lr} mov r7, sp sub sp, sp, #12 - movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC4_0+8)) - movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC4_0+8)) -LPC4_0: + movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC3_0+8)) + movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC3_0+8)) +LPC3_0: add r0, pc, r0 ldr r0, [r0] dmb ish cmp r0, #3 - bne LBB4_3 -LBB4_1: - movw r0, :lower16:(l_anon.[ID].16-(LPC4_4+8)) + bne LBB3_3 +LBB3_1: + movw r0, :lower16:(l_anon.[ID].11-(LPC3_4+8)) mov r1, #15 - movt r0, :upper16:(l_anon.[ID].16-(LPC4_4+8)) -LPC4_4: + movt r0, :upper16:(l_anon.[ID].11-(LPC3_4+8)) +LPC3_4: add r0, pc, r0 bl SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) cmp r0, #0 movne sp, r7 popne {r7, pc} -LBB4_2: - movw r0, :lower16:(l_anon.[ID].8-(LPC4_5+8)) +LBB3_2: + movw r0, :lower16:(l_anon.[ID].8-(LPC3_5+8)) mov r1, #43 - movt r0, :upper16:(l_anon.[ID].8-(LPC4_5+8)) - movw r2, :lower16:(l_anon.[ID].15-(LPC4_6+8)) - movt r2, :upper16:(l_anon.[ID].15-(LPC4_6+8)) -LPC4_5: + movt r0, :upper16:(l_anon.[ID].8-(LPC3_5+8)) + movw r2, :lower16:(l_anon.[ID].16-(LPC3_6+8)) + movt r2, :upper16:(l_anon.[ID].16-(LPC3_6+8)) +LPC3_5: add r0, pc, r0 -LPC4_6: +LPC3_6: add r2, pc, r2 mov lr, pc b SYM(core::panicking::panic::GENERATED_ID, 0) -LBB4_3: - movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC4_1+8)) +LBB3_3: + movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC3_1+8)) mov r2, #1 - movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC4_1+8)) - movw r3, :lower16:(l_anon.[ID].0-(LPC4_2+8)) - movt r3, :upper16:(l_anon.[ID].0-(LPC4_2+8)) - movw r1, :lower16:(l_anon.[ID].15-(LPC4_3+8)) - movt r1, :upper16:(l_anon.[ID].15-(LPC4_3+8)) + movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC3_1+8)) + movw r3, :lower16:(l_anon.[ID].0-(LPC3_2+8)) + movt r3, :upper16:(l_anon.[ID].0-(LPC3_2+8)) + movw r1, :lower16:(l_anon.[ID].16-(LPC3_3+8)) + movt r1, :upper16:(l_anon.[ID].16-(LPC3_3+8)) strb r2, [r7, #-5] sub r2, r7, #5 -LPC4_3: +LPC3_3: add r1, pc, r1 str r2, [r7, #-4] -LPC4_1: +LPC3_1: add r0, pc, r0 -LPC4_2: +LPC3_2: add r3, pc, r3 sub r2, r7, #4 str r1, [sp] mov r1, #0 bl SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) - b LBB4_1 + b LBB3_1 .globl _get_obj .p2align 2 @@ -326,9 +304,9 @@ LPC4_2: _get_obj: push {r4, r7, lr} add r7, sp, #4 - movw r0, :lower16:(LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-(LPC5_0+8)) - movt r0, :upper16:(LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-(LPC5_0+8)) -LPC5_0: + movw r0, :lower16:(LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-(LPC4_0+8)) + movt r0, :upper16:(LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-(LPC4_0+8)) +LPC4_0: ldr r0, [pc, r0] ldr r4, [r0] bl _get_class @@ -343,18 +321,18 @@ _access_ivars: push {r4, r5, r6, r7, lr} add r7, sp, #12 bl _get_obj - movw r1, :lower16:(L_anon.[ID].11-(LPC6_0+8)) + movw r1, :lower16:(L_anon.[ID].12-(LPC5_0+8)) mov r2, #4 - movt r1, :upper16:(L_anon.[ID].11-(LPC6_0+8)) + movt r1, :upper16:(L_anon.[ID].12-(LPC5_0+8)) mov r4, r0 -LPC6_0: +LPC5_0: add r1, pc, r1 bl SYM(objc2::runtime::AnyObject::lookup_instance_variable_dynamically::GENERATED_ID, 0) bl _ivar_getOffset ldrb r5, [r4, r0] - movw r1, :lower16:(L_anon.[ID].12-(LPC6_1+8)) - movt r1, :upper16:(L_anon.[ID].12-(LPC6_1+8)) -LPC6_1: + movw r1, :lower16:(L_anon.[ID].13-(LPC5_1+8)) + movt r1, :upper16:(L_anon.[ID].13-(LPC5_1+8)) +LPC5_1: add r1, pc, r1 mov r0, r4 mov r2, #4 @@ -374,58 +352,58 @@ SYM(::class::REGISTER_CLASS, 0)-(LPC7_0+8)) - movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC7_0+8)) -LPC7_0: + movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC6_0+8)) + movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC6_0+8)) +LPC6_0: add r0, pc, r0 ldr r0, [r0] dmb ish cmp r0, #3 - bne LBB7_3 -LBB7_1: - movw r0, :lower16:(l_anon.[ID].16-(LPC7_4+8)) + bne LBB6_3 +LBB6_1: + movw r0, :lower16:(l_anon.[ID].11-(LPC6_4+8)) mov r1, #15 - movt r0, :upper16:(l_anon.[ID].16-(LPC7_4+8)) -LPC7_4: + movt r0, :upper16:(l_anon.[ID].11-(LPC6_4+8)) +LPC6_4: add r0, pc, r0 bl SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) cmp r0, #0 movne sp, r7 popne {r7, pc} -LBB7_2: - movw r0, :lower16:(l_anon.[ID].8-(LPC7_5+8)) +LBB6_2: + movw r0, :lower16:(l_anon.[ID].8-(LPC6_5+8)) mov r1, #43 - movt r0, :upper16:(l_anon.[ID].8-(LPC7_5+8)) - movw r2, :lower16:(l_anon.[ID].15-(LPC7_6+8)) - movt r2, :upper16:(l_anon.[ID].15-(LPC7_6+8)) -LPC7_5: + movt r0, :upper16:(l_anon.[ID].8-(LPC6_5+8)) + movw r2, :lower16:(l_anon.[ID].16-(LPC6_6+8)) + movt r2, :upper16:(l_anon.[ID].16-(LPC6_6+8)) +LPC6_5: add r0, pc, r0 -LPC7_6: +LPC6_6: add r2, pc, r2 mov lr, pc b SYM(core::panicking::panic::GENERATED_ID, 0) -LBB7_3: - movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC7_1+8)) +LBB6_3: + movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC6_1+8)) mov r2, #1 - movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC7_1+8)) - movw r3, :lower16:(l_anon.[ID].0-(LPC7_2+8)) - movt r3, :upper16:(l_anon.[ID].0-(LPC7_2+8)) - movw r1, :lower16:(l_anon.[ID].15-(LPC7_3+8)) - movt r1, :upper16:(l_anon.[ID].15-(LPC7_3+8)) + movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC6_1+8)) + movw r3, :lower16:(l_anon.[ID].0-(LPC6_2+8)) + movt r3, :upper16:(l_anon.[ID].0-(LPC6_2+8)) + movw r1, :lower16:(l_anon.[ID].16-(LPC6_3+8)) + movt r1, :upper16:(l_anon.[ID].16-(LPC6_3+8)) strb r2, [r7, #-5] sub r2, r7, #5 -LPC7_3: +LPC6_3: add r1, pc, r1 str r2, [r7, #-4] -LPC7_1: +LPC6_1: add r0, pc, r0 -LPC7_2: +LPC6_2: add r3, pc, r3 sub r2, r7, #4 str r1, [sp] mov r1, #0 bl SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) - b LBB7_1 + b LBB6_1 .p2align 2 .code 32 @@ -434,24 +412,24 @@ SYM(::class::REGISTER_CLASS, 0),4,2 + .section __TEXT,__const l_anon.[ID].17: .ascii "NSCopying" -l_anon.[ID].18: - .ascii "could not create new class " - -l_anon.[ID].19: - .ascii ". Perhaps a class with that name already exists?" - - .section __DATA,__const - .p2align 2, 0x0 -l_anon.[ID].20: - .long l_anon.[ID].18 - .asciz "\033\000\000" - .long l_anon.[ID].19 - .asciz "0\000\000" - - .p2align 2, 0x0 -l_anon.[ID].21: - .long l_anon.[ID].16 - .asciz "\017\000\000" - .section __TEXT,__objc_methname,cstring_literals .globl L_OBJC_METH_VAR_NAME_d874ee9262978be2 L_OBJC_METH_VAR_NAME_d874ee9262978be2: diff --git a/crates/test-assembly/crates/test_declare_class/expected/apple-armv7s.s b/crates/test-assembly/crates/test_declare_class/expected/apple-armv7s.s index bff3a5d5f..69350aaec 100644 --- a/crates/test-assembly/crates/test_declare_class/expected/apple-armv7s.s +++ b/crates/test-assembly/crates/test_declare_class/expected/apple-armv7s.s @@ -11,31 +11,31 @@ SYM(::call_once::<::__add_protocol_methods::GENERATED_ID, 0) - movw r9, :lower16:(_copyWithZone-(LPC1_24+8)) + add r0, sp, #8 + bl SYM(objc2::declare::ClassBuilder::add_protocol::GENERATED_ID, 0) +LBB1_4: + movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166-(LPC1_24+8)) + add r0, sp, #8 + movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166-(LPC1_24+8)) mov r3, #1 - movt r9, :upper16:(_copyWithZone-(LPC1_24+8)) - movw r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166-(LPC1_25+8)) - movt r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166-(LPC1_25+8)) LPC1_24: - add r9, pc, r9 -LPC1_25: ldr r1, [pc, r1] - movw r2, :lower16:(l_anon.[ID].7-(LPC1_26+8)) - movt r2, :upper16:(l_anon.[ID].7-(LPC1_26+8)) - strd r8, r9, [sp] -LPC1_26: + movw r2, :lower16:(l_anon.[ID].7-(LPC1_25+8)) + movt r2, :upper16:(l_anon.[ID].7-(LPC1_25+8)) + movw r9, :lower16:(_copyWithZone-(LPC1_26+8)) + movt r9, :upper16:(_copyWithZone-(LPC1_26+8)) +LPC1_25: add r2, pc, r2 +LPC1_26: + add r9, pc, r9 + strd r8, r9, [sp] bl SYM(objc2::declare::ClassBuilder::add_method_inner::GENERATED_ID, 0) ldr r0, [sp, #8] bl SYM(objc2::declare::ClassBuilder::register::GENERATED_ID, 0) sub sp, r7, #20 pop {r8, r10, r11} pop {r4, r5, r7, pc} -LBB1_3: +LBB1_5: movw r0, :lower16:(l_anon.[ID].8-(LPC1_27+8)) mov r1, #43 movt r0, :upper16:(l_anon.[ID].8-(LPC1_27+8)) @@ -208,37 +212,18 @@ LPC1_28: add r2, pc, r2 mov lr, pc b SYM(core::panicking::panic::GENERATED_ID, 0) -LBB1_4: - movw r0, :lower16:(l_anon.[ID].20-(LPC1_29+8)) - mov r5, #0 - movt r0, :upper16:(l_anon.[ID].20-(LPC1_29+8)) - movw r2, :lower16:(l_anon.[ID].21-(LPC1_30+8)) - movt r2, :upper16:(l_anon.[ID].21-(LPC1_30+8)) - movw r1, :lower16:(l_anon.[ID].15-(LPC1_31+8)) - movt r1, :upper16:(l_anon.[ID].15-(LPC1_31+8)) - movw r3, :lower16:(SYM(<&str as core[CRATE_ID]::fmt::Display>::fmt, 0)-(LPC1_32+8)) - movt r3, :upper16:(SYM(<&str as core[CRATE_ID]::fmt::Display>::fmt, 0)-(LPC1_32+8)) - str r5, [sp, #24] - mov r5, #2 +LBB1_6: + movw r0, :lower16:(l_anon.[ID].11-(LPC1_29+8)) + mov r1, #15 + movt r0, :upper16:(l_anon.[ID].11-(LPC1_29+8)) + movw r2, :lower16:(l_anon.[ID].16-(LPC1_30+8)) + movt r2, :upper16:(l_anon.[ID].16-(LPC1_30+8)) LPC1_29: add r0, pc, r0 - str r5, [sp, #12] - mov r5, #1 LPC1_30: add r2, pc, r2 -LPC1_32: - add r3, pc, r3 - str r5, [sp, #20] - sub r5, r7, #28 - str r0, [sp, #8] -LPC1_31: - add r1, pc, r1 - add r0, sp, #8 - str r5, [sp, #16] - str r3, [r7, #-24] - str r2, [r7, #-28] mov lr, pc - b SYM(core::panicking::panic_fmt::GENERATED_ID, 0) + b SYM(objc2::__macro_helpers::declare_class::failed_declaring_class::GENERATED_ID, 0) .p2align 2 .code 32 @@ -253,16 +238,6 @@ SYM(<::call_once<::fmt, 0): - push {r7, lr} - mov r7, sp - mov r2, r1 - ldrd r0, r1, [r0] - bl SYM(::fmt::GENERATED_ID, 0) - pop {r7, pc} - .globl _get_class .p2align 2 .code 32 @@ -270,58 +245,58 @@ _get_class: push {r7, lr} mov r7, sp sub sp, sp, #12 - movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC4_0+8)) - movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC4_0+8)) -LPC4_0: + movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC3_0+8)) + movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC3_0+8)) +LPC3_0: add r0, pc, r0 ldr r0, [r0] dmb ish cmp r0, #3 - bne LBB4_3 -LBB4_1: - movw r0, :lower16:(l_anon.[ID].16-(LPC4_4+8)) + bne LBB3_3 +LBB3_1: + movw r0, :lower16:(l_anon.[ID].11-(LPC3_4+8)) mov r1, #15 - movt r0, :upper16:(l_anon.[ID].16-(LPC4_4+8)) -LPC4_4: + movt r0, :upper16:(l_anon.[ID].11-(LPC3_4+8)) +LPC3_4: add r0, pc, r0 bl SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) cmp r0, #0 movne sp, r7 popne {r7, pc} -LBB4_2: - movw r0, :lower16:(l_anon.[ID].8-(LPC4_5+8)) +LBB3_2: + movw r0, :lower16:(l_anon.[ID].8-(LPC3_5+8)) mov r1, #43 - movt r0, :upper16:(l_anon.[ID].8-(LPC4_5+8)) - movw r2, :lower16:(l_anon.[ID].15-(LPC4_6+8)) - movt r2, :upper16:(l_anon.[ID].15-(LPC4_6+8)) -LPC4_5: + movt r0, :upper16:(l_anon.[ID].8-(LPC3_5+8)) + movw r2, :lower16:(l_anon.[ID].16-(LPC3_6+8)) + movt r2, :upper16:(l_anon.[ID].16-(LPC3_6+8)) +LPC3_5: add r0, pc, r0 -LPC4_6: +LPC3_6: add r2, pc, r2 mov lr, pc b SYM(core::panicking::panic::GENERATED_ID, 0) -LBB4_3: - movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC4_1+8)) +LBB3_3: + movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC3_1+8)) mov r2, #1 - movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC4_1+8)) - movw r3, :lower16:(l_anon.[ID].0-(LPC4_2+8)) - movt r3, :upper16:(l_anon.[ID].0-(LPC4_2+8)) - movw r1, :lower16:(l_anon.[ID].15-(LPC4_3+8)) - movt r1, :upper16:(l_anon.[ID].15-(LPC4_3+8)) + movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC3_1+8)) + movw r3, :lower16:(l_anon.[ID].0-(LPC3_2+8)) + movt r3, :upper16:(l_anon.[ID].0-(LPC3_2+8)) + movw r1, :lower16:(l_anon.[ID].16-(LPC3_3+8)) + movt r1, :upper16:(l_anon.[ID].16-(LPC3_3+8)) strb r2, [r7, #-5] -LPC4_3: +LPC3_3: add r1, pc, r1 sub r2, r7, #5 str r2, [r7, #-4] -LPC4_1: +LPC3_1: add r0, pc, r0 str r1, [sp] -LPC4_2: +LPC3_2: add r3, pc, r3 sub r2, r7, #4 mov r1, #0 bl SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) - b LBB4_1 + b LBB3_1 .globl _get_obj .p2align 2 @@ -329,9 +304,9 @@ LPC4_2: _get_obj: push {r4, r7, lr} add r7, sp, #4 - movw r0, :lower16:(LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-(LPC5_0+8)) - movt r0, :upper16:(LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-(LPC5_0+8)) -LPC5_0: + movw r0, :lower16:(LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-(LPC4_0+8)) + movt r0, :upper16:(LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-(LPC4_0+8)) +LPC4_0: ldr r0, [pc, r0] ldr r4, [r0] bl _get_class @@ -346,19 +321,19 @@ _access_ivars: push {r4, r5, r6, r7, lr} add r7, sp, #12 bl _get_obj - movw r1, :lower16:(L_anon.[ID].11-(LPC6_0+8)) + movw r1, :lower16:(L_anon.[ID].12-(LPC5_0+8)) mov r2, #4 - movt r1, :upper16:(L_anon.[ID].11-(LPC6_0+8)) + movt r1, :upper16:(L_anon.[ID].12-(LPC5_0+8)) mov r4, r0 -LPC6_0: +LPC5_0: add r1, pc, r1 bl SYM(objc2::runtime::AnyObject::lookup_instance_variable_dynamically::GENERATED_ID, 0) bl _ivar_getOffset - movw r1, :lower16:(L_anon.[ID].12-(LPC6_1+8)) + movw r1, :lower16:(L_anon.[ID].13-(LPC5_1+8)) mov r2, #4 - movt r1, :upper16:(L_anon.[ID].12-(LPC6_1+8)) + movt r1, :upper16:(L_anon.[ID].13-(LPC5_1+8)) ldrb r5, [r4, r0] -LPC6_1: +LPC5_1: add r1, pc, r1 mov r0, r4 bl SYM(objc2::runtime::AnyObject::lookup_instance_variable_dynamically::GENERATED_ID, 0) @@ -377,58 +352,58 @@ SYM(::class::REGISTER_CLASS, 0)-(LPC7_0+8)) - movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC7_0+8)) -LPC7_0: + movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC6_0+8)) + movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC6_0+8)) +LPC6_0: add r0, pc, r0 ldr r0, [r0] dmb ish cmp r0, #3 - bne LBB7_3 -LBB7_1: - movw r0, :lower16:(l_anon.[ID].16-(LPC7_4+8)) + bne LBB6_3 +LBB6_1: + movw r0, :lower16:(l_anon.[ID].11-(LPC6_4+8)) mov r1, #15 - movt r0, :upper16:(l_anon.[ID].16-(LPC7_4+8)) -LPC7_4: + movt r0, :upper16:(l_anon.[ID].11-(LPC6_4+8)) +LPC6_4: add r0, pc, r0 bl SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) cmp r0, #0 movne sp, r7 popne {r7, pc} -LBB7_2: - movw r0, :lower16:(l_anon.[ID].8-(LPC7_5+8)) +LBB6_2: + movw r0, :lower16:(l_anon.[ID].8-(LPC6_5+8)) mov r1, #43 - movt r0, :upper16:(l_anon.[ID].8-(LPC7_5+8)) - movw r2, :lower16:(l_anon.[ID].15-(LPC7_6+8)) - movt r2, :upper16:(l_anon.[ID].15-(LPC7_6+8)) -LPC7_5: + movt r0, :upper16:(l_anon.[ID].8-(LPC6_5+8)) + movw r2, :lower16:(l_anon.[ID].16-(LPC6_6+8)) + movt r2, :upper16:(l_anon.[ID].16-(LPC6_6+8)) +LPC6_5: add r0, pc, r0 -LPC7_6: +LPC6_6: add r2, pc, r2 mov lr, pc b SYM(core::panicking::panic::GENERATED_ID, 0) -LBB7_3: - movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC7_1+8)) +LBB6_3: + movw r0, :lower16:(SYM(::class::REGISTER_CLASS, 0)-(LPC6_1+8)) mov r2, #1 - movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC7_1+8)) - movw r3, :lower16:(l_anon.[ID].0-(LPC7_2+8)) - movt r3, :upper16:(l_anon.[ID].0-(LPC7_2+8)) - movw r1, :lower16:(l_anon.[ID].15-(LPC7_3+8)) - movt r1, :upper16:(l_anon.[ID].15-(LPC7_3+8)) + movt r0, :upper16:(SYM(::class::REGISTER_CLASS, 0)-(LPC6_1+8)) + movw r3, :lower16:(l_anon.[ID].0-(LPC6_2+8)) + movt r3, :upper16:(l_anon.[ID].0-(LPC6_2+8)) + movw r1, :lower16:(l_anon.[ID].16-(LPC6_3+8)) + movt r1, :upper16:(l_anon.[ID].16-(LPC6_3+8)) strb r2, [r7, #-5] -LPC7_3: +LPC6_3: add r1, pc, r1 sub r2, r7, #5 str r2, [r7, #-4] -LPC7_1: +LPC6_1: add r0, pc, r0 str r1, [sp] -LPC7_2: +LPC6_2: add r3, pc, r3 sub r2, r7, #4 mov r1, #0 bl SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) - b LBB7_1 + b LBB6_1 .p2align 2 .code 32 @@ -437,24 +412,24 @@ SYM(::class::REGISTER_CLASS, 0),4,2 + .section __TEXT,__const l_anon.[ID].17: .ascii "NSCopying" -l_anon.[ID].18: - .ascii "could not create new class " - -l_anon.[ID].19: - .ascii ". Perhaps a class with that name already exists?" - - .section __DATA,__const - .p2align 2, 0x0 -l_anon.[ID].20: - .long l_anon.[ID].18 - .asciz "\033\000\000" - .long l_anon.[ID].19 - .asciz "0\000\000" - - .p2align 2, 0x0 -l_anon.[ID].21: - .long l_anon.[ID].16 - .asciz "\017\000\000" - .section __TEXT,__objc_methname,cstring_literals .globl L_OBJC_METH_VAR_NAME_d874ee9262978be2 L_OBJC_METH_VAR_NAME_d874ee9262978be2: diff --git a/crates/test-assembly/crates/test_declare_class/expected/apple-old-x86.s b/crates/test-assembly/crates/test_declare_class/expected/apple-old-x86.s index 2be2d853c..5cd9cfd8f 100644 --- a/crates/test-assembly/crates/test_declare_class/expected/apple-old-x86.s +++ b/crates/test-assembly/crates/test_declare_class/expected/apple-old-x86.s @@ -14,7 +14,7 @@ SYM(::call_once::<::__add_protocol_methods::GENERATED_ID, 0) - add esp, 8 - lea ecx, [esi + _copyWithZone-L1$pb] - lea edx, [esi + l_anon.[ID].7-L1$pb] - push ecx - push edi + call SYM(objc2::declare::ClassBuilder::add_protocol::GENERATED_ID, 0) + add esp, 16 +LBB1_4: + sub esp, 8 + lea eax, [esi + _copyWithZone-L1$pb] + lea ecx, [esi + l_anon.[ID].7-L1$pb] + push eax + lea eax, [esi + l_anon.[ID].2-L1$pb] + push eax push 1 - push edx + push ecx push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166-L1$pb] - push eax + push ebx call SYM(objc2::declare::ClassBuilder::add_method_inner::GENERATED_ID, 0) add esp, 20 - push dword ptr [ebp - 36] + push dword ptr [ebp - 16] call SYM(objc2::declare::ClassBuilder::register::GENERATED_ID, 0) - add esp, 60 + add esp, 28 pop esi pop edi pop ebx pop ebp ret -LBB1_3: +LBB1_5: sub esp, 4 lea eax, [esi + l_anon.[ID].10-L1$pb] lea ecx, [esi + l_anon.[ID].8-L1$pb] @@ -168,24 +174,13 @@ LBB1_3: push 43 push ecx call SYM(core::panicking::panic::GENERATED_ID, 0) -LBB1_4: - lea eax, [esi + l_anon.[ID].21-L1$pb] - mov dword ptr [ebp - 44], eax - lea eax, [esi + SYM(<&str as core[CRATE_ID]::fmt::Display>::fmt, 0)-L1$pb] - mov dword ptr [ebp - 40], eax - lea eax, [esi + l_anon.[ID].20-L1$pb] - mov dword ptr [ebp - 36], eax - mov dword ptr [ebp - 32], 2 - mov dword ptr [ebp - 20], 0 - lea eax, [ebp - 44] - mov dword ptr [ebp - 28], eax - mov dword ptr [ebp - 24], 1 - sub esp, 8 - lea eax, [esi + l_anon.[ID].15-L1$pb] - lea ecx, [ebp - 36] +LBB1_6: + sub esp, 4 + lea eax, [esi + l_anon.[ID].16-L1$pb] push eax - push ecx - call SYM(core::panicking::panic_fmt::GENERATED_ID, 0) + push 15 + push edi + call SYM(objc2::__macro_helpers::declare_class::failed_declaring_class::GENERATED_ID, 0) .p2align 4, 0x90 SYM(<::call_once<::class::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0): @@ -202,21 +197,6 @@ SYM(<::call_once<::fmt, 0): - push ebp - mov ebp, esp - sub esp, 8 - mov eax, dword ptr [ebp + 8] - sub esp, 4 - push dword ptr [ebp + 12] - push dword ptr [eax + 4] - push dword ptr [eax] - call SYM(::fmt::GENERATED_ID, 0) - add esp, 24 - pop ebp - ret - .globl _get_class .p2align 4, 0x90 _get_class: @@ -225,35 +205,35 @@ _get_class: push edi push esi sub esp, 16 - call L4$pb -L4$pb: + call L3$pb +L3$pb: pop esi - mov eax, dword ptr [esi + SYM(::class::REGISTER_CLASS, 0)-L4$pb] + mov eax, dword ptr [esi + SYM(::class::REGISTER_CLASS, 0)-L3$pb] cmp eax, 3 - jne LBB4_1 -LBB4_2: + jne LBB3_1 +LBB3_2: sub esp, 8 - lea eax, [esi + l_anon.[ID].16-L4$pb] + lea eax, [esi + l_anon.[ID].11-L3$pb] push 15 push eax call SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) add esp, 16 test eax, eax - je LBB4_4 + je LBB3_4 add esp, 16 pop esi pop edi pop ebp ret -LBB4_1: +LBB3_1: mov byte ptr [ebp - 9], 1 lea eax, [ebp - 9] mov dword ptr [ebp - 16], eax sub esp, 12 - lea eax, [esi + l_anon.[ID].15-L4$pb] - lea ecx, [esi + l_anon.[ID].0-L4$pb] + lea eax, [esi + l_anon.[ID].16-L3$pb] + lea ecx, [esi + l_anon.[ID].0-L3$pb] lea edx, [ebp - 16] - lea edi, [esi + SYM(::class::REGISTER_CLASS, 0)-L4$pb] + lea edi, [esi + SYM(::class::REGISTER_CLASS, 0)-L3$pb] push eax push ecx push edx @@ -261,11 +241,11 @@ LBB4_1: push edi call SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) add esp, 32 - jmp LBB4_2 -LBB4_4: + jmp LBB3_2 +LBB3_4: sub esp, 4 - lea eax, [esi + l_anon.[ID].15-L4$pb] - lea ecx, [esi + l_anon.[ID].8-L4$pb] + lea eax, [esi + l_anon.[ID].16-L3$pb] + lea ecx, [esi + l_anon.[ID].8-L3$pb] push eax push 43 push ecx @@ -278,10 +258,10 @@ _get_obj: mov ebp, esp push esi push eax - call L5$pb -L5$pb: + call L4$pb +L4$pb: pop eax - mov eax, dword ptr [eax + LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-L5$pb] + mov eax, dword ptr [eax + LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-L4$pb] mov esi, dword ptr [eax] call _get_class sub esp, 8 @@ -302,12 +282,12 @@ _access_ivars: push edi push esi sub esp, 12 - call L6$pb -L6$pb: + call L5$pb +L5$pb: pop edi call _get_obj mov esi, eax - lea eax, [edi + L_anon.[ID].11-L6$pb] + lea eax, [edi + L_anon.[ID].12-L5$pb] mov dword ptr [esp + 4], eax mov dword ptr [esp], esi mov dword ptr [esp + 8], 4 @@ -315,7 +295,7 @@ L6$pb: mov dword ptr [esp], eax call _ivar_getOffset movzx ebx, byte ptr [esi + eax] - lea eax, [edi + L_anon.[ID].12-L6$pb] + lea eax, [edi + L_anon.[ID].13-L5$pb] mov dword ptr [esp + 4], eax mov dword ptr [esp], esi mov dword ptr [esp + 8], 4 @@ -342,35 +322,35 @@ SYM(::class::REGISTER_CLASS, 0)-L7$pb] + mov eax, dword ptr [esi + SYM(::class::REGISTER_CLASS, 0)-L6$pb] cmp eax, 3 - jne LBB7_1 -LBB7_2: + jne LBB6_1 +LBB6_2: sub esp, 8 - lea eax, [esi + l_anon.[ID].16-L7$pb] + lea eax, [esi + l_anon.[ID].11-L6$pb] push 15 push eax call SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) add esp, 16 test eax, eax - je LBB7_4 + je LBB6_4 add esp, 16 pop esi pop edi pop ebp ret -LBB7_1: +LBB6_1: mov byte ptr [ebp - 9], 1 lea eax, [ebp - 9] mov dword ptr [ebp - 16], eax sub esp, 12 - lea eax, [esi + l_anon.[ID].15-L7$pb] - lea ecx, [esi + l_anon.[ID].0-L7$pb] + lea eax, [esi + l_anon.[ID].16-L6$pb] + lea ecx, [esi + l_anon.[ID].0-L6$pb] lea edx, [ebp - 16] - lea edi, [esi + SYM(::class::REGISTER_CLASS, 0)-L7$pb] + lea edi, [esi + SYM(::class::REGISTER_CLASS, 0)-L6$pb] push eax push ecx push edx @@ -378,11 +358,11 @@ LBB7_1: push edi call SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) add esp, 32 - jmp LBB7_2 -LBB7_4: + jmp LBB6_2 +LBB6_4: sub esp, 4 - lea eax, [esi + l_anon.[ID].15-L7$pb] - lea ecx, [esi + l_anon.[ID].8-L7$pb] + lea eax, [esi + l_anon.[ID].16-L6$pb] + lea ecx, [esi + l_anon.[ID].8-L6$pb] push eax push 43 push ecx @@ -396,12 +376,12 @@ SYM(::class::REGISTER_CLASS, 0),4,2 + .section __TEXT,__const l_anon.[ID].17: .ascii "NSCopying" -l_anon.[ID].18: - .ascii "could not create new class " - -l_anon.[ID].19: - .ascii ". Perhaps a class with that name already exists?" - - .section __DATA,__const - .p2align 2, 0x0 -l_anon.[ID].20: - .long l_anon.[ID].18 - .asciz "\033\000\000" - .long l_anon.[ID].19 - .asciz "0\000\000" - - .p2align 2, 0x0 -l_anon.[ID].21: - .long l_anon.[ID].16 - .asciz "\017\000\000" - .section __TEXT,__cstring,cstring_literals .globl L_OBJC_METH_VAR_NAME_d874ee9262978be2 L_OBJC_METH_VAR_NAME_d874ee9262978be2: diff --git a/crates/test-assembly/crates/test_declare_class/expected/apple-x86.s b/crates/test-assembly/crates/test_declare_class/expected/apple-x86.s index aefd03523..079d17352 100644 --- a/crates/test-assembly/crates/test_declare_class/expected/apple-x86.s +++ b/crates/test-assembly/crates/test_declare_class/expected/apple-x86.s @@ -14,7 +14,7 @@ SYM(::call_once::<::__add_protocol_methods::GENERATED_ID, 0) - add esp, 8 - lea ecx, [esi + _copyWithZone-L1$pb] - lea edx, [esi + l_anon.[ID].7-L1$pb] - push ecx - push edi + call SYM(objc2::declare::ClassBuilder::add_protocol::GENERATED_ID, 0) + add esp, 16 +LBB1_4: + sub esp, 8 + lea eax, [esi + _copyWithZone-L1$pb] + lea ecx, [esi + l_anon.[ID].7-L1$pb] + push eax + lea eax, [esi + l_anon.[ID].2-L1$pb] + push eax push 1 - push edx + push ecx push dword ptr [esi + L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166-L1$pb] - push eax + push ebx call SYM(objc2::declare::ClassBuilder::add_method_inner::GENERATED_ID, 0) add esp, 20 - push dword ptr [ebp - 36] + push dword ptr [ebp - 16] call SYM(objc2::declare::ClassBuilder::register::GENERATED_ID, 0) - add esp, 60 + add esp, 28 pop esi pop edi pop ebx pop ebp ret -LBB1_3: +LBB1_5: sub esp, 4 lea eax, [esi + l_anon.[ID].10-L1$pb] lea ecx, [esi + l_anon.[ID].8-L1$pb] @@ -168,24 +174,13 @@ LBB1_3: push 43 push ecx call SYM(core::panicking::panic::GENERATED_ID, 0) -LBB1_4: - lea eax, [esi + l_anon.[ID].21-L1$pb] - mov dword ptr [ebp - 44], eax - lea eax, [esi + SYM(<&str as core[CRATE_ID]::fmt::Display>::fmt, 0)-L1$pb] - mov dword ptr [ebp - 40], eax - lea eax, [esi + l_anon.[ID].20-L1$pb] - mov dword ptr [ebp - 36], eax - mov dword ptr [ebp - 32], 2 - mov dword ptr [ebp - 20], 0 - lea eax, [ebp - 44] - mov dword ptr [ebp - 28], eax - mov dword ptr [ebp - 24], 1 - sub esp, 8 - lea eax, [esi + l_anon.[ID].15-L1$pb] - lea ecx, [ebp - 36] +LBB1_6: + sub esp, 4 + lea eax, [esi + l_anon.[ID].16-L1$pb] push eax - push ecx - call SYM(core::panicking::panic_fmt::GENERATED_ID, 0) + push 15 + push edi + call SYM(objc2::__macro_helpers::declare_class::failed_declaring_class::GENERATED_ID, 0) .p2align 4, 0x90 SYM(<::call_once<::class::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0): @@ -202,21 +197,6 @@ SYM(<::call_once<::fmt, 0): - push ebp - mov ebp, esp - sub esp, 8 - mov eax, dword ptr [ebp + 8] - sub esp, 4 - push dword ptr [ebp + 12] - push dword ptr [eax + 4] - push dword ptr [eax] - call SYM(::fmt::GENERATED_ID, 0) - add esp, 24 - pop ebp - ret - .globl _get_class .p2align 4, 0x90 _get_class: @@ -225,35 +205,35 @@ _get_class: push edi push esi sub esp, 16 - call L4$pb -L4$pb: + call L3$pb +L3$pb: pop esi - mov eax, dword ptr [esi + SYM(::class::REGISTER_CLASS, 0)-L4$pb] + mov eax, dword ptr [esi + SYM(::class::REGISTER_CLASS, 0)-L3$pb] cmp eax, 3 - jne LBB4_1 -LBB4_2: + jne LBB3_1 +LBB3_2: sub esp, 8 - lea eax, [esi + l_anon.[ID].16-L4$pb] + lea eax, [esi + l_anon.[ID].11-L3$pb] push 15 push eax call SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) add esp, 16 test eax, eax - je LBB4_4 + je LBB3_4 add esp, 16 pop esi pop edi pop ebp ret -LBB4_1: +LBB3_1: mov byte ptr [ebp - 9], 1 lea eax, [ebp - 9] mov dword ptr [ebp - 16], eax sub esp, 12 - lea eax, [esi + l_anon.[ID].15-L4$pb] - lea ecx, [esi + l_anon.[ID].0-L4$pb] + lea eax, [esi + l_anon.[ID].16-L3$pb] + lea ecx, [esi + l_anon.[ID].0-L3$pb] lea edx, [ebp - 16] - lea edi, [esi + SYM(::class::REGISTER_CLASS, 0)-L4$pb] + lea edi, [esi + SYM(::class::REGISTER_CLASS, 0)-L3$pb] push eax push ecx push edx @@ -261,11 +241,11 @@ LBB4_1: push edi call SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) add esp, 32 - jmp LBB4_2 -LBB4_4: + jmp LBB3_2 +LBB3_4: sub esp, 4 - lea eax, [esi + l_anon.[ID].15-L4$pb] - lea ecx, [esi + l_anon.[ID].8-L4$pb] + lea eax, [esi + l_anon.[ID].16-L3$pb] + lea ecx, [esi + l_anon.[ID].8-L3$pb] push eax push 43 push ecx @@ -278,10 +258,10 @@ _get_obj: mov ebp, esp push esi push eax - call L5$pb -L5$pb: + call L4$pb +L4$pb: pop eax - mov eax, dword ptr [eax + LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-L5$pb] + mov eax, dword ptr [eax + LL_OBJC_SELECTOR_REFERENCES_new$non_lazy_ptr-L4$pb] mov esi, dword ptr [eax] call _get_class sub esp, 8 @@ -302,12 +282,12 @@ _access_ivars: push edi push esi sub esp, 12 - call L6$pb -L6$pb: + call L5$pb +L5$pb: pop edi call _get_obj mov esi, eax - lea eax, [edi + L_anon.[ID].11-L6$pb] + lea eax, [edi + L_anon.[ID].12-L5$pb] mov dword ptr [esp + 4], eax mov dword ptr [esp], esi mov dword ptr [esp + 8], 4 @@ -315,7 +295,7 @@ L6$pb: mov dword ptr [esp], eax call _ivar_getOffset movzx ebx, byte ptr [esi + eax] - lea eax, [edi + L_anon.[ID].12-L6$pb] + lea eax, [edi + L_anon.[ID].13-L5$pb] mov dword ptr [esp + 4], eax mov dword ptr [esp], esi mov dword ptr [esp + 8], 4 @@ -342,35 +322,35 @@ SYM(::class::REGISTER_CLASS, 0)-L7$pb] + mov eax, dword ptr [esi + SYM(::class::REGISTER_CLASS, 0)-L6$pb] cmp eax, 3 - jne LBB7_1 -LBB7_2: + jne LBB6_1 +LBB6_2: sub esp, 8 - lea eax, [esi + l_anon.[ID].16-L7$pb] + lea eax, [esi + l_anon.[ID].11-L6$pb] push 15 push eax call SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) add esp, 16 test eax, eax - je LBB7_4 + je LBB6_4 add esp, 16 pop esi pop edi pop ebp ret -LBB7_1: +LBB6_1: mov byte ptr [ebp - 9], 1 lea eax, [ebp - 9] mov dword ptr [ebp - 16], eax sub esp, 12 - lea eax, [esi + l_anon.[ID].15-L7$pb] - lea ecx, [esi + l_anon.[ID].0-L7$pb] + lea eax, [esi + l_anon.[ID].16-L6$pb] + lea ecx, [esi + l_anon.[ID].0-L6$pb] lea edx, [ebp - 16] - lea edi, [esi + SYM(::class::REGISTER_CLASS, 0)-L7$pb] + lea edi, [esi + SYM(::class::REGISTER_CLASS, 0)-L6$pb] push eax push ecx push edx @@ -378,11 +358,11 @@ LBB7_1: push edi call SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) add esp, 32 - jmp LBB7_2 -LBB7_4: + jmp LBB6_2 +LBB6_4: sub esp, 4 - lea eax, [esi + l_anon.[ID].15-L7$pb] - lea ecx, [esi + l_anon.[ID].8-L7$pb] + lea eax, [esi + l_anon.[ID].16-L6$pb] + lea ecx, [esi + l_anon.[ID].8-L6$pb] push eax push 43 push ecx @@ -396,12 +376,12 @@ SYM(::class::REGISTER_CLASS, 0),4,2 + .section __TEXT,__const l_anon.[ID].17: .ascii "NSCopying" -l_anon.[ID].18: - .ascii "could not create new class " - -l_anon.[ID].19: - .ascii ". Perhaps a class with that name already exists?" - - .section __DATA,__const - .p2align 2, 0x0 -l_anon.[ID].20: - .long l_anon.[ID].18 - .asciz "\033\000\000" - .long l_anon.[ID].19 - .asciz "0\000\000" - - .p2align 2, 0x0 -l_anon.[ID].21: - .long l_anon.[ID].16 - .asciz "\017\000\000" - .section __TEXT,__objc_methname,cstring_literals .globl L_OBJC_METH_VAR_NAME_d874ee9262978be2 L_OBJC_METH_VAR_NAME_d874ee9262978be2: diff --git a/crates/test-assembly/crates/test_declare_class/expected/apple-x86_64.s b/crates/test-assembly/crates/test_declare_class/expected/apple-x86_64.s index c63e960fa..0c9c9cb7f 100644 --- a/crates/test-assembly/crates/test_declare_class/expected/apple-x86_64.s +++ b/crates/test-assembly/crates/test_declare_class/expected/apple-x86_64.s @@ -15,28 +15,28 @@ SYM(::call_once::<::call_once::<::__add_protocol_methods::GENERATED_ID, 0) + call SYM(objc2::declare::ClassBuilder::add_protocol::GENERATED_ID, 0) +LBB1_4: mov rsi, qword ptr [rip + L_OBJC_SELECTOR_REFERENCES_4a8c690dbc9d8166] lea rdx, [rip + l_anon.[ID].7] + lea r8, [rip + l_anon.[ID].2] lea r9, [rip + _copyWithZone] + lea rdi, [rbp - 40] mov ecx, 1 - mov rdi, rax - mov r8, r14 call SYM(objc2::declare::ClassBuilder::add_method_inner::GENERATED_ID, 0) - mov rdi, qword ptr [rbp - 80] + mov rdi, qword ptr [rbp - 40] call SYM(objc2::declare::ClassBuilder::register::GENERATED_ID, 0) - add rsp, 64 + add rsp, 16 pop rbx pop r12 pop r14 pop r15 pop rbp ret -LBB1_3: +LBB1_5: lea rdi, [rip + l_anon.[ID].8] lea rdx, [rip + l_anon.[ID].10] mov esi, 43 call SYM(core::panicking::panic::GENERATED_ID, 0) -LBB1_4: - lea rax, [rip + l_anon.[ID].21] - mov qword ptr [rbp - 96], rax - lea rax, [rip + SYM(<&str as core[CRATE_ID]::fmt::Display>::fmt, 0)] - mov qword ptr [rbp - 88], rax - lea rax, [rip + l_anon.[ID].20] - mov qword ptr [rbp - 80], rax - mov qword ptr [rbp - 72], 2 - mov qword ptr [rbp - 48], 0 - lea rax, [rbp - 96] - mov qword ptr [rbp - 64], rax - mov qword ptr [rbp - 56], 1 - lea rsi, [rip + l_anon.[ID].15] - lea rdi, [rbp - 80] - call SYM(core::panicking::panic_fmt::GENERATED_ID, 0) +LBB1_6: + lea rdi, [rip + l_anon.[ID].11] + lea rdx, [rip + l_anon.[ID].16] + mov esi, 15 + call SYM(objc2::__macro_helpers::declare_class::failed_declaring_class::GENERATED_ID, 0) .p2align 4, 0x90 SYM(<::call_once<::class::{closure#0}>::{closure#0} as core[CRATE_ID]::ops::function::FnOnce<(&std[CRATE_ID]::sync::once::OnceState,)>>::call_once::{shim:vtable#0}, 0): @@ -154,17 +147,6 @@ SYM(<::call_once<::fmt, 0): - push rbp - mov rbp, rsp - mov rdx, rsi - mov rax, qword ptr [rdi] - mov rsi, qword ptr [rdi + 8] - mov rdi, rax - pop rbp - jmp SYM(::fmt::GENERATED_ID, 0) - .globl _get_class .p2align 4, 0x90 _get_class: @@ -173,30 +155,30 @@ _get_class: sub rsp, 16 mov rax, qword ptr [rip + SYM(::class::REGISTER_CLASS, 0)] cmp rax, 3 - jne LBB4_1 -LBB4_2: - lea rdi, [rip + l_anon.[ID].16] + jne LBB3_1 +LBB3_2: + lea rdi, [rip + l_anon.[ID].11] mov esi, 15 call SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) test rax, rax - je LBB4_4 + je LBB3_4 add rsp, 16 pop rbp ret -LBB4_1: +LBB3_1: mov byte ptr [rbp - 1], 1 lea rax, [rbp - 1] mov qword ptr [rbp - 16], rax lea rdi, [rip + SYM(::class::REGISTER_CLASS, 0)] lea rcx, [rip + l_anon.[ID].0] - lea r8, [rip + l_anon.[ID].15] + lea r8, [rip + l_anon.[ID].16] lea rdx, [rbp - 16] xor esi, esi call SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) - jmp LBB4_2 -LBB4_4: + jmp LBB3_2 +LBB3_4: lea rdi, [rip + l_anon.[ID].8] - lea rdx, [rip + l_anon.[ID].15] + lea rdx, [rip + l_anon.[ID].16] mov esi, 43 call SYM(core::panicking::panic::GENERATED_ID, 0) @@ -228,14 +210,14 @@ _access_ivars: push rax call _get_obj mov rbx, rax - lea rsi, [rip + L_anon.[ID].11] + lea rsi, [rip + L_anon.[ID].12] mov edx, 4 mov rdi, rax call SYM(objc2::runtime::AnyObject::lookup_instance_variable_dynamically::GENERATED_ID, 0) mov rdi, rax call _ivar_getOffset movzx r14d, byte ptr [rbx + rax] - lea rsi, [rip + L_anon.[ID].12] + lea rsi, [rip + L_anon.[ID].13] mov edx, 4 mov rdi, rbx call SYM(objc2::runtime::AnyObject::lookup_instance_variable_dynamically::GENERATED_ID, 0) @@ -261,30 +243,30 @@ SYM(::class::REGISTER_CLASS, 0)] cmp rax, 3 - jne LBB7_1 -LBB7_2: - lea rdi, [rip + l_anon.[ID].16] + jne LBB6_1 +LBB6_2: + lea rdi, [rip + l_anon.[ID].11] mov esi, 15 call SYM(objc2::runtime::AnyClass::get::GENERATED_ID, 0) test rax, rax - je LBB7_4 + je LBB6_4 add rsp, 16 pop rbp ret -LBB7_1: +LBB6_1: mov byte ptr [rbp - 1], 1 lea rax, [rbp - 1] mov qword ptr [rbp - 16], rax lea rdi, [rip + SYM(::class::REGISTER_CLASS, 0)] lea rcx, [rip + l_anon.[ID].0] - lea r8, [rip + l_anon.[ID].15] + lea r8, [rip + l_anon.[ID].16] lea rdx, [rbp - 16] xor esi, esi call SYM(std::sys_common::once::queue::Once::call::GENERATED_ID, 0) - jmp LBB7_2 -LBB7_4: + jmp LBB6_2 +LBB6_4: lea rdi, [rip + l_anon.[ID].8] - lea rdx, [rip + l_anon.[ID].15] + lea rdx, [rip + l_anon.[ID].16] mov esi, 43 call SYM(core::panicking::panic::GENERATED_ID, 0) @@ -297,16 +279,16 @@ SYM(::class::REGISTER_CLASS, 0),8,3 + .section __TEXT,__const l_anon.[ID].17: .ascii "NSCopying" -l_anon.[ID].18: - .ascii "could not create new class " - -l_anon.[ID].19: - .ascii ". Perhaps a class with that name already exists?" - - .section __DATA,__const - .p2align 3, 0x0 -l_anon.[ID].20: - .quad l_anon.[ID].18 - .asciz "\033\000\000\000\000\000\000" - .quad l_anon.[ID].19 - .asciz "0\000\000\000\000\000\000" - - .p2align 3, 0x0 -l_anon.[ID].21: - .quad l_anon.[ID].16 - .asciz "\017\000\000\000\000\000\000" - .section __TEXT,__objc_methname,cstring_literals .globl L_OBJC_METH_VAR_NAME_d874ee9262978be2 L_OBJC_METH_VAR_NAME_d874ee9262978be2: diff --git a/crates/test-ui/ui/declare_class_invalid_receiver.rs b/crates/test-ui/ui/declare_class_invalid_receiver.rs index 78d6ca5eb..63ff3f45c 100644 --- a/crates/test-ui/ui/declare_class_invalid_receiver.rs +++ b/crates/test-ui/ui/declare_class_invalid_receiver.rs @@ -31,6 +31,11 @@ declare_class!( fn test_class(this: &AnyClass) { unimplemented!() } + + #[method(testClass)] + fn test_object(this: &NSObject) { + unimplemented!() + } } unsafe impl CustomObject { diff --git a/crates/test-ui/ui/declare_class_invalid_receiver.stderr b/crates/test-ui/ui/declare_class_invalid_receiver.stderr index b68f7a2d1..c9a190597 100644 --- a/crates/test-ui/ui/declare_class_invalid_receiver.stderr +++ b/crates/test-ui/ui/declare_class_invalid_receiver.stderr @@ -22,14 +22,14 @@ error[E0277]: the trait bound `Box: MessageReceiver` is not satisf &'a mut T &'a AnyClass = note: required for `extern "C" fn(Box, objc2::runtime::Sel)` to implement `MethodImplementation` -note: required by a bound in `ClassBuilder::add_method` - --> $WORKSPACE/crates/objc2/src/declare/mod.rs +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | - | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) | ---------- required by a bound in this associated function -... + | where | F: MethodImplementation, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Id: MessageReceiver` is not satisfied @@ -56,14 +56,14 @@ error[E0277]: the trait bound `Id: MessageReceiver` is not satisfi &'a mut T &'a AnyClass = note: required for `extern "C" fn(Id, objc2::runtime::Sel)` to implement `MethodImplementation` -note: required by a bound in `ClassBuilder::add_method` - --> $WORKSPACE/crates/objc2/src/declare/mod.rs +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | - | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) | ---------- required by a bound in this associated function -... + | where | F: MethodImplementation, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `CustomObject: MessageReceiver` is not satisfied @@ -90,17 +90,17 @@ error[E0277]: the trait bound `CustomObject: MessageReceiver` is not satisfied &'a mut T &'a AnyClass = note: required for `extern "C" fn(CustomObject, objc2::runtime::Sel)` to implement `MethodImplementation` -note: required by a bound in `ClassBuilder::add_method` - --> $WORKSPACE/crates/objc2/src/declare/mod.rs +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | - | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) | ---------- required by a bound in this associated function -... + | where | F: MethodImplementation, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `AnyClass: Message` is not satisfied +error[E0271]: type mismatch resolving `::Callee == CustomObject` --> ui/declare_class_invalid_receiver.rs | | / declare_class!( @@ -110,25 +110,45 @@ error[E0277]: the trait bound `AnyClass: Message` is not satisfied ... | | | } | | ); - | |_^ the trait `Message` is not implemented for `AnyClass` - | - = help: the following other types implement trait `Message`: - CustomObject - Exception - NSObject - __NSProxy - ProtocolObject

- AnyObject - __RcTestObject -note: required by a bound in `ClassBuilder::add_method` - --> $WORKSPACE/crates/objc2/src/declare/mod.rs - | - | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | | ^ + | | | + | |_expected `CustomObject`, found `AnyClass` + | required by a bound introduced by this call + | +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs + | + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) | ---------- required by a bound in this associated function | where - | T: Message + ?Sized, - | ^^^^^^^ required by this bound in `ClassBuilder::add_method` - = note: this error originates in the macro `$crate::__rewrite_self_param_inner` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) + | F: MethodImplementation, + | ^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` + = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0271]: type mismatch resolving `::Callee == CustomObject` + --> ui/declare_class_invalid_receiver.rs + | + | / declare_class!( + | | struct CustomObject; + | | + | | unsafe impl ClassType for CustomObject { +... | + | | } + | | ); + | | ^ + | | | + | |_expected `CustomObject`, found `NSObject` + | required by a bound introduced by this call + | +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs + | + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | ---------- required by a bound in this associated function + | where + | F: MethodImplementation, + | ^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` + = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Box: MessageReceiver` is not satisfied --> ui/declare_class_invalid_receiver.rs @@ -154,14 +174,14 @@ error[E0277]: the trait bound `Box: MessageReceiver` is not satisf &'a mut T &'a AnyClass = note: required for `extern "C" fn(Box, objc2::runtime::Sel) -> IdReturnValue` to implement `MethodImplementation` -note: required by a bound in `ClassBuilder::add_method` - --> $WORKSPACE/crates/objc2/src/declare/mod.rs +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | - | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) | ---------- required by a bound in this associated function -... + | where | F: MethodImplementation, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Id: MessageReceiver` is not satisfied @@ -188,14 +208,14 @@ error[E0277]: the trait bound `Id: MessageReceiver` is not satisfi &'a mut T &'a AnyClass = note: required for `extern "C" fn(Id, objc2::runtime::Sel) -> IdReturnValue` to implement `MethodImplementation` -note: required by a bound in `ClassBuilder::add_method` - --> $WORKSPACE/crates/objc2/src/declare/mod.rs +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | - | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) | ---------- required by a bound in this associated function -... + | where | F: MethodImplementation, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `CustomObject: MessageReceiver` is not satisfied @@ -222,14 +242,14 @@ error[E0277]: the trait bound `CustomObject: MessageReceiver` is not satisfied &'a mut T &'a AnyClass = note: required for `extern "C" fn(CustomObject, objc2::runtime::Sel) -> IdReturnValue` to implement `MethodImplementation` -note: required by a bound in `ClassBuilder::add_method` - --> $WORKSPACE/crates/objc2/src/declare/mod.rs +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | - | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) | ---------- required by a bound in this associated function -... + | where | F: MethodImplementation, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Box: MessageReceiver` is not satisfied diff --git a/crates/test-ui/ui/declare_class_mut_self_not_mutable.stderr b/crates/test-ui/ui/declare_class_mut_self_not_mutable.stderr index 7cb287282..34f33f2ee 100644 --- a/crates/test-ui/ui/declare_class_mut_self_not_mutable.stderr +++ b/crates/test-ui/ui/declare_class_mut_self_not_mutable.stderr @@ -20,14 +20,14 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM MutableWithImmutableSuperclass = note: required for `CustomObject` to implement `IsAllowedMutable` = note: required for `&mut CustomObject` to implement `MessageReceiver` -note: required by a bound in `ClassBuilder::add_method` - --> $WORKSPACE/crates/objc2/src/declare/mod.rs +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | - | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) | ---------- required by a bound in this associated function -... + | where | F: MethodImplementation, - | ^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` + | ^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied @@ -52,14 +52,14 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM MutableWithImmutableSuperclass = note: required for `CustomObject` to implement `IsAllowedMutable` = note: required for `&mut CustomObject` to implement `MessageReceiver` -note: required by a bound in `ClassBuilder::add_method` - --> $WORKSPACE/crates/objc2/src/declare/mod.rs +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | - | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) | ---------- required by a bound in this associated function -... + | where | F: MethodImplementation, - | ^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` + | ^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied @@ -84,14 +84,14 @@ error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedM MutableWithImmutableSuperclass = note: required for `CustomObject` to implement `IsAllowedMutable` = note: required for `&mut CustomObject` to implement `MessageReceiver` -note: required by a bound in `ClassBuilder::add_method` - --> $WORKSPACE/crates/objc2/src/declare/mod.rs +note: required by a bound in `ClassBuilderHelper::::add_method` + --> $WORKSPACE/crates/objc2/src/__macro_helpers/declare_class.rs | - | pub unsafe fn add_method(&mut self, sel: Sel, func: F) + | pub unsafe fn add_method(&mut self, sel: Sel, func: F) | ---------- required by a bound in this associated function -... + | where | F: MethodImplementation, - | ^^^^^^^^^^ required by this bound in `ClassBuilder::add_method` + | ^^^^^^^^^^ required by this bound in `ClassBuilderHelper::::add_method` = note: this error originates in the macro `$crate::__declare_class_register_out` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `InteriorMutable: mutability::MutabilityIsAllowedMutable` is not satisfied