Bug 1498755 - Part 10: Move list of Servo Boxed types to a separate header file r=emilio
authorCameron McCormack <cam@mcc.id.au>
Sun, 14 Oct 2018 00:06:05 +0000
changeset 499657 5adb545ddcfd3f1275a6ad5ea62bb2b9588a48dc
parent 499656 a15068898e082edd7f030a8e81a1d8fbf34ea45c
child 499658 8819dd315519624abe75cb340aa1ae8cfd62ca86
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1498755
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1498755 - Part 10: Move list of Servo Boxed types to a separate header file r=emilio Depends on D8651 Differential Revision: https://phabricator.services.mozilla.com/D8652
layout/style/ServoBindingTypes.h
layout/style/ServoBindings.toml
layout/style/ServoBoxedTypeList.h
layout/style/moz.build
servo/components/style/build_gecko.rs
servo/components/style/properties/helpers/animated_properties.mako.rs
--- a/layout/style/ServoBindingTypes.h
+++ b/layout/style/ServoBindingTypes.h
@@ -151,22 +151,21 @@
 #include "mozilla/ServoComputedData.h"
 #include "mozilla/ServoTypes.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/gfx/Types.h"
 #include "nsCSSPropertyID.h"
 #include "nsStyleAutoArray.h"
 #include "nsTArray.h"
 
-struct RawServoAuthorStyles;
-struct RawServoStyleSet;
-struct RawServoSelectorList;
-struct RawServoSourceSizeList;
 struct RawServoAnimationValueMap;
-struct StyleUseCounters;
+
+#define SERVO_BOXED_TYPE(name_, type_) struct type_;
+#include "mozilla/ServoBoxedTypeList.h"
+#undef SERVO_BOXED_TYPE
 
 #define SERVO_ARC_TYPE(name_, type_) struct type_;
 #include "mozilla/ServoArcTypeList.h"
 #undef SERVO_ARC_TYPE
 
 namespace mozilla {
 class ServoElementSnapshot;
 class ComputedStyle;
@@ -244,16 +243,21 @@ typedef mozilla::dom::StyleChildrenItera
   struct MOZ_MUST_USE_TYPE type_##Strong     \
   {                                          \
     type_* mPtr;                             \
     already_AddRefed<type_> Consume();       \
   };
 #include "mozilla/ServoArcTypeList.h"
 #undef SERVO_ARC_TYPE
 
+// TODO(heycam): Handle these elsewhere.
+DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoAnimationValueMap)
+DECL_BORROWED_REF_TYPE_FOR(RawServoAnimationValueMap)
+DECL_BORROWED_MUT_REF_TYPE_FOR(RawServoAnimationValueMap)
+
 typedef mozilla::ComputedStyle const* ComputedStyleBorrowed;
 typedef mozilla::ComputedStyle const* ComputedStyleBorrowedOrNull;
 typedef ServoComputedData const* ServoComputedDataBorrowed;
 
 struct MOZ_MUST_USE_TYPE ComputedStyleStrong
 {
   mozilla::ComputedStyle* mPtr;
   already_AddRefed<mozilla::ComputedStyle> Consume();
@@ -264,27 +268,28 @@ struct MOZ_MUST_USE_TYPE ComputedStyleSt
   DECL_BORROWED_REF_TYPE_FOR(type_)       \
   DECL_BORROWED_MUT_REF_TYPE_FOR(type_)
 
 #define DECL_NULLABLE_OWNED_REF_TYPE_FOR(type_)    \
   typedef type_* type_##OwnedOrNull;               \
   DECL_NULLABLE_BORROWED_REF_TYPE_FOR(type_)       \
   DECL_NULLABLE_BORROWED_MUT_REF_TYPE_FOR(type_)
 
+#define SERVO_BOXED_TYPE(name_, type_)    \
+  DECL_OWNED_REF_TYPE_FOR(type_)          \
+  DECL_NULLABLE_OWNED_REF_TYPE_FOR(type_)
+#include "mozilla/ServoBoxedTypeList.h"
+#undef SERVO_BOXED_TYPE
+
 // This is a reference to a reference of RawServoDeclarationBlock, which
 // corresponds to Option<&Arc<Locked<RawServoDeclarationBlock>>> in Servo side.
 DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoDeclarationBlockStrong)
-DECL_OWNED_REF_TYPE_FOR(RawServoAuthorStyles)
-DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoAuthorStyles)
-DECL_OWNED_REF_TYPE_FOR(RawServoStyleSet)
-DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoStyleSet)
 DECL_NULLABLE_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
 DECL_OWNED_REF_TYPE_FOR(StyleChildrenIterator)
 DECL_OWNED_REF_TYPE_FOR(ServoElementSnapshot)
-DECL_OWNED_REF_TYPE_FOR(RawServoAnimationValueMap)
 
 // We don't use BorrowedMut because the nodes may alias
 // Servo itself doesn't directly read or mutate these;
 // it only asks Gecko to do so. In case we wish to in
 // the future, we should ensure that things being mutated
 // are protected from noalias violations by a cell type
 DECL_BORROWED_REF_TYPE_FOR(RawGeckoNode)
 DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawGeckoNode)
@@ -314,25 +319,16 @@ DECL_BORROWED_REF_TYPE_FOR(nsTimingFunct
 DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoFontFaceRuleList)
 DECL_BORROWED_REF_TYPE_FOR(RawGeckoAnimationPropertySegment)
 DECL_BORROWED_REF_TYPE_FOR(RawGeckoComputedTiming)
 DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoServoStyleRuleList)
 DECL_BORROWED_MUT_REF_TYPE_FOR(nsCSSPropertyIDSet)
 DECL_BORROWED_REF_TYPE_FOR(RawGeckoCSSPropertyIDList)
 DECL_BORROWED_REF_TYPE_FOR(nsXBLBinding)
 DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoStyleChildrenIterator)
-DECL_OWNED_REF_TYPE_FOR(RawServoSelectorList)
-DECL_BORROWED_REF_TYPE_FOR(RawServoSelectorList)
-DECL_OWNED_REF_TYPE_FOR(RawServoSourceSizeList)
-DECL_BORROWED_REF_TYPE_FOR(RawServoSourceSizeList)
-DECL_NULLABLE_BORROWED_REF_TYPE_FOR(RawServoSourceSizeList)
-DECL_OWNED_REF_TYPE_FOR(StyleUseCounters)
-DECL_NULLABLE_OWNED_REF_TYPE_FOR(StyleUseCounters)
-DECL_BORROWED_REF_TYPE_FOR(StyleUseCounters)
-DECL_NULLABLE_BORROWED_REF_TYPE_FOR(StyleUseCounters)
 
 #undef DECL_ARC_REF_TYPE_FOR
 #undef DECL_OWNED_REF_TYPE_FOR
 #undef DECL_NULLABLE_OWNED_REF_TYPE_FOR
 #undef DECL_BORROWED_REF_TYPE_FOR
 #undef DECL_NULLABLE_BORROWED_REF_TYPE_FOR
 #undef DECL_BORROWED_MUT_REF_TYPE_FOR
 #undef DECL_NULLABLE_BORROWED_MUT_REF_TYPE_FOR
@@ -350,37 +346,31 @@ DECL_NULLABLE_BORROWED_REF_TYPE_FOR(Styl
     static void Release(type_* aPtr) {               \
       Servo_##name_##_Release(aPtr);                 \
     }                                                \
   };                                                 \
   }
 #include "mozilla/ServoArcTypeList.h"
 #undef SERVO_ARC_TYPE
 
-#define DEFINE_BOXED_TYPE(name_, type_)                     \
+#define SERVO_BOXED_TYPE(name_, type_)                      \
   extern "C" void Servo_##name_##_Drop(type_##Owned ptr);   \
   namespace mozilla {                                       \
   template<>                                                \
   class DefaultDelete<type_>                                \
   {                                                         \
   public:                                                   \
     void operator()(type_* aPtr) const                      \
     {                                                       \
       Servo_##name_##_Drop(aPtr);                           \
     }                                                       \
   };                                                        \
   }
-
-DEFINE_BOXED_TYPE(StyleSet, RawServoStyleSet);
-DEFINE_BOXED_TYPE(AuthorStyles, RawServoAuthorStyles);
-DEFINE_BOXED_TYPE(SelectorList, RawServoSelectorList);
-DEFINE_BOXED_TYPE(SourceSizeList, RawServoSourceSizeList);
-DEFINE_BOXED_TYPE(UseCounters, StyleUseCounters);
-
-#undef DEFINE_BOXED_TYPE
+#include "mozilla/ServoBoxedTypeList.h"
+#undef SERVO_BOXED_TYPE
 
 #define DEFINE_ARRAY_TYPE_FOR(type_)                                \
   struct nsTArrayBorrowed_##type_ {                                 \
     nsTArray<type_>* mArray;                                        \
     MOZ_IMPLICIT nsTArrayBorrowed_##type_(nsTArray<type_>* aArray)  \
       : mArray(aArray) {}                                           \
   }
 DEFINE_ARRAY_TYPE_FOR(uintptr_t);
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -222,16 +222,17 @@ whitelist-vars = [
     "kNameSpaceID_.*",
     "kGenericFont_.*",
     "kPresContext_.*",
     "nsContentUtils_.*",
     "GECKO_IS_NIGHTLY",
 ]
 whitelist-types = [
     "RawGecko.*",
+    "RawServoAnimationValueMap",  # TODO(heycam): Handle this elsewhere.
     "mozilla::DeclarationBlockMutationClosure",
     "mozilla::AnimationPropertySegment",
     "mozilla::AnonymousCounterStyle",
     "mozilla::AtomArray",
     "mozilla::ComputedTiming",
     "mozilla::ComputedTimingFunction",
     "mozilla::ComputedTimingFunction::BeforeFlag",
     "mozilla::SeenPtrs",
@@ -645,28 +646,21 @@ structs-types = [
     "InheritTarget",
     "DocumentMatchingFunction",
     "StyleAnimation",
     "StyleRuleInclusion",
     "nsStyleTransformMatrix::MatrixTransformOperator",
     "RawGeckoGfxMatrix4x4",
     "FontFamilyName",
     "mozilla::SharedFontList",
+    "RawServoAnimationValueMap",
 ]
 array-types = [
     { cpp-type = "uintptr_t", rust-type = "usize" },
 ]
-servo-owned-types = [
-    { name = "RawServoStyleSet", opaque = true },
-    { name = "RawServoAuthorStyles", opaque = true },
-    { name = "RawServoSelectorList", opaque = false },
-    { name = "RawServoSourceSizeList", opaque = false },
-    { name = "StyleUseCounters", opaque = false },
-    { name = "RawServoAnimationValueMap", opaque = true },
-]
 servo-immutable-borrow-types = [
     "RawGeckoNode",
     "RawGeckoElement",
     "RawGeckoDocument",
     "RawServoDeclarationBlockStrong",
     "RawGeckoPresContext",
     "RawGeckoXBLBinding",
 ]
@@ -680,15 +674,16 @@ servo-borrow-types = [
     "RawGeckoKeyframeList",
     "RawGeckoPropertyValuePairList",
     "RawGeckoComputedKeyframeValuesList",
     "RawGeckoFontFaceRuleList",
     "RawGeckoServoStyleRuleList",
     "RawGeckoServoAnimationValueList",
     "RawGeckoStyleAnimationList",
     "RawGeckoStyleChildrenIterator",
+    "RawServoAnimationValueMap",
 ]
 fixups = [
     # Remap the templated string type to the helper type
     { pat = "\\bnsTString\\s*<\\s*u16\\s*>", rep = "nsString" },
     # hack for gecko-owned string
     { pat = "<\\s*nsString\\s*", rep = "<nsStringRepr" },
 ]
new file mode 100644
--- /dev/null
+++ b/layout/style/ServoBoxedTypeList.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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/. */
+
+/* a list of all Servo Box<T> types used across bindings, for preprocessing */
+
+// The first argument is the name of the Servo type used inside the Box.
+// This doesn't need to be accurate; it's only used to generate nice looking
+// FFI function names.
+//
+// The second argument is the name of an opaque Gecko type that will
+// correspond to the Servo type used inside the Box.  The convention for the
+// the name of the opaque Gecko type is "RawServo{Type}", where {Type} is
+// the name of the Servo type or something close to it.
+//
+// See the comment at the top of ServoBindingTypes.h for how to use these.
+//
+// If you add an entry to this file, you should also add impls of HasFFI
+// (with FFIType equal to ::gecko_bindings::structs::RawServo{Type}),
+// HasSimpleFFI, and HasBoxFFI to the Servo type. You will also need to
+// add a Servo_{FriendlyServoName}_Drop function to servo/ports/gecko/glue.rs.
+//
+// TODO(heycam): Do some of this automatically.
+
+SERVO_BOXED_TYPE(StyleSet, RawServoStyleSet)
+SERVO_BOXED_TYPE(AuthorStyles, RawServoAuthorStyles)
+SERVO_BOXED_TYPE(SelectorList, RawServoSelectorList)
+SERVO_BOXED_TYPE(SourceSizeList, RawServoSourceSizeList)
+SERVO_BOXED_TYPE(UseCounters, StyleUseCounters)
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -87,16 +87,17 @@ EXPORTS.mozilla += [
     'MappedDeclarations.h',
     'MediaFeatureChange.h',
     'PostTraversalTask.h',
     'PreloadedStyleSheet.h',
     'RustCell.h',
     'ServoArcTypeList.h',
     'ServoBindings.h',
     'ServoBindingTypes.h',
+    'ServoBoxedTypeList.h',
     'ServoComputedData.h',
     'ServoComputedDataInlines.h',
     'ServoCSSParser.h',
     'ServoCSSRuleList.h',
     'ServoElementSnapshot.h',
     'ServoElementSnapshotTable.h',
     'ServoStyleSet.h',
     'ServoStyleSetInlines.h',
--- a/servo/components/style/build_gecko.rs
+++ b/servo/components/style/build_gecko.rs
@@ -295,47 +295,58 @@ mod bindings {
         }
         let bytes = result.into_bytes();
         File::create(&out_file)
             .unwrap()
             .write_all(&bytes)
             .expect("Unable to write output");
     }
 
-    fn get_arc_types() -> Vec<String> {
+    fn get_types(filename: &str, macro_name: &str) -> Vec<String> {
         // Read the file
-        let mut list_file = File::open(DISTDIR_PATH.join("include/mozilla/ServoArcTypeList.h"))
-            .expect("Unable to open ServoArcTypeList.h");
+        let path = DISTDIR_PATH.join("include/mozilla/").join(filename);
+        let mut list_file = File::open(path)
+            .expect(&format!("Unable to open {}", filename));
         let mut content = String::new();
         list_file
             .read_to_string(&mut content)
-            .expect("Fail to read ServoArcTypeList.h");
+            .expect(&format!("Failed to read {}", filename));
         // Remove comments
         let block_comment_re = Regex::new(r#"(?s)/\*.*?\*/"#).unwrap();
         let line_comment_re = Regex::new(r#"//.*"#).unwrap();
         let content = block_comment_re.replace_all(&content, "");
         let content = line_comment_re.replace_all(&content, "");
         // Extract the list
-        let re = Regex::new(r#"^SERVO_ARC_TYPE\(\w+,\s*(\w+)\)$"#).unwrap();
+        let re_string = format!(r#"^{}\(\w+,\s*(\w+)\)$"#, macro_name);
+        let re = Regex::new(&re_string).unwrap();
         content
             .lines()
             .map(|line| line.trim())
             .filter(|line| !line.is_empty())
             .map(|line| {
                 re.captures(&line)
                     .expect(&format!(
-                        "Unrecognized line in ServoArcTypeList.h: '{}'",
+                        "Unrecognized line in {}: '{}'",
+                        filename,
                         line
                     )).get(1)
                     .unwrap()
                     .as_str()
                     .to_string()
             }).collect()
     }
 
+    fn get_arc_types() -> Vec<String> {
+        get_types("ServoArcTypeList.h", "SERVO_ARC_TYPE")
+    }
+
+    fn get_boxed_types() -> Vec<String> {
+        get_types("ServoBoxedTypeList.h", "SERVO_BOXED_TYPE")
+    }
+
     struct BuilderWithConfig<'a> {
         builder: Builder,
         config: &'a Table,
         used_keys: HashSet<&'static str>,
     }
     impl<'a> BuilderWithConfig<'a> {
         fn new(builder: Builder, config: &'a Table) -> Self {
             BuilderWithConfig {
@@ -521,45 +532,42 @@ mod bindings {
             .handle_table_items("array-types", |builder, item| {
                 let cpp_type = item["cpp-type"].as_str().unwrap();
                 let rust_type = item["rust-type"].as_str().unwrap();
                 builder
                     .raw_line(format!(concat!("pub type nsTArrayBorrowed_{}<'a> = ",
                                               "&'a mut ::gecko_bindings::structs::nsTArray<{}>;"),
                                       cpp_type, rust_type))
             })
-            .handle_table_items("servo-owned-types", |mut builder, item| {
-                let name = item["name"].as_str().unwrap();
-                builder = builder.blacklist_type(format!("{}Owned", name))
-                    .raw_line(format!("pub type {0}Owned = ::gecko_bindings::sugar::ownership::Owned<{0}>;", name))
-                    .blacklist_type(format!("{}OwnedOrNull", name))
-                    .raw_line(format!(concat!("pub type {0}OwnedOrNull = ",
-                                              "::gecko_bindings::sugar::ownership::OwnedOrNull<{0}>;"), name))
-                    .mutable_borrowed_type(name);
-                if item["opaque"].as_bool().unwrap() {
-                    builder = builder.zero_size_type(name, &structs_types);
-                }
-                builder
-            })
             .handle_str_items("servo-immutable-borrow-types", |b, ty| b.borrowed_type(ty))
             // Right now the only immutable borrow types are ones which we import
             // from the |structs| module. As such, we don't need to create an opaque
             // type with zero_size_type. If we ever introduce immutable borrow types
             // which _do_ need to be opaque, we'll need a separate mode.
             .handle_str_items("servo-borrow-types", |b, ty| b.mutable_borrowed_type(ty))
             .get_builder();
         for ty in get_arc_types().iter() {
             builder = builder
                 .blacklist_type(format!("{}Strong", ty))
                 .raw_line(format!(
                     "pub type {0}Strong = ::gecko_bindings::sugar::ownership::Strong<{0}>;",
                     ty
                 )).borrowed_type(ty)
                 .zero_size_type(ty, &structs_types);
         }
+        for ty in get_boxed_types().iter() {
+            builder = builder
+                .blacklist_type(format!("{}Owned", ty))
+                .raw_line(format!("pub type {0}Owned = ::gecko_bindings::sugar::ownership::Owned<{0}>;", ty))
+                .blacklist_type(format!("{}OwnedOrNull", ty))
+                .raw_line(format!(concat!("pub type {0}OwnedOrNull = ",
+                                          "::gecko_bindings::sugar::ownership::OwnedOrNull<{0}>;"), ty))
+                .mutable_borrowed_type(ty)
+                .zero_size_type(ty, &structs_types);
+        }
         write_binding_file(builder, BINDINGS_FILE, &fixups);
     }
 
     fn generate_atoms() {
         let script = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap())
             .join("gecko")
             .join("regen_atoms.py");
         println!("cargo:rerun-if-changed={}", script.display());
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -4,17 +4,17 @@
 
 <%namespace name="helpers" file="/helpers.mako.rs" />
 
 <%
     from data import to_idl_name, SYSTEM_FONT_LONGHANDS, to_camel_case
     from itertools import groupby
 %>
 
-#[cfg(feature = "gecko")] use gecko_bindings::bindings::RawServoAnimationValueMap;
+#[cfg(feature = "gecko")] use gecko_bindings::structs::RawServoAnimationValueMap;
 #[cfg(feature = "gecko")] use gecko_bindings::structs::RawGeckoGfxMatrix4x4;
 #[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSPropertyID;
 #[cfg(feature = "gecko")] use gecko_bindings::sugar::ownership::{HasFFI, HasSimpleFFI};
 use itertools::{EitherOrBoth, Itertools};
 use num_traits::Zero;
 use properties::{CSSWideKeyword, PropertyDeclaration};
 use properties::longhands;
 use properties::longhands::font_weight::computed_value::T as FontWeight;