Bug 1498755 - Part 5: Split ServoCell out into a separate header, rename it, and clean it up a bit r=emilio
authorCameron McCormack <cam@mcc.id.au>
Sun, 14 Oct 2018 00:05:54 +0000
changeset 496940 7c22eed0a6de3dfaf527eda236dda01e064c1010
parent 496939 fb4ec4a85293a3f83fb5b8c37bf85da3d1b0b60d
child 496941 77e7f45a9c3d23544adec8ac3f986401d4c288fc
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [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 5: Split ServoCell out into a separate header, rename it, and clean it up a bit r=emilio Depends on D8646 Differential Revision: https://phabricator.services.mozilla.com/D8647
dom/base/Element.h
layout/style/RustCell.h
layout/style/ServoBindings.toml
layout/style/ServoTypes.h
layout/style/moz.build
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -11,17 +11,17 @@
  */
 
 #ifndef mozilla_dom_Element_h__
 #define mozilla_dom_Element_h__
 
 #include "mozilla/dom/FragmentOrElement.h" // for base class
 #include "nsChangeHint.h"                  // for enum
 #include "mozilla/EventStates.h"           // for member
-#include "mozilla/ServoTypes.h"
+#include "mozilla/RustCell.h"
 #include "mozilla/dom/DirectionalityUtils.h"
 #include "nsILinkHandler.h"
 #include "nsINodeList.h"
 #include "nsNodeUtils.h"
 #include "AttrArray.h"
 #include "mozilla/FlushType.h"
 #include "nsDOMAttributeMap.h"
 #include "nsPresContext.h"
@@ -55,16 +55,17 @@ class nsDOMTokenList;
 struct nsRect;
 class nsFocusManager;
 class nsGlobalWindowInner;
 class nsGlobalWindowOuter;
 class nsDOMCSSAttributeDeclaration;
 class nsISMILAttr;
 class nsDocument;
 class nsDOMStringMap;
+struct ServoNodeData;
 
 namespace mozilla {
 class DeclarationBlock;
 struct MutationClosureData;
 class TextEditor;
 namespace css {
   struct URLValue;
 } // namespace css
@@ -1979,17 +1980,17 @@ private:
   void AsElement() = delete;
 
   // Data members
   EventStates mState;
   // Per-node data managed by Servo.
   //
   // There should not be data on nodes that are in the flattened tree, or
   // descendants of display: none elements.
-  mozilla::ServoCell<ServoNodeData*> mServoData;
+  mozilla::RustCell<ServoNodeData*> mServoData;
 };
 
 class RemoveFromBindingManagerRunnable : public mozilla::Runnable
 {
 public:
   RemoveFromBindingManagerRunnable(nsBindingManager* aManager,
                                    nsIContent* aContent,
                                    nsIDocument* aDoc);
new file mode 100644
--- /dev/null
+++ b/layout/style/RustCell.h
@@ -0,0 +1,41 @@
+/* -*- 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/. */
+
+/* an object with the same layout as a Rust std::cell::Cell<T> */
+
+#ifndef mozilla_RustCell_h
+#define mozilla_RustCell_h
+
+namespace mozilla {
+
+/**
+ * Object with the same layout as std::cell::Cell<T>.
+ *
+ * ServoBindings.toml defines a mapping so that generated bindings use a
+ * real std::cell::Cell<T>.
+ *
+ * Note that while the layout matches, this doesn't have the same ABI as a
+ * std::cell::Cell<T>, so values of this type can't be passed over FFI
+ * functions.
+ */
+template<typename T>
+class RustCell
+{
+public:
+  RustCell()
+    : mValue()
+  {
+  }
+
+  T Get() const { return mValue; }
+
+private:
+  T mValue;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_RustCell_h
--- a/layout/style/ServoBindings.toml
+++ b/layout/style/ServoBindings.toml
@@ -437,18 +437,17 @@ opaque-types = [
     "gfxSize_Super",  # Ditto.
     "mozilla::StyleAnimationValue",
     "StyleAnimationValue", # pulls in a whole bunch of stuff we don't need in the bindings
     "mozilla::dom::.*Callback", # Pulls in ErrorResult and other things that
                                 # don't align properly on Linux 32-bit
     "mozilla::SchedulerGroup", # Non-standard-layout packing of field into superclass
 ]
 mapped-generic-types = [
-    { generic = true, gecko = "mozilla::ServoUnsafeCell", servo = "::std::cell::UnsafeCell" },
-    { generic = true, gecko = "mozilla::ServoCell", servo = "::std::cell::Cell" },
+    { generic = true, gecko = "mozilla::RustCell", servo = "::std::cell::Cell" },
     { generic = false, gecko = "ServoNodeData", servo = "AtomicRefCell<ElementData>" },
     { generic = false, gecko = "mozilla::ServoWritingMode", servo = "::logical_geometry::WritingMode" },
     { generic = false, gecko = "mozilla::ServoCustomPropertiesMap", servo = "Option<::servo_arc::Arc<::custom_properties::CustomPropertiesMap>>" },
     { generic = false, gecko = "mozilla::ServoRuleNode", servo = "Option<::rule_tree::StrongRuleNode>" },
     { generic = false, gecko = "mozilla::ServoVisitedStyle", servo = "Option<::servo_arc::RawOffsetArc<::properties::ComputedValues>>" },
     { generic = false, gecko = "mozilla::ServoComputedValueFlags", servo = "::properties::computed_value_flags::ComputedValueFlags" },
     { generic = true, gecko = "mozilla::ServoRawOffsetArc", servo = "::servo_arc::RawOffsetArc" },
     { generic = false, gecko = "ComputedStyleStrong", servo = "::gecko_bindings::sugar::ownership::Strong<::properties::ComputedValues>" },
--- a/layout/style/ServoTypes.h
+++ b/layout/style/ServoTypes.h
@@ -9,39 +9,18 @@
 
 #include "mozilla/TypedEnumBits.h"
 
 /*
  * Type definitions used to interact with Servo. This gets included by nsINode,
  * so don't add significant include dependencies to this file.
  */
 
-struct ServoNodeData;
 namespace mozilla {
 
-/*
- * Replaced types. These get mapped to associated Servo types in bindgen.
- */
-
-template<typename T>
-struct ServoUnsafeCell {
-  T value;
-
-  // Ensure that primitive types (i.e. pointers) get zero-initialized.
-  ServoUnsafeCell() : value() {};
-};
-
-template<typename T>
-struct ServoCell {
-  ServoUnsafeCell<T> value;
-  T Get() const { return value.value; }
-  void Set(T arg) { value.value = arg; }
-  ServoCell() : value() {};
-};
-
 // Indicates whether the Servo style system should expect the style on an element
 // to have already been resolved (i.e. via a parallel traversal), or whether it
 // may be lazily computed.
 enum class LazyComputeBehavior {
   Allow,
   Assert,
 };
 
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -83,16 +83,17 @@ EXPORTS.mozilla += [
     'DeclarationBlock.h',
     'DocumentStyleRootIterator.h',
     'GeckoBindings.h',
     'LayerAnimationInfo.h',
     'MappedDeclarations.h',
     'MediaFeatureChange.h',
     'PostTraversalTask.h',
     'PreloadedStyleSheet.h',
+    'RustCell.h',
     'ServoArcTypeList.h',
     'ServoBindings.h',
     'ServoBindingTypes.h',
     'ServoComputedData.h',
     'ServoComputedDataInlines.h',
     'ServoCSSParser.h',
     'ServoCSSRuleList.h',
     'ServoElementSnapshot.h',