@@ -2,9 +2,8 @@ use core::mem;
2
2
3
3
use crate :: __macro_helpers:: IdReturnValue ;
4
4
use crate :: encode:: { EncodeArgument , EncodeArguments , EncodeReturn , RefEncode } ;
5
- use crate :: mutability:: IsAllowedMutable ;
6
5
use crate :: rc:: Allocated ;
7
- use crate :: runtime:: { AnyClass , Imp , Sel } ;
6
+ use crate :: runtime:: { Imp , MessageReceiver , Sel } ;
8
7
use crate :: Message ;
9
8
10
9
mod private {
@@ -19,7 +18,7 @@ mod private {
19
18
// Note: `Sized` is intentionally added to make the trait not object safe.
20
19
pub trait MethodImplementation : private:: Sealed + Sized {
21
20
/// The callee type of the method.
22
- type Callee : RefEncode + ? Sized ;
21
+ type Callee : ? Sized + RefEncode ;
23
22
/// The return type of the method.
24
23
type Ret : EncodeReturn ;
25
24
/// The argument types of the method.
@@ -29,67 +28,39 @@ pub trait MethodImplementation: private::Sealed + Sized {
29
28
fn __imp ( self ) -> Imp ;
30
29
}
31
30
32
- macro_rules! method_impl_generic {
33
- ( <$ ( $l : lifetime ) , * > T : $t_bound : ident $ ( + $t_bound2 : ident) ? , $r : ident , $f : ty , $( $t: ident) ,* ) => {
34
- impl <$ ( $l , ) * T , $r , $( $t) ,* > private:: Sealed for $f
31
+ macro_rules! method_impl_inner {
32
+ ( $ ( ( $unsafe : ident) ) ? $abi : literal ; $( $t: ident) ,* ) => {
33
+ impl <T , R , $( $t) ,* > private:: Sealed for $( $unsafe ) ? extern $abi fn ( T , Sel $ ( , $t ) * ) -> R
35
34
where
36
- T : ?Sized + $t_bound $ ( + $t_bound2 ) ? ,
37
- $r : EncodeReturn ,
35
+ T : ?Sized + MessageReceiver ,
36
+ R : EncodeReturn ,
38
37
$( $t: EncodeArgument , ) *
39
38
{ }
40
39
41
- impl <$ ( $l , ) * T , $r , $( $t) ,* > MethodImplementation for $f
40
+ impl <T , R , $( $t) ,* > MethodImplementation for $( $unsafe ) ? extern $abi fn ( T , Sel $ ( , $t ) * ) -> R
42
41
where
43
- T : ?Sized + $t_bound $ ( + $t_bound2 ) ? ,
44
- $r : EncodeReturn ,
42
+ T : ?Sized + MessageReceiver ,
43
+ R : EncodeReturn ,
45
44
$( $t: EncodeArgument , ) *
46
45
{
47
- type Callee = T ;
48
- type Ret = $r;
49
- type Args = ( $( $t, ) * ) ;
50
-
51
- fn __imp( self ) -> Imp {
52
- unsafe { mem:: transmute( self ) }
53
- }
54
- }
55
- } ;
56
- }
57
-
58
- macro_rules! method_impl_concrete {
59
- ( <$( $l: lifetime) ,* > $callee: ident, $r: ident, $f: ty, $( $t: ident) ,* ) => {
60
- impl <$( $l, ) * $r, $( $t) ,* > private:: Sealed for $f
61
- where
62
- $r: EncodeReturn ,
63
- $( $t: EncodeArgument , ) *
64
- { }
65
-
66
- impl <$( $l, ) * $r, $( $t) ,* > MethodImplementation for $f
67
- where
68
- $r: EncodeReturn ,
69
- $( $t: EncodeArgument , ) *
70
- {
71
- type Callee = $callee;
72
- type Ret = $r;
46
+ type Callee = T :: __Inner;
47
+ type Ret = R ;
73
48
type Args = ( $( $t, ) * ) ;
74
49
75
50
fn __imp( self ) -> Imp {
51
+ // SAFETY: Transmuting to an `unsafe` function pointer
76
52
unsafe { mem:: transmute( self ) }
77
53
}
78
54
}
79
- } ;
80
- }
81
55
82
- macro_rules! method_impl_allocated {
83
- ( <> Allocated <T >, $f: ty, $( $t: ident) ,* ) => {
84
- #[ doc( hidden) ]
85
- impl <T , $( $t) ,* > private:: Sealed for $f
56
+ impl <T , $( $t) ,* > private:: Sealed for $( $unsafe) ? extern $abi fn ( Allocated <T >, Sel $( , $t) * ) -> IdReturnValue
86
57
where
87
58
T : ?Sized + Message ,
88
59
$( $t: EncodeArgument , ) *
89
60
{ }
90
61
91
62
#[ doc( hidden) ]
92
- impl <T , $( $t) ,* > MethodImplementation for $f
63
+ impl <T , $( $t) ,* > MethodImplementation for $( $unsafe ) ? extern $abi fn ( Allocated < T > , Sel $ ( , $t ) * ) -> IdReturnValue
93
64
where
94
65
T : ?Sized + Message ,
95
66
$( $t: EncodeArgument , ) *
@@ -113,29 +84,14 @@ macro_rules! method_impl_allocated {
113
84
} ;
114
85
}
115
86
116
- macro_rules! method_impl_abi {
117
- ( $abi: literal; $( $t: ident) ,* ) => {
118
- method_impl_generic!( <' a> T : Message , R , extern $abi fn ( & ' a T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
119
- method_impl_generic!( <' a> T : Message + IsAllowedMutable , R , extern $abi fn ( & ' a mut T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
120
- method_impl_generic!( <> T : Message , R , unsafe extern $abi fn ( * const T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
121
- method_impl_generic!( <> T : Message , R , unsafe extern $abi fn ( * mut T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
122
- method_impl_generic!( <' a> T : Message , R , unsafe extern $abi fn ( & ' a T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
123
- method_impl_generic!( <' a> T : Message + IsAllowedMutable , R , unsafe extern $abi fn ( & ' a mut T , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
124
-
125
- method_impl_concrete!( <' a> AnyClass , R , extern $abi fn ( & ' a AnyClass , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
126
- method_impl_concrete!( <> AnyClass , R , unsafe extern $abi fn ( * const AnyClass , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
127
- method_impl_concrete!( <' a> AnyClass , R , unsafe extern $abi fn ( & ' a AnyClass , Sel $( , $t) * ) -> R , $( $t) ,* ) ;
128
-
129
- method_impl_allocated!( <> Allocated <T >, extern $abi fn ( Allocated <T >, Sel $( , $t) * ) -> IdReturnValue , $( $t) ,* ) ;
130
- method_impl_allocated!( <> Allocated <T >, unsafe extern $abi fn ( Allocated <T >, Sel $( , $t) * ) -> IdReturnValue , $( $t) ,* ) ;
131
- } ;
132
- }
133
-
134
87
macro_rules! method_impl {
135
88
( $( $t: ident) ,* ) => {
136
- method_impl_abi!( "C" ; $( $t) ,* ) ;
89
+ method_impl_inner!( ( unsafe ) "C" ; $( $t) ,* ) ;
90
+ method_impl_inner!( "C" ; $( $t) ,* ) ;
91
+ #[ cfg( feature = "unstable-c-unwind" ) ]
92
+ method_impl_inner!( ( unsafe ) "C-unwind" ; $( $t) ,* ) ;
137
93
#[ cfg( feature = "unstable-c-unwind" ) ]
138
- method_impl_abi !( "C-unwind" ; $( $t) ,* ) ;
94
+ method_impl_inner !( "C-unwind" ; $( $t) ,* ) ;
139
95
} ;
140
96
}
141
97
0 commit comments