Skip to content

Commit

Permalink
style: Remove HasFFI as well
Browse files Browse the repository at this point in the history
After the previous patches we only have one trait which we should also
tweak / rework, so let's put it all on that single trait.

Differential Revision: https://phabricator.services.mozilla.com/D177515
  • Loading branch information
emilio authored and Loirooriol committed Nov 17, 2023
1 parent 7a304df commit 4bebc4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
5 changes: 2 additions & 3 deletions components/style/gecko/arc_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::gecko_bindings::structs::{
RawServoMozDocumentRule, RawServoNamespaceRule, RawServoPageRule, RawServoStyleRule,
RawServoStyleSheetContents, RawServoSupportsRule, ServoCssRules,
};
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasFFI, Strong};
use crate::gecko_bindings::sugar::ownership::{HasArcFFI, Strong};
use crate::media_queries::MediaList;
use crate::properties::animated_properties::AnimationValue;
use crate::properties::{ComputedValues, PropertyDeclarationBlock};
Expand All @@ -33,10 +33,9 @@ use std::{mem, ptr};

macro_rules! impl_arc_ffi {
($servo_type:ty => $gecko_type:ty[$addref:ident, $release:ident]) => {
unsafe impl HasFFI for $servo_type {
unsafe impl HasArcFFI for $servo_type {
type FFIType = $gecko_type;
}
unsafe impl HasArcFFI for $servo_type {}

#[no_mangle]
pub unsafe extern "C" fn $addref(obj: &$gecko_type) {
Expand Down
32 changes: 11 additions & 21 deletions components/style/gecko_bindings/sugar/ownership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,18 @@ use std::mem::{forget, transmute};
use std::ops::{Deref, DerefMut};
use std::ptr;

/// Indicates that a given Servo type has a corresponding Gecko FFI type.
pub unsafe trait HasFFI: Sized + 'static {
/// The corresponding Gecko type that this rust type represents.
///
/// See the examples in `components/style/gecko/conversions.rs`.
type FFIType: Sized;
}

/// Helper trait for conversions between FFI Strong/Borrowed types and Arcs
///
/// Should be implemented by types which are passed over FFI as Arcs via Strong
/// and Borrowed.
///
/// In this case, the FFIType is the rough equivalent of ArcInner<Self>.
pub unsafe trait HasArcFFI: HasFFI {
pub unsafe trait HasArcFFI: Sized + 'static {
/// The corresponding Gecko type that this rust type represents.
///
/// See the examples in `components/style/gecko/conversions.rs`.
type FFIType: Sized;

// these methods can't be on Borrowed because it leads to an unspecified
// impl parameter
/// Artificially increments the refcount of a (possibly null) borrowed Arc
Expand Down Expand Up @@ -163,26 +160,21 @@ impl<GeckoType> Strong<GeckoType> {

/// A few helpers implemented on top of Arc<ServoType> to make it more
/// comfortable to use and write safe code with.
pub unsafe trait FFIArcHelpers {
/// The Rust FFI type that we're implementing methods for.
type Inner: HasArcFFI;

pub unsafe trait FFIArcHelpers<T: HasArcFFI> {
/// Converts an Arc into a strong FFI reference.
///
/// Arc<ServoType> -> Strong<GeckoType>
fn into_strong(self) -> Strong<<Self::Inner as HasFFI>::FFIType>;
fn into_strong(self) -> Strong<T::FFIType>;

/// Produces a borrowed FFI reference by borrowing an Arc.
///
/// &Arc<ServoType> -> &GeckoType
///
/// Then the `arc_as_borrowed` method can go away.
fn as_borrowed(&self) -> &<Self::Inner as HasFFI>::FFIType;
fn as_borrowed(&self) -> &T::FFIType;
}

unsafe impl<T: HasArcFFI> FFIArcHelpers for RawOffsetArc<T> {
type Inner = T;

unsafe impl<T: HasArcFFI> FFIArcHelpers<T> for RawOffsetArc<T> {
#[inline]
fn into_strong(self) -> Strong<T::FFIType> {
unsafe { transmute(self) }
Expand All @@ -194,9 +186,7 @@ unsafe impl<T: HasArcFFI> FFIArcHelpers for RawOffsetArc<T> {
}
}

unsafe impl<T: HasArcFFI> FFIArcHelpers for Arc<T> {
type Inner = T;

unsafe impl<T: HasArcFFI> FFIArcHelpers<T> for Arc<T> {
#[inline]
fn into_strong(self) -> Strong<T::FFIType> {
Arc::into_raw_offset(self).into_strong()
Expand Down

0 comments on commit 4bebc4b

Please sign in to comment.