@@ -139,13 +139,26 @@ macro_rules! __class_inner {
139139/// - runtime, causing UB (unlikely)
140140///
141141/// The `"unstable-static-sel-inlined"` feature is the even more extreme
142- /// version - it yields the best performance and is closest to real
142+ /// version - it yield better performance and is closer to real
143143/// Objective-C code, but probably won't work unless your code and its
144144/// inlining is written in a very certain way.
145145///
146146/// Enabling LTO greatly increases the chance that these features work.
147147///
148+ /// On Apple/Darwin targets, these limitations can be overcome with the
149+ /// `"unstable-darwin-objc"` feature which uses the nightly-only `darwin_objc`
150+ /// language feature. This experimental language feature implements the
151+ /// Objective-C static selector ABI directly in the Rust compiler and should
152+ /// work in more if not all cases. Using `"unstable-darwin-objc"` requires
153+ /// `darwin_objc` to be enabled in every crate that uses this macro, which can
154+ /// be achieved in `objc2` crates by enabling their own
155+ /// `"unstable-darwin-objc"` features and in your own crates by adding
156+ /// `#![feature(darwin_objc)]`.
157+ ///
158+ /// See [rust-lang/rust#145496] for the tracking issue for the feature.
159+ ///
148160/// [rust-lang/rust#53929]: https://github.com/rust-lang/rust/issues/53929
161+ /// [rust-lang/rust#145496]: https://github.com/rust-lang/rust/issues/145496
149162///
150163///
151164/// # Examples
@@ -267,9 +280,9 @@ macro_rules! __sel_helper {
267280 // Base-case
268281 {
269282 ( $( $parsed_sel: tt) * )
270- } => ( {
283+ } => {
271284 $crate:: __sel_data!( $( $parsed_sel) * )
272- } ) ;
285+ } ;
273286 // Single identifier
274287 {
275288 ( )
@@ -309,7 +322,6 @@ macro_rules! __sel_data {
309322 $crate:: __macro_helpers:: concat!(
310323 $crate:: __macro_helpers:: stringify!( $first) ,
311324 $( ':' , $( $( $crate:: __macro_helpers:: stringify!( $rest) , ) ? ':' , ) * ) ?
312- '\0' ,
313325 )
314326 } ;
315327}
@@ -323,7 +335,7 @@ macro_rules! __sel_inner {
323335 $crate:: __macro_helpers:: CachedSel :: new( ) ;
324336 #[ allow( unused_unsafe) ]
325337 unsafe {
326- CACHED_SEL . get( $data)
338+ CACHED_SEL . get( $crate :: __macro_helpers :: concat! ( $ data, '\0' ) )
327339 }
328340 } } ;
329341}
@@ -405,7 +417,7 @@ macro_rules! __statics_sel {
405417 ( $data: expr)
406418 ( $hash: expr)
407419 } => {
408- const X : & [ $crate:: __macro_helpers:: u8 ] = $data. as_bytes( ) ;
420+ const X : & [ $crate:: __macro_helpers:: u8 ] = $crate :: __macro_helpers :: concat! ( $ data, '\0' ) . as_bytes( ) ;
409421
410422 /// Clang marks this with LLVM's `unnamed_addr`.
411423 /// See rust-lang/rust#18297
@@ -559,11 +571,26 @@ macro_rules! __statics_class {
559571 }
560572}
561573
574+ #[ doc( hidden) ]
575+ #[ macro_export]
576+ #[ cfg( all( feature = "unstable-static-sel" , feature = "unstable-darwin-objc" ) ) ]
577+ macro_rules! __sel_inner {
578+ ( $data: expr, $_hash: expr) => { {
579+ let ptr = $crate:: __macro_helpers:: core_darwin_objc:: selector!( $data) ;
580+ let ptr = ptr. cast_const( ) . cast:: <$crate:: __macro_helpers:: u8 >( ) ;
581+ #[ allow( unused_unsafe) ]
582+ unsafe {
583+ $crate:: runtime:: Sel :: __internal_from_ptr( ptr)
584+ }
585+ } } ;
586+ }
587+
562588#[ doc( hidden) ]
563589#[ macro_export]
564590#[ cfg( all(
565591 feature = "unstable-static-sel" ,
566- not( feature = "unstable-static-sel-inlined" )
592+ not( feature = "unstable-darwin-objc" ) ,
593+ not( feature = "unstable-static-sel-inlined" ) ,
567594) ) ]
568595macro_rules! __sel_inner {
569596 ( $data: expr, $hash: expr) => { {
@@ -595,7 +622,11 @@ macro_rules! __sel_inner {
595622
596623#[ doc( hidden) ]
597624#[ macro_export]
598- #[ cfg( feature = "unstable-static-sel-inlined" ) ]
625+ #[ cfg( all(
626+ feature = "unstable-static-sel" ,
627+ not( feature = "unstable-darwin-objc" ) ,
628+ feature = "unstable-static-sel-inlined" ,
629+ ) ) ]
599630macro_rules! __sel_inner {
600631 ( $data: expr, $hash: expr) => { {
601632 $crate:: __statics_sel! {
@@ -615,6 +646,24 @@ macro_rules! __sel_inner {
615646#[ macro_export]
616647#[ cfg( all(
617648 feature = "unstable-static-class" ,
649+ feature = "unstable-darwin-objc" ,
650+ not( feature = "gnustep-1-7" ) ,
651+ ) ) ]
652+ macro_rules! __class_inner {
653+ ( $name: expr, $_hash: expr) => { {
654+ let ptr = $crate:: __macro_helpers:: core_darwin_objc:: class!( $name) ;
655+ let ptr = ptr. cast_const( ) . cast:: <$crate:: runtime:: AnyClass >( ) ;
656+ #[ allow( unused_unsafe) ]
657+ let r: & ' static $crate:: runtime:: AnyClass = unsafe { & * ptr } ;
658+ r
659+ } } ;
660+ }
661+
662+ #[ doc( hidden) ]
663+ #[ macro_export]
664+ #[ cfg( all(
665+ feature = "unstable-static-class" ,
666+ not( feature = "unstable-darwin-objc" ) ,
618667 not( feature = "gnustep-1-7" ) ,
619668 not( feature = "unstable-static-class-inlined" )
620669) ) ]
@@ -639,6 +688,7 @@ macro_rules! __class_inner {
639688#[ macro_export]
640689#[ cfg( all(
641690 feature = "unstable-static-class" ,
691+ not( feature = "unstable-darwin-objc" ) ,
642692 not( feature = "gnustep-1-7" ) ,
643693 feature = "unstable-static-class-inlined"
644694) ) ]
0 commit comments