Skip to content

Commit

Permalink
Remove HasStableHash
Browse files Browse the repository at this point in the history
Follow-up to #626
  • Loading branch information
madsmtm committed Sep 6, 2024
1 parent 79efa93 commit 4a3d690
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
1 change: 1 addition & 0 deletions crates/objc2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* **BREAKING**: Removed the `ffi::SEL` and `ffi::objc_selector` types. Use
`runtime::Sel` instead.
* **BREAKING**: Removed `ffi` exception function pointer aliases.
* **BREAKING**: Removed `mutability::HasStableHash`.

### Fixed
* Remove an incorrect assertion when adding protocols to classes in an unexpected
Expand Down
35 changes: 0 additions & 35 deletions crates/objc2/src/mutability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,40 +525,6 @@ unsafe impl<T: ?Sized + ClassType> IsMainThreadOnly for T where
}
unsafe impl<P: ?Sized + IsMainThreadOnly> IsMainThreadOnly for ProtocolObject<P> {}

/// Marker trait for classes whose `hash` and `isEqual:` methods are stable.
///
/// This is useful for hashing collection types like `NSDictionary` and
/// `NSSet` which require that their keys never change.
///
/// This is implemented for classes whose [`ClassType::Mutability`] is one of:
/// - [`Immutable`].
/// - [`Mutable`].
/// - [`ImmutableWithMutableSubclass`].
/// - [`MutableWithImmutableSuperclass`].
///
/// Since all of these do not use interior mutability, and since the `hash`
/// and `isEqual:` methods are required to not use external sources like
/// thread locals or randomness to determine their result, we can guarantee
/// that the hash is stable for these types.
///
///
/// # Safety
///
/// This is a sealed trait, and should not need to be implemented. Open an
/// issue if you know a use-case where this restrition should be lifted!
//
// TODO: Exclude generic types like `NSArray<NSView>` from this!
pub unsafe trait HasStableHash: private_traits::Sealed {}

trait MutabilityHashIsStable: Mutability {}
impl MutabilityHashIsStable for Immutable {}
impl MutabilityHashIsStable for Mutable {}
impl<MS: ?Sized> MutabilityHashIsStable for ImmutableWithMutableSubclass<MS> {}
impl<IS: ?Sized> MutabilityHashIsStable for MutableWithImmutableSuperclass<IS> {}

unsafe impl<T: ?Sized + ClassType> HasStableHash for T where T::Mutability: MutabilityHashIsStable {}
unsafe impl<P: ?Sized + HasStableHash> HasStableHash for ProtocolObject<P> {}

/// Retrieve the immutable/mutable counterpart class, and fall back to `Self`
/// if not applicable.
///
Expand Down Expand Up @@ -751,7 +717,6 @@ mod tests {
_: &dyn IsAllowedMutable,
_: &dyn IsMutable,
_: &dyn IsMainThreadOnly,
_: &dyn HasStableHash,
_: &dyn CounterpartOrSelf<Immutable = (), Mutable = ()>,
) {
}
Expand Down

0 comments on commit 4a3d690

Please sign in to comment.