Bug 1587678 - Part 3: Remove unnecessary JSContext* parameter. r=Yoric
☠☠ backed out by 31f16b9b5863 ☠ ☠
authorTooru Fujisawa <arai_a@mac.com>
Mon, 21 Oct 2019 14:32:09 +0000
changeset 498381 00eab227096178b7d95e0a375cb25a300095219b
parent 498380 16e2bc05dda0eca201e9752839d51a86841677b1
child 498382 4f8232cb3be9a6c545f5cfe9e1930435a3876078
push id36717
push usernbeleuzu@mozilla.com
push dateMon, 21 Oct 2019 21:51:55 +0000
treeherdermozilla-central@563f437f24b9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1587678
milestone71.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 1587678 - Part 3: Remove unnecessary JSContext* parameter. r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D49565
js/src/frontend/BinASTTokenReaderContext.cpp
js/src/frontend/BinASTTokenReaderContext.h
--- a/js/src/frontend/BinASTTokenReaderContext.cpp
+++ b/js/src/frontend/BinASTTokenReaderContext.cpp
@@ -539,17 +539,17 @@ class HuffmanPreludeReader {
 
   MOZ_MUST_USE JS::Result<Ok> pushValue(NormalizedInterfaceAndField identity,
                                         const Interface& interface) {
     // Note: In this case, for compatibility, we do *not* check whether
     // the interface has already been visited.
     auto& table = dictionary_.tableForField(identity);
     if (table.is<HuffmanTableUnreachable>()) {
       // Effectively, an `Interface` is a sum with a single entry.
-      HuffmanTableIndexedSymbolsSum sum(cx_);
+      HuffmanTableIndexedSymbolsSum sum;
       MOZ_TRY(sum.initWithSingleValue(
           cx_, BinASTSymbol::fromKind(BinASTKind(interface.kind_))));
       table = {mozilla::VariantType<HuffmanTableIndexedSymbolsSum>{},
                std::move(sum)};
     }
 
     // Spec:
     // 4. If the effective type is a monomorphic interface, push all of the
@@ -850,27 +850,27 @@ class HuffmanPreludeReader {
       return raiseDuplicateTableError(entry.identity_);
     }
 
     uint8_t headerByte;
     MOZ_TRY_VAR(headerByte, reader_.readByte<Compression::No>());
     switch (headerByte) {
       case TableHeader::SingleValue: {
         // Construct in-place.
-        table = {mozilla::VariantType<typename Entry::Table>{}, cx_};
+        table = {mozilla::VariantType<typename Entry::Table>{}};
         auto& tableRef = table.template as<typename Entry::Table>();
 
         // The table contains a single value.
         MOZ_TRY((readSingleValueTable<Entry>(tableRef, entry)));
         return Ok();
       }
       case TableHeader::MultipleValues: {
         // Table contains multiple values.
         // Construct in-place.
-        table = {mozilla::VariantType<typename Entry::Table>{}, cx_};
+        table = {mozilla::VariantType<typename Entry::Table>{}};
         auto& tableRef = table.template as<typename Entry::Table>();
 
         MOZ_TRY((readMultipleValuesTable<Entry>(tableRef, entry)));
         return Ok();
       }
       case TableHeader::Unreachable:
         // Table is unreachable, nothing to do.
         return Ok();
@@ -1045,17 +1045,16 @@ using Sum = HuffmanPreludeReader::Sum;
 using UnsignedLong = HuffmanPreludeReader::UnsignedLong;
 
 BinASTTokenReaderContext::BinASTTokenReaderContext(JSContext* cx,
                                                    ErrorReporter* er,
                                                    const uint8_t* start,
                                                    const size_t length)
     : BinASTTokenReaderBase(cx, er, start, length),
       metadata_(nullptr),
-      dictionary_(cx),
       posBeforeTree_(nullptr) {
   MOZ_ASSERT(er);
 }
 
 BinASTTokenReaderContext::~BinASTTokenReaderContext() {
   if (metadata_ && metadataOwned_ == MetadataOwnership::Owned) {
     UniqueBinASTSourceMetadataPtr ptr(metadata_);
   }
@@ -1731,17 +1730,17 @@ const BinASTSymbol* GenericHuffmanTable:
       [](const typename TwoLookupsHuffmanTable::Iterator& iterator) {
         return iterator.operator->();
       },
       [](const typename ThreeLookupsHuffmanTable::Iterator& iterator) {
         return iterator.operator->();
       });
 }
 
-GenericHuffmanTable::GenericHuffmanTable(JSContext*)
+GenericHuffmanTable::GenericHuffmanTable()
     : implementation_(HuffmanTableUnreachable{}) {}
 
 JS::Result<Ok> GenericHuffmanTable::initComplete(JSContext* cx) {
   return implementation_.match(
       [](SingleEntryHuffmanTable& implementation) -> JS::Result<Ok> {
         MOZ_CRASH("SingleEntryHuffmanTable shouldn't have multiple entries!");
       },
       [cx](TwoEntriesHuffmanTable& implementation) -> JS::Result<Ok> {
@@ -1844,32 +1843,32 @@ JS::Result<Ok> GenericHuffmanTable::init
     return implementation_.template as<TwoEntriesHuffmanTable>().initStart(
         cx, numberOfSymbols, largestBitLength);
   }
 
   // Find the (hopefully) fastest implementation of HuffmanTable for
   // `largestBitLength`.
   // ...hopefully, only one lookup.
   if (largestBitLength <= SingleLookupHuffmanTable::MAX_BIT_LENGTH) {
-    implementation_ = {mozilla::VariantType<SingleLookupHuffmanTable>{}, cx,
+    implementation_ = {mozilla::VariantType<SingleLookupHuffmanTable>{},
                        SingleLookupHuffmanTable::Use::ToplevelTable};
     return implementation_.template as<SingleLookupHuffmanTable>().initStart(
         cx, numberOfSymbols, largestBitLength);
   }
 
   // ...if a single-lookup table would be too large, let's see if
   // we can fit in a two-lookup table.
   if (largestBitLength <= TwoLookupsHuffmanTable::MAX_BIT_LENGTH) {
-    implementation_ = {mozilla::VariantType<TwoLookupsHuffmanTable>{}, cx};
+    implementation_ = {mozilla::VariantType<TwoLookupsHuffmanTable>{}};
     return implementation_.template as<TwoLookupsHuffmanTable>().initStart(
         cx, numberOfSymbols, largestBitLength);
   }
 
   // ...otherwise, we'll need three lookups.
-  implementation_ = {mozilla::VariantType<ThreeLookupsHuffmanTable>{}, cx};
+  implementation_ = {mozilla::VariantType<ThreeLookupsHuffmanTable>{}};
   return implementation_.template as<ThreeLookupsHuffmanTable>().initStart(
       cx, numberOfSymbols, largestBitLength);
 }
 
 JS::Result<Ok> GenericHuffmanTable::addSymbol(size_t index, uint32_t bits,
                                               uint8_t bitLength,
                                               const BinASTSymbol& value) {
   return implementation_.match(
@@ -2283,17 +2282,17 @@ JS::Result<Ok> MultiLookupHuffmanTable<S
   FixedLengthVector<size_t> suffixTablesIndices;
   if (MOZ_UNLIKELY(!suffixTablesIndices.allocate(cx, suffixTables_.length()))) {
     return cx->alreadyReportedError();
   }
 
   // We may now create the subtables.
   size_t i = 0;
   for (auto& bucket : buckets) {
-    new (mozilla::KnownNotNull, &suffixTables_[i]) Subtable(cx);
+    new (mozilla::KnownNotNull, &suffixTables_[i]) Subtable();
     suffixTablesIndices[i] = 0;
 
     if (bucket.numberOfSymbols_ != 0) {
       // Often, a subtable will end up empty because all the prefixes end up
       // in `shortKeys_`. In such a case, we want to avoid initializing the
       // table.
       MOZ_TRY(suffixTables_[i].initStart(
           cx,
@@ -2826,17 +2825,17 @@ MOZ_MUST_USE JS::Result<Ok>
 HuffmanPreludeReader::readSingleValueTable<UnsignedLong>(
     HuffmanTableExplicitSymbolsU32& table, const UnsignedLong& entry) {
   BINJS_MOZ_TRY_DECL(index, reader_.readUnpackedLong());
   MOZ_TRY(
       table.initWithSingleValue(cx_, BinASTSymbol::fromUnsignedLong(index)));
   return Ok();
 }
 
-HuffmanDictionary::HuffmanDictionary(JSContext* cx)
+HuffmanDictionary::HuffmanDictionary()
     : fields_(BINAST_PARAM_NUMBER_OF_INTERFACE_AND_FIELD(
           mozilla::AsVariant(HuffmanTableUnreachable()))),
       listLengths_(BINAST_PARAM_NUMBER_OF_LIST_TYPES(
           mozilla::AsVariant(HuffmanTableUnreachable()))) {}
 
 HuffmanTableValue& HuffmanDictionary::tableForField(
     NormalizedInterfaceAndField index) {
   return fields_[static_cast<size_t>(index.identity_)];
--- a/js/src/frontend/BinASTTokenReaderContext.h
+++ b/js/src/frontend/BinASTTokenReaderContext.h
@@ -447,17 +447,17 @@ class SingleLookupHuffmanTable {
     // Used as a `shortKeys_` in a `MultiLookupHuffmanTable`.
     ShortKeys,
   };
 
   // The largest bit length that may be represented by this table.
   static const uint8_t MAX_BIT_LENGTH = sizeof(InternalIndex) * 8;
 
   explicit SingleLookupHuffmanTable(
-      JSContext* cx, Use use = Use::LeafOfMultiLookupHuffmanTable)
+      Use use = Use::LeafOfMultiLookupHuffmanTable)
       : largestBitLength_(-1)
 #ifdef DEBUG
         ,
         use_(use)
 #endif  // DEBUG
   {
   }
   SingleLookupHuffmanTable(SingleLookupHuffmanTable&& other) = default;
@@ -471,17 +471,16 @@ class SingleLookupHuffmanTable {
 
   JS::Result<Ok> initComplete(JSContext* cx);
 
   // Add a `(bit, bitLength) => value` mapping.
   // The symbol is the `index`-th item in this table.
   JS::Result<Ok> addSymbol(size_t index, uint32_t bits, uint8_t bitLength,
                            const BinASTSymbol& value);
 
-  SingleLookupHuffmanTable() = delete;
   SingleLookupHuffmanTable(SingleLookupHuffmanTable&) = delete;
 
   // Lookup a value in the table.
   //
   // The return of this method contains:
   //
   // - the resulting value (`nullptr` if the value is not in the table);
   // - the number of bits in the entry associated to this value.
@@ -674,19 +673,18 @@ class SingleLookupHuffmanTable {
 /// - 1 subtable with 2^1 = 2 references.
 template <typename Subtable, uint8_t PrefixBitLength>
 class MultiLookupHuffmanTable {
  public:
   // The largest bit length that may be represented by this table.
   static const uint8_t MAX_BIT_LENGTH =
       PrefixBitLength + Subtable::MAX_BIT_LENGTH;
 
-  explicit MultiLookupHuffmanTable(JSContext* cx)
-      : cx_(cx),
-        shortKeys_(cx, SingleLookupHuffmanTable::Use::ShortKeys),
+  MultiLookupHuffmanTable()
+      : shortKeys_(SingleLookupHuffmanTable::Use::ShortKeys),
         largestBitLength_(-1) {}
   MultiLookupHuffmanTable(MultiLookupHuffmanTable&& other) = default;
 
   // Initialize a Huffman table containing `numberOfSymbols`.
   // Symbols must be added with `addSymbol`.
   // If you initialize with `initStart`, you MUST call `initComplete()`
   // at the end of initialization.
   JS::Result<Ok> initStart(JSContext* cx, size_t numberOfSymbols,
@@ -694,17 +692,16 @@ class MultiLookupHuffmanTable {
 
   JS::Result<Ok> initComplete(JSContext* cx);
 
   // Add a `(bit, bitLength) => value` mapping.
   // The symbol is the `index`-th item in this table.
   JS::Result<Ok> addSymbol(size_t index, uint32_t bits, uint8_t bitLength,
                            const BinASTSymbol& value);
 
-  MultiLookupHuffmanTable() = delete;
   MultiLookupHuffmanTable(MultiLookupHuffmanTable&) = delete;
 
   // Lookup a value in the table.
   //
   // The return of this method contains:
   //
   // - the resulting value (`nullptr` if the value is not in the table);
   // - the number of bits in the entry associated to this value.
@@ -735,18 +732,16 @@ class MultiLookupHuffmanTable {
 
  public:
   // An index into table `values_`.
   // We use `uint8_t` instead of `size_t` to limit the space
   // used by the table.
   using InternalIndex = uint8_t;
 
  private:
-  JSContext* cx_;
-
   // Fast lookup for values whose keys fit within 8 bits.
   // Such values are not added to `suffixTables`.
   SingleLookupHuffmanTable shortKeys_;
 
   // The entries in this Huffman Table, sorted in the order of insertion.
   //
   // Invariant (once `init*` has been called):
   // - Length is the number of values inserted in the table.
@@ -789,18 +784,17 @@ using ThreeLookupsHuffmanTable =
 // Part of variants `HuffmanTableValue`, `HuffmanTableListLength` and
 // `GenericHuffmanTable::implementation`.
 struct HuffmanTableUnreachable {};
 
 // Generic implementation of Huffman tables.
 //
 //
 struct GenericHuffmanTable {
-  explicit GenericHuffmanTable(JSContext* cx);
-  explicit GenericHuffmanTable() = delete;
+  GenericHuffmanTable();
 
   // Initialize a Huffman table containing a single value.
   JS::Result<Ok> initWithSingleValue(JSContext* cx, const BinASTSymbol& value);
 
   // Initialize a Huffman table containing `numberOfSymbols`.
   // Symbols must be added with `addSymbol`.
   // If you initialize with `initStart`, you MUST call `initComplete()`
   // at the end of initialization.
@@ -871,40 +865,35 @@ struct GenericHuffmanTable {
 // Attempting to get a value from this table is an internal error.
 //
 // Part of variants `HuffmanTableValue` and `HuffmanTableListLength`.
 struct HuffmanTableInitializing {};
 
 // These classes are all parts of variant `HuffmanTableValue`.
 
 struct HuffmanTableExplicitSymbolsF64 : GenericHuffmanTable {
-  explicit HuffmanTableExplicitSymbolsF64(JSContext* cx)
-      : GenericHuffmanTable(cx) {}
+  HuffmanTableExplicitSymbolsF64() : GenericHuffmanTable() {}
 };
 
 struct HuffmanTableExplicitSymbolsU32 : GenericHuffmanTable {
-  explicit HuffmanTableExplicitSymbolsU32(JSContext* cx)
-      : GenericHuffmanTable(cx) {}
+  HuffmanTableExplicitSymbolsU32() : GenericHuffmanTable() {}
 };
 
 struct HuffmanTableIndexedSymbolsSum : GenericHuffmanTable {
-  explicit HuffmanTableIndexedSymbolsSum(JSContext* cx)
-      : GenericHuffmanTable(cx) {}
+  HuffmanTableIndexedSymbolsSum() : GenericHuffmanTable() {}
 };
 
 struct HuffmanTableIndexedSymbolsBool : GenericHuffmanTable {
-  explicit HuffmanTableIndexedSymbolsBool(JSContext* cx)
-      : GenericHuffmanTable(cx) {}
+  HuffmanTableIndexedSymbolsBool() : GenericHuffmanTable() {}
 };
 
 // A Huffman table that may only ever contain two values:
 // `BinASTKind::_Null` and another `BinASTKind`.
 struct HuffmanTableIndexedSymbolsMaybeInterface : GenericHuffmanTable {
-  explicit HuffmanTableIndexedSymbolsMaybeInterface(JSContext* cx)
-      : GenericHuffmanTable(cx) {}
+  HuffmanTableIndexedSymbolsMaybeInterface() : GenericHuffmanTable() {}
 
   // `true` if this table only contains values for `null`.
   bool isAlwaysNull() const {
     MOZ_ASSERT(length() == 1 || length() == 2);
 
     // By definition, we have either 1 or 2 values.
     // By definition, if we have 2 values, one of them is not null.
     if (length() == 2) {
@@ -912,59 +901,55 @@ struct HuffmanTableIndexedSymbolsMaybeIn
     }
 
     // Otherwise, check the single value.
     return begin()->toKind() == BinASTKind::_Null;
   }
 };
 
 struct HuffmanTableIndexedSymbolsStringEnum : GenericHuffmanTable {
-  explicit HuffmanTableIndexedSymbolsStringEnum(JSContext* cx)
-      : GenericHuffmanTable(cx) {}
+  HuffmanTableIndexedSymbolsStringEnum() : GenericHuffmanTable() {}
 };
 
 struct HuffmanTableIndexedSymbolsLiteralString : GenericHuffmanTable {
-  explicit HuffmanTableIndexedSymbolsLiteralString(JSContext* cx)
-      : GenericHuffmanTable(cx) {}
+  HuffmanTableIndexedSymbolsLiteralString() : GenericHuffmanTable() {}
 };
 
 struct HuffmanTableIndexedSymbolsOptionalLiteralString : GenericHuffmanTable {
-  explicit HuffmanTableIndexedSymbolsOptionalLiteralString(JSContext* cx)
-      : GenericHuffmanTable(cx) {}
+  HuffmanTableIndexedSymbolsOptionalLiteralString() : GenericHuffmanTable() {}
 };
 
 // A single Huffman table, used for values.
 using HuffmanTableValue = mozilla::Variant<
     HuffmanTableUnreachable,  // Default value.
     HuffmanTableInitializing, HuffmanTableExplicitSymbolsF64,
     HuffmanTableExplicitSymbolsU32, HuffmanTableIndexedSymbolsSum,
     HuffmanTableIndexedSymbolsMaybeInterface, HuffmanTableIndexedSymbolsBool,
     HuffmanTableIndexedSymbolsStringEnum,
     HuffmanTableIndexedSymbolsLiteralString,
     HuffmanTableIndexedSymbolsOptionalLiteralString>;
 
 struct HuffmanTableExplicitSymbolsListLength : GenericHuffmanTable {
-  explicit HuffmanTableExplicitSymbolsListLength(JSContext* cx)
-      : GenericHuffmanTable(cx) {}
+  HuffmanTableExplicitSymbolsListLength() : GenericHuffmanTable() {}
 };
 
 // A single Huffman table, specialized for list lengths.
 using HuffmanTableListLength =
     mozilla::Variant<HuffmanTableUnreachable,  // Default value.
                      HuffmanTableInitializing,
                      HuffmanTableExplicitSymbolsListLength>;
 
 // A Huffman dictionary for the current file.
 //
 // A Huffman dictionary consists in a (contiguous) set of Huffman tables
 // to predict field values and a second (contiguous) set of Huffman tables
 // to predict list lengths.
 class HuffmanDictionary {
  public:
-  explicit HuffmanDictionary(JSContext* cx);
+  HuffmanDictionary();
 
   HuffmanTableValue& tableForField(NormalizedInterfaceAndField index);
   HuffmanTableListLength& tableForListLength(BinASTList list);
 
  private:
   // Huffman tables for `(Interface, Field)` pairs, used to decode the value of
   // `Interface::Field`. Some tables may be `HuffmanTableUnreacheable`
   // if they represent fields of interfaces that actually do not show up