Auto merge of #19751 - servo:selectors, r=bholley

Clean up the selectors crate for a new crates.io release

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19751)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-01-12 16:55:12 -06:00 committed by GitHub
commit 6ca651c0c8
19 changed files with 101 additions and 190 deletions

30
Cargo.lock generated
View file

@ -1043,7 +1043,7 @@ dependencies = [
"nsstring 0.1.0", "nsstring 0.1.0",
"parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.19.0", "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)", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"style 0.0.1", "style 0.0.1",
"style_traits 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)", "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-fontconfig 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_allocator 0.0.1", "servo_allocator 0.0.1",
"servo_arc 0.0.1", "servo_arc 0.1.0",
"servo_atoms 0.0.1", "servo_atoms 0.0.1",
"servo_geometry 0.0.1", "servo_geometry 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
@ -1488,7 +1488,7 @@ dependencies = [
"selectors 0.19.0", "selectors 0.19.0",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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_atoms 0.0.1",
"servo_config 0.0.1", "servo_config 0.0.1",
"servo_geometry 0.0.1", "servo_geometry 0.0.1",
@ -1541,7 +1541,7 @@ dependencies = [
"selectors 0.19.0", "selectors 0.19.0",
"serde_json 1.0.2 (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_allocator 0.0.1",
"servo_arc 0.0.1", "servo_arc 0.1.0",
"servo_atoms 0.0.1", "servo_atoms 0.0.1",
"servo_config 0.0.1", "servo_config 0.0.1",
"servo_geometry 0.0.1", "servo_geometry 0.0.1",
@ -1693,7 +1693,8 @@ dependencies = [
"euclid 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hashglobe 0.1.0", "hashglobe 0.1.0",
"mozjs 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "mozjs 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_arc 0.0.1", "selectors 0.19.0",
"servo_arc 0.1.0",
"smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "string_cache 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1716,7 +1717,7 @@ name = "malloc_size_of_tests"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"malloc_size_of 0.0.1", "malloc_size_of 0.0.1",
"servo_arc 0.0.1", "servo_arc 0.1.0",
] ]
[[package]] [[package]]
@ -2605,7 +2606,7 @@ dependencies = [
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"servo_allocator 0.0.1", "servo_allocator 0.0.1",
"servo_arc 0.0.1", "servo_arc 0.1.0",
"servo_atoms 0.0.1", "servo_atoms 0.0.1",
"servo_config 0.0.1", "servo_config 0.0.1",
"servo_geometry 0.0.1", "servo_geometry 0.0.1",
@ -2650,7 +2651,7 @@ dependencies = [
"range 0.0.1", "range 0.0.1",
"script_traits 0.0.1", "script_traits 0.0.1",
"selectors 0.19.0", "selectors 0.19.0",
"servo_arc 0.0.1", "servo_arc 0.1.0",
"servo_atoms 0.0.1", "servo_atoms 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
"style 0.0.1", "style 0.0.1",
@ -2717,14 +2718,11 @@ dependencies = [
"cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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)", "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)", "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 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)", "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)", "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)", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -2914,7 +2912,7 @@ dependencies = [
[[package]] [[package]]
name = "servo_arc" name = "servo_arc"
version = "0.0.1" version = "0.1.0"
dependencies = [ dependencies = [
"nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3143,7 +3141,7 @@ dependencies = [
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.19.0", "selectors 0.19.0",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "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_atoms 0.0.1",
"servo_config 0.0.1", "servo_config 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
@ -3182,7 +3180,7 @@ dependencies = [
"rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"selectors 0.19.0", "selectors 0.19.0",
"serde_json 1.0.2 (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_atoms 0.0.1",
"servo_config 0.0.1", "servo_config 0.0.1",
"servo_url 0.0.1", "servo_url 0.0.1",
@ -3203,7 +3201,7 @@ dependencies = [
"malloc_size_of_derive 0.0.1", "malloc_size_of_derive 0.0.1",
"selectors 0.19.0", "selectors 0.19.0",
"serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "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_atoms 0.0.1",
"webrender_api 0.56.1 (git+https://github.com/servo/webrender)", "webrender_api 0.56.1 (git+https://github.com/servo/webrender)",
] ]

View file

@ -17,6 +17,7 @@ cssparser = "0.23.0"
euclid = "0.16" euclid = "0.16"
hashglobe = { path = "../hashglobe" } hashglobe = { path = "../hashglobe" }
mozjs = { version = "0.1.8", features = ["promises"], optional = true } mozjs = { version = "0.1.8", features = ["promises"], optional = true }
selectors = { path = "../selectors" }
servo_arc = { path = "../servo_arc" } servo_arc = { path = "../servo_arc" }
smallbitvec = "1.0.3" smallbitvec = "1.0.3"
smallvec = "0.6" smallvec = "0.6"

View file

@ -49,6 +49,7 @@ extern crate euclid;
extern crate hashglobe; extern crate hashglobe;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
extern crate mozjs as js; extern crate mozjs as js;
extern crate selectors;
extern crate servo_arc; extern crate servo_arc;
extern crate smallbitvec; extern crate smallbitvec;
extern crate smallvec; extern crate smallvec;
@ -640,6 +641,13 @@ impl<T: MallocSizeOf, U> MallocSizeOf for euclid::TypedVector2D<T, U> {
} }
} }
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")] #[cfg(feature = "servo")]
impl<Static: string_cache::StaticAtomSet> MallocSizeOf for string_cache::Atom<Static> { impl<Static: string_cache::StaticAtomSet> MallocSizeOf for string_cache::Atom<Static> {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize { fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {

View file

@ -1,8 +1,8 @@
[package] [package]
name = "selectors" name = "selectors"
version = "0.19.0" # Not yet published version = "0.19.0"
authors = ["Simon Sapin <simon.sapin@exyr.org>", "Alan Jeffrey <ajeffrey@mozilla.com>"] authors = ["The Servo Project Developers"]
documentation = "https://docs.rs/selectors/" documentation = "https://docs.rs/selectors/"
description = "CSS Selectors matching for Rust" description = "CSS Selectors matching for Rust"
@ -15,11 +15,8 @@ build = "build.rs"
[lib] [lib]
name = "selectors" name = "selectors"
path = "lib.rs" path = "lib.rs"
# https://github.com/servo/servo/issues/16710
doctest = false
[features] [features]
gecko_like_types = []
bench = [] bench = []
[dependencies] [dependencies]
@ -28,15 +25,10 @@ matches = "0.1"
cssparser = "0.23.0" cssparser = "0.23.0"
log = "0.3" log = "0.3"
fnv = "1.0" fnv = "1.0"
malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = { path = "../malloc_size_of_derive" }
phf = "0.7.18" phf = "0.7.18"
precomputed-hash = "0.1" precomputed-hash = "0.1"
servo_arc = { path = "../servo_arc" } servo_arc = { version = "0.1", path = "../servo_arc" }
smallvec = "0.6" smallvec = "0.6"
[dev-dependencies]
size_of_test = {path = "../size_of_test"}
[build-dependencies] [build-dependencies]
phf_codegen = "0.7.18" phf_codegen = "0.7.18"

View file

@ -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;

View file

@ -10,11 +10,8 @@
#[macro_use] extern crate log; #[macro_use] extern crate log;
#[macro_use] extern crate matches; #[macro_use] extern crate matches;
extern crate fnv; extern crate fnv;
extern crate malloc_size_of;
#[macro_use] extern crate malloc_size_of_derive;
extern crate phf; extern crate phf;
extern crate precomputed_hash; extern crate precomputed_hash;
#[cfg(test)] #[macro_use] extern crate size_of_test;
extern crate servo_arc; extern crate servo_arc;
extern crate smallvec; extern crate smallvec;
@ -25,8 +22,6 @@ pub mod context;
pub mod matching; pub mod matching;
mod nth_index_cache; mod nth_index_cache;
pub mod parser; pub mod parser;
#[cfg(test)] mod size_of_tests;
#[cfg(any(test, feature = "gecko_like_types"))] pub mod gecko_like_types;
pub mod sink; pub mod sink;
mod tree; mod tree;
pub mod visitor; pub mod visitor;

View file

@ -19,7 +19,7 @@ use std::borrow::{Borrow, Cow};
use std::fmt::{self, Display, Debug, Write}; use std::fmt::{self, Display, Debug, Write};
use std::iter::Rev; use std::iter::Rev;
use std::slice; use std::slice;
use visitor::SelectorVisitor; pub use visitor::{Visit, SelectorVisitor};
/// A trait that represents a pseudo-element. /// A trait that represents a pseudo-element.
pub trait PseudoElement : Sized + ToCss { pub trait PseudoElement : Sized + ToCss {
@ -86,17 +86,17 @@ macro_rules! with_all_bounds {
pub trait SelectorImpl: Clone + Sized + 'static { pub trait SelectorImpl: Clone + Sized + 'static {
type ExtraMatchingData: Sized + Default + 'static; type ExtraMatchingData: Sized + Default + 'static;
type AttrValue: $($InSelector)*; type AttrValue: $($InSelector)*;
type Identifier: $($InSelector)* + PrecomputedHash; type Identifier: $($InSelector)*;
type ClassName: $($InSelector)* + PrecomputedHash; type ClassName: $($InSelector)*;
type LocalName: $($InSelector)* + Borrow<Self::BorrowedLocalName> + PrecomputedHash; type LocalName: $($InSelector)* + Borrow<Self::BorrowedLocalName>;
type NamespaceUrl: $($CommonBounds)* + Default + Borrow<Self::BorrowedNamespaceUrl> + PrecomputedHash; type NamespaceUrl: $($CommonBounds)* + Default + Borrow<Self::BorrowedNamespaceUrl>;
type NamespacePrefix: $($InSelector)* + Default; type NamespacePrefix: $($InSelector)* + Default;
type BorrowedNamespaceUrl: ?Sized + Eq; type BorrowedNamespaceUrl: ?Sized + Eq;
type BorrowedLocalName: ?Sized + Eq; type BorrowedLocalName: ?Sized + Eq;
/// non tree-structural pseudo-classes /// non tree-structural pseudo-classes
/// (see: https://drafts.csswg.org/selectors/#structural-pseudos) /// (see: https://drafts.csswg.org/selectors/#structural-pseudos)
type NonTSPseudoClass: $($CommonBounds)* + Sized + ToCss + SelectorMethods<Impl = Self>; type NonTSPseudoClass: $($CommonBounds)* + Sized + ToCss;
/// pseudo-elements /// pseudo-elements
type PseudoElement: $($CommonBounds)* + PseudoElement<Impl = Self>; type PseudoElement: $($CommonBounds)* + PseudoElement<Impl = Self>;
@ -266,7 +266,7 @@ where
/// off the upper bits) at the expense of making the fourth somewhat more /// 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 /// complicated to assemble, because we often bail out before checking all the
/// hashes. /// hashes.
#[derive(Clone, Debug, Eq, MallocSizeOf, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct AncestorHashes { pub struct AncestorHashes {
pub packed_hashes: [u32; 3], pub packed_hashes: [u32; 3],
} }
@ -275,14 +275,24 @@ impl AncestorHashes {
pub fn new<Impl: SelectorImpl>( pub fn new<Impl: SelectorImpl>(
selector: &Selector<Impl>, selector: &Selector<Impl>,
quirks_mode: QuirksMode, 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) Self::from_iter(selector.iter(), quirks_mode)
} }
fn from_iter<Impl: SelectorImpl>( fn from_iter<Impl: SelectorImpl>(
iter: SelectorIter<Impl>, iter: SelectorIter<Impl>,
quirks_mode: QuirksMode, 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. // Compute ancestor hashes for the bloom filter.
let mut hashes = [0u32; 4]; let mut hashes = [0u32; 4];
let mut hash_iter = AncestorIter::new(iter) let mut hash_iter = AncestorIter::new(iter)
@ -316,15 +326,7 @@ impl AncestorHashes {
} }
} }
pub trait SelectorMethods { impl<Impl: SelectorImpl> Visit for Selector<Impl> where Impl::NonTSPseudoClass: Visit<Impl=Impl> {
type Impl: SelectorImpl;
fn visit<V>(&self, visitor: &mut V) -> bool
where
V: SelectorVisitor<Impl = Self::Impl>;
}
impl<Impl: SelectorImpl> SelectorMethods for Selector<Impl> {
type Impl = Impl; type Impl = Impl;
fn visit<V>(&self, visitor: &mut V) -> bool fn visit<V>(&self, visitor: &mut V) -> bool
@ -354,7 +356,7 @@ impl<Impl: SelectorImpl> SelectorMethods for Selector<Impl> {
} }
} }
impl<Impl: SelectorImpl> SelectorMethods for Component<Impl> { impl<Impl: SelectorImpl> Visit for Component<Impl> where Impl::NonTSPseudoClass: Visit<Impl=Impl> {
type Impl = Impl; type Impl = Impl;
fn visit<V>(&self, visitor: &mut V) -> bool fn visit<V>(&self, visitor: &mut V) -> bool
@ -789,7 +791,12 @@ pub enum Component<Impl: SelectorImpl> {
impl<Impl: SelectorImpl> Component<Impl> { impl<Impl: SelectorImpl> Component<Impl> {
/// Compute the ancestor hash to check against the bloom filter. /// Compute the ancestor hash to check against the bloom filter.
fn ancestor_hash(&self, quirks_mode: QuirksMode) -> Option<u32> { fn ancestor_hash(&self, quirks_mode: QuirksMode) -> Option<u32>
where Impl::Identifier: PrecomputedHash,
Impl::ClassName: PrecomputedHash,
Impl::LocalName: PrecomputedHash,
Impl::NamespaceUrl: PrecomputedHash,
{
match *self { match *self {
Component::LocalName(LocalName { ref name, ref lower_name }) => { Component::LocalName(LocalName { ref name, ref lower_name }) => {
// Only insert the local-name into the filter if it's all // Only insert the local-name into the filter if it's all
@ -1998,7 +2005,7 @@ pub mod tests {
} }
} }
impl SelectorMethods for PseudoClass { impl Visit for PseudoClass {
type Impl = DummySelectorImpl; type Impl = DummySelectorImpl;
fn visit<V>(&self, _visitor: &mut V) -> bool fn visit<V>(&self, _visitor: &mut V) -> bool
@ -2068,12 +2075,6 @@ pub mod tests {
} }
} }
impl PrecomputedHash for DummyAtom {
fn precomputed_hash(&self) -> u32 {
return 0
}
}
impl<'i> Parser<'i> for DummyParser { impl<'i> Parser<'i> for DummyParser {
type Impl = DummySelectorImpl; type Impl = DummySelectorImpl;
type Error = SelectorParseErrorKind<'i>; type Error = SelectorParseErrorKind<'i>;

View file

@ -1,74 +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 precomputed_hash::PrecomputedHash;
use std::fmt;
use visitor::SelectorVisitor;
size_of_test!(size_of_selector, Selector<Impl>, 8);
size_of_test!(size_of_pseudo_element, gecko_like_types::PseudoElement, 24);
size_of_test!(size_of_component, Component<Impl>, 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<V>(&self, _visitor: &mut V) -> bool
where V: SelectorVisitor<Impl = Self::Impl> { unimplemented!() }
}
impl ToCss for PseudoClass {
fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write { unimplemented!() }
}
impl ToCss for gecko_like_types::PseudoElement {
fn to_css<W>(&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<String> for Atom {
fn from(_: String) -> Self { unimplemented!() }
}
impl<'a> From<&'a str> for Atom {
fn from(_: &'a str) -> Self { unimplemented!() }
}
impl PrecomputedHash for Atom {
fn precomputed_hash(&self) -> u32 { unimplemented!() }
}

View file

@ -15,7 +15,7 @@ use std::fmt::Debug;
/// Opaque representation of an Element, for identity comparisons. We use /// Opaque representation of an Element, for identity comparisons. We use
/// NonZeroPtrMut to get the NonZero optimization. /// NonZeroPtrMut to get the NonZero optimization.
#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct OpaqueElement(pub NonZeroPtrMut<()>); pub struct OpaqueElement(NonZeroPtrMut<()>);
impl OpaqueElement { impl OpaqueElement {
/// Creates a new OpaqueElement from an arbitrarily-typed pointer. /// Creates a new OpaqueElement from an arbitrarily-typed pointer.

View file

@ -44,3 +44,31 @@ pub trait SelectorVisitor {
true 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<V>(&self, visitor: &mut V) -> bool
where
V: SelectorVisitor<Impl = Self::Impl>;
}

View file

@ -1,9 +1,10 @@
[package] [package]
name = "servo_arc" name = "servo_arc"
version = "0.0.1" version = "0.1.0"
authors = ["The Servo Project Developers"] authors = ["The Servo Project Developers"]
license = "MPL-2.0" 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] [lib]
name = "servo_arc" name = "servo_arc"

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 waste storage on the weak reference count.
//! * We don't do extra RMU operations to handle the possibility of weak references. //! * We don't do extra RMU operations to handle the possibility of weak references.

View file

@ -12,7 +12,7 @@ use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
use invalidation::element::document_state::InvalidationMatchingData; use invalidation::element::document_state::InvalidationMatchingData;
use selector_parser::{Direction, SelectorParser}; use selector_parser::{Direction, SelectorParser};
use selectors::SelectorList; 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 selectors::visitor::SelectorVisitor;
use std::fmt; use std::fmt;
use string_cache::{Atom, Namespace, WeakAtom, WeakNamespace}; 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; type Impl = SelectorImpl;
fn visit<V>(&self, visitor: &mut V) -> bool fn visit<V>(&self, visitor: &mut V) -> bool

View file

@ -15,7 +15,7 @@ use selector_parser::Direction;
use selector_parser::SelectorImpl; use selector_parser::SelectorImpl;
use selectors::attr::NamespaceConstraint; use selectors::attr::NamespaceConstraint;
use selectors::parser::{Combinator, Component}; use selectors::parser::{Combinator, Component};
use selectors::parser::{Selector, SelectorIter, SelectorMethods}; use selectors::parser::{Selector, SelectorIter, Visit};
use selectors::visitor::SelectorVisitor; use selectors::visitor::SelectorVisitor;
use smallvec::SmallVec; use smallvec::SmallVec;

View file

@ -19,7 +19,7 @@ use properties::PropertyFlags;
use properties::longhands::display::computed_value::T as Display; use properties::longhands::display::computed_value::T as Display;
use selector_parser::{AttrValue as SelectorAttrValue, PseudoElementCascadeType, SelectorParser}; use selector_parser::{AttrValue as SelectorAttrValue, PseudoElementCascadeType, SelectorParser};
use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity}; use selectors::attr::{AttrSelectorOperation, NamespaceConstraint, CaseSensitivity};
use selectors::parser::{SelectorMethods, SelectorParseErrorKind}; use selectors::parser::{Visit, SelectorParseErrorKind};
use selectors::visitor::SelectorVisitor; use selectors::visitor::SelectorVisitor;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
@ -312,7 +312,7 @@ impl ToCss for NonTSPseudoClass {
} }
} }
impl SelectorMethods for NonTSPseudoClass { impl Visit for NonTSPseudoClass {
type Impl = SelectorImpl; type Impl = SelectorImpl;

View file

@ -31,7 +31,7 @@ use selectors::bloom::{BloomFilter, NonCountingBloomFilter};
use selectors::matching::{ElementSelectorFlags, matches_selector, MatchingContext, MatchingMode}; use selectors::matching::{ElementSelectorFlags, matches_selector, MatchingContext, MatchingMode};
use selectors::matching::VisitedHandlingMode; use selectors::matching::VisitedHandlingMode;
use selectors::parser::{AncestorHashes, Combinator, Component, Selector}; use selectors::parser::{AncestorHashes, Combinator, Component, Selector};
use selectors::parser::{SelectorIter, SelectorMethods}; use selectors::parser::{SelectorIter, Visit};
use selectors::visitor::SelectorVisitor; use selectors::visitor::SelectorVisitor;
use servo_arc::{Arc, ArcBorrow}; use servo_arc::{Arc, ArcBorrow};
use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards}; use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards};

View file

@ -22,11 +22,7 @@ log = {version = "0.3.5", features = ["release_max_level_info"]}
malloc_size_of = {path = "../../components/malloc_size_of"} malloc_size_of = {path = "../../components/malloc_size_of"}
nsstring = {path = "../../support/gecko/nsstring"} nsstring = {path = "../../support/gecko/nsstring"}
parking_lot = "0.4" parking_lot = "0.4"
# Turn on gecko_like_types because of so that crates which use this selectors = {path = "../../components/selectors"}
# 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"]}
servo_arc = {path = "../../components/servo_arc"} servo_arc = {path = "../../components/servo_arc"}
smallvec = "0.6" smallvec = "0.6"
style = {path = "../../components/style", features = ["gecko"]} style = {path = "../../components/style", features = ["gecko"]}

View file

@ -20,7 +20,7 @@ geckoservo = {path = "../../../ports/geckolib"}
libc = "0.2" libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]} log = {version = "0.3.5", features = ["release_max_level_info"]}
malloc_size_of = {path = "../../../components/malloc_size_of"} 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"} size_of_test = {path = "../../../components/size_of_test"}
smallvec = "0.6" smallvec = "0.6"
style_traits = {path = "../../../components/style_traits"} style_traits = {path = "../../../components/style_traits"}

View file

@ -2,29 +2,22 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * 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 servo_arc::Arc;
use std::mem::{size_of, align_of};
use style; use style;
use style::applicable_declarations::ApplicableDeclarationBlock; use style::applicable_declarations::ApplicableDeclarationBlock;
use style::data::{ElementData, ElementStyles}; 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::properties::ComputedValues;
use style::rule_tree::{RuleNode, StrongRuleNode}; use style::rule_tree::{RuleNode, StrongRuleNode};
use style::values::computed; use style::values::computed;
use style::values::specified; use style::values::specified;
#[test] size_of_test!(size_of_selector, selectors::parser::Selector<SelectorImpl>, 8);
fn size_of_selectors_dummy_types() { size_of_test!(size_of_pseudo_element, selector_parser::PseudoElement, 24);
assert_eq!(size_of::<dummies::PseudoClass>(), size_of::<real::NonTSPseudoClass>());
assert_eq!(align_of::<dummies::PseudoClass>(), align_of::<real::NonTSPseudoClass>());
assert_eq!(size_of::<dummies::PseudoElement>(), size_of::<real::PseudoElement>()); size_of_test!(size_of_component, selectors::parser::Component<SelectorImpl>, 32);
assert_eq!(align_of::<dummies::PseudoElement>(), align_of::<real::PseudoElement>()); size_of_test!(size_of_pseudo_class, selector_parser::NonTSPseudoClass, 24);
assert_eq!(size_of::<dummies::Atom>(), size_of::<style::Atom>());
assert_eq!(align_of::<dummies::Atom>(), align_of::<style::Atom>());
}
// The size of this is critical to performance on the bloom-basic microbenchmark. // 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 // When iterating over a large Rule array, we want to be able to fast-reject