Bug 1373018 - Part 10: stylo: Remove StyleSource; r?bholley draft
authorManish Goregaokar <manishearth@gmail.com>
Sat, 10 Jun 2017 22:27:45 -0700
changeset 595125 3447e52dabfef140b786c3b06f4012f94138ee32
parent 595124 07f5c386cc10f148337d3cbe9627c755f8909d38
child 595126 5f9d0eeda93d8064c669669aa889d8ada4cc4224
child 595173 9f8e3d6c1522c46ecaf513e174f9833249920ef1
push id64258
push userbmo:manishearth@gmail.com
push dateFri, 16 Jun 2017 03:04:15 +0000
reviewersbholley
bugs1373018
milestone56.0a1
Bug 1373018 - Part 10: stylo: Remove StyleSource; r?bholley MozReview-Commit-ID: 4IcROeDNoBA
dom/animation/EffectCompositor.cpp
dom/animation/KeyframeEffectReadOnly.cpp
dom/smil/nsSMILCSSProperty.cpp
dom/smil/nsSMILCSSValueType.cpp
layout/base/ServoRestyleManager.cpp
layout/generic/nsFrame.cpp
layout/inspector/inDOMUtils.cpp
layout/style/GeckoStyleContext.cpp
layout/style/GeckoStyleContext.h
layout/style/ServoStyleContext.h
layout/style/ServoStyleSet.cpp
layout/style/StyleAnimationValue.cpp
layout/style/StyleContextSource.h
layout/style/moz.build
layout/style/nsComputedDOMStyle.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleContext.cpp
layout/style/nsStyleContext.h
layout/style/nsStyleContextInlines.h
layout/style/nsStyleTransformMatrix.cpp
layout/tables/nsTableColGroupFrame.cpp
--- a/dom/animation/EffectCompositor.cpp
+++ b/dom/animation/EffectCompositor.cpp
@@ -165,17 +165,17 @@ FindAnimationsForCompositor(const nsIFra
   //
   // Those cases are probably not important but just to be safe, let's make
   // sure the cascade is up to date since if it *is* up to date, this is
   // basically a no-op.
   Maybe<NonOwningAnimationTarget> pseudoElement =
     EffectCompositor::GetAnimationElementAndPseudoForFrame(aFrame);
   if (pseudoElement) {
     StyleBackendType backend =
-      aFrame->StyleContext()->StyleSource().IsServoComputedValues()
+      aFrame->StyleContext()->IsServo()
       ? StyleBackendType::Servo
       : StyleBackendType::Gecko;
     EffectCompositor::MaybeUpdateCascadeResults(backend,
                                                 pseudoElement->mElement,
                                                 pseudoElement->mPseudoType,
                                                 aFrame->StyleContext());
   }
 
--- a/dom/animation/KeyframeEffectReadOnly.cpp
+++ b/dom/animation/KeyframeEffectReadOnly.cpp
@@ -297,17 +297,17 @@ KeyframeEffectReadOnly::UpdateProperties
   MOZ_ASSERT(aStyleContext);
 
   if (!mDocument->IsStyledByServo()) {
     DoUpdateProperties(Move(aStyleContext));
     return;
   }
 
   const ServoComputedValues* currentStyle =
-    aStyleContext->StyleSource().AsServoComputedValues();
+    aStyleContext->ComputedValues();
 
   DoUpdateProperties(currentStyle);
 }
 
 void
 KeyframeEffectReadOnly::UpdateProperties(
   const ServoComputedValues* aComputedValues)
 {
--- a/dom/smil/nsSMILCSSProperty.cpp
+++ b/dom/smil/nsSMILCSSProperty.cpp
@@ -64,17 +64,17 @@ nsSMILCSSProperty::GetBaseValue() const
     nsSMILValue tmpVal(&nsSMILCSSValueType::sSingleton);
     Swap(baseValue, tmpVal);
     return baseValue;
   }
 
   AnimationValue computedValue;
   if (mElement->IsStyledByServo()) {
     const ServoComputedValues* currentStyle =
-      mBaseStyleContext->StyleSource().AsServoComputedValues();
+      mBaseStyleContext->ComputedValues();
     computedValue.mServo =
       Servo_ComputedValues_ExtractAnimationValue(currentStyle, mPropID)
       .Consume();
     if (!computedValue.mServo) {
       return baseValue;
     }
   } else if (!StyleAnimationValue::ExtractComputedValue(mPropID,
                                                         mBaseStyleContext,
--- a/dom/smil/nsSMILCSSValueType.cpp
+++ b/dom/smil/nsSMILCSSValueType.cpp
@@ -696,17 +696,17 @@ ValueFromStringHelper(nsCSSPropertyID aP
                         ParsingMode::AllowAllNumericValues,
                         doc->GetCompatibilityMode()).Consume();
   if (!servoDeclarationBlock) {
     return result;
   }
 
   // Get a suitable style context for Servo
   const ServoComputedValues* currentStyle =
-    aStyleContext->StyleSource().AsServoComputedValues();
+    aStyleContext->ComputedValues();
 
   // Compute value
   aPresContext->StyleSet()->AsServo()->GetAnimationValues(servoDeclarationBlock,
                                                           aTargetElement,
                                                           currentStyle,
                                                           result);
   if (result.IsEmpty()) {
     return result;
--- a/layout/base/ServoRestyleManager.cpp
+++ b/layout/base/ServoRestyleManager.cpp
@@ -377,17 +377,17 @@ ServoRestyleManager::ProcessPostTraversa
   //
   // Otherwise we should probably encode that information somehow to avoid
   // expensive checks in the common case.
   //
   // Also, we're going to need to check for pseudos of display: contents
   // elements, though that is buggy right now even in non-stylo mode, see
   // bug 1251799.
   const bool recreateContext = oldStyleContext &&
-    oldStyleContext->StyleSource().AsServoComputedValues() != computedValues;
+    oldStyleContext->ComputedValues() != computedValues;
 
   RefPtr<nsStyleContext> newContext = nullptr;
   if (recreateContext) {
     MOZ_ASSERT(styleFrame || displayContentsNode);
 
     auto pseudo = aElement->GetPseudoElementType();
     nsIAtom* pseudoTag = pseudo == CSSPseudoElementType::NotPseudo
       ? nullptr : nsCSSPseudoElements::GetPseudoAtom(pseudo);
--- a/layout/generic/nsFrame.cpp
+++ b/layout/generic/nsFrame.cpp
@@ -7193,17 +7193,17 @@ nsIFrame::ListGeneric(nsACString& aTo, c
   aTo += nsPrintfCString(" [sc=%p", static_cast<void*>(mStyleContext));
   if (mStyleContext) {
     nsIAtom* pseudoTag = mStyleContext->GetPseudo();
     if (pseudoTag) {
       nsAutoString atomString;
       pseudoTag->ToString(atomString);
       aTo += nsPrintfCString("%s", NS_LossyConvertUTF16toASCII(atomString).get());
     }
-    if (mStyleContext->StyleSource().IsGeckoRuleNodeOrNull()) {
+    if (mStyleContext->IsGecko()) {
       if (!mStyleContext->GetParent() ||
           (GetParent() && GetParent()->StyleContext() != mStyleContext->GetParent())) {
         aTo += nsPrintfCString("^%p", mStyleContext->GetParent());
         if (mStyleContext->GetParent()) {
           aTo += nsPrintfCString("^%p", mStyleContext->GetParent()->GetParent());
           if (mStyleContext->GetParent()->GetParent()) {
             aTo += nsPrintfCString("^%p", mStyleContext->GetParent()->GetParent()->GetParent());
           }
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -238,24 +238,23 @@ inDOMUtils::GetCSSStyleRules(nsIDOMEleme
   RefPtr<nsStyleContext> styleContext =
     GetCleanStyleContextForElement(element, pseudoElt);
   if (!styleContext) {
     // This can fail for elements that are not in the document or
     // if the document they're in doesn't have a presshell.  Bail out.
     return NS_OK;
   }
 
-  NonOwningStyleContextSource source = styleContext->StyleSource();
-  if (source.IsNull()) {
-    return NS_OK;
-  }
 
   nsCOMPtr<nsIMutableArray> rules = nsArray::Create();
-  if (source.IsGeckoRuleNodeOrNull()) {
-    nsRuleNode* ruleNode = source.AsGeckoRuleNode();
+  if (auto gecko = styleContext->GetAsGecko()) {
+    nsRuleNode* ruleNode = gecko->RuleNode();
+    if (!ruleNode) {
+      return NS_OK;
+    }
 
     AutoTArray<nsRuleNode*, 16> ruleNodes;
     while (!ruleNode->IsRoot()) {
       ruleNodes.AppendElement(ruleNode);
       ruleNode = ruleNode->GetParent();
     }
 
     for (nsRuleNode* ruleNode : Reversed(ruleNodes)) {
--- a/layout/style/GeckoStyleContext.cpp
+++ b/layout/style/GeckoStyleContext.cpp
@@ -207,17 +207,17 @@ GeckoStyleContext::FindChildWithRules(co
 
   RefPtr<GeckoStyleContext> result;
   MOZ_ASSERT(aSource);
   GeckoStyleContext *list = aSource->IsRoot() ? mEmptyChild : mChild;
 
   if (list) {
     GeckoStyleContext *child = list;
     do {
-      if (child->StyleSource() == aSource &&
+      if (child->RuleNode() == aSource &&
           child->mPseudoTag == aPseudoTag &&
           !child->IsStyleIfVisited() &&
           child->RelevantLinkVisited() == aRelevantLinkVisited) {
         bool match = false;
         if (aSourceIfVisited) {
           match = child->GetStyleIfVisited() &&
                   child->GetStyleIfVisited()->RuleNode() == aSourceIfVisited;
         } else {
--- a/layout/style/GeckoStyleContext.h
+++ b/layout/style/GeckoStyleContext.h
@@ -89,20 +89,16 @@ public:
   void LogChildStyleContextTree(uint32_t aStructs) const;
 #endif
 
   // Only called for Gecko-backed nsStyleContexts.
   void ApplyStyleFixups(bool aSkipParentDisplayBasedStyleFixup);
 
   bool HasNoChildren() const;
 
-  NonOwningStyleContextSource StyleSource() const {
-    return NonOwningStyleContextSource(mRuleNode);
-  }
-
   nsRuleNode* RuleNode() const {
     MOZ_ASSERT(mRuleNode);
     return mRuleNode;
   }
 
   ~GeckoStyleContext() {
     Destructor();
   }
--- a/layout/style/ServoStyleContext.h
+++ b/layout/style/ServoStyleContext.h
@@ -18,19 +18,16 @@ public:
                     nsIAtom* aPseudoTag,
                     CSSPseudoElementType aPseudoType,
                     already_AddRefed<ServoComputedValues> aComputedValues);
 
   nsPresContext* PresContext() const {
     return mPresContext;
   }
 
-  NonOwningStyleContextSource StyleSource() const {
-    return NonOwningStyleContextSource(mSource);
-  }
   ServoComputedValues* ComputedValues() const {
     return mSource;
   }
   ~ServoStyleContext() {
     Destructor();
   }
 private:
   nsPresContext* mPresContext;
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -436,33 +436,33 @@ ServoStyleSet::ResolveStyleForText(nsICo
   MOZ_ASSERT(aTextNode->GetParent());
   MOZ_ASSERT(aParentContext);
 
   // Gecko expects text node style contexts to be like elements that match no
   // rules: inherit the inherit structs, reset the reset structs. This is cheap
   // enough to do on the main thread, which means that the parallel style system
   // can avoid worrying about text nodes.
   const ServoComputedValues* parentComputedValues =
-    aParentContext->StyleSource().AsServoComputedValues();
+    aParentContext->ComputedValues();
   RefPtr<ServoComputedValues> computedValues =
     Servo_ComputedValues_Inherit(mRawSet.get(),
                                  parentComputedValues,
                                  InheritTarget::Text).Consume();
 
   return GetContext(computedValues.forget(), aParentContext,
                     nsCSSAnonBoxes::mozText,
                     CSSPseudoElementType::InheritingAnonBox,
                     nullptr);
 }
 
 already_AddRefed<nsStyleContext>
 ServoStyleSet::ResolveStyleForFirstLetterContinuation(nsStyleContext* aParentContext)
 {
   const ServoComputedValues* parent =
-    aParentContext->StyleSource().AsServoComputedValues();
+    aParentContext->ComputedValues();
   RefPtr<ServoComputedValues> computedValues =
     Servo_ComputedValues_Inherit(mRawSet.get(),
                                  parent,
                                  InheritTarget::FirstLetterContinuation)
                                  .Consume();
   MOZ_ASSERT(computedValues);
 
   return GetContext(computedValues.forget(), aParentContext,
@@ -566,17 +566,17 @@ ServoStyleSet::ResolveInheritingAnonymou
              !nsCSSAnonBoxes::IsNonInheritingAnonBox(aPseudoTag));
 
   UpdateStylistIfNeeded();
 
   bool skipFixup =
     nsCSSAnonBoxes::AnonBoxSkipsParentDisplayBasedStyleFixup(aPseudoTag);
 
   const ServoComputedValues* parentStyle =
-    aParentContext ? aParentContext->StyleSource().AsServoComputedValues()
+    aParentContext ? aParentContext->ComputedValues()
                    : nullptr;
   RefPtr<ServoComputedValues> computedValues =
     Servo_ComputedValues_GetForAnonymousBox(parentStyle, aPseudoTag, skipFixup,
                                             mRawSet.get()).Consume();
 #ifdef DEBUG
   if (!computedValues) {
     nsString pseudo;
     aPseudoTag->ToString(pseudo);
--- a/layout/style/StyleAnimationValue.cpp
+++ b/layout/style/StyleAnimationValue.cpp
@@ -4784,17 +4784,17 @@ StyleAnimationValue::ExtractComputedValu
     }
     case eStyleAnimType_Discrete: {
       if (aProperty == eCSSProperty_visibility) {
         aComputedValue.SetIntValue(
           static_cast<const nsStyleVisibility*>(styleStruct)->mVisible,
           eUnit_Visibility);
         return true;
       }
-      if (aStyleContext->StyleSource().IsServoComputedValues()) {
+      if (aStyleContext->IsServo()) {
         NS_ERROR("stylo: extracting discretely animated values not supported");
         return false;
       }
       auto cssValue = MakeUnique<nsCSSValue>(eCSSUnit_Unset);
       aStyleContext->RuleNode()->GetDiscretelyAnimatedCSSValue(aProperty,
                                                                cssValue.get());
       aComputedValue.SetAndAdoptCSSValueValue(cssValue.release(),
                                               eUnit_DiscreteCSSValue);
@@ -5355,31 +5355,31 @@ AnimationValue::FromString(nsCSSProperty
     return result;
   }
 
   // GetStyleContext() flushes style, so we shouldn't assume that any
   // non-owning references we have are still valid.
   RefPtr<nsStyleContext> styleContext =
     nsComputedDOMStyle::GetStyleContext(aElement, nullptr, shell);
 
-  if (styleContext->StyleSource().IsServoComputedValues()) {
+  if (auto servoContext = styleContext->GetAsServo()) {
     nsPresContext* presContext = shell->GetPresContext();
     if (!presContext) {
       return result;
     }
 
     RefPtr<RawServoDeclarationBlock> declarations =
       KeyframeUtils::ParseProperty(aProperty, aValue, doc);
 
     if (!declarations) {
       return result;
     }
 
     const ServoComputedValues* computedValues =
-      styleContext->StyleSource().AsServoComputedValues();
+      servoContext->ComputedValues();
     result.mServo = presContext->StyleSet()
                                ->AsServo()
                                ->ComputeAnimationValue(aElement,
                                                        declarations,
                                                        computedValues);
     return result;
   }
 
deleted file mode 100644
--- a/layout/style/StyleContextSource.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-#ifndef mozilla_StyleContextSource_h
-#define mozilla_StyleContextSource_h
-
-#include "mozilla/ServoBindingTypes.h"
-#include "nsRuleNode.h"
-
-namespace mozilla {
-
-// Tagged union between Gecko Rule Nodes and Servo Computed Values.
-//
-// The rule node is the node in the lexicographic tree of rule nodes
-// (the "rule tree") that indicates which style rules are used to
-// compute the style data, and in what cascading order.  The least
-// specific rule matched is the one whose rule node is a child of the
-// root of the rule tree, and the most specific rule matched is the
-// |mRule| member of the rule node.
-//
-// In the Servo case, we hold an atomically-refcounted handle to a
-// Servo ComputedValues struct, which is more or less the Servo equivalent
-// of an nsStyleContext.
-
-// Underlying pointer without any strong ownership semantics.
-struct NonOwningStyleContextSource
-{
-  MOZ_IMPLICIT NonOwningStyleContextSource(nsRuleNode* aRuleNode)
-    : mBits(reinterpret_cast<uintptr_t>(aRuleNode)) {}
-  explicit NonOwningStyleContextSource(const ServoComputedValues* aComputedValues)
-    : mBits(reinterpret_cast<uintptr_t>(aComputedValues) | 1) {}
-
-  bool operator==(const NonOwningStyleContextSource& aOther) const {
-    MOZ_ASSERT(IsServoComputedValues() == aOther.IsServoComputedValues(),
-               "Comparing Servo to Gecko - probably a bug");
-    return mBits == aOther.mBits;
-  }
-  bool operator!=(const NonOwningStyleContextSource& aOther) const {
-    return !(*this == aOther);
-  }
-
-  // We intentionally avoid exposing IsGeckoRuleNode() here, because that would
-  // encourage callers to do:
-  //
-  // if (source.IsGeckoRuleNode()) {
-  //   // Code that we would run unconditionally if it weren't for Servo.
-  // }
-  //
-  // We want these branches to compile away when MOZ_STYLO is disabled, but that
-  // won't happen if there's an implicit null-check.
-  bool IsNull() const { return !mBits; }
-  bool IsGeckoRuleNodeOrNull() const { return !IsServoComputedValues(); }
-  bool IsServoComputedValues() const {
-#ifdef MOZ_STYLO
-    return mBits & 1;
-#else
-    return false;
-#endif
-  }
-
-  nsRuleNode* AsGeckoRuleNode() const {
-    MOZ_ASSERT(IsGeckoRuleNodeOrNull() && !IsNull());
-    return reinterpret_cast<nsRuleNode*>(mBits);
-  }
-
-  const ServoComputedValues* AsServoComputedValues() const {
-    MOZ_ASSERT(IsServoComputedValues());
-    return reinterpret_cast<ServoComputedValues*>(mBits & ~1);
-  }
-
-private:
-  uintptr_t mBits;
-};
-
-} // namespace mozilla
-
-#endif // mozilla_StyleContextSource_h
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -124,17 +124,16 @@ EXPORTS.mozilla += [
     'ServoStyleSheet.h',
     'ServoSupportsRule.h',
     'ServoTypes.h',
     'ServoUtils.h',
     'SheetType.h',
     'StyleAnimationValue.h',
     'StyleBackendType.h',
     'StyleComplexColor.h',
-    'StyleContextSource.h',
     'StyleSetHandle.h',
     'StyleSetHandleInlines.h',
     'StyleSheet.h',
     'StyleSheetInfo.h',
     'StyleSheetInlines.h',
     'URLExtraData.h',
 ]
 
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -559,17 +559,17 @@ private:
  */
 static bool
 MustReresolveStyle(const nsStyleContext* aContext)
 {
   MOZ_ASSERT(aContext);
 
   if (aContext->HasPseudoElementData()) {
     if (!aContext->GetPseudo() ||
-        aContext->StyleSource().IsServoComputedValues()) {
+        aContext->IsServo()) {
       // TODO(emilio): When ::first-line is supported in Servo, we may want to
       // fix this to avoid re-resolving pseudo-element styles.
       return true;
     }
 
     return aContext->GetParent() &&
            aContext->GetParent()->HasPseudoElementData();
   }
@@ -866,17 +866,17 @@ nsComputedDOMStyle::UpdateCurrentStyleSo
 
       SetFrameStyleContext(mInnerFrame->StyleContext());
       NS_ASSERTION(mStyleContext, "Frame without style context?");
     }
   }
 
   if (!mStyleContext || MustReresolveStyle(mStyleContext)) {
 #ifdef DEBUG
-    if (mStyleContext && mStyleContext->StyleSource().IsGeckoRuleNodeOrNull()) {
+    if (mStyleContext && mStyleContext->IsGecko()) {
       // We want to check that going through this path because of
       // HasPseudoElementData is rare, because it slows us down a good
       // bit.  So check that we're really inside something associated
       // with a pseudo-element that contains elements.  (We also allow
       // the element to be NAC, just in case some chrome JS calls
       // getComputedStyle on a NAC-implemented pseudo.)
       nsStyleContext* topWithPseudoElementData = mStyleContext;
       while (topWithPseudoElementData->GetParent()->HasPseudoElementData()) {
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -10396,17 +10396,17 @@ nsRuleNode::GetDiscretelyAnimatedCSSValu
 }
 
 /* static */ bool
 nsRuleNode::HasAuthorSpecifiedRules(nsStyleContext* aStyleContext,
                                     uint32_t ruleTypeMask,
                                     bool aAuthorColorsAllowed)
 {
 #ifdef MOZ_STYLO
-  if (aStyleContext->StyleSource().IsServoComputedValues()) {
+  if (aStyleContext->IsServo()) {
     NS_WARNING("stylo: nsRuleNode::HasAuthorSpecifiedRules not implemented");
     return true;
   }
 #endif
 
   RefPtr<GeckoStyleContext> styleContext = aStyleContext->AsGecko();
 
   uint32_t inheritBits = 0;
--- a/layout/style/nsStyleContext.cpp
+++ b/layout/style/nsStyleContext.cpp
@@ -99,19 +99,24 @@ void
 nsStyleContext::FinishConstruction()
 {
   // This check has to be done "backward", because if it were written the
   // more natural way it wouldn't fail even when it needed to.
   static_assert((UINT64_MAX >> NS_STYLE_CONTEXT_TYPE_SHIFT) >=
                  static_cast<CSSPseudoElementTypeBase>(
                    CSSPseudoElementType::MAX),
                 "pseudo element bits no longer fit in a uint64_t");
-  MOZ_ASSERT(!StyleSource().IsNull());
 
 #ifdef DEBUG
+  if (auto servo = GetAsServo()) {
+    MOZ_ASSERT(servo->ComputedValues());
+  } else {
+    MOZ_ASSERT(RuleNode());
+  }
+
   static_assert(MOZ_ARRAY_LENGTH(nsStyleContext::sDependencyTable)
                   == nsStyleStructID_Length,
                 "Number of items in dependency table doesn't match IDs");
 #endif
 
   if (mParent) {
     mParent->AddChild(this);
   }
@@ -122,22 +127,22 @@ nsStyleContext::FinishConstruction()
   static_assert(NS_STYLE_INHERIT_MASK & NS_STYLE_INHERIT_BIT(LastItem),
                 "NS_STYLE_INHERIT_MASK must be bigger, and other bits shifted");
   #undef eStyleStruct_LastItem
 }
 
 void
 nsStyleContext::Destructor()
 {
+#ifdef DEBUG
   if (const GeckoStyleContext* gecko = GetAsGecko()) {
     NS_ASSERTION(gecko->HasNoChildren(), "destructing context with children");
   }
   MOZ_ASSERT(!IsServo() || !mCachedResetData);
 
-#ifdef DEBUG
   if (IsServo()) {
     MOZ_ASSERT(!mCachedResetData,
                "Servo shouldn't cache reset structs in nsStyleContext");
     for (const auto* data : mCachedInheritedData.mStyleStructs) {
       MOZ_ASSERT(!data,
                  "Servo shouldn't cache inherit structs in nsStyleContext");
     }
   }
@@ -570,20 +575,16 @@ nsStyleContext::CalcStyleDifference(nsSt
 }
 
 class MOZ_STACK_CLASS FakeStyleContext
 {
 public:
   explicit FakeStyleContext(const ServoComputedValues* aComputedValues)
     : mComputedValues(aComputedValues) {}
 
-  mozilla::NonOwningStyleContextSource StyleSource() const {
-    return mozilla::NonOwningStyleContextSource(mComputedValues);
-  }
-
   nsStyleContext* GetStyleIfVisited() {
     // Bug 1364484: Figure out what to do here for Stylo visited values.  We can
     // get the visited computed values:
     // RefPtr<ServoComputedValues> visitedComputedValues =
     //   Servo_ComputedValues_GetVisitedStyle(mComputedValues).Consume();
     // But what's the best way to create the nsStyleContext?
     return nullptr;
   }
@@ -683,22 +684,16 @@ void nsStyleContext::List(FILE* out, int
   if (aListDescendants) {
     if (GeckoStyleContext* gecko = GetAsGecko()) {
       gecko->ListDescendants(out, aIndent);
     }
   }
 }
 #endif
 
-NonOwningStyleContextSource
-nsStyleContext::StyleSource() const
-{
-  MOZ_STYLO_FORWARD(StyleSource, ())
-}
-
 // Overridden to prevent the global delete from being called, since the memory
 // came out of an nsIArena instead of the global delete operator's heap.
 void
 nsStyleContext::Destroy()
 {
   if (IsGecko()) {
     // Get the pres context.
     RefPtr<nsPresContext> presContext = PresContext();
--- a/layout/style/nsStyleContext.h
+++ b/layout/style/nsStyleContext.h
@@ -7,17 +7,16 @@
 
 #ifndef _nsStyleContext_h_
 #define _nsStyleContext_h_
 
 #include "mozilla/Assertions.h"
 #include "mozilla/RestyleLogging.h"
 #include "mozilla/ServoStyleSet.h"
 #include "mozilla/ServoUtils.h"
-#include "mozilla/StyleContextSource.h"
 #include "mozilla/StyleComplexColor.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsStyleSet.h"
 
 class nsIAtom;
 class nsPresContext;
 
 namespace mozilla {
@@ -265,16 +264,17 @@ public:
    * happen because it was inherited from the parent style context, or
    * because it was stored conditionally on the rule node.
    */
   bool HasCachedDependentStyleData(nsStyleStructID aSID) {
     return mBits & nsCachedStyleData::GetBitForSID(aSID);
   }
 
   inline nsRuleNode* RuleNode();
+  inline ServoComputedValues* ComputedValues();
 
   void AddStyleBit(const uint64_t& aBit) { mBits |= aBit; }
 
   /**
    * Define typesafe getter functions for each style struct by
    * preprocessing the list of style structs.  These functions are the
    * preferred way to get style data.  The macro creates functions like:
    *   const nsStyleBorder* StyleBorder();
@@ -433,18 +433,16 @@ public:
         cachedData = nullptr;
       }
     } else {
       cachedData = mCachedInheritedData.mStyleStructs[aSID];
     }
     return cachedData;
   }
 
-  mozilla::NonOwningStyleContextSource StyleSource() const;
-
 protected:
   // protected destructor to discourage deletion outside of Release()
   ~nsStyleContext() {}
   // Where the actual destructor lives
   // We use this instead of a real destructor because we need
   // this to be called *before* the subclass fields are destroyed
   // by the subclass destructor
   void Destructor();
@@ -461,17 +459,17 @@ protected:
   void RemoveChild(nsStyleContext* aChild);
 
   void SetStyleBits();
 
   const void* StyleStructFromServoComputedValues(nsStyleStructID aSID) {
     switch (aSID) {
 #define STYLE_STRUCT(name_, checkdata_cb_)                                    \
       case eStyleStruct_##name_:                                              \
-        return Servo_GetStyle##name_(StyleSource().AsServoComputedValues());
+        return Servo_GetStyle##name_(ComputedValues());
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT
       default:
         MOZ_ASSERT_UNREACHABLE("unexpected nsStyleStructID value");
         return nullptr;
     }
   }
 
--- a/layout/style/nsStyleContextInlines.h
+++ b/layout/style/nsStyleContextInlines.h
@@ -25,16 +25,23 @@ MOZ_DEFINE_STYLO_METHODS(nsStyleContext,
 
 nsRuleNode*
 nsStyleContext::RuleNode()
 {
     MOZ_RELEASE_ASSERT(IsGecko());
     return AsGecko()->RuleNode();
 }
 
+ServoComputedValues*
+nsStyleContext::ComputedValues()
+{
+    MOZ_RELEASE_ASSERT(IsServo());
+    return AsServo()->ComputedValues();
+}
+
 #define STYLE_STRUCT(name_, checkdata_cb_)                      \
 const nsStyle##name_ *                                          \
 nsStyleContext::Style##name_() {                                \
   return DoGetStyle##name_<true>();                             \
 }                                                               \
 const nsStyle##name_ *                                          \
 nsStyleContext::ThreadsafeStyle##name_() {                      \
   if (mozilla::ServoStyleSet::IsInServoTraversal()) {           \
@@ -47,38 +54,39 @@ const nsStyle##name_ * nsStyleContext::P
 }
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT
 
 // Helper functions for GetStyle* and PeekStyle*
 #define STYLE_STRUCT_INHERITED(name_, checkdata_cb_)                \
 template<bool aComputeData>                                         \
 const nsStyle##name_ * nsStyleContext::DoGetStyle##name_() {        \
-  if (IsGecko()) {                                                  \
+  if (auto gecko = GetAsGecko()) {                                  \
     const nsStyle##name_ * cachedData =                             \
       static_cast<nsStyle##name_*>(                                 \
         mCachedInheritedData.mStyleStructs[eStyleStruct_##name_]);  \
     if (cachedData) /* Have it cached already, yay */               \
       return cachedData;                                            \
     if (!aComputeData) {                                            \
       /* We always cache inherited structs on the context when we */\
       /* compute them. */                                           \
       return nullptr;                                               \
     }                                                               \
     /* Have the rulenode deal */                                    \
     AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_);                    \
     const nsStyle##name_ * newData =                                \
-      StyleSource().AsGeckoRuleNode()->                             \
+      gecko->RuleNode()->                                           \
         GetStyle##name_<aComputeData>(this->AsGecko(), mBits);      \
     /* always cache inherited data on the style context; the rule */\
     /* node set the bit in mBits for us if needed. */               \
     mCachedInheritedData.mStyleStructs[eStyleStruct_##name_] =      \
       const_cast<nsStyle##name_ *>(newData);                        \
     return newData;                                                 \
   }                                                                 \
+  auto servo = AsServo();                                           \
   /**                                                               \
    * Also (conservatively) set the owning bit in the parent style   \
    * context if we're a text node.                                  \
    *                                                                \
    * This causes the parent element's style context to cache any    \
    * inherited structs we request for a text node, which means we   \
    * don't have to compute change hints for the text node, as       \
    * handling the change on the parent element is sufficient.       \
@@ -103,57 +111,57 @@ const nsStyle##name_ * nsStyleContext::D
   }                                                                 \
                                                                     \
   const bool needToCompute = !(mBits & NS_STYLE_INHERIT_BIT(name_));\
   if (!aComputeData && needToCompute) {                             \
     return nullptr;                                                 \
   }                                                                 \
                                                                     \
   const nsStyle##name_* data =                                      \
-    Servo_GetStyle##name_(StyleSource().AsServoComputedValues());   \
+    Servo_GetStyle##name_(servo->ComputedValues());   \
   /* perform any remaining main thread work on the struct */        \
   if (needToCompute) {                                              \
     MOZ_ASSERT(NS_IsMainThread());                                  \
     MOZ_ASSERT(!mozilla::ServoStyleSet::IsInServoTraversal());      \
     const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext());  \
-    /* the Servo-backed StyleContextSource owns the struct */       \
+    /* the ServoStyleContext owns the struct */                     \
     AddStyleBit(NS_STYLE_INHERIT_BIT(name_));                       \
   }                                                                 \
   return data;                                                      \
 }
 
-#define STYLE_STRUCT_RESET(name_, checkdata_cb_)                    \
-template<bool aComputeData>                                         \
-const nsStyle##name_ * nsStyleContext::DoGetStyle##name_() {        \
-  if (IsGecko()) {                                                  \
-    if (mCachedResetData) {                                         \
-      const nsStyle##name_ * cachedData =                           \
-        static_cast<nsStyle##name_*>(                               \
-          mCachedResetData->mStyleStructs[eStyleStruct_##name_]);   \
-      if (cachedData) /* Have it cached already, yay */             \
-        return cachedData;                                          \
-    }                                                               \
-    /* Have the rulenode deal */                                    \
-    AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_);                    \
-    return StyleSource().AsGeckoRuleNode()->                        \
-      GetStyle##name_<aComputeData>(this->AsGecko());               \
-  }                                                                 \
-  const bool needToCompute = !(mBits & NS_STYLE_INHERIT_BIT(name_));\
-  if (!aComputeData && needToCompute) {                             \
-    return nullptr;                                                 \
-  }                                                                 \
-  const nsStyle##name_* data =                                      \
-    Servo_GetStyle##name_(StyleSource().AsServoComputedValues());   \
-  /* perform any remaining main thread work on the struct */        \
-  if (needToCompute) {                                              \
-    const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext());  \
-    /* the Servo-backed StyleContextSource owns the struct */       \
-    AddStyleBit(NS_STYLE_INHERIT_BIT(name_));                       \
-  }                                                                 \
-  return data;                                                      \
+#define STYLE_STRUCT_RESET(name_, checkdata_cb_)                              \
+template<bool aComputeData>                                                   \
+const nsStyle##name_ * nsStyleContext::DoGetStyle##name_() {                  \
+  if (auto gecko = GetAsGecko()) {                                            \
+    if (mCachedResetData) {                                                   \
+      const nsStyle##name_ * cachedData =                                     \
+        static_cast<nsStyle##name_*>(                                         \
+          mCachedResetData->mStyleStructs[eStyleStruct_##name_]);             \
+      if (cachedData) /* Have it cached already, yay */                       \
+        return cachedData;                                                    \
+    }                                                                         \
+    /* Have the rulenode deal */                                              \
+    AUTO_CHECK_DEPENDENCY(eStyleStruct_##name_);                              \
+    return gecko->RuleNode()->GetStyle##name_<aComputeData>(this->AsGecko()); \
+  }                                                                           \
+  auto servo = AsServo();                                                     \
+  const bool needToCompute = !(mBits & NS_STYLE_INHERIT_BIT(name_));          \
+  if (!aComputeData && needToCompute) {                                       \
+    return nullptr;                                                           \
+  }                                                                           \
+  const nsStyle##name_* data =                                                \
+    Servo_GetStyle##name_(servo->ComputedValues());                           \
+  /* perform any remaining main thread work on the struct */                  \
+  if (needToCompute) {                                                        \
+    const_cast<nsStyle##name_*>(data)->FinishStyle(PresContext());            \
+    /* the ServoStyleContext owns the struct */                               \
+    AddStyleBit(NS_STYLE_INHERIT_BIT(name_));                                 \
+  }                                                                           \
+  return data;                                                                \
 }
 #include "nsStyleStructList.h"
 #undef STYLE_STRUCT_RESET
 #undef STYLE_STRUCT_INHERITED
 
 
 nsPresContext*
 nsStyleContext::PresContext() const
--- a/layout/style/nsStyleTransformMatrix.cpp
+++ b/layout/style/nsStyleTransformMatrix.cpp
@@ -509,17 +509,17 @@ ProcessMatrixOperator(Matrix4x4& aMatrix
                                                     aContains3dTransform);
     return matrix;
   };
 
   Matrix4x4 matrix1 = readTransform(aData->Item(1));
   Matrix4x4 matrix2 = readTransform(aData->Item(2));
   double progress = aData->Item(3).GetPercentValue();
 
-  if (aContext && aContext->StyleSource().IsServoComputedValues()) {
+  if (aContext && aContext->IsServo()) {
     aMatrix =
       OperateTransformMatrixByServo<Operator>(matrix1, matrix2, progress)
         * aMatrix;
     return;
   }
 
   aMatrix =
     OperateTransformMatrix<Operator>(matrix1, matrix2, progress) * aMatrix;
--- a/layout/tables/nsTableColGroupFrame.cpp
+++ b/layout/tables/nsTableColGroupFrame.cpp
@@ -292,17 +292,17 @@ nsTableColGroupFrame::RemoveFrame(ChildL
       contentRemoval = true;
       // Remove any anonymous column frames this <col> produced via a colspan
       nsTableColFrame* col = colFrame->GetNextCol();
       nsTableColFrame* nextCol;
       while (col && col->GetColType() == eColAnonymousCol) {
 #ifdef DEBUG
         nsIFrame* providerFrame;
         nsStyleContext* psc = colFrame->GetParentStyleContext(&providerFrame);
-        if (psc->StyleSource().IsGeckoRuleNodeOrNull()) {
+        if (psc->IsGecko()) {
           // This check code is useful only in Gecko-backed style system.
           if (static_cast<nsStyleContext*>(colFrame->StyleContext()->GetParent()) == psc) {
             NS_ASSERTION(col->StyleContext() == colFrame->StyleContext() &&
                          col->GetContent() == colFrame->GetContent(),
                          "How did that happen??");
           }
           // else colFrame is being removed because of a frame
           // reconstruct on it, and its style context is still the old