diff --git a/components/servo_arc/Cargo.toml b/components/servo_arc/Cargo.toml index 0f50d9cd41f..c975ad55412 100644 --- a/components/servo_arc/Cargo.toml +++ b/components/servo_arc/Cargo.toml @@ -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" diff --git a/components/servo_arc/lib.rs b/components/servo_arc/lib.rs index a201e5f7065..cc71827283a 100644 --- a/components/servo_arc/lib.rs +++ b/components/servo_arc/lib.rs @@ -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`. /// @@ -811,6 +818,7 @@ impl Arc> { /// 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(header: H, items: I) -> Self where I: Iterator + ExactSizeIterator, @@ -904,7 +912,7 @@ impl ThinArc { { // 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, }) @@ -913,11 +921,6 @@ impl ThinArc { // 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 } @@ -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 @@ -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 } @@ -1309,13 +1307,12 @@ impl fmt::Debug for ArcUnion { #[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); diff --git a/components/style_derive/Cargo.toml b/components/style_derive/Cargo.toml index 8456f1c6485..98dc1852e8c 100644 --- a/components/style_derive/Cargo.toml +++ b/components/style_derive/Cargo.toml @@ -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] diff --git a/components/style_derive/animate.rs b/components/style_derive/animate.rs index daa34f56e51..9549100ad08 100644 --- a/components/style_derive/animate.rs +++ b/components/style_derive/animate.rs @@ -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 { diff --git a/components/style_derive/compute_squared_distance.rs b/components/style_derive/compute_squared_distance.rs index 04866b8ac7d..022ab115eea 100644 --- a/components/style_derive/compute_squared_distance.rs +++ b/components/style_derive/compute_squared_distance.rs @@ -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 { diff --git a/components/style_derive/lib.rs b/components/style_derive/lib.rs index a2c39f84308..079db00c5a3 100644 --- a/components/style_derive/lib.rs +++ b/components/style_derive/lib.rs @@ -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; diff --git a/components/style_derive/parse.rs b/components/style_derive/parse.rs index d73e1993c89..b1a1213435c 100644 --- a/components/style_derive/parse.rs +++ b/components/style_derive/parse.rs @@ -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}; @@ -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)); } } diff --git a/components/style_derive/specified_value_info.rs b/components/style_derive/specified_value_info.rs index 5d14aaa05ac..e29f2bc416e 100644 --- a/components/style_derive/specified_value_info.rs +++ b/components/style_derive/specified_value_info.rs @@ -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::(&input); diff --git a/components/style_derive/to_animated_value.rs b/components/style_derive/to_animated_value.rs index e6a79e4dc7f..45282f0c448 100644 --- a/components/style_derive/to_animated_value.rs +++ b/components/style_derive/to_animated_value.rs @@ -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| { diff --git a/components/style_derive/to_animated_zero.rs b/components/style_derive/to_animated_zero.rs index ea2eebc2bf2..008e94cbcfb 100644 --- a/components/style_derive/to_animated_zero.rs +++ b/components/style_derive/to_animated_zero.rs @@ -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 { diff --git a/components/style_derive/to_computed_value.rs b/components/style_derive/to_computed_value.rs index b14c4bc3dee..5e0f595c6b9 100644 --- a/components/style_derive/to_computed_value.rs +++ b/components/style_derive/to_computed_value.rs @@ -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}; diff --git a/components/style_derive/to_css.rs b/components/style_derive/to_css.rs index c844a1c84ef..aa335366485 100644 --- a/components/style_derive/to_css.rs +++ b/components/style_derive/to_css.rs @@ -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}; @@ -209,7 +203,7 @@ fn derive_variant_fields_expr( let mut iter = bindings .iter() .filter_map(|binding| { - let attrs = cg::parse_field_attrs::(binding.ast()); + let attrs = cg::parse_field_attrs::(&binding.ast()); if attrs.skip { return None; } diff --git a/components/style_derive/to_resolved_value.rs b/components/style_derive/to_resolved_value.rs index 47933940e8a..e049f91152a 100644 --- a/components/style_derive/to_resolved_value.rs +++ b/components/style_derive/to_resolved_value.rs @@ -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| { diff --git a/components/style_traits/Cargo.toml b/components/style_traits/Cargo.toml index e9a059718ec..3b9ecd7aaed 100644 --- a/components/style_traits/Cargo.toml +++ b/components/style_traits/Cargo.toml @@ -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] @@ -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 } diff --git a/components/style_traits/arc_slice.rs b/components/style_traits/arc_slice.rs index baa2798923d..1f10ed9455c 100644 --- a/components/style_traits/arc_slice.rs +++ b/components/style_traits/arc_slice.rs @@ -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. /// diff --git a/components/style_traits/dom.rs b/components/style_traits/dom.rs index dcc60c445ec..d8c660d2be9 100644 --- a/components/style_traits/dom.rs +++ b/components/style_traits/dom.rs @@ -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 diff --git a/components/style_traits/lib.rs b/components/style_traits/lib.rs index 2c64e399ca5..334b3a891bd 100644 --- a/components/style_traits/lib.rs +++ b/components/style_traits/lib.rs @@ -9,17 +9,37 @@ #![crate_name = "style_traits"] #![crate_type = "rlib"] -use bitflags::bitflags; -use cssparser::{CowRcStr, Token}; -use malloc_size_of_derive::MallocSizeOf; -use selectors::parser::SelectorParseErrorKind; -use serde::{Deserialize, Serialize}; +extern crate app_units; +#[macro_use] +extern crate bitflags; +extern crate cssparser; +extern crate euclid; +#[macro_use] +extern crate lazy_static; +extern crate malloc_size_of; +#[macro_use] +extern crate malloc_size_of_derive; +extern crate selectors; +#[macro_use] +extern crate serde; +extern crate servo_arc; #[cfg(feature = "servo")] -use servo_atoms::Atom; -use size_of_test::size_of_test; +extern crate servo_atoms; +extern crate to_shmem; +#[macro_use] +extern crate to_shmem_derive; +#[cfg(feature = "servo")] +extern crate webrender_api; +#[cfg(feature = "servo")] +extern crate url; #[cfg(feature = "servo")] pub use webrender_api::units::DevicePixel; +use cssparser::{CowRcStr, Token}; +use selectors::parser::SelectorParseErrorKind; +#[cfg(feature = "servo")] +use servo_atoms::Atom; + /// One hardware pixel. /// /// This unit corresponds to the smallest addressable element of the display hardware. @@ -78,11 +98,9 @@ pub use crate::values::{ /// The error type for all CSS parsing routines. pub type ParseError<'i> = cssparser::ParseError<'i, StyleParseErrorKind<'i>>; -size_of_test!(ParseError, 64); /// Error in property value parsing pub type ValueParseError<'i> = cssparser::ParseError<'i, ValueParseErrorKind<'i>>; -size_of_test!(ValueParseError, 48); #[derive(Clone, Debug, PartialEq)] /// Errors that can be encountered while parsing CSS values. @@ -149,7 +167,6 @@ pub enum StyleParseErrorKind<'i> { /// The property is not allowed within a page rule. NotAllowedInPageRule, } -size_of_test!(StyleParseErrorKind, 56); impl<'i> From> for StyleParseErrorKind<'i> { fn from(this: ValueParseErrorKind<'i>) -> Self { @@ -171,7 +188,6 @@ pub enum ValueParseErrorKind<'i> { /// An invalid filter value was encountered. InvalidFilter(Token<'i>), } -size_of_test!(ValueParseErrorKind, 40); impl<'i> StyleParseErrorKind<'i> { /// Create an InvalidValue parse error diff --git a/components/style_traits/owned_slice.rs b/components/style_traits/owned_slice.rs index 5a1b1006ccd..36ba3162e59 100644 --- a/components/style_traits/owned_slice.rs +++ b/components/style_traits/owned_slice.rs @@ -6,14 +6,13 @@ //! A replacement for `Box<[T]>` that cbindgen can understand. +use malloc_size_of::{MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps}; +use serde::de::{Deserialize, Deserializer}; +use serde::ser::{Serialize, Serializer}; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; use std::ptr::NonNull; use std::{fmt, iter, mem, slice}; - -use malloc_size_of::{MallocShallowSizeOf, MallocSizeOf, MallocSizeOfOps}; -use serde::de::{Deserialize, Deserializer}; -use serde::ser::{Serialize, Serializer}; use to_shmem::{self, SharedMemoryBuilder, ToShmem}; /// A struct that basically replaces a `Box<[T]>`, but which cbindgen can diff --git a/components/style_traits/owned_str.rs b/components/style_traits/owned_str.rs index b7f1f29b8a9..ebfdcd5e066 100644 --- a/components/style_traits/owned_str.rs +++ b/components/style_traits/owned_str.rs @@ -6,14 +6,10 @@ //! A replacement for `Box` that has a defined layout for FFI. +use crate::owned_slice::OwnedSlice; use std::fmt; use std::ops::{Deref, DerefMut}; -use malloc_size_of_derive::MallocSizeOf; -use to_shmem_derive::ToShmem; - -use crate::owned_slice::OwnedSlice; - /// A struct that basically replaces a Box, but with a defined layout, /// suitable for FFI. #[repr(C)] diff --git a/components/style_traits/rustfmt.toml b/components/style_traits/rustfmt.toml new file mode 100644 index 00000000000..c7ad93bafe3 --- /dev/null +++ b/components/style_traits/rustfmt.toml @@ -0,0 +1 @@ +disable_all_formatting = true diff --git a/components/style_traits/specified_value_info.rs b/components/style_traits/specified_value_info.rs index cdba95d8890..b73d576715a 100644 --- a/components/style_traits/specified_value_info.rs +++ b/components/style_traits/specified_value_info.rs @@ -4,13 +4,11 @@ //! Value information for devtools. -use std::ops::Range; -use std::sync::Arc as StdArc; - -use servo_arc::Arc; - use crate::arc_slice::ArcSlice; use crate::owned_slice::OwnedSlice; +use servo_arc::Arc; +use std::ops::Range; +use std::sync::Arc as StdArc; /// Type of value that a property supports. This is used by Gecko's /// devtools to make sense about value it parses, and types listed diff --git a/components/style_traits/values.rs b/components/style_traits/values.rs index 3c9f0acacd0..14025023cb3 100644 --- a/components/style_traits/values.rs +++ b/components/style_traits/values.rs @@ -4,13 +4,11 @@ //! Helper types and traits for the handling of CSS values. -use std::fmt::{self, Write}; - use app_units::Au; -use cssparser::{ - serialize_string, ParseError, Parser, ToCss as CssparserToCss, Token, UnicodeRange, -}; +use cssparser::ToCss as CssparserToCss; +use cssparser::{serialize_string, ParseError, Parser, Token, UnicodeRange}; use servo_arc::Arc; +use std::fmt::{self, Write}; /// Serialises a value according to its CSS representation. /// @@ -380,7 +378,7 @@ impl Separator for Space { let mut results = vec![parse_one(input)?]; loop { input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. - if let Ok(item) = input.r#try(&mut parse_one) { + if let Ok(item) = input.try(&mut parse_one) { results.push(item); } else { return Ok(results); @@ -406,9 +404,9 @@ impl Separator for CommaWithSpace { loop { input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. let comma_location = input.current_source_location(); - let comma = input.r#try(|i| i.expect_comma()).is_ok(); + let comma = input.try(|i| i.expect_comma()).is_ok(); input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. - if let Ok(item) = input.r#try(&mut parse_one) { + if let Ok(item) = input.try(&mut parse_one) { results.push(item); } else if comma { return Err(comma_location.new_unexpected_token_error(Token::Comma)); @@ -506,9 +504,6 @@ impl_to_css_for_predefined_type!(::cssparser::UnicodeRange); /// Helper types for the handling of specified values. pub mod specified { - use malloc_size_of_derive::MallocSizeOf; - use serde::{Deserialize, Serialize}; - use crate::ParsingMode; /// Whether to allow negative lengths or not.