diff --git a/crates/header-translator/src/method.rs b/crates/header-translator/src/method.rs index a3dd0de43..1e8cbf359 100644 --- a/crates/header-translator/src/method.rs +++ b/crates/header-translator/src/method.rs @@ -140,7 +140,8 @@ impl MethodModifiers { /// This also encodes the "method family" that a method belongs to. #[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] pub enum MemoryManagement { - IdCopyOrMutCopy, + IdCopy, + IdMutableCopy, IdNew, IdInit, IdOther, @@ -175,8 +176,8 @@ impl MemoryManagement { error!("the `alloc` method-family requires manual handling"); Self::IdOther } - (false, true, false, false, false) => Self::IdCopyOrMutCopy, - (false, false, true, false, false) => Self::IdCopyOrMutCopy, + (false, true, false, false, false) => Self::IdCopy, + (false, false, true, false, false) => Self::IdMutableCopy, (false, false, false, true, false) => Self::IdNew, (false, false, false, false, true) => Self::IdInit, (false, false, false, false, false) => Self::IdOther, @@ -199,7 +200,8 @@ impl MemoryManagement { modifiers.designated_initializer, id_type, ) { - (false, false, true, false, false, Self::IdCopyOrMutCopy) => Self::IdCopyOrMutCopy, + (false, false, true, false, false, Self::IdCopy) => Self::IdCopy, + (false, false, true, false, false, Self::IdMutableCopy) => Self::IdMutableCopy, (false, false, true, false, false, Self::IdNew) => Self::IdNew, // For the `init` family there's another restriction: // > must be instance methods @@ -689,7 +691,8 @@ impl fmt::Display for Method { } let id_mm_name = match &self.memory_management { - MemoryManagement::IdCopyOrMutCopy => Some("CopyOrMutCopy"), + MemoryManagement::IdCopy => Some("Copy"), + MemoryManagement::IdMutableCopy => Some("MutableCopy"), MemoryManagement::IdNew => Some("New"), MemoryManagement::IdInit => Some("Init"), MemoryManagement::IdOther => Some("Other"), diff --git a/crates/objc2/src/__macro_helpers/declare_class.rs b/crates/objc2/src/__macro_helpers/declare_class.rs index 97dd4550b..8acada1ea 100644 --- a/crates/objc2/src/__macro_helpers/declare_class.rs +++ b/crates/objc2/src/__macro_helpers/declare_class.rs @@ -15,7 +15,7 @@ use crate::runtime::{AnyProtocol, MethodDescription}; use crate::{ClassType, DeclaredClass, Message, ProtocolType}; use super::declared_ivars::{register_with_ivars, setup_dealloc}; -use super::{CopyOrMutCopy, Init, MaybeUnwrap, New, Other}; +use super::{Copy, Init, MaybeUnwrap, MutableCopy, New, Other}; /// Helper type for implementing `MethodImplementation` with a receiver of /// `Allocated`, without exposing that implementation to users. @@ -75,7 +75,19 @@ where } // Receiver and return type have no correlation -impl MessageReceiveRetained for CopyOrMutCopy +impl MessageReceiveRetained for Copy +where + Receiver: MessageReceiver, + Ret: MaybeOptionRetained, +{ + #[inline] + fn into_return(obj: Ret) -> RetainedReturnValue { + obj.consumed_return() + } +} + +// Receiver and return type have no correlation +impl MessageReceiveRetained for MutableCopy where Receiver: MessageReceiver, Ret: MaybeOptionRetained, diff --git a/crates/objc2/src/__macro_helpers/method_family.rs b/crates/objc2/src/__macro_helpers/method_family.rs index 6e4c72e95..66af3bf26 100644 --- a/crates/objc2/src/__macro_helpers/method_family.rs +++ b/crates/objc2/src/__macro_helpers/method_family.rs @@ -24,8 +24,9 @@ pub struct RetainSemantics {} pub type New = RetainSemantics<1>; pub type Alloc = RetainSemantics<2>; pub type Init = RetainSemantics<3>; -pub type CopyOrMutCopy = RetainSemantics<4>; -pub type Other = RetainSemantics<5>; +pub type Copy = RetainSemantics<4>; +pub type MutableCopy = RetainSemantics<5>; +pub type Other = RetainSemantics<6>; pub const fn retain_semantics(selector: &str) -> u8 { let selector = selector.as_bytes(); @@ -40,8 +41,8 @@ pub const fn retain_semantics(selector: &str) -> u8 { (false, true, false, false, false) => 2, (false, false, true, false, false) => 3, (false, false, false, true, false) => 4, - (false, false, false, false, true) => 4, - (false, false, false, false, false) => 5, + (false, false, false, false, true) => 5, + (false, false, false, false, false) => 6, _ => unreachable!(), } } diff --git a/crates/objc2/src/__macro_helpers/mod.rs b/crates/objc2/src/__macro_helpers/mod.rs index 81df0e6b4..04e5b8555 100644 --- a/crates/objc2/src/__macro_helpers/mod.rs +++ b/crates/objc2/src/__macro_helpers/mod.rs @@ -37,7 +37,7 @@ pub use self::declare_class::{ pub use self::declared_ivars::DeclaredIvarsHelper; pub use self::image_info::ImageInfo; pub use self::method_family::{ - retain_semantics, Alloc, CopyOrMutCopy, Init, New, Other, RetainSemantics, + retain_semantics, Alloc, Copy, Init, MutableCopy, New, Other, RetainSemantics, }; pub use self::module_info::ModuleInfo; pub use self::msg_send::MsgSend; diff --git a/crates/objc2/src/__macro_helpers/msg_send_retained.rs b/crates/objc2/src/__macro_helpers/msg_send_retained.rs index 232afa3e8..2d673b043 100644 --- a/crates/objc2/src/__macro_helpers/msg_send_retained.rs +++ b/crates/objc2/src/__macro_helpers/msg_send_retained.rs @@ -6,7 +6,7 @@ use crate::runtime::{AnyClass, AnyObject, Sel}; use crate::{sel, ClassType, DeclaredClass, Message}; use super::declared_ivars::set_finalized; -use super::{Alloc, ConvertArguments, CopyOrMutCopy, Init, MsgSend, New, Other, TupleExtender}; +use super::{Alloc, ConvertArguments, Copy, Init, MsgSend, MutableCopy, New, Other, TupleExtender}; pub trait MsgSendRetained { #[track_caller] @@ -329,7 +329,7 @@ impl MsgSendSuperRetained, Option>> } } -impl MsgSendRetained>> for CopyOrMutCopy { +impl MsgSendRetained>> for Copy { #[inline] unsafe fn send_message_retained< A: ConvertArguments, @@ -348,9 +348,47 @@ impl MsgSendRetained>> fo } } -impl MsgSendSuperRetained>> - for CopyOrMutCopy -{ +impl MsgSendSuperRetained>> for Copy { + type Inner = T::Inner; + + #[inline] + unsafe fn send_super_message_retained< + A: ConvertArguments, + R: MaybeUnwrap>>, + >( + obj: T, + superclass: &AnyClass, + sel: Sel, + args: A, + ) -> R { + // SAFETY: Same as in `send_message_retained` + let obj = unsafe { MsgSend::send_super_message(obj, superclass, sel, args) }; + // SAFETY: Same as in `send_message_retained` + let obj = unsafe { Retained::from_raw(obj) }; + R::maybe_unwrap::(obj, ()) + } +} + +impl MsgSendRetained>> for MutableCopy { + #[inline] + unsafe fn send_message_retained< + A: ConvertArguments, + R: MaybeUnwrap>>, + >( + obj: T, + sel: Sel, + args: A, + ) -> R { + // SAFETY: Checked by caller + let obj = unsafe { MsgSend::send_message(obj, sel, args) }; + // SAFETY: The selector is `copy` or `mutableCopy`, so this has +1 + // retain count + let obj = unsafe { Retained::from_raw(obj) }; + R::maybe_unwrap::(obj, ()) + } +} + +impl MsgSendSuperRetained>> for MutableCopy { type Inner = T::Inner; #[inline] @@ -525,7 +563,16 @@ impl MsgSendRetainedFailed<'_> for Init { } } -impl MsgSendRetainedFailed<'_> for CopyOrMutCopy { +impl MsgSendRetainedFailed<'_> for Copy { + type Args = (); + + #[cold] + fn failed(_: Self::Args) -> ! { + panic!("failed copying object") + } +} + +impl MsgSendRetainedFailed<'_> for MutableCopy { type Args = (); #[cold] diff --git a/crates/objc2/src/macros/__attribute_helpers.rs b/crates/objc2/src/macros/__attribute_helpers.rs index 07b4a7774..8c2009e52 100644 --- a/crates/objc2/src/macros/__attribute_helpers.rs +++ b/crates/objc2/src/macros/__attribute_helpers.rs @@ -68,7 +68,7 @@ macro_rules! __extract_and_apply_cfg_attributes { /// 2. The retain semantics, if any was present in the selector for /// `#[method_id(...)]`. /// -/// One of `New`, `Alloc`, `Init`, `CopyOrMutCopy` and `Other`. +/// One of `New`, `Alloc`, `Init`, `Copy`, `MutableCopy` and `Other`. /// ($($retain_semantics:ident)?) /// /// 3. The `optional` attribute, if any. 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 c7fde3ac7..9eb8b619a 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 @@ -147,19 +147,15 @@ Lloh11: b LBB5_2 .loh AdrpAdd Lloh10, Lloh11 - .globl _error_autoreleased + .globl _error_mutable_copy .p2align 2 -_error_autoreleased: +_error_mutable_copy: sub sp, sp, #32 stp x29, x30, [sp, #16] add x29, sp, #16 str xzr, [sp, #8] add x2, sp, #8 bl _objc_msgSend - ; InlineAsm Start - mov x29, x29 - ; InlineAsm End - bl _objc_retainAutoreleasedReturnValue cbz x0, LBB6_3 mov x1, x0 mov x0, #0 @@ -179,6 +175,38 @@ Lloh13: b LBB6_2 .loh AdrpAdd Lloh12, Lloh13 + .globl _error_autoreleased + .p2align 2 +_error_autoreleased: + sub sp, sp, #32 + stp x29, x30, [sp, #16] + add x29, sp, #16 + str xzr, [sp, #8] + add x2, sp, #8 + bl _objc_msgSend + ; InlineAsm Start + mov x29, x29 + ; InlineAsm End + bl _objc_retainAutoreleasedReturnValue + cbz x0, LBB7_3 + mov x1, x0 + mov x0, #0 +LBB7_2: + ldp x29, x30, [sp, #16] + add sp, sp, #32 + ret +LBB7_3: + ldr x0, [sp, #8] +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_retained::encountered_error::, 0) + mov x1, x0 + mov w0, #1 + b LBB7_2 + .loh AdrpAdd Lloh14, Lloh15 + .section __TEXT,__const l_anon.[ID].0: .ascii "error parameter should be set if the method returns NULL" @@ -215,4 +243,9 @@ l_anon.[ID].7: .quad l_anon.[ID].2 .asciz "6\000\000\000\000\000\000\000 \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" + .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 2db4bfd24..95b7a0de5 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 @@ -154,6 +154,36 @@ LPC5_0: sub sp, r7, #4 pop {r4, r7, pc} + .globl _error_mutable_copy + .p2align 2 + .code 32 +_error_mutable_copy: + push {r4, r7, lr} + add r7, sp, #4 + sub sp, sp, #4 + mov r4, #0 + str r4, [sp] + mov r2, sp + bl _objc_msgSend + mov r1, r0 + cmp r0, #0 + beq LBB6_2 + mov r0, r4 + sub sp, r7, #4 + 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)) +LPC6_0: + add r1, pc, r1 + bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_retained::encountered_error::, 0) + mov r1, r0 + mov r4, #1 + mov r0, r4 + sub sp, r7, #4 + pop {r4, r7, pc} + .globl _error_autoreleased .p2align 2 .code 32 @@ -171,15 +201,15 @@ _error_autoreleased: bl _objc_retainAutoreleasedReturnValue mov r1, r0 cmp r0, #0 - beq LBB6_2 + beq LBB7_2 mov r0, r4 sub sp, r7, #4 pop {r4, r7, pc} -LBB6_2: +LBB7_2: ldr r0, [sp] - movw r1, :lower16:(l_anon.[ID].7-(LPC6_0+8)) - movt r1, :upper16:(l_anon.[ID].7-(LPC6_0+8)) -LPC6_0: + movw r1, :lower16:(l_anon.[ID].8-(LPC7_0+8)) + movt r1, :upper16:(l_anon.[ID].8-(LPC7_0+8)) +LPC7_0: add r1, pc, r1 bl SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_retained::encountered_error::, 0) mov r1, r0 @@ -224,4 +254,9 @@ l_anon.[ID].7: .long l_anon.[ID].2 .asciz "6\000\000\000 \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" + .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 18b2919c5..e38609839 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 @@ -207,15 +207,54 @@ LBB5_2: pop ebp ret - .globl _error_autoreleased + .globl _error_mutable_copy .p2align 4, 0x90 -_error_autoreleased: +_error_mutable_copy: push ebp mov ebp, esp push esi push eax call L6$pb L6$pb: + pop esi + mov eax, dword ptr [ebp + 8] + mov ecx, dword ptr [ebp + 12] + mov dword ptr [ebp - 8], 0 + sub esp, 4 + lea edx, [ebp - 8] + push edx + push ecx + push eax + call _objc_msgSend + add esp, 16 + test eax, eax + je LBB6_2 + mov edx, eax + xor eax, eax + add esp, 4 + pop esi + pop ebp + ret +LBB6_2: + mov ecx, dword ptr [ebp - 8] + lea edx, [esi + l_anon.[ID].7-L6$pb] + call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_retained::encountered_error::, 0) + mov edx, eax + mov eax, 1 + add esp, 4 + pop esi + pop ebp + ret + + .globl _error_autoreleased + .p2align 4, 0x90 +_error_autoreleased: + push ebp + mov ebp, esp + push esi + push eax + call L7$pb +L7$pb: pop esi mov eax, dword ptr [ebp + 8] mov ecx, dword ptr [ebp + 12] @@ -237,16 +276,16 @@ L6$pb: call _objc_retainAutoreleasedReturnValue add esp, 16 test eax, eax - je LBB6_2 + je LBB7_2 mov edx, eax xor eax, eax add esp, 4 pop esi pop ebp ret -LBB6_2: +LBB7_2: mov ecx, dword ptr [ebp - 8] - lea edx, [esi + l_anon.[ID].7-L6$pb] + lea edx, [esi + l_anon.[ID].8-L7$pb] call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_retained::encountered_error::, 0) mov edx, eax mov eax, 1 @@ -291,4 +330,9 @@ l_anon.[ID].7: .long l_anon.[ID].2 .asciz "6\000\000\000 \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" + .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 539ac12b5..0a72bccb8 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 @@ -135,6 +135,32 @@ LBB5_2: pop rbp ret + .globl _error_mutable_copy + .p2align 4, 0x90 +_error_mutable_copy: + 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 LBB6_2 + mov rdx, rax + xor eax, eax + add rsp, 16 + pop rbp + ret +LBB6_2: + mov rdi, qword ptr [rbp - 8] + lea rsi, [rip + l_anon.[ID].7] + call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_retained::encountered_error::, 0) + mov rdx, rax + mov eax, 1 + add rsp, 16 + pop rbp + ret + .globl _error_autoreleased .p2align 4, 0x90 _error_autoreleased: @@ -152,15 +178,15 @@ _error_autoreleased: ## InlineAsm End test rax, rax - je LBB6_2 + je LBB7_2 mov rdx, rax xor eax, eax add rsp, 16 pop rbp ret -LBB6_2: +LBB7_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_retained::encountered_error::, 0) mov rdx, rax mov eax, 1 @@ -204,4 +230,9 @@ l_anon.[ID].7: .quad l_anon.[ID].2 .asciz "6\000\000\000\000\000\000\000 \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" + .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 08acddc0e..96d149d8d 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 @@ -263,11 +263,11 @@ error_copy: .Lfunc_end5: .size error_copy, .Lfunc_end5-error_copy - .section .text.error_autoreleased,"ax",@progbits - .globl error_autoreleased + .section .text.error_mutable_copy,"ax",@progbits + .globl error_mutable_copy .p2align 4, 0x90 - .type error_autoreleased,@function -error_autoreleased: + .type error_mutable_copy,@function +error_mutable_copy: push ebx push edi push esi @@ -290,9 +290,6 @@ error_autoreleased: push edi push esi call eax - add esp, 4 - push eax - call objc_retainAutoreleasedReturnValue@PLT add esp, 16 test eax, eax je .LBB6_2 @@ -312,7 +309,58 @@ error_autoreleased: mov eax, 1 jmp .LBB6_3 .Lfunc_end6: - .size error_autoreleased, .Lfunc_end6-error_autoreleased + .size error_mutable_copy, .Lfunc_end6-error_mutable_copy + + .section .text.error_autoreleased,"ax",@progbits + .globl error_autoreleased + .p2align 4, 0x90 + .type error_autoreleased,@function +error_autoreleased: + push ebx + push edi + push esi + sub esp, 16 + mov esi, dword ptr [esp + 32] + mov edi, dword ptr [esp + 36] + call .L7$pb +.L7$pb: + pop ebx + mov dword ptr [esp + 12], 0 +.Ltmp7: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp7-.L7$pb) + sub esp, 8 + push edi + push esi + call objc_msg_lookup@PLT + add esp, 12 + lea ecx, [esp + 16] + push ecx + push edi + push esi + call eax + add esp, 4 + push eax + call objc_retainAutoreleasedReturnValue@PLT + add esp, 16 + test eax, eax + je .LBB7_2 + mov edx, eax + xor eax, eax +.LBB7_3: + add esp, 16 + pop esi + pop edi + pop ebx + ret +.LBB7_2: + mov ecx, dword ptr [esp + 12] + lea edx, [ebx + .Lanon.[ID].8@GOTOFF] + call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_retained::encountered_error::, 0) + mov edx, eax + mov eax, 1 + jmp .LBB7_3 +.Lfunc_end7: + .size error_autoreleased, .Lfunc_end7-error_autoreleased .type .Lanon.[ID].0,@object .section .rodata..Lanon.[ID].0,"a",@progbits @@ -372,4 +420,12 @@ error_autoreleased: .asciz "6\000\000\000 \000\000\000\005\000\000" .size .Lanon.[ID].7, 16 + .type .Lanon.[ID].8,@object + .section .data.rel.ro..Lanon.[ID].8,"aw",@progbits + .p2align 2, 0x0 +.Lanon.[ID].8: + .long .Lanon.[ID].2 + .asciz "6\000\000\000%\000\000\000\005\000\000" + .size .Lanon.[ID].8, 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 2403ff1c1..9be2c580f 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 @@ -189,6 +189,43 @@ error_copy: .Lfunc_end5: .size error_copy, .Lfunc_end5-error_copy + .section .text.error_mutable_copy,"ax",@progbits + .globl error_mutable_copy + .p2align 4, 0x90 + .type error_mutable_copy,@function +error_mutable_copy: + 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 .LBB6_2 + mov rdx, rax + xor eax, eax + add rsp, 8 + pop rbx + pop r14 + ret +.LBB6_2: + mov rdi, qword ptr [rsp] + lea rsi, [rip + .Lanon.[ID].7] + call SYM(objc2[CRATE_ID]::__macro_helpers::msg_send_retained::encountered_error::, 0) + mov rdx, rax + mov eax, 1 + add rsp, 8 + pop rbx + pop r14 + ret +.Lfunc_end6: + .size error_mutable_copy, .Lfunc_end6-error_mutable_copy + .section .text.error_autoreleased,"ax",@progbits .globl error_autoreleased .p2align 4, 0x90 @@ -208,16 +245,16 @@ error_autoreleased: mov rdi, rax call qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] test rax, rax - je .LBB6_2 + je .LBB7_2 mov rdx, rax xor eax, eax add rsp, 8 pop rbx pop r14 ret -.LBB6_2: +.LBB7_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_retained::encountered_error::, 0) mov rdx, rax mov eax, 1 @@ -225,8 +262,8 @@ error_autoreleased: pop rbx pop r14 ret -.Lfunc_end6: - .size error_autoreleased, .Lfunc_end6-error_autoreleased +.Lfunc_end7: + .size error_autoreleased, .Lfunc_end7-error_autoreleased .type .Lanon.[ID].0,@object .section .rodata..Lanon.[ID].0,"a",@progbits @@ -286,4 +323,12 @@ error_autoreleased: .asciz "6\000\000\000\000\000\000\000 \000\000\000\005\000\000" .size .Lanon.[ID].7, 24 + .type .Lanon.[ID].8,@object + .section .data.rel.ro..Lanon.[ID].8,"aw",@progbits + .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" + .size .Lanon.[ID].8, 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 2d28548bb..18f8cbf32 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::{CopyOrMutCopy, Init, MsgSend, MsgSendRetained, New, Other}; +use objc2::__macro_helpers::{Copy, Init, MsgSend, MsgSendRetained, MutableCopy, New, Other}; use objc2::rc::{Allocated, Retained}; use objc2::runtime::{AnyClass, AnyObject, Sel}; @@ -24,7 +24,12 @@ unsafe fn error_init(obj: Allocated, sel: Sel) -> Result Result> { - CopyOrMutCopy::send_message_retained_error(obj, sel, ()) + Copy::send_message_retained_error(obj, sel, ()) +} + +#[no_mangle] +unsafe fn error_mutable_copy(obj: &AnyObject, sel: Sel) -> Result> { + MutableCopy::send_message_retained_error(obj, sel, ()) } #[no_mangle] diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-aarch64.s b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-aarch64.s index 1c6a7dc22..635ce7084 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-aarch64.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-aarch64.s @@ -118,6 +118,28 @@ Lloh5: bl SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) .loh AdrpAdd Lloh4, Lloh5 + .globl _handle_mutable_copy + .p2align 2 +_handle_mutable_copy: + b _objc_msgSend + + .globl _handle_mutable_copy_fallible + .p2align 2 +_handle_mutable_copy_fallible: + stp x29, x30, [sp, #-16]! + mov x29, sp + bl _objc_msgSend + cbz x0, LBB11_2 + ldp x29, x30, [sp], #16 + ret +LBB11_2: +Lloh6: + adrp x0, l_anon.[ID].4@PAGE +Lloh7: + add x0, x0, l_anon.[ID].4@PAGEOFF + bl SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + .loh AdrpAdd Lloh6, Lloh7 + .globl _handle_autoreleased .p2align 2 _handle_autoreleased: @@ -156,19 +178,19 @@ _handle_autoreleased_fallible: mov x29, x29 ; InlineAsm End bl _objc_retainAutoreleasedReturnValue - cbz x0, LBB12_2 + cbz x0, LBB14_2 ldp x29, x30, [sp, #16] ldp x20, x19, [sp], #32 ret -LBB12_2: -Lloh6: - adrp x2, l_anon.[ID].4@PAGE -Lloh7: - add x2, x2, l_anon.[ID].4@PAGEOFF +LBB14_2: +Lloh8: + adrp x2, l_anon.[ID].5@PAGE +Lloh9: + add x2, x2, l_anon.[ID].5@PAGEOFF mov x0, x20 mov x1, x19 - bl SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) - .loh AdrpAdd Lloh6, Lloh7 + bl SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + .loh AdrpAdd Lloh8, Lloh9 .globl _handle_with_out_param .p2align 2 @@ -217,6 +239,11 @@ l_anon.[ID].3: .p2align 3, 0x0 l_anon.[ID].4: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\000L\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000B\000\000\000\005\000\000" + + .p2align 3, 0x0 +l_anon.[ID].5: + .quad l_anon.[ID].0 + .asciz "9\000\000\000\000\000\000\000V\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-armv7s.s b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-armv7s.s index ef5b9d52d..7be51ae5e 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-armv7s.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-armv7s.s @@ -118,6 +118,29 @@ LPC9_0: mov lr, pc b SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + .globl _handle_mutable_copy + .p2align 2 + .code 32 +_handle_mutable_copy: + b _objc_msgSend + + .globl _handle_mutable_copy_fallible + .p2align 2 + .code 32 +_handle_mutable_copy_fallible: + push {r7, lr} + mov r7, sp + bl _objc_msgSend + cmp r0, #0 + popne {r7, pc} +LBB11_1: + movw r0, :lower16:(l_anon.[ID].4-(LPC11_0+8)) + movt r0, :upper16:(l_anon.[ID].4-(LPC11_0+8)) +LPC11_0: + add r0, pc, r0 + mov lr, pc + b SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + .globl _handle_autoreleased .p2align 2 .code 32 @@ -160,15 +183,15 @@ _handle_autoreleased_fallible: bl _objc_retainAutoreleasedReturnValue cmp r0, #0 popne {r4, r5, r7, pc} -LBB12_1: - movw r2, :lower16:(l_anon.[ID].4-(LPC12_0+8)) - movt r2, :upper16:(l_anon.[ID].4-(LPC12_0+8)) -LPC12_0: +LBB14_1: + movw r2, :lower16:(l_anon.[ID].5-(LPC14_0+8)) + movt r2, :upper16:(l_anon.[ID].5-(LPC14_0+8)) +LPC14_0: add r2, pc, r2 mov r0, r5 mov r1, r4 mov lr, pc - b SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + b SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) .globl _handle_with_out_param .p2align 2 @@ -214,6 +237,11 @@ l_anon.[ID].3: .p2align 2, 0x0 l_anon.[ID].4: .long l_anon.[ID].0 - .asciz "9\000\000\000L\000\000\000\005\000\000" + .asciz "9\000\000\000B\000\000\000\005\000\000" + + .p2align 2, 0x0 +l_anon.[ID].5: + .long l_anon.[ID].0 + .asciz "9\000\000\000V\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86.s b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86.s index a63ddc290..f5c04a976 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86.s @@ -189,6 +189,40 @@ LBB9_2: mov dword ptr [esp], eax call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + .globl _handle_mutable_copy + .p2align 4, 0x90 +_handle_mutable_copy: + push ebp + mov ebp, esp + pop ebp + jmp _objc_msgSend + + .globl _handle_mutable_copy_fallible + .p2align 4, 0x90 +_handle_mutable_copy_fallible: + push ebp + mov ebp, esp + push esi + sub esp, 20 + call L11$pb +L11$pb: + pop esi + mov eax, dword ptr [ebp + 8] + mov ecx, dword ptr [ebp + 12] + mov dword ptr [esp + 4], ecx + mov dword ptr [esp], eax + call _objc_msgSend + test eax, eax + je LBB11_2 + add esp, 20 + pop esi + pop ebp + ret +LBB11_2: + lea eax, [esi + l_anon.[ID].4-L11$pb] + mov dword ptr [esp], eax + call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + .globl _handle_autoreleased .p2align 4, 0x90 _handle_autoreleased: @@ -245,8 +279,8 @@ _handle_autoreleased_fallible: push edi push esi sub esp, 12 - call L12$pb -L12$pb: + call L14$pb +L14$pb: pop ebx mov edi, dword ptr [ebp + 12] mov esi, dword ptr [ebp + 8] @@ -265,20 +299,20 @@ L12$pb: call _objc_retainAutoreleasedReturnValue add esp, 16 test eax, eax - je LBB12_2 + je LBB14_2 add esp, 12 pop esi pop edi pop ebx pop ebp ret -LBB12_2: +LBB14_2: sub esp, 4 - lea eax, [ebx + l_anon.[ID].4-L12$pb] + lea eax, [ebx + l_anon.[ID].5-L14$pb] push eax push edi push esi - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) .globl _handle_with_out_param .p2align 4, 0x90 @@ -340,6 +374,11 @@ l_anon.[ID].3: .p2align 2, 0x0 l_anon.[ID].4: .long l_anon.[ID].0 - .asciz "9\000\000\000L\000\000\000\005\000\000" + .asciz "9\000\000\000B\000\000\000\005\000\000" + + .p2align 2, 0x0 +l_anon.[ID].5: + .long l_anon.[ID].0 + .asciz "9\000\000\000V\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86_64.s b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86_64.s index 628490cab..635b949bb 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/apple-x86_64.s @@ -134,6 +134,28 @@ LBB9_2: lea rdi, [rip + l_anon.[ID].3] call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + .globl _handle_mutable_copy + .p2align 4, 0x90 +_handle_mutable_copy: + push rbp + mov rbp, rsp + pop rbp + jmp _objc_msgSend + + .globl _handle_mutable_copy_fallible + .p2align 4, 0x90 +_handle_mutable_copy_fallible: + push rbp + mov rbp, rsp + call _objc_msgSend + test rax, rax + je LBB11_2 + pop rbp + ret +LBB11_2: + lea rdi, [rip + l_anon.[ID].4] + call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + .globl _handle_autoreleased .p2align 4, 0x90 _handle_autoreleased: @@ -185,16 +207,16 @@ _handle_autoreleased_fallible: ## InlineAsm End test rax, rax - je LBB12_2 + je LBB14_2 pop rbx pop r14 pop rbp ret -LBB12_2: - lea rdx, [rip + l_anon.[ID].4] +LBB14_2: + lea rdx, [rip + l_anon.[ID].5] mov rdi, r14 mov rsi, rbx - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) + call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0) .globl _handle_with_out_param .p2align 4, 0x90 @@ -250,6 +272,11 @@ l_anon.[ID].3: .p2align 3, 0x0 l_anon.[ID].4: .quad l_anon.[ID].0 - .asciz "9\000\000\000\000\000\000\000L\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000B\000\000\000\005\000\000" + + .p2align 3, 0x0 +l_anon.[ID].5: + .quad l_anon.[ID].0 + .asciz "9\000\000\000\000\000\000\000V\000\000\000\005\000\000" .subsections_via_symbols diff --git a/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86.s b/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86.s index 9225de7ae..60dd84c14 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86.s @@ -374,6 +374,73 @@ handle_copy_fallible: .Lfunc_end9: .size handle_copy_fallible, .Lfunc_end9-handle_copy_fallible + .section .text.handle_mutable_copy,"ax",@progbits + .globl handle_mutable_copy + .p2align 4, 0x90 + .type handle_mutable_copy,@function +handle_mutable_copy: + push ebx + push edi + push esi + mov esi, dword ptr [esp + 16] + mov edi, dword ptr [esp + 20] + call .L10$pb +.L10$pb: + pop ebx +.Ltmp10: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp10-.L10$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 + pop esi + pop edi + pop ebx + ret +.Lfunc_end10: + .size handle_mutable_copy, .Lfunc_end10-handle_mutable_copy + + .section .text.handle_mutable_copy_fallible,"ax",@progbits + .globl handle_mutable_copy_fallible + .p2align 4, 0x90 + .type handle_mutable_copy_fallible,@function +handle_mutable_copy_fallible: + push ebx + push edi + push esi + sub esp, 16 + mov esi, dword ptr [esp + 32] + mov edi, dword ptr [esp + 36] + call .L11$pb +.L11$pb: + pop ebx +.Ltmp11: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp11-.L11$pb) + mov dword ptr [esp + 4], edi + mov dword ptr [esp], esi + call objc_msg_lookup@PLT + mov dword ptr [esp + 4], edi + mov dword ptr [esp], esi + call eax + test eax, eax + je .LBB11_2 + add esp, 16 + pop esi + pop edi + pop ebx + ret +.LBB11_2: + lea eax, [ebx + .Lanon.[ID].4@GOTOFF] + mov dword ptr [esp], eax + call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@PLT +.Lfunc_end11: + .size handle_mutable_copy_fallible, .Lfunc_end11-handle_mutable_copy_fallible + .section .text.handle_autoreleased,"ax",@progbits .globl handle_autoreleased .p2align 4, 0x90 @@ -385,11 +452,11 @@ handle_autoreleased: sub esp, 16 mov esi, dword ptr [esp + 32] mov edi, dword ptr [esp + 36] - call .L10$pb -.L10$pb: + call .L12$pb +.L12$pb: pop ebx -.Ltmp10: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp10-.L10$pb) +.Ltmp12: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp12-.L12$pb) mov dword ptr [esp + 4], edi mov dword ptr [esp], esi call objc_msg_lookup@PLT @@ -403,8 +470,8 @@ handle_autoreleased: pop edi pop ebx ret -.Lfunc_end10: - .size handle_autoreleased, .Lfunc_end10-handle_autoreleased +.Lfunc_end12: + .size handle_autoreleased, .Lfunc_end12-handle_autoreleased .section .text.handle_autoreleased_with_arg,"ax",@progbits .globl handle_autoreleased_with_arg @@ -419,11 +486,11 @@ handle_autoreleased_with_arg: movzx edi, byte ptr [esp + 40] mov esi, dword ptr [esp + 32] mov ebp, dword ptr [esp + 36] - call .L11$pb -.L11$pb: + call .L13$pb +.L13$pb: pop ebx -.Ltmp11: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp11-.L11$pb) +.Ltmp13: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp13-.L13$pb) sub esp, 8 push ebp push esi @@ -442,8 +509,8 @@ handle_autoreleased_with_arg: pop ebx pop ebp ret -.Lfunc_end11: - .size handle_autoreleased_with_arg, .Lfunc_end11-handle_autoreleased_with_arg +.Lfunc_end13: + .size handle_autoreleased_with_arg, .Lfunc_end13-handle_autoreleased_with_arg .section .text.handle_autoreleased_fallible,"ax",@progbits .globl handle_autoreleased_fallible @@ -455,11 +522,11 @@ handle_autoreleased_fallible: push esi mov edi, dword ptr [esp + 20] mov esi, dword ptr [esp + 16] - call .L12$pb -.L12$pb: + call .L14$pb +.L14$pb: pop ebx -.Ltmp12: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp12-.L12$pb) +.Ltmp14: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp14-.L14$pb) sub esp, 8 push edi push esi @@ -473,20 +540,20 @@ handle_autoreleased_fallible: call objc_retainAutoreleasedReturnValue@PLT add esp, 16 test eax, eax - je .LBB12_2 + je .LBB14_2 pop esi pop edi pop ebx ret -.LBB12_2: +.LBB14_2: sub esp, 4 - lea eax, [ebx + .Lanon.[ID].4@GOTOFF] + lea eax, [ebx + .Lanon.[ID].5@GOTOFF] push eax push edi push esi - call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@PLT -.Lfunc_end12: - .size handle_autoreleased_fallible, .Lfunc_end12-handle_autoreleased_fallible + call SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@PLT +.Lfunc_end14: + .size handle_autoreleased_fallible, .Lfunc_end14-handle_autoreleased_fallible .section .text.handle_with_out_param,"ax",@progbits .globl handle_with_out_param @@ -501,11 +568,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 .L15$pb +.L15$pb: pop ebx -.Ltmp13: - add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp13-.L13$pb) +.Ltmp15: + add ebx, offset _GLOBAL_OFFSET_TABLE_+(.Ltmp15-.L15$pb) mov edi, dword ptr [ebp] mov dword ptr [esp + 4], esi mov dword ptr [esp], eax @@ -529,8 +596,8 @@ handle_with_out_param: pop ebx pop ebp ret -.Lfunc_end13: - .size handle_with_out_param, .Lfunc_end13-handle_with_out_param +.Lfunc_end15: + .size handle_with_out_param, .Lfunc_end15-handle_with_out_param .type .Lanon.[ID].0,@object .section .rodata..Lanon.[ID].0,"a",@progbits @@ -567,7 +634,15 @@ handle_with_out_param: .p2align 2, 0x0 .Lanon.[ID].4: .long .Lanon.[ID].0 - .asciz "9\000\000\000L\000\000\000\005\000\000" + .asciz "9\000\000\000B\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 "9\000\000\000V\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_retained/expected/gnustep-x86_64.s b/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86_64.s index a418462de..c81d46e4a 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86_64.s +++ b/crates/test-assembly/crates/test_msg_send_retained/expected/gnustep-x86_64.s @@ -264,6 +264,52 @@ handle_copy_fallible: .Lfunc_end9: .size handle_copy_fallible, .Lfunc_end9-handle_copy_fallible + .section .text.handle_mutable_copy,"ax",@progbits + .globl handle_mutable_copy + .p2align 4, 0x90 + .type handle_mutable_copy,@function +handle_mutable_copy: + 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 + add rsp, 8 + pop rbx + pop r14 + jmp rax +.Lfunc_end10: + .size handle_mutable_copy, .Lfunc_end10-handle_mutable_copy + + .section .text.handle_mutable_copy_fallible,"ax",@progbits + .globl handle_mutable_copy_fallible + .p2align 4, 0x90 + .type handle_mutable_copy_fallible,@function +handle_mutable_copy_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 .LBB11_2 + add rsp, 8 + pop rbx + pop r14 + ret +.LBB11_2: + lea rdi, [rip + .Lanon.[ID].4] + call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@GOTPCREL] +.Lfunc_end11: + .size handle_mutable_copy_fallible, .Lfunc_end11-handle_mutable_copy_fallible + .section .text.handle_autoreleased,"ax",@progbits .globl handle_autoreleased .p2align 4, 0x90 @@ -283,8 +329,8 @@ handle_autoreleased: pop rbx pop r14 jmp qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] -.Lfunc_end10: - .size handle_autoreleased, .Lfunc_end10-handle_autoreleased +.Lfunc_end12: + .size handle_autoreleased, .Lfunc_end12-handle_autoreleased .section .text.handle_autoreleased_with_arg,"ax",@progbits .globl handle_autoreleased_with_arg @@ -307,8 +353,8 @@ handle_autoreleased_with_arg: pop r14 pop r15 jmp qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] -.Lfunc_end11: - .size handle_autoreleased_with_arg, .Lfunc_end11-handle_autoreleased_with_arg +.Lfunc_end13: + .size handle_autoreleased_with_arg, .Lfunc_end13-handle_autoreleased_with_arg .section .text.handle_autoreleased_fallible,"ax",@progbits .globl handle_autoreleased_fallible @@ -327,18 +373,18 @@ handle_autoreleased_fallible: mov rdi, rax call qword ptr [rip + objc_retainAutoreleasedReturnValue@GOTPCREL] test rax, rax - je .LBB12_2 + je .LBB14_2 add rsp, 8 pop rbx pop r14 ret -.LBB12_2: - lea rdx, [rip + .Lanon.[ID].4] +.LBB14_2: + lea rdx, [rip + .Lanon.[ID].5] mov rdi, r14 mov rsi, rbx - call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@GOTPCREL] -.Lfunc_end12: - .size handle_autoreleased_fallible, .Lfunc_end12-handle_autoreleased_fallible + call qword ptr [rip + SYM( as objc2::__macro_helpers::msg_send_retained::MsgSendRetainedFailed>::failed::GENERATED_ID, 0)@GOTPCREL] +.Lfunc_end14: + .size handle_autoreleased_fallible, .Lfunc_end14-handle_autoreleased_fallible .section .text.handle_with_out_param,"ax",@progbits .globl handle_with_out_param @@ -371,8 +417,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_end15: + .size handle_with_out_param, .Lfunc_end15-handle_with_out_param .type .Lanon.[ID].0,@object .section .rodata..Lanon.[ID].0,"a",@progbits @@ -409,7 +455,15 @@ handle_with_out_param: .p2align 3, 0x0 .Lanon.[ID].4: .quad .Lanon.[ID].0 - .asciz "9\000\000\000\000\000\000\000L\000\000\000\005\000\000" + .asciz "9\000\000\000\000\000\000\000B\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 "9\000\000\000\000\000\000\000V\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_retained/lib.rs b/crates/test-assembly/crates/test_msg_send_retained/lib.rs index 33bac0e03..6f7f3bfd5 100644 --- a/crates/test-assembly/crates/test_msg_send_retained/lib.rs +++ b/crates/test-assembly/crates/test_msg_send_retained/lib.rs @@ -1,5 +1,5 @@ //! Test assembly output of `msg_send_id!` internals. -use objc2::__macro_helpers::{Alloc, CopyOrMutCopy, Init, MsgSendRetained, New, Other}; +use objc2::__macro_helpers::{Alloc, Copy, Init, MsgSendRetained, MutableCopy, New, Other}; use objc2::rc::{Allocated, Retained}; use objc2::runtime::{AnyClass, AnyObject, Sel}; @@ -48,12 +48,22 @@ unsafe fn handle_alloc_init_release(cls: &AnyClass, sel1: Sel, sel2: Sel) { #[no_mangle] unsafe fn handle_copy(obj: &AnyObject, sel: Sel) -> Option> { - CopyOrMutCopy::send_message_retained(obj, sel, ()) + Copy::send_message_retained(obj, sel, ()) } #[no_mangle] unsafe fn handle_copy_fallible(obj: &AnyObject, sel: Sel) -> Retained { - CopyOrMutCopy::send_message_retained(obj, sel, ()) + Copy::send_message_retained(obj, sel, ()) +} + +#[no_mangle] +unsafe fn handle_mutable_copy(obj: &AnyObject, sel: Sel) -> Option> { + MutableCopy::send_message_retained(obj, sel, ()) +} + +#[no_mangle] +unsafe fn handle_mutable_copy_fallible(obj: &AnyObject, sel: Sel) -> Retained { + MutableCopy::send_message_retained(obj, sel, ()) } #[no_mangle] diff --git a/crates/test-ui/ui/declare_class_invalid_receiver.stderr b/crates/test-ui/ui/declare_class_invalid_receiver.stderr index 01190f2c4..55f9964ba 100644 --- a/crates/test-ui/ui/declare_class_invalid_receiver.stderr +++ b/crates/test-ui/ui/declare_class_invalid_receiver.stderr @@ -272,7 +272,7 @@ error[E0277]: the trait bound `Box: MessageReceiver` is not satisf *const T *mut T NonNull - = note: required for `RetainSemantics<5>` to implement `MessageReceiveRetained, Retained>` + = note: required for `RetainSemantics<6>` to implement `MessageReceiveRetained, Retained>` = note: this error originates in the macro `$crate::__declare_class_method_out_inner` 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 `Retained: MessageReceiver` is not satisfied @@ -295,7 +295,7 @@ error[E0277]: the trait bound `Retained: MessageReceiver` is not s *const T *mut T NonNull - = note: required for `RetainSemantics<5>` to implement `MessageReceiveRetained, Retained>` + = note: required for `RetainSemantics<6>` to implement `MessageReceiveRetained, Retained>` = note: this error originates in the macro `$crate::__declare_class_method_out_inner` 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 @@ -318,7 +318,7 @@ error[E0277]: the trait bound `CustomObject: MessageReceiver` is not satisfied *const T *mut T NonNull - = note: required for `RetainSemantics<5>` to implement `MessageReceiveRetained>` + = note: required for `RetainSemantics<6>` to implement `MessageReceiveRetained>` = note: this error originates in the macro `$crate::__declare_class_method_out_inner` 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 `Allocated: MessageReceiver` is not satisfied @@ -341,7 +341,7 @@ error[E0277]: the trait bound `Allocated: MessageReceiver` is not *const T *mut T NonNull - = note: required for `RetainSemantics<5>` to implement `MessageReceiveRetained, Retained>` + = note: required for `RetainSemantics<6>` to implement `MessageReceiveRetained, Retained>` = note: this error originates in the macro `$crate::__declare_class_method_out_inner` 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 `RetainSemantics<3>: MessageReceiveRetained<&CustomObject, Retained>` is not satisfied diff --git a/crates/test-ui/ui/declare_class_invalid_syntax.stderr b/crates/test-ui/ui/declare_class_invalid_syntax.stderr index a9643e000..1f361e7c5 100644 --- a/crates/test-ui/ui/declare_class_invalid_syntax.stderr +++ b/crates/test-ui/ui/declare_class_invalid_syntax.stderr @@ -521,4 +521,5 @@ error[E0277]: the trait bound `RetainSemantics<2>: MessageReceiveRetained<&AnyCl `RetainSemantics<3>` implements `MessageReceiveRetained, Ret>` `RetainSemantics<4>` implements `MessageReceiveRetained` `RetainSemantics<5>` implements `MessageReceiveRetained` + `RetainSemantics<6>` implements `MessageReceiveRetained` = note: this error originates in the macro `$crate::__declare_class_method_out_inner` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/test-ui/ui/declare_class_invalid_type2.stderr b/crates/test-ui/ui/declare_class_invalid_type2.stderr index 3499055e7..82ec5a2c6 100644 --- a/crates/test-ui/ui/declare_class_invalid_type2.stderr +++ b/crates/test-ui/ui/declare_class_invalid_type2.stderr @@ -30,5 +30,5 @@ error[E0277]: the trait bound `i32: MaybeOptionRetained` is not satisfied = help: the following other types implement trait `MaybeOptionRetained`: Option> Retained - = note: required for `RetainSemantics<5>` to implement `MessageReceiveRetained<&CustomObject, i32>` + = note: required for `RetainSemantics<6>` to implement `MessageReceiveRetained<&CustomObject, i32>` = note: this error originates in the macro `$crate::__declare_class_method_out_inner` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) 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 f1ac0135c..a58f8403a 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 @@ -124,5 +124,5 @@ error[E0277]: the trait bound `&mut CustomObject: MessageReceiver` is not satisf *mut T NonNull = note: `MessageReceiver` is implemented for `&CustomObject`, but not for `&mut CustomObject` - = note: required for `RetainSemantics<5>` to implement `MessageReceiveRetained<&mut CustomObject, Retained>` + = note: required for `RetainSemantics<6>` to implement `MessageReceiveRetained<&mut CustomObject, Retained>` = note: this error originates in the macro `$crate::__declare_class_method_out_inner` which comes from the expansion of the macro `declare_class` (in Nightly builds, run with -Z macro-backtrace for more info) 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 6699ea9cc..94a952a36 100644 --- a/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr +++ b/crates/test-ui/ui/extern_methods_not_allowed_mutable.stderr @@ -45,5 +45,5 @@ error[E0277]: the trait bound `&mut MyObject: MessageReceiver` is not satisfied NonNull = note: `MessageReceiver` is implemented for `&MyObject`, but not for `&mut MyObject` = note: required for `&mut MyObject` to implement `MsgSend` - = note: required for `RetainSemantics<5>` to implement `MsgSendRetained<&mut MyObject, Option>>` + = note: required for `RetainSemantics<6>` to implement `MsgSendRetained<&mut MyObject, Option>>` = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `extern_methods` (in Nightly builds, run with -Z macro-backtrace for more info) 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 6cb8a9571..dc102caed 100644 --- a/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr +++ b/crates/test-ui/ui/msg_send_not_allowed_mutable.stderr @@ -34,5 +34,5 @@ error[E0277]: the trait bound `&mut NSObject: MessageReceiver` is not satisfied NonNull = note: `MessageReceiver` is implemented for `&NSObject`, but not for `&mut NSObject` = note: required for `&mut NSObject` to implement `MsgSend` - = note: required for `RetainSemantics<5>` to implement `MsgSendRetained<&mut NSObject, Option>>` + = note: required for `RetainSemantics<6>` to implement `MsgSendRetained<&mut NSObject, Option>>` = note: this error originates in the macro `$crate::__msg_send_id_helper` which comes from the expansion of the macro `msg_send_id` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/generated b/generated index ad1b23246..431aba632 160000 --- a/generated +++ b/generated @@ -1 +1 @@ -Subproject commit ad1b232464c199b05f82ae80c25b0ac13e2c0f93 +Subproject commit 431aba6324dd1526596e63ae817bf381a9fb826c