Auto merge of #29361 - federicomenaquintero:selectors-shmem-feature, r=delan

Add a "shmem" feature to selectors to avoid publishing that dependency

<!-- Please describe your changes on the following line: -->

Hopefully as a way to help #29105, this PR adds a `shmem` feature to the selectors crate.  This is so that the crate can be released with that feature off by default, as the `ToShmem` derives are only of interest to Servo, I think.

All the places where servo's source code includes the selectors crate are made to turn on this feature.
This commit is contained in:
bors-servo 2023-02-15 10:26:18 +01:00 committed by GitHub
commit a01035e6fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 59 additions and 43 deletions

View file

@ -39,7 +39,7 @@ rayon = "1"
script = { path = "../script" } script = { path = "../script" }
script_layout_interface = { path = "../script_layout_interface" } script_layout_interface = { path = "../script_layout_interface" }
script_traits = { path = "../script_traits" } script_traits = { path = "../script_traits" }
selectors = { path = "../selectors" } selectors = { path = "../selectors", features = ["shmem"] }
serde_json = "1.0" serde_json = "1.0"
servo_allocator = { path = "../allocator" } servo_allocator = { path = "../allocator" }
servo_arc = { path = "../servo_arc" } servo_arc = { path = "../servo_arc" }

View file

@ -37,7 +37,7 @@ range = { path = "../range" }
script = { path = "../script" } script = { path = "../script" }
script_layout_interface = { path = "../script_layout_interface" } script_layout_interface = { path = "../script_layout_interface" }
script_traits = { path = "../script_traits" } script_traits = { path = "../script_traits" }
selectors = { path = "../selectors" } selectors = { path = "../selectors", features = ["shmem"] }
servo_allocator = { path = "../allocator" } servo_allocator = { path = "../allocator" }
servo_arc = { path = "../servo_arc" } servo_arc = { path = "../servo_arc" }
servo_atoms = { path = "../atoms" } servo_atoms = { path = "../atoms" }

View file

@ -37,7 +37,7 @@ hashglobe = { path = "../hashglobe" }
http = { version = "0.2", optional = true } http = { version = "0.2", optional = true }
hyper_serde = { version = "0.13", optional = true } hyper_serde = { version = "0.13", optional = true }
keyboard-types = { version = "0.6", optional = true } keyboard-types = { version = "0.6", optional = true }
selectors = { path = "../selectors" } selectors = { path = "../selectors", features = ["shmem"] }
serde = { version = "1.0.27", optional = true } serde = { version = "1.0.27", optional = true }
serde_bytes = { version = "0.11", optional = true } serde_bytes = { version = "0.11", optional = true }
servo_arc = { path = "../servo_arc" } servo_arc = { path = "../servo_arc" }

View file

@ -88,7 +88,7 @@ regex = "1.1"
script_layout_interface = { path = "../script_layout_interface" } script_layout_interface = { path = "../script_layout_interface" }
script_plugins = { path = "../script_plugins" } script_plugins = { path = "../script_plugins" }
script_traits = { path = "../script_traits" } script_traits = { path = "../script_traits" }
selectors = { path = "../selectors" } selectors = { path = "../selectors", features = ["shmem"] }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_bytes = "0.11" serde_bytes = "0.11"
servo-media = { git = "https://github.com/servo/media" } servo-media = { git = "https://github.com/servo/media" }

View file

@ -30,7 +30,7 @@ parking_lot = "0.11"
profile_traits = { path = "../profile_traits" } profile_traits = { path = "../profile_traits" }
range = { path = "../range" } range = { path = "../range" }
script_traits = { path = "../script_traits" } script_traits = { path = "../script_traits" }
selectors = { path = "../selectors" } selectors = { path = "../selectors", features = ["shmem"] }
servo_arc = { path = "../servo_arc" } servo_arc = { path = "../servo_arc" }
servo_atoms = { path = "../atoms" } servo_atoms = { path = "../atoms" }
servo_url = { path = "../url" } servo_url = { path = "../url" }

View file

@ -16,6 +16,7 @@ path = "lib.rs"
[features] [features]
bench = [] bench = []
shmem = [ "dep:to_shmem", "dep:to_shmem_derive" ]
[dependencies] [dependencies]
bitflags = "1.0" bitflags = "1.0"
@ -27,8 +28,8 @@ phf = "0.8"
precomputed-hash = "0.1" precomputed-hash = "0.1"
servo_arc = { version = "0.1", path = "../servo_arc" } servo_arc = { version = "0.1", path = "../servo_arc" }
smallvec = "1.0" smallvec = "1.0"
to_shmem = { path = "../to_shmem" } to_shmem = { path = "../to_shmem", optional = true }
to_shmem_derive = { path = "../to_shmem_derive" } to_shmem_derive = { path = "../to_shmem_derive", optional = true }
[build-dependencies] [build-dependencies]
phf_codegen = "0.8" phf_codegen = "0.8"

View file

@ -6,15 +6,16 @@ use crate::parser::SelectorImpl;
use cssparser::ToCss; use cssparser::ToCss;
use std::fmt; use std::fmt;
#[derive(Clone, Eq, PartialEq, ToShmem)] #[derive(Clone, Eq, PartialEq)]
#[shmem(no_bounds)] #[cfg_attr(feature = "shmem", derive(ToShmem))]
#[cfg_attr(feature = "shmem", shmem(no_bounds))]
pub struct AttrSelectorWithOptionalNamespace<Impl: SelectorImpl> { pub struct AttrSelectorWithOptionalNamespace<Impl: SelectorImpl> {
#[shmem(field_bound)] #[cfg_attr(feature = "shmem", shmem(field_bound))]
pub namespace: Option<NamespaceConstraint<(Impl::NamespacePrefix, Impl::NamespaceUrl)>>, pub namespace: Option<NamespaceConstraint<(Impl::NamespacePrefix, Impl::NamespaceUrl)>>,
#[shmem(field_bound)] #[cfg_attr(feature = "shmem", shmem(field_bound))]
pub local_name: Impl::LocalName, pub local_name: Impl::LocalName,
pub local_name_lower: Impl::LocalName, pub local_name_lower: Impl::LocalName,
#[shmem(field_bound)] #[cfg_attr(feature = "shmem", shmem(field_bound))]
pub operation: ParsedAttrSelectorOperation<Impl::AttrValue>, pub operation: ParsedAttrSelectorOperation<Impl::AttrValue>,
pub never_matches: bool, pub never_matches: bool,
} }
@ -28,7 +29,8 @@ impl<Impl: SelectorImpl> AttrSelectorWithOptionalNamespace<Impl> {
} }
} }
#[derive(Clone, Eq, PartialEq, ToShmem)] #[derive(Clone, Eq, PartialEq)]
#[cfg_attr(feature = "shmem", derive(ToShmem))]
pub enum NamespaceConstraint<NamespaceUrl> { pub enum NamespaceConstraint<NamespaceUrl> {
Any, Any,
@ -36,7 +38,8 @@ pub enum NamespaceConstraint<NamespaceUrl> {
Specific(NamespaceUrl), Specific(NamespaceUrl),
} }
#[derive(Clone, Eq, PartialEq, ToShmem)] #[derive(Clone, Eq, PartialEq)]
#[cfg_attr(feature = "shmem", derive(ToShmem))]
pub enum ParsedAttrSelectorOperation<AttrValue> { pub enum ParsedAttrSelectorOperation<AttrValue> {
Exists, Exists,
WithValue { WithValue {
@ -76,7 +79,8 @@ impl<AttrValue> AttrSelectorOperation<AttrValue> {
} }
} }
#[derive(Clone, Copy, Eq, PartialEq, ToShmem)] #[derive(Clone, Copy, Eq, PartialEq)]
#[cfg_attr(feature = "shmem", derive(ToShmem))]
pub enum AttrSelectorOperator { pub enum AttrSelectorOperator {
Equal, Equal,
Includes, Includes,
@ -136,7 +140,8 @@ impl AttrSelectorOperator {
/// The definition of whitespace per CSS Selectors Level 3 § 4. /// The definition of whitespace per CSS Selectors Level 3 § 4.
pub static SELECTOR_WHITESPACE: &[char] = &[' ', '\t', '\n', '\r', '\x0C']; pub static SELECTOR_WHITESPACE: &[char] = &[' ', '\t', '\n', '\r', '\x0C'];
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "shmem", derive(ToShmem))]
pub enum ParsedCaseSensitivity { pub enum ParsedCaseSensitivity {
// 's' was specified. // 's' was specified.
ExplicitCaseSensitive, ExplicitCaseSensitive,

View file

@ -193,7 +193,8 @@ fn split_from_end<T>(s: &[T], at: usize) -> (&[T], &[T]) {
bitflags! { bitflags! {
/// Flags that indicate at which point of parsing a selector are we. /// Flags that indicate at which point of parsing a selector are we.
#[derive(Default, ToShmem)] #[derive(Default)]
#[cfg_attr(feature = "shmem", derive(ToShmem))]
pub (crate) struct SelectorFlags : u8 { pub (crate) struct SelectorFlags : u8 {
const HAS_PSEUDO = 1 << 0; const HAS_PSEUDO = 1 << 0;
const HAS_SLOTTED = 1 << 1; const HAS_SLOTTED = 1 << 1;
@ -201,7 +202,8 @@ bitflags! {
} }
} }
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "shmem", derive(ToShmem))]
pub struct SpecificityAndFlags { pub struct SpecificityAndFlags {
/// There are two free bits here, since we use ten bits for each specificity /// There are two free bits here, since we use ten bits for each specificity
/// kind (id, class, element). /// kind (id, class, element).

View file

@ -18,7 +18,9 @@ extern crate phf;
extern crate precomputed_hash; extern crate precomputed_hash;
extern crate servo_arc; extern crate servo_arc;
extern crate smallvec; extern crate smallvec;
#[cfg(feature = "shmem")]
extern crate to_shmem; extern crate to_shmem;
#[cfg(feature = "shmem")]
#[macro_use] #[macro_use]
extern crate to_shmem_derive; extern crate to_shmem_derive;

View file

@ -327,10 +327,11 @@ pub trait Parser<'i> {
} }
} }
#[derive(Clone, Debug, Eq, PartialEq, ToShmem)] #[derive(Clone, Debug, Eq, PartialEq)]
#[shmem(no_bounds)] #[cfg_attr(feature = "shmem", derive(ToShmem))]
#[cfg_attr(feature = "shmem", shmem(no_bounds))]
pub struct SelectorList<Impl: SelectorImpl>( pub struct SelectorList<Impl: SelectorImpl>(
#[shmem(field_bound)] pub SmallVec<[Selector<Impl>; 1]>, #[cfg_attr(feature = "shmem", shmem(field_bound))] pub SmallVec<[Selector<Impl>; 1]>,
); );
/// How to treat invalid selectors in a selector list. /// How to treat invalid selectors in a selector list.
@ -555,10 +556,12 @@ pub fn namespace_empty_string<Impl: SelectorImpl>() -> Impl::NamespaceUrl {
/// ///
/// This reordering doesn't change the semantics of selector matching, and we /// This reordering doesn't change the semantics of selector matching, and we
/// handle it in to_css to make it invisible to serialization. /// handle it in to_css to make it invisible to serialization.
#[derive(Clone, Eq, PartialEq, ToShmem)] #[derive(Clone, Eq, PartialEq)]
#[shmem(no_bounds)] #[cfg_attr(feature = "shmem", derive(ToShmem))]
#[cfg_attr(feature = "shmem", shmem(no_bounds))]
pub struct Selector<Impl: SelectorImpl>( pub struct Selector<Impl: SelectorImpl>(
#[shmem(field_bound)] ThinArc<SpecificityAndFlags, Component<Impl>>, #[cfg_attr(feature = "shmem", shmem(field_bound))]
ThinArc<SpecificityAndFlags, Component<Impl>>,
); );
impl<Impl: SelectorImpl> Selector<Impl> { impl<Impl: SelectorImpl> Selector<Impl> {
@ -934,7 +937,8 @@ impl<'a, Impl: SelectorImpl> Iterator for AncestorIter<'a, Impl> {
} }
} }
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "shmem", derive(ToShmem))]
pub enum Combinator { pub enum Combinator {
Child, // > Child, // >
Descendant, // space Descendant, // space
@ -985,27 +989,28 @@ impl Combinator {
/// optimal packing and cache performance, see [1]. /// optimal packing and cache performance, see [1].
/// ///
/// [1] https://bugzilla.mozilla.org/show_bug.cgi?id=1357973 /// [1] https://bugzilla.mozilla.org/show_bug.cgi?id=1357973
#[derive(Clone, Eq, PartialEq, ToShmem)] #[derive(Clone, Eq, PartialEq)]
#[shmem(no_bounds)] #[cfg_attr(feature = "shmem", derive(ToShmem))]
#[cfg_attr(feature = "shmem", shmem(no_bounds))]
pub enum Component<Impl: SelectorImpl> { pub enum Component<Impl: SelectorImpl> {
Combinator(Combinator), Combinator(Combinator),
ExplicitAnyNamespace, ExplicitAnyNamespace,
ExplicitNoNamespace, ExplicitNoNamespace,
DefaultNamespace(#[shmem(field_bound)] Impl::NamespaceUrl), DefaultNamespace(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::NamespaceUrl),
Namespace( Namespace(
#[shmem(field_bound)] Impl::NamespacePrefix, #[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::NamespacePrefix,
#[shmem(field_bound)] Impl::NamespaceUrl, #[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::NamespaceUrl,
), ),
ExplicitUniversalType, ExplicitUniversalType,
LocalName(LocalName<Impl>), LocalName(LocalName<Impl>),
ID(#[shmem(field_bound)] Impl::Identifier), ID(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::Identifier),
Class(#[shmem(field_bound)] Impl::Identifier), Class(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::Identifier),
AttributeInNoNamespaceExists { AttributeInNoNamespaceExists {
#[shmem(field_bound)] #[cfg_attr(feature = "shmem", shmem(field_bound))]
local_name: Impl::LocalName, local_name: Impl::LocalName,
local_name_lower: Impl::LocalName, local_name_lower: Impl::LocalName,
}, },
@ -1013,7 +1018,7 @@ pub enum Component<Impl: SelectorImpl> {
AttributeInNoNamespace { AttributeInNoNamespace {
local_name: Impl::LocalName, local_name: Impl::LocalName,
operator: AttrSelectorOperator, operator: AttrSelectorOperator,
#[shmem(field_bound)] #[cfg_attr(feature = "shmem", shmem(field_bound))]
value: Impl::AttrValue, value: Impl::AttrValue,
case_sensitivity: ParsedCaseSensitivity, case_sensitivity: ParsedCaseSensitivity,
never_matches: bool, never_matches: bool,
@ -1036,7 +1041,7 @@ pub enum Component<Impl: SelectorImpl> {
FirstOfType, FirstOfType,
LastOfType, LastOfType,
OnlyOfType, OnlyOfType,
NonTSPseudoClass(#[shmem(field_bound)] Impl::NonTSPseudoClass), NonTSPseudoClass(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::NonTSPseudoClass),
/// The ::slotted() pseudo-element: /// The ::slotted() pseudo-element:
/// ///
/// https://drafts.csswg.org/css-scoping/#slotted-pseudo /// https://drafts.csswg.org/css-scoping/#slotted-pseudo
@ -1051,7 +1056,7 @@ pub enum Component<Impl: SelectorImpl> {
Slotted(Selector<Impl>), Slotted(Selector<Impl>),
/// The `::part` pseudo-element. /// The `::part` pseudo-element.
/// https://drafts.csswg.org/css-shadow-parts/#part /// https://drafts.csswg.org/css-shadow-parts/#part
Part(#[shmem(field_bound)] Box<[Impl::Identifier]>), Part(#[cfg_attr(feature = "shmem", shmem(field_bound))] Box<[Impl::Identifier]>),
/// The `:host` pseudo-class: /// The `:host` pseudo-class:
/// ///
/// https://drafts.csswg.org/css-scoping/#host-selector /// https://drafts.csswg.org/css-scoping/#host-selector
@ -1076,7 +1081,7 @@ pub enum Component<Impl: SelectorImpl> {
/// Same comment as above re. the argument. /// Same comment as above re. the argument.
Is(Box<[Selector<Impl>]>), Is(Box<[Selector<Impl>]>),
/// An implementation-dependent pseudo-element selector. /// An implementation-dependent pseudo-element selector.
PseudoElement(#[shmem(field_bound)] Impl::PseudoElement), PseudoElement(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::PseudoElement),
} }
impl<Impl: SelectorImpl> Component<Impl> { impl<Impl: SelectorImpl> Component<Impl> {
@ -1219,10 +1224,11 @@ impl<Impl: SelectorImpl> Component<Impl> {
} }
} }
#[derive(Clone, Eq, PartialEq, ToShmem)] #[derive(Clone, Eq, PartialEq)]
#[shmem(no_bounds)] #[cfg_attr(feature = "shmem", derive(ToShmem))]
#[cfg_attr(feature = "shmem", shmem(no_bounds))]
pub struct LocalName<Impl: SelectorImpl> { pub struct LocalName<Impl: SelectorImpl> {
#[shmem(field_bound)] #[cfg_attr(feature = "shmem", shmem(field_bound))]
pub name: Impl::LocalName, pub name: Impl::LocalName,
pub lower_name: Impl::LocalName, pub lower_name: Impl::LocalName,
} }

View file

@ -59,7 +59,7 @@ owning_ref = "0.4"
parking_lot = "0.11" parking_lot = "0.11"
precomputed-hash = "0.1.1" precomputed-hash = "0.1.1"
rayon = "1" rayon = "1"
selectors = { path = "../selectors" } selectors = { path = "../selectors", features = ["shmem"] }
serde = { version = "1.0", optional = true, features = ["derive"] } serde = { version = "1.0", optional = true, features = ["derive"] }
servo_arc = { path = "../servo_arc" } servo_arc = { path = "../servo_arc" }
servo_atoms = { path = "../atoms", optional = true } servo_atoms = { path = "../atoms", optional = true }

View file

@ -21,7 +21,7 @@ euclid = "0.22"
lazy_static = "1" lazy_static = "1"
malloc_size_of = { path = "../malloc_size_of" } malloc_size_of = { path = "../malloc_size_of" }
malloc_size_of_derive = "0.1" malloc_size_of_derive = "0.1"
selectors = { path = "../selectors" } selectors = { path = "../selectors", features = ["shmem"] }
serde = "1.0" serde = "1.0"
servo_arc = { path = "../servo_arc" } servo_arc = { path = "../servo_arc" }
servo_atoms = { path = "../atoms", optional = true } servo_atoms = { path = "../atoms", optional = true }

View file

@ -16,7 +16,7 @@ euclid = "0.22"
html5ever = "0.26" html5ever = "0.26"
rayon = "1" rayon = "1"
serde_json = "1.0" serde_json = "1.0"
selectors = {path = "../../../components/selectors"} selectors = {path = "../../../components/selectors", features = ["shmem"] }
servo_arc = {path = "../../../components/servo_arc"} servo_arc = {path = "../../../components/servo_arc"}
servo_atoms = {path = "../../../components/atoms"} servo_atoms = {path = "../../../components/atoms"}
servo_config = {path = "../../../components/config"} servo_config = {path = "../../../components/config"}