Skip to content

Commit

Permalink
Revert changes to servo_arc, style_derive, and style_traits
Browse files Browse the repository at this point in the history
This reverts the Rust edition updates to these three traits as well as
incorporates https://phabricator.services.mozilla.com/D117887. The
purpose of this change is to reduce the diff with upstream stylo.

Finally, formatting is disabled for these crates as well.
  • Loading branch information
mrobinson committed Feb 20, 2024
1 parent 2fa7691 commit d0c16cc
Show file tree
Hide file tree
Showing 22 changed files with 84 additions and 105 deletions.
1 change: 0 additions & 1 deletion components/servo_arc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ authors = ["The Servo Project Developers"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/servo/servo"
description = "A fork of std::sync::Arc with some extra functionality and without weak references"
edition = "2018"

[lib]
name = "servo_arc"
Expand Down
39 changes: 18 additions & 21 deletions components/servo_arc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,30 @@
// duplicate those here.
#![allow(missing_docs)]

#[cfg(feature = "servo")]
extern crate serde;
extern crate stable_deref_trait;

#[cfg(feature = "servo")]
use serde::{Deserialize, Serialize};
use stable_deref_trait::{CloneStableDeref, StableDeref};
use std::alloc::{self, Layout};
use std::borrow;
use std::cmp::Ordering;
use std::convert::From;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::iter::{ExactSizeIterator, Iterator};
use std::marker::PhantomData;
use std::mem::{self, align_of, size_of};
use std::ops::{Deref, DerefMut};
use std::os::raw::c_void;
use std::process;
use std::ptr;
use std::slice;
use std::sync::atomic;
use std::sync::atomic::Ordering::{Acquire, Relaxed, Release};
use std::{borrow, fmt, isize, process, ptr, slice, usize};

use nodrop::NoDrop;
#[cfg(feature = "servo")]
use serde::{Deserialize, Serialize};
use stable_deref_trait::{CloneStableDeref, StableDeref};
use std::{isize, usize};

/// A soft limit on the amount of references that may be made to an `Arc`.
///
Expand Down Expand Up @@ -811,6 +818,7 @@ impl<H, T> Arc<HeaderSlice<H, [T]>> {

/// Creates an Arc for a HeaderSlice using the given header struct and
/// iterator to generate the slice. The resulting Arc will be fat.
#[inline]
pub fn from_header_and_iter<I>(header: H, items: I) -> Self
where
I: Iterator<Item = T> + ExactSizeIterator,
Expand Down Expand Up @@ -904,7 +912,7 @@ impl<H, T> ThinArc<H, T> {
{
// Synthesize transient Arc, which never touches the refcount of the ArcInner.
let transient = unsafe {
NoDrop::new(Arc {
mem::ManuallyDrop::new(Arc {
p: ptr::NonNull::new_unchecked(thin_to_thick(self.ptr.as_ptr())),
phantom: PhantomData,
})
Expand All @@ -913,11 +921,6 @@ impl<H, T> ThinArc<H, T> {
// Expose the transient Arc to the callback, which may clone it if it wants.
let result = f(&transient);

// Forget the transient Arc to leave the refcount untouched.
// XXXManishearth this can be removed when unions stabilize,
// since then NoDrop becomes zero overhead
mem::forget(transient);

// Forward the result.
result
}
Expand Down Expand Up @@ -1129,7 +1132,7 @@ impl<'a, T> ArcBorrow<'a, T> {
/// Compare two `ArcBorrow`s via pointer equality. Will only return
/// true if they come from the same allocation
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
std::ptr::eq(this.0, other.0)
this.0 as *const T == other.0 as *const T
}

/// Temporarily converts |self| into a bonafide Arc and exposes it to the
Expand All @@ -1141,16 +1144,11 @@ impl<'a, T> ArcBorrow<'a, T> {
T: 'static,
{
// Synthesize transient Arc, which never touches the refcount.
let transient = unsafe { NoDrop::new(Arc::from_raw(self.0)) };
let transient = unsafe { mem::ManuallyDrop::new(Arc::from_raw(self.0)) };

// Expose the transient Arc to the callback, which may clone it if it wants.
let result = f(&transient);

// Forget the transient Arc to leave the refcount untouched.
// XXXManishearth this can be removed when unions stabilize,
// since then NoDrop becomes zero overhead
mem::forget(transient);

// Forward the result.
result
}
Expand Down Expand Up @@ -1309,13 +1307,12 @@ impl<A: fmt::Debug, B: fmt::Debug> fmt::Debug for ArcUnion<A, B> {

#[cfg(test)]
mod tests {
use super::{Arc, HeaderWithLength, ThinArc};
use std::clone::Clone;
use std::ops::Drop;
use std::sync::atomic;
use std::sync::atomic::Ordering::{Acquire, SeqCst};

use super::{Arc, HeaderWithLength, ThinArc};

#[derive(PartialEq)]
struct Canary(*mut atomic::AtomicUsize);

Expand Down
1 change: 0 additions & 1 deletion components/style_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name = "style_derive"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
edition = "2018"
publish = false

[lib]
Expand Down
6 changes: 1 addition & 5 deletions components/style_derive/animate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use darling::util::PathList;
use darling::FromDeriveInput;
use darling::FromField;
use darling::FromVariant;
use derive_common::cg;
use proc_macro2::TokenStream;
use quote::quote;
use quote::TokenStreamExt;
use syn::{parse_quote, DeriveInput, WhereClause};
use syn::{DeriveInput, WhereClause};
use synstructure::{Structure, VariantInfo};

pub fn derive(mut input: DeriveInput) -> TokenStream {
Expand Down
4 changes: 1 addition & 3 deletions components/style_derive/compute_squared_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::animate::{AnimationFieldAttrs, AnimationInputAttrs, AnimationVariantAttrs};
use darling::FromField;
use derive_common::cg;
use proc_macro2::TokenStream;
use quote::quote;
use quote::TokenStreamExt;
use syn::{parse_quote, DeriveInput, WhereClause};
use syn::{DeriveInput, WhereClause};
use synstructure;

pub fn derive(mut input: DeriveInput) -> TokenStream {
Expand Down
11 changes: 11 additions & 0 deletions components/style_derive/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

#![recursion_limit = "128"]

#[macro_use]
extern crate darling;
extern crate derive_common;
extern crate proc_macro;
extern crate proc_macro2;
#[macro_use]
extern crate quote;
#[macro_use]
extern crate syn;
extern crate synstructure;

use proc_macro::TokenStream;

mod animate;
Expand Down
7 changes: 2 additions & 5 deletions components/style_derive/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::to_css::{CssBitflagAttrs, CssVariantAttrs};
use darling::FromField;
use darling::FromVariant;
use derive_common::cg;
use proc_macro2::{Span, TokenStream};
use quote::{quote, TokenStreamExt};
use syn::parse_quote;
use quote::TokenStreamExt;
use syn::{self, DeriveInput, Ident, Path};
use synstructure::{Structure, VariantInfo};

Expand Down Expand Up @@ -132,7 +129,7 @@ fn parse_non_keyword_variant(
}
} else {
quote! {
if let Ok(v) = input.r#try(|i| <#ty as crate::parser::Parse>::parse(context, i)) {
if let Ok(v) = input.try(|i| <#ty as crate::parser::Parse>::parse(context, i)) {
return Ok(#name::#variant_name(v));
}
}
Expand Down
6 changes: 1 addition & 5 deletions components/style_derive/specified_value_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

use crate::parse::ParseVariantAttrs;
use crate::to_css::{CssFieldAttrs, CssInputAttrs, CssVariantAttrs};
use darling::FromDeriveInput;
use darling::FromField;
use darling::FromVariant;
use derive_common::cg;
use proc_macro2::TokenStream;
use quote::quote;
use quote::TokenStreamExt;
use syn::{parse_quote, Data, DeriveInput, Fields, Ident, Type};
use syn::{Data, DeriveInput, Fields, Ident, Type};

pub fn derive(mut input: DeriveInput) -> TokenStream {
let css_attrs = cg::parse_input_attrs::<CssInputAttrs>(&input);
Expand Down
5 changes: 2 additions & 3 deletions components/style_derive/to_animated_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::to_computed_value;
use proc_macro2::TokenStream;
use quote::quote;
use syn::{parse_quote, DeriveInput};
use syn::DeriveInput;
use synstructure::BindStyle;
use to_computed_value;

pub fn derive(input: DeriveInput) -> TokenStream {
let trait_impl = |from_body, to_body| {
Expand Down
3 changes: 1 addition & 2 deletions components/style_derive/to_animated_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
use crate::animate::{AnimationFieldAttrs, AnimationInputAttrs, AnimationVariantAttrs};
use derive_common::cg;
use proc_macro2::TokenStream;
use quote::quote;
use quote::TokenStreamExt;
use syn::{self, parse_quote};
use syn;
use synstructure;

pub fn derive(mut input: syn::DeriveInput) -> TokenStream {
Expand Down
3 changes: 0 additions & 3 deletions components/style_derive/to_computed_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use darling::FromField;
use derive_common::cg;
use proc_macro2::TokenStream;
use quote::quote;
use syn::parse_quote;
use syn::{DeriveInput, Ident, Path};
use synstructure::{BindStyle, BindingInfo};

Expand Down
8 changes: 1 addition & 7 deletions components/style_derive/to_css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use darling::util::Override;
use darling::FromDeriveInput;
use darling::FromField;
use darling::FromMeta;
use darling::FromVariant;
use derive_common::cg;
use proc_macro2::{Span, TokenStream};
use quote::quote;
use quote::{ToTokens, TokenStreamExt};
use syn::parse_quote;
use syn::{self, Data, Ident, Path, WhereClause};
use synstructure::{BindingInfo, Structure, VariantInfo};

Expand Down Expand Up @@ -209,7 +203,7 @@ fn derive_variant_fields_expr(
let mut iter = bindings
.iter()
.filter_map(|binding| {
let attrs = cg::parse_field_attrs::<CssFieldAttrs>(binding.ast());
let attrs = cg::parse_field_attrs::<CssFieldAttrs>(&binding.ast());
if attrs.skip {
return None;
}
Expand Down
6 changes: 2 additions & 4 deletions components/style_derive/to_resolved_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::to_computed_value;
use darling::FromField;
use derive_common::cg;
use proc_macro2::TokenStream;
use quote::quote;
use syn::{parse_quote, DeriveInput};
use syn::DeriveInput;
use synstructure::BindStyle;
use to_computed_value;

pub fn derive(input: DeriveInput) -> TokenStream {
let trait_impl = |from_body, to_body| {
Expand Down
3 changes: 1 addition & 2 deletions components/style_traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name = "style_traits"
version = "0.0.1"
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
edition = "2018"
publish = false

[lib]
Expand All @@ -22,7 +21,7 @@ euclid = "0.22"
lazy_static = "1"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = "0.1"
selectors = { path = "../selectors", features = ["shmem"] }
selectors = { path = "../selectors" }
serde = "1.0"
servo_arc = { path = "../servo_arc" }
servo_atoms = { path = "../atoms", optional = true }
Expand Down
8 changes: 3 additions & 5 deletions components/style_traits/arc_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

//! A thin atomically-reference-counted slice.

use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
use servo_arc::ThinArc;
use std::ops::Deref;
use std::ptr::NonNull;
use std::{iter, mem};

use lazy_static::lazy_static;
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps, MallocUnconditionalSizeOf};
use serde::de::{Deserialize, Deserializer};
use serde::ser::{Serialize, Serializer};
use servo_arc::ThinArc;
use to_shmem_derive::ToShmem;

/// A canary that we stash in ArcSlices.
///
Expand Down
3 changes: 0 additions & 3 deletions components/style_traits/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

//! Types used to access the DOM from style calculation.

use bitflags::bitflags;
use malloc_size_of::malloc_size_of_is_0;
use malloc_size_of_derive::MallocSizeOf;
use serde::{Deserialize, Serialize};

/// An opaque handle to a node, which, unlike UnsafeNode, cannot be transformed
/// back into a non-opaque representation. The only safe operation that can be
Expand Down

0 comments on commit d0c16cc

Please sign in to comment.