From 0929f727097d4bfdfc67f097aa87bc5ca7cdaac2 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 13:53:35 +0100 Subject: [PATCH 01/11] Re-enable selectors doctests Closes #16710, which was actually fixed by 6dff251e35736fa74eaab6ddbc8b6ecec08ecf48 in #19395. This exercises that fix. Green AppVeyor build: https://ci.appveyor.com/project/servo/servo/build/1.0.24124 --- components/selectors/Cargo.toml | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index 8da7aaaea35..86466213adc 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -15,8 +15,6 @@ build = "build.rs" [lib] name = "selectors" path = "lib.rs" -# https://github.com/servo/servo/issues/16710 -doctest = false [features] gecko_like_types = [] From 5a82a1d45556a884f6ed56bed0241dda348357ca Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 14:07:41 +0100 Subject: [PATCH 02/11] Reverse the dependency between selectors and malloc_size_of --- Cargo.lock | 3 +-- components/malloc_size_of/Cargo.toml | 1 + components/malloc_size_of/lib.rs | 8 ++++++++ components/selectors/Cargo.toml | 2 -- components/selectors/lib.rs | 2 -- components/selectors/parser.rs | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 34643bd0e8b..818493ea05f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1693,6 +1693,7 @@ dependencies = [ "euclid 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "hashglobe 0.1.0", "mozjs 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "selectors 0.19.0", "servo_arc 0.0.1", "smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2717,8 +2718,6 @@ dependencies = [ "cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "malloc_size_of 0.0.1", - "malloc_size_of_derive 0.0.1", "matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/malloc_size_of/Cargo.toml b/components/malloc_size_of/Cargo.toml index a5c3acfb861..9b24d6dade8 100644 --- a/components/malloc_size_of/Cargo.toml +++ b/components/malloc_size_of/Cargo.toml @@ -17,6 +17,7 @@ cssparser = "0.23.0" euclid = "0.16" hashglobe = { path = "../hashglobe" } mozjs = { version = "0.1.8", features = ["promises"], optional = true } +selectors = { path = "../selectors" } servo_arc = { path = "../servo_arc" } smallbitvec = "1.0.3" smallvec = "0.6" diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs index b366de512f0..2ec16f380de 100644 --- a/components/malloc_size_of/lib.rs +++ b/components/malloc_size_of/lib.rs @@ -49,6 +49,7 @@ extern crate euclid; extern crate hashglobe; #[cfg(feature = "servo")] extern crate mozjs as js; +extern crate selectors; extern crate servo_arc; extern crate smallbitvec; extern crate smallvec; @@ -640,6 +641,13 @@ impl MallocSizeOf for euclid::TypedVector2D { } } +impl MallocSizeOf for selectors::parser::AncestorHashes { + fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize { + let selectors::parser::AncestorHashes { ref packed_hashes } = *self; + packed_hashes.size_of(ops) + } +} + #[cfg(feature = "servo")] impl MallocSizeOf for string_cache::Atom { fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index 86466213adc..0dfca53e32f 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -26,8 +26,6 @@ matches = "0.1" cssparser = "0.23.0" log = "0.3" fnv = "1.0" -malloc_size_of = { path = "../malloc_size_of" } -malloc_size_of_derive = { path = "../malloc_size_of_derive" } phf = "0.7.18" precomputed-hash = "0.1" servo_arc = { path = "../servo_arc" } diff --git a/components/selectors/lib.rs b/components/selectors/lib.rs index c8e7ce175d5..a0f929ecfbb 100644 --- a/components/selectors/lib.rs +++ b/components/selectors/lib.rs @@ -10,8 +10,6 @@ #[macro_use] extern crate log; #[macro_use] extern crate matches; extern crate fnv; -extern crate malloc_size_of; -#[macro_use] extern crate malloc_size_of_derive; extern crate phf; extern crate precomputed_hash; #[cfg(test)] #[macro_use] extern crate size_of_test; diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index 99b73353abf..e39ba36bd4e 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -266,7 +266,7 @@ where /// off the upper bits) at the expense of making the fourth somewhat more /// complicated to assemble, because we often bail out before checking all the /// hashes. -#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct AncestorHashes { pub packed_hashes: [u32; 3], } From b0003f77e422e9f11ad79d29e114c9247c441433 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 14:26:24 +0100 Subject: [PATCH 03/11] Prepare servo_arc for publication on crates.io --- Cargo.lock | 26 +++++++++++++------------- components/selectors/Cargo.toml | 2 +- components/servo_arc/Cargo.toml | 5 +++-- components/servo_arc/lib.rs | 2 +- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 818493ea05f..79aa891ded5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1043,7 +1043,7 @@ dependencies = [ "nsstring 0.1.0", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.19.0", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "style 0.0.1", "style_traits 0.0.1", @@ -1084,7 +1084,7 @@ dependencies = [ "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "servo-fontconfig 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "servo_allocator 0.0.1", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "servo_atoms 0.0.1", "servo_geometry 0.0.1", "servo_url 0.0.1", @@ -1488,7 +1488,7 @@ dependencies = [ "selectors 0.19.0", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "servo_atoms 0.0.1", "servo_config 0.0.1", "servo_geometry 0.0.1", @@ -1541,7 +1541,7 @@ dependencies = [ "selectors 0.19.0", "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "servo_allocator 0.0.1", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "servo_atoms 0.0.1", "servo_config 0.0.1", "servo_geometry 0.0.1", @@ -1694,7 +1694,7 @@ dependencies = [ "hashglobe 0.1.0", "mozjs 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.19.0", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1717,7 +1717,7 @@ name = "malloc_size_of_tests" version = "0.0.1" dependencies = [ "malloc_size_of 0.0.1", - "servo_arc 0.0.1", + "servo_arc 0.1.0", ] [[package]] @@ -2606,7 +2606,7 @@ dependencies = [ "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "servo_allocator 0.0.1", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "servo_atoms 0.0.1", "servo_config 0.0.1", "servo_geometry 0.0.1", @@ -2651,7 +2651,7 @@ dependencies = [ "range 0.0.1", "script_traits 0.0.1", "selectors 0.19.0", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "servo_atoms 0.0.1", "servo_url 0.0.1", "style 0.0.1", @@ -2722,7 +2722,7 @@ dependencies = [ "phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "size_of_test 0.0.1", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2913,7 +2913,7 @@ dependencies = [ [[package]] name = "servo_arc" -version = "0.0.1" +version = "0.1.0" dependencies = [ "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3142,7 +3142,7 @@ dependencies = [ "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.19.0", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "servo_atoms 0.0.1", "servo_config 0.0.1", "servo_url 0.0.1", @@ -3181,7 +3181,7 @@ dependencies = [ "rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.19.0", "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "servo_atoms 0.0.1", "servo_config 0.0.1", "servo_url 0.0.1", @@ -3202,7 +3202,7 @@ dependencies = [ "malloc_size_of_derive 0.0.1", "selectors 0.19.0", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", - "servo_arc 0.0.1", + "servo_arc 0.1.0", "servo_atoms 0.0.1", "webrender_api 0.56.1 (git+https://github.com/servo/webrender)", ] diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index 0dfca53e32f..acae6f8f5e4 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -28,7 +28,7 @@ log = "0.3" fnv = "1.0" phf = "0.7.18" precomputed-hash = "0.1" -servo_arc = { path = "../servo_arc" } +servo_arc = { version = "0.1", path = "../servo_arc" } smallvec = "0.6" [dev-dependencies] diff --git a/components/servo_arc/Cargo.toml b/components/servo_arc/Cargo.toml index 9a82346e68b..84b75cab345 100644 --- a/components/servo_arc/Cargo.toml +++ b/components/servo_arc/Cargo.toml @@ -1,9 +1,10 @@ [package] name = "servo_arc" -version = "0.0.1" +version = "0.1.0" authors = ["The Servo Project Developers"] license = "MPL-2.0" -publish = false +repository = "https://github.com/servo/servo" +description = "A fork of std::sync::Arc with some extra functionality and without weak references" [lib] name = "servo_arc" diff --git a/components/servo_arc/lib.rs b/components/servo_arc/lib.rs index 0e77abd6e4b..d7694901130 100644 --- a/components/servo_arc/lib.rs +++ b/components/servo_arc/lib.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Fork of Arc for Servo. This has the following advantages over std::Arc: +//! Fork of Arc for Servo. This has the following advantages over std::sync::Arc: //! //! * We don't waste storage on the weak reference count. //! * We don't do extra RMU operations to handle the possibility of weak references. From 5d920df460191aac756541000fcb321300d8e8a2 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 14:55:38 +0100 Subject: [PATCH 04/11] =?UTF-8?q?Move=20PrecomputedHash=20bounds=20to=20wh?= =?UTF-8?q?ere=20they=E2=80=99re=20actually=20needed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/selectors/parser.rs | 35 +++++++++++++++++---------- components/selectors/size_of_tests.rs | 5 ---- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index e39ba36bd4e..7e7194b109e 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -86,10 +86,10 @@ macro_rules! with_all_bounds { pub trait SelectorImpl: Clone + Sized + 'static { type ExtraMatchingData: Sized + Default + 'static; type AttrValue: $($InSelector)*; - type Identifier: $($InSelector)* + PrecomputedHash; - type ClassName: $($InSelector)* + PrecomputedHash; - type LocalName: $($InSelector)* + Borrow + PrecomputedHash; - type NamespaceUrl: $($CommonBounds)* + Default + Borrow + PrecomputedHash; + type Identifier: $($InSelector)*; + type ClassName: $($InSelector)*; + type LocalName: $($InSelector)* + Borrow; + type NamespaceUrl: $($CommonBounds)* + Default + Borrow; type NamespacePrefix: $($InSelector)* + Default; type BorrowedNamespaceUrl: ?Sized + Eq; type BorrowedLocalName: ?Sized + Eq; @@ -275,14 +275,24 @@ impl AncestorHashes { pub fn new( selector: &Selector, quirks_mode: QuirksMode, - ) -> Self { + ) -> Self + where Impl::Identifier: PrecomputedHash, + Impl::ClassName: PrecomputedHash, + Impl::LocalName: PrecomputedHash, + Impl::NamespaceUrl: PrecomputedHash, + { Self::from_iter(selector.iter(), quirks_mode) } fn from_iter( iter: SelectorIter, quirks_mode: QuirksMode, - ) -> Self { + ) -> Self + where Impl::Identifier: PrecomputedHash, + Impl::ClassName: PrecomputedHash, + Impl::LocalName: PrecomputedHash, + Impl::NamespaceUrl: PrecomputedHash, + { // Compute ancestor hashes for the bloom filter. let mut hashes = [0u32; 4]; let mut hash_iter = AncestorIter::new(iter) @@ -789,7 +799,12 @@ pub enum Component { impl Component { /// Compute the ancestor hash to check against the bloom filter. - fn ancestor_hash(&self, quirks_mode: QuirksMode) -> Option { + fn ancestor_hash(&self, quirks_mode: QuirksMode) -> Option + where Impl::Identifier: PrecomputedHash, + Impl::ClassName: PrecomputedHash, + Impl::LocalName: PrecomputedHash, + Impl::NamespaceUrl: PrecomputedHash, + { match *self { Component::LocalName(LocalName { ref name, ref lower_name }) => { // Only insert the local-name into the filter if it's all @@ -2068,12 +2083,6 @@ pub mod tests { } } - impl PrecomputedHash for DummyAtom { - fn precomputed_hash(&self) -> u32 { - return 0 - } - } - impl<'i> Parser<'i> for DummyParser { type Impl = DummySelectorImpl; type Error = SelectorParseErrorKind<'i>; diff --git a/components/selectors/size_of_tests.rs b/components/selectors/size_of_tests.rs index 8f0d6da94ef..35f4e6f0ab0 100644 --- a/components/selectors/size_of_tests.rs +++ b/components/selectors/size_of_tests.rs @@ -7,7 +7,6 @@ use gecko_like_types; use gecko_like_types::*; use parser; use parser::*; -use precomputed_hash::PrecomputedHash; use std::fmt; use visitor::SelectorVisitor; @@ -68,7 +67,3 @@ impl From for Atom { impl<'a> From<&'a str> for Atom { fn from(_: &'a str) -> Self { unimplemented!() } } - -impl PrecomputedHash for Atom { - fn precomputed_hash(&self) -> u32 { unimplemented!() } -} From 7d1dc7286a76293e9c5dd3891a6e8ea051e3c09f Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 15:09:24 +0100 Subject: [PATCH 05/11] Move selectors size_of tests to Stylo tests --- Cargo.lock | 1 - components/selectors/Cargo.toml | 4 -- components/selectors/gecko_like_types.rs | 28 ---------- components/selectors/lib.rs | 3 -- components/selectors/size_of_tests.rs | 69 ------------------------ ports/geckolib/Cargo.toml | 6 +-- ports/geckolib/tests/Cargo.toml | 2 +- ports/geckolib/tests/size_of.rs | 19 +++---- 8 files changed, 8 insertions(+), 124 deletions(-) delete mode 100644 components/selectors/gecko_like_types.rs delete mode 100644 components/selectors/size_of_tests.rs diff --git a/Cargo.lock b/Cargo.lock index 79aa891ded5..f81f1c939de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2723,7 +2723,6 @@ dependencies = [ "phf_codegen 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)", "precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "servo_arc 0.1.0", - "size_of_test 0.0.1", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index acae6f8f5e4..303ed822e41 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -17,7 +17,6 @@ name = "selectors" path = "lib.rs" [features] -gecko_like_types = [] bench = [] [dependencies] @@ -31,8 +30,5 @@ precomputed-hash = "0.1" servo_arc = { version = "0.1", path = "../servo_arc" } smallvec = "0.6" -[dev-dependencies] -size_of_test = {path = "../size_of_test"} - [build-dependencies] phf_codegen = "0.7.18" diff --git a/components/selectors/gecko_like_types.rs b/components/selectors/gecko_like_types.rs deleted file mode 100644 index de0c4034e8c..00000000000 --- a/components/selectors/gecko_like_types.rs +++ /dev/null @@ -1,28 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -//! These types need to have the same size and alignment as the respectively corresponding -//! types in components/style/gecko/selector_parser.rs - -#[derive(Clone, Debug, Eq, PartialEq)] -#[allow(dead_code)] -pub enum PseudoClass { - Bare, - String(Box<[u16]>), - Dir(Box<()>), - MozAny(Box<[()]>), -} - -#[derive(Clone, Debug, Eq, PartialEq)] -pub enum PseudoElement { - A, - B, - Tree(Box<[String]>), -} - -#[derive(Clone, Debug, Default, Eq, PartialEq)] -pub struct Atom(usize); - -#[derive(Clone, Eq, PartialEq)] -pub struct Impl; diff --git a/components/selectors/lib.rs b/components/selectors/lib.rs index a0f929ecfbb..49d769d2500 100644 --- a/components/selectors/lib.rs +++ b/components/selectors/lib.rs @@ -12,7 +12,6 @@ extern crate fnv; extern crate phf; extern crate precomputed_hash; -#[cfg(test)] #[macro_use] extern crate size_of_test; extern crate servo_arc; extern crate smallvec; @@ -23,8 +22,6 @@ pub mod context; pub mod matching; mod nth_index_cache; pub mod parser; -#[cfg(test)] mod size_of_tests; -#[cfg(any(test, feature = "gecko_like_types"))] pub mod gecko_like_types; pub mod sink; mod tree; pub mod visitor; diff --git a/components/selectors/size_of_tests.rs b/components/selectors/size_of_tests.rs deleted file mode 100644 index 35f4e6f0ab0..00000000000 --- a/components/selectors/size_of_tests.rs +++ /dev/null @@ -1,69 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -use cssparser::ToCss; -use gecko_like_types; -use gecko_like_types::*; -use parser; -use parser::*; -use std::fmt; -use visitor::SelectorVisitor; - -size_of_test!(size_of_selector, Selector, 8); -size_of_test!(size_of_pseudo_element, gecko_like_types::PseudoElement, 24); - -size_of_test!(size_of_component, Component, 32); -size_of_test!(size_of_pseudo_class, PseudoClass, 24); - -impl parser::PseudoElement for gecko_like_types::PseudoElement { - type Impl = Impl; -} - -// Boilerplate - -impl SelectorImpl for Impl { - type ExtraMatchingData = u64; - type AttrValue = Atom; - type Identifier = Atom; - type ClassName = Atom; - type LocalName = Atom; - type NamespaceUrl = Atom; - type NamespacePrefix = Atom; - type BorrowedLocalName = Atom; - type BorrowedNamespaceUrl = Atom; - type NonTSPseudoClass = PseudoClass; - type PseudoElement = gecko_like_types::PseudoElement; - - #[inline] - fn is_active_or_hover(_pseudo_class: &Self::NonTSPseudoClass) -> bool { - unimplemented!() - } -} - -impl SelectorMethods for PseudoClass { - type Impl = Impl; - - fn visit(&self, _visitor: &mut V) -> bool - where V: SelectorVisitor { unimplemented!() } -} - -impl ToCss for PseudoClass { - fn to_css(&self, _: &mut W) -> fmt::Result where W: fmt::Write { unimplemented!() } -} - -impl ToCss for gecko_like_types::PseudoElement { - fn to_css(&self, _: &mut W) -> fmt::Result where W: fmt::Write { unimplemented!() } -} - -impl fmt::Display for Atom { - fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result { unimplemented!() } -} - -impl From for Atom { - fn from(_: String) -> Self { unimplemented!() } -} - -impl<'a> From<&'a str> for Atom { - fn from(_: &'a str) -> Self { unimplemented!() } -} diff --git a/ports/geckolib/Cargo.toml b/ports/geckolib/Cargo.toml index 9fbe688571a..384331d40ad 100644 --- a/ports/geckolib/Cargo.toml +++ b/ports/geckolib/Cargo.toml @@ -22,11 +22,7 @@ log = {version = "0.3.5", features = ["release_max_level_info"]} malloc_size_of = {path = "../../components/malloc_size_of"} nsstring = {path = "../../support/gecko/nsstring"} parking_lot = "0.4" -# Turn on gecko_like_types because of so that crates which use this -# crate and also dev-depend on stylo_tests get reasonable behavior -# during rebuilds. See https://github.com/rust-lang/cargo/issues/3923 -# for the cargo problem behind this. -selectors = {path = "../../components/selectors", features = ["gecko_like_types"]} +selectors = {path = "../../components/selectors"} servo_arc = {path = "../../components/servo_arc"} smallvec = "0.6" style = {path = "../../components/style", features = ["gecko"]} diff --git a/ports/geckolib/tests/Cargo.toml b/ports/geckolib/tests/Cargo.toml index 60a1c6236d1..6a9cb3ec99d 100644 --- a/ports/geckolib/tests/Cargo.toml +++ b/ports/geckolib/tests/Cargo.toml @@ -20,7 +20,7 @@ geckoservo = {path = "../../../ports/geckolib"} libc = "0.2" log = {version = "0.3.5", features = ["release_max_level_info"]} malloc_size_of = {path = "../../../components/malloc_size_of"} -selectors = {path = "../../../components/selectors", features = ["gecko_like_types"]} +selectors = {path = "../../../components/selectors"} size_of_test = {path = "../../../components/size_of_test"} smallvec = "0.6" style_traits = {path = "../../../components/style_traits"} diff --git a/ports/geckolib/tests/size_of.rs b/ports/geckolib/tests/size_of.rs index e62e233ebb0..eaa95dce24f 100644 --- a/ports/geckolib/tests/size_of.rs +++ b/ports/geckolib/tests/size_of.rs @@ -2,29 +2,22 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use selectors::gecko_like_types as dummies; +use selectors; use servo_arc::Arc; -use std::mem::{size_of, align_of}; use style; use style::applicable_declarations::ApplicableDeclarationBlock; use style::data::{ElementData, ElementStyles}; -use style::gecko::selector_parser as real; +use style::gecko::selector_parser::{self, SelectorImpl}; use style::properties::ComputedValues; use style::rule_tree::{RuleNode, StrongRuleNode}; use style::values::computed; use style::values::specified; -#[test] -fn size_of_selectors_dummy_types() { - assert_eq!(size_of::(), size_of::()); - assert_eq!(align_of::(), align_of::()); +size_of_test!(size_of_selector, selectors::parser::Selector, 8); +size_of_test!(size_of_pseudo_element, selector_parser::PseudoElement, 24); - assert_eq!(size_of::(), size_of::()); - assert_eq!(align_of::(), align_of::()); - - assert_eq!(size_of::(), size_of::()); - assert_eq!(align_of::(), align_of::()); -} +size_of_test!(size_of_component, selectors::parser::Component, 32); +size_of_test!(size_of_pseudo_class, selector_parser::NonTSPseudoClass, 24); // The size of this is critical to performance on the bloom-basic microbenchmark. // When iterating over a large Rule array, we want to be able to fast-reject From 116a6de59c7d5124a6a83994dd5d43fcb503eece Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 15:04:57 +0100 Subject: [PATCH 06/11] =?UTF-8?q?Make=20OpaqueElement=E2=80=99s=20field=20?= =?UTF-8?q?private.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s not used anywhere, and this reduces the public API surface. --- components/selectors/tree.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/selectors/tree.rs b/components/selectors/tree.rs index 7a83feb83d0..0ae6d7307a5 100644 --- a/components/selectors/tree.rs +++ b/components/selectors/tree.rs @@ -15,7 +15,7 @@ use std::fmt::Debug; /// Opaque representation of an Element, for identity comparisons. We use /// NonZeroPtrMut to get the NonZero optimization. #[derive(Clone, Debug, Eq, Hash, PartialEq)] -pub struct OpaqueElement(pub NonZeroPtrMut<()>); +pub struct OpaqueElement(NonZeroPtrMut<()>); impl OpaqueElement { /// Creates a new OpaqueElement from an arbitrarily-typed pointer. From 79f93cfb5b2260561260e76501600e8fdae503fe Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 15:05:39 +0100 Subject: [PATCH 07/11] The selectors crate has had many contributors --- components/selectors/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index 303ed822e41..76c4552dd35 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -2,7 +2,7 @@ name = "selectors" version = "0.19.0" # Not yet published -authors = ["Simon Sapin ", "Alan Jeffrey "] +authors = ["The Servo Project Developers"] documentation = "https://docs.rs/selectors/" description = "CSS Selectors matching for Rust" From c14b766ff512dac4014f9f24a44938d7d449450b Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 15:26:56 +0100 Subject: [PATCH 08/11] Rename SelectorMethods to Visit, after its one method. --- components/selectors/parser.rs | 10 +++++----- components/style/gecko/selector_parser.rs | 4 ++-- .../style/invalidation/element/invalidation_map.rs | 2 +- components/style/servo/selector_parser.rs | 4 ++-- components/style/stylist.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index 7e7194b109e..18447d1f9a5 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -96,7 +96,7 @@ macro_rules! with_all_bounds { /// non tree-structural pseudo-classes /// (see: https://drafts.csswg.org/selectors/#structural-pseudos) - type NonTSPseudoClass: $($CommonBounds)* + Sized + ToCss + SelectorMethods; + type NonTSPseudoClass: $($CommonBounds)* + Sized + ToCss + Visit; /// pseudo-elements type PseudoElement: $($CommonBounds)* + PseudoElement; @@ -326,7 +326,7 @@ impl AncestorHashes { } } -pub trait SelectorMethods { +pub trait Visit { type Impl: SelectorImpl; fn visit(&self, visitor: &mut V) -> bool @@ -334,7 +334,7 @@ pub trait SelectorMethods { V: SelectorVisitor; } -impl SelectorMethods for Selector { +impl Visit for Selector { type Impl = Impl; fn visit(&self, visitor: &mut V) -> bool @@ -364,7 +364,7 @@ impl SelectorMethods for Selector { } } -impl SelectorMethods for Component { +impl Visit for Component { type Impl = Impl; fn visit(&self, visitor: &mut V) -> bool @@ -2013,7 +2013,7 @@ pub mod tests { } } - impl SelectorMethods for PseudoClass { + impl Visit for PseudoClass { type Impl = DummySelectorImpl; fn visit(&self, _visitor: &mut V) -> bool diff --git a/components/style/gecko/selector_parser.rs b/components/style/gecko/selector_parser.rs index c87c2682aaa..4a7bd18c855 100644 --- a/components/style/gecko/selector_parser.rs +++ b/components/style/gecko/selector_parser.rs @@ -12,7 +12,7 @@ use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI}; use invalidation::element::document_state::InvalidationMatchingData; use selector_parser::{Direction, SelectorParser}; use selectors::SelectorList; -use selectors::parser::{self as selector_parser, Selector, SelectorMethods, SelectorParseErrorKind}; +use selectors::parser::{self as selector_parser, Selector, Visit, SelectorParseErrorKind}; use selectors::visitor::SelectorVisitor; use std::fmt; use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; @@ -113,7 +113,7 @@ impl ToCss for NonTSPseudoClass { } } -impl SelectorMethods for NonTSPseudoClass { +impl Visit for NonTSPseudoClass { type Impl = SelectorImpl; fn visit(&self, visitor: &mut V) -> bool diff --git a/components/style/invalidation/element/invalidation_map.rs b/components/style/invalidation/element/invalidation_map.rs index 9cbfcb77e8b..854d0189610 100644 --- a/components/style/invalidation/element/invalidation_map.rs +++ b/components/style/invalidation/element/invalidation_map.rs @@ -15,7 +15,7 @@ use selector_parser::Direction; use selector_parser::SelectorImpl; use selectors::attr::NamespaceConstraint; use selectors::parser::{Combinator, Component}; -use selectors::parser::{Selector, SelectorIter, SelectorMethods}; +use selectors::parser::{Selector, SelectorIter, Visit}; use selectors::visitor::SelectorVisitor; use smallvec::SmallVec; diff --git a/components/style/servo/selector_parser.rs b/components/style/servo/selector_parser.rs index dbedda39590..bc6cc31cf7d 100644 --- a/components/style/servo/selector_parser.rs +++ b/components/style/servo/selector_parser.rs @@ -19,7 +19,7 @@ use properties::PropertyFlags; use properties::longhands::display::computed_value::T as Display; use selector_parser::{AttrValue as SelectorAttrValue, PseudoElementCascadeType, SelectorParser}; use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity}; -use selectors::parser::{SelectorMethods, SelectorParseErrorKind}; +use selectors::parser::{Visit, SelectorParseErrorKind}; use selectors::visitor::SelectorVisitor; use std::fmt; use std::mem; @@ -312,7 +312,7 @@ impl ToCss for NonTSPseudoClass { } } -impl SelectorMethods for NonTSPseudoClass { +impl Visit for NonTSPseudoClass { type Impl = SelectorImpl; diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 15c0e4ad174..ee767010c65 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -31,7 +31,7 @@ use selectors::bloom::{BloomFilter, NonCountingBloomFilter}; use selectors::matching::{ElementSelectorFlags, matches_selector, MatchingContext, MatchingMode}; use selectors::matching::VisitedHandlingMode; use selectors::parser::{AncestorHashes, Combinator, Component, Selector}; -use selectors::parser::{SelectorIter, SelectorMethods}; +use selectors::parser::{SelectorIter, Visit}; use selectors::visitor::SelectorVisitor; use servo_arc::{Arc, ArcBorrow}; use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards}; From 1a6010f19fc4064de8a285194dbace78770716ec Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 15:40:16 +0100 Subject: [PATCH 09/11] Document selectors::Visit --- components/selectors/parser.rs | 10 +--------- components/selectors/visitor.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index 18447d1f9a5..5543914c3f6 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -19,7 +19,7 @@ use std::borrow::{Borrow, Cow}; use std::fmt::{self, Display, Debug, Write}; use std::iter::Rev; use std::slice; -use visitor::SelectorVisitor; +pub use visitor::{Visit, SelectorVisitor}; /// A trait that represents a pseudo-element. pub trait PseudoElement : Sized + ToCss { @@ -326,14 +326,6 @@ impl AncestorHashes { } } -pub trait Visit { - type Impl: SelectorImpl; - - fn visit(&self, visitor: &mut V) -> bool - where - V: SelectorVisitor; -} - impl Visit for Selector { type Impl = Impl; diff --git a/components/selectors/visitor.rs b/components/selectors/visitor.rs index 929040f9ffb..d0064194790 100644 --- a/components/selectors/visitor.rs +++ b/components/selectors/visitor.rs @@ -44,3 +44,31 @@ pub trait SelectorVisitor { true } } + +/// Enables traversing selector components stored in various types +pub trait Visit { + /// The type parameter of selector component types. + type Impl: SelectorImpl; + + /// Traverse selector components inside `self`. + /// + /// Implementations of this method should call `SelectorVisitor` methods + /// or other impls of `Visit` as appropriate based on the fields of `Self`. + /// + /// A return value of `false` indicates terminating the traversal. + /// It should be propagated with an early return. + /// On the contrary, `true` indicates that all fields of `self` have been traversed: + /// + /// ```rust,ignore + /// if !visitor.visit_simple_selector(&self.some_simple_selector) { + /// return false; + /// } + /// if !self.some_component.visit(visitor) { + /// return false; + /// } + /// true + /// ``` + fn visit(&self, visitor: &mut V) -> bool + where + V: SelectorVisitor; +} From 358bac953d72eebace05a980d49f6d342b84bd21 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 15:44:07 +0100 Subject: [PATCH 10/11] =?UTF-8?q?Move=20Visit=20trait=20bounds=20to=20wher?= =?UTF-8?q?e=20they=E2=80=99re=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/selectors/parser.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index 5543914c3f6..465e6acaa8c 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -96,7 +96,7 @@ macro_rules! with_all_bounds { /// non tree-structural pseudo-classes /// (see: https://drafts.csswg.org/selectors/#structural-pseudos) - type NonTSPseudoClass: $($CommonBounds)* + Sized + ToCss + Visit; + type NonTSPseudoClass: $($CommonBounds)* + Sized + ToCss; /// pseudo-elements type PseudoElement: $($CommonBounds)* + PseudoElement; @@ -326,7 +326,7 @@ impl AncestorHashes { } } -impl Visit for Selector { +impl Visit for Selector where Impl::NonTSPseudoClass: Visit { type Impl = Impl; fn visit(&self, visitor: &mut V) -> bool @@ -356,7 +356,7 @@ impl Visit for Selector { } } -impl Visit for Component { +impl Visit for Component where Impl::NonTSPseudoClass: Visit { type Impl = Impl; fn visit(&self, visitor: &mut V) -> bool From befadc563a41c4e5920864760a9c84495a734aa1 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jan 2018 17:45:36 +0100 Subject: [PATCH 11/11] Prepare to publish selectors 0.19.0 to crates.io --- components/selectors/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index 76c4552dd35..38b93e74a34 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "selectors" -version = "0.19.0" # Not yet published +version = "0.19.0" authors = ["The Servo Project Developers"] documentation = "https://docs.rs/selectors/"