Skip to content

Commit

Permalink
Rename internal RetainSemantics to MethodFamily
Browse files Browse the repository at this point in the history
This more precisely captures what it actually is, and allows us to use
the name RetainSemantics for something that _implements_ the semantics.
  • Loading branch information
madsmtm committed Jan 19, 2025
1 parent 6866a37 commit 67e6f41
Show file tree
Hide file tree
Showing 32 changed files with 139 additions and 139 deletions.
2 changes: 1 addition & 1 deletion crates/header-translator/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ impl fmt::Display for Method {
MemoryManagement::Normal => None,
};
if let Some(id_mm_name) = id_mm_name {
write!(f, " #[method_id(@__retain_semantics {id_mm_name} ")?;
write!(f, " #[method_id(@__method_family {id_mm_name} ")?;
} else {
write!(f, " #[method(")?;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/src/__macro_helpers/define_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ unsafe impl Encode for RetainedReturnValue {
// can't actually modify the `self` argument (e.g. `let self = foo(self)` is
// not allowed).
//
// See `MsgSendRetained` and `RetainSemantics` for details on the retain semantics
// we're following here.
// See `MsgSendRetained` and `MethodFamily` for details on the retain
// semantics we're following here.
pub trait MessageReceiveRetained<Receiver, Ret> {
fn into_return(obj: Ret) -> RetainedReturnValue;
}
Expand Down
20 changes: 10 additions & 10 deletions crates/objc2/src/__macro_helpers/method_family.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Helper for specifying the retain semantics for a given selector family.
/// Helper for specifying the method family for a given selector.
///
/// Note that we can't actually check if a method is in a method family; only
/// whether the _selector_ is in a _selector_ family.
Expand All @@ -17,18 +17,18 @@
/// which means it can't be a class method!
///
/// <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#retainable-object-pointers-as-operands-and-arguments>
// TODO: Use an enum instead of u8 here when stable
// TODO: Use an enum instead of u8 here when possible in `const`.
#[derive(Debug)]
pub struct RetainSemantics<const INNER: u8> {}
pub struct MethodFamily<const INNER: u8> {}

pub type New = RetainSemantics<1>;
pub type Alloc = RetainSemantics<2>;
pub type Init = RetainSemantics<3>;
pub type Copy = RetainSemantics<4>;
pub type MutableCopy = RetainSemantics<5>;
pub type Other = RetainSemantics<6>;
pub type New = MethodFamily<1>;
pub type Alloc = MethodFamily<2>;
pub type Init = MethodFamily<3>;
pub type Copy = MethodFamily<4>;
pub type MutableCopy = MethodFamily<5>;
pub type Other = MethodFamily<6>;

pub const fn retain_semantics(selector: &str) -> u8 {
pub const fn method_family(selector: &str) -> u8 {
let selector = selector.as_bytes();
match (
in_selector_family(selector, b"new"),
Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/__macro_helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub use self::define_class::{
pub use self::defined_ivars::DefinedIvarsHelper;
pub use self::image_info::ImageInfo;
pub use self::method_family::{
retain_semantics, Alloc, Copy, Init, MutableCopy, New, Other, RetainSemantics,
method_family, Alloc, Copy, Init, MethodFamily, MutableCopy, New, Other,
};
pub use self::module_info::ModuleInfo;
pub use self::msg_send::MsgSend;
Expand Down
40 changes: 20 additions & 20 deletions crates/objc2/src/macros/__attribute_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ macro_rules! __extract_and_apply_cfg_attributes {
/// 1. The `method` or `method_id` attribute.
/// (#[$method_or_method_id:ident($($sel:tt)*)])
///
/// 2. The retain semantics, if any was present in the selector for
/// 2. The method family, if any was present in the selector for
/// `#[method_id(...)]`.
///
/// One of `New`, `Alloc`, `Init`, `Copy`, `MutableCopy` and `Other`.
/// ($($retain_semantics:ident)?)
/// ($($method_family:ident)?)
///
/// 3. The `optional` attribute, if any.
/// ($(#[optional])?)
Expand All @@ -89,7 +89,7 @@ macro_rules! __extract_custom_attributes {
($($m)*)
// No already parsed attributes
() // method/method_id
() // retain semantics
() // method family
() // optional
() // checked

Expand All @@ -108,7 +108,7 @@ macro_rules! __extract_custom_attributes_inner {
()
// And we found no `method` or `method_id` attributes
()
($($retain_semantics:tt)*)
($($method_family:tt)*)
($($m_optional:tt)*)
($($m_checked:tt)*)

Expand All @@ -124,7 +124,7 @@ macro_rules! __extract_custom_attributes_inner {
()
// And we found a `method` or `method_id` attribute
($($m_method:tt)*)
($($retain_semantics:tt)*)
($($method_family:tt)*)
($($m_optional:tt)*)
($($m_checked:tt)*)

Expand All @@ -136,7 +136,7 @@ macro_rules! __extract_custom_attributes_inner {
$($macro_args)*
// Append attributes to the end of the macro arguments
($($m_method)*)
($($retain_semantics)*)
($($method_family)*)
($($m_optional)*)
($($m_checked)*)
}
Expand All @@ -150,7 +150,7 @@ macro_rules! __extract_custom_attributes_inner {
)
// If no existing `method` nor `method_id` attributes exist
()
($($retain_semantics:tt)*)
($($method_family:tt)*)
($($m_optional:tt)*)
($($m_checked:tt)*)

Expand All @@ -161,7 +161,7 @@ macro_rules! __extract_custom_attributes_inner {
($($rest)*)
// Add method attribute
(#[method($($sel)*)])
($($retain_semantics)*)
($($method_family)*)
($($m_optional)*)
($($m_checked)*)

Expand All @@ -176,7 +176,7 @@ macro_rules! __extract_custom_attributes_inner {
$($rest:tt)*
)
($($m_method:tt)*)
($($retain_semantics:tt)*)
($($method_family:tt)*)
($($m_optional:tt)*)
($($m_checked:tt)*)

Expand All @@ -186,10 +186,10 @@ macro_rules! __extract_custom_attributes_inner {
$crate::__macro_helpers::compile_error!("cannot specify the `method`/`method_id` attribute twice");
};

// `method_id` attribute with retain semantics
// `method_id` attribute with method family
{
(
#[method_id(@__retain_semantics $retain_semantics:ident $($sel:tt)*)]
#[method_id(@__method_family $method_family:ident $($sel:tt)*)]
$($rest:tt)*
)
// If no existing `method` nor `method_id` attributes exist
Expand All @@ -205,7 +205,7 @@ macro_rules! __extract_custom_attributes_inner {
($($rest)*)
// Add method_id attribute
(#[method_id($($sel)*)])
($retain_semantics)
($method_family)
($($m_optional)*)
($($m_checked)*)

Expand All @@ -221,7 +221,7 @@ macro_rules! __extract_custom_attributes_inner {
)
// If no existing `method` nor `method_id` attributes exist
()
($($retain_semantics:tt)*)
($($method_family:tt)*)
($($m_optional:tt)*)
($($m_checked:tt)*)

Expand All @@ -232,7 +232,7 @@ macro_rules! __extract_custom_attributes_inner {
($($rest)*)
// Add method_id attribute
(#[method_id($($sel)*)])
($($retain_semantics)*)
($($method_family)*)
($($m_optional)*)
($($m_checked)*)

Expand All @@ -247,7 +247,7 @@ macro_rules! __extract_custom_attributes_inner {
$($rest:tt)*
)
($($m_method:tt)*)
($($retain_semantics:tt)*)
($($method_family:tt)*)
($($m_optional:tt)*)
($($m_checked:tt)*)

Expand All @@ -264,7 +264,7 @@ macro_rules! __extract_custom_attributes_inner {
$($rest:tt)*
)
($($m_method:tt)*)
($($retain_semantics:tt)*)
($($method_family:tt)*)
// If no existing `optional` attributes exist
()
($($m_checked:tt)*)
Expand All @@ -275,7 +275,7 @@ macro_rules! __extract_custom_attributes_inner {
$crate::__extract_custom_attributes_inner! {
($($rest)*)
($($m_method)*)
($($retain_semantics)*)
($($method_family)*)
// Add optional attribute
(#[optional])
($($m_checked)*)
Expand All @@ -291,7 +291,7 @@ macro_rules! __extract_custom_attributes_inner {
$($rest:tt)*
)
($($m_method:tt)*)
($($retain_semantics:tt)*)
($($method_family:tt)*)
($($m_optional:tt)*)
($($m_checked:tt)*)

Expand All @@ -308,7 +308,7 @@ macro_rules! __extract_custom_attributes_inner {
$($rest:tt)*
)
($($m_method:tt)*)
($($retain_semantics:tt)*)
($($method_family:tt)*)
($($m_optional:tt)*)
($($m_checked:tt)*)

Expand All @@ -318,7 +318,7 @@ macro_rules! __extract_custom_attributes_inner {
$crate::__extract_custom_attributes_inner! {
($($rest)*)
($($m_method)*)
($($retain_semantics)*)
($($method_family)*)
($($m_optional)*)
(
$($m_checked)*
Expand Down
28 changes: 14 additions & 14 deletions crates/objc2/src/macros/__method_msg_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ macro_rules! __method_msg_send_id {

()
()
($($retain_semantics:ident)?)
($($method_family:ident)?)
) => {
$crate::__msg_send_id_helper! {
($receiver)
($($retain_semantics)?)
($($method_family)?)
(MsgSendRetained)
(send_message_retained)
($sel)
Expand All @@ -186,7 +186,7 @@ macro_rules! __method_msg_send_id {

($($sel_parsed:tt)*)
($($arg_parsed:tt)*)
($($retain_semantics:ident)?)
($($method_family:ident)?)
) => ({
let _ = $arg;
$crate::__method_msg_send_id! {
Expand All @@ -196,7 +196,7 @@ macro_rules! __method_msg_send_id {

($($sel_parsed)*)
($($arg_parsed)*)
($($retain_semantics)?)
($($method_family)?)
}
});

Expand All @@ -208,7 +208,7 @@ macro_rules! __method_msg_send_id {

($($sel_parsed:tt)*)
($($arg_parsed:tt)*)
($($retain_semantics:ident)?)
($($method_family:ident)?)
) => {
$crate::__method_msg_send_id! {
($receiver)
Expand All @@ -217,7 +217,7 @@ macro_rules! __method_msg_send_id {

($($sel_parsed)* $($sel)? :)
($($arg_parsed)* $arg,)
($($retain_semantics)?)
($($method_family)?)
}
};
// Handle path separator token
Expand All @@ -228,7 +228,7 @@ macro_rules! __method_msg_send_id {

($($sel_parsed:tt)*)
($($arg_parsed:tt)*)
($($retain_semantics:ident)?)
($($method_family:ident)?)
) => {
$crate::__method_msg_send_id! {
($receiver)
Expand All @@ -237,7 +237,7 @@ macro_rules! __method_msg_send_id {

($($sel_parsed)* $($sel)? : :)
($($arg_parsed)* $arg1, $arg2,)
($($retain_semantics)?)
($($method_family)?)
}
};

Expand All @@ -251,11 +251,11 @@ macro_rules! __method_msg_send_id {
// a selector, and haven't just gotten an empty `#[method()]`.
($($sel_parsed:tt)+)
($($arg_parsed:tt)*)
($($retain_semantics:ident)?)
($($method_family:ident)?)
) => {
$crate::__msg_send_id_helper! {
($receiver)
($($retain_semantics)?)
($($method_family)?)
(MsgSendRetained)
(send_message_retained)
($($sel_parsed)*)
Expand All @@ -272,11 +272,11 @@ macro_rules! __method_msg_send_id {

($($sel_parsed:tt)*)
($($arg_parsed:tt)*)
($($retain_semantics:ident)?)
($($method_family:ident)?)
) => {
$crate::__msg_send_id_helper! {
($receiver)
($($retain_semantics)?)
($($method_family)?)
(MsgSendRetained)
// Use error method
(send_message_retained_error)
Expand All @@ -293,7 +293,7 @@ macro_rules! __method_msg_send_id {

($($sel_parsed:tt)*)
($($arg_parsed:tt)*)
($($retain_semantics:ident)?)
($($method_family:ident)?)
) => ({
$crate::__macro_helpers::compile_error!(
"variadic methods are not yet supported"
Expand All @@ -308,7 +308,7 @@ macro_rules! __method_msg_send_id {

($($sel_parsed:tt)*)
($($arg_parsed:tt)*)
($($retain_semantics:ident)?)
($($method_family:ident)?)
) => ({
$crate::__macro_helpers::compile_error!(
"number of arguments in function and selector did not match"
Expand Down
Loading

0 comments on commit 67e6f41

Please sign in to comment.