Bug 1731435 - Fix. r=rhunt
authorLars T Hansen <lhansen@mozilla.com>
Tue, 21 Sep 2021 06:48:20 +0000
changeset 592575 9013de5043168b8e1b47e63495cd899fb4053fb2
parent 592574 1b323f897482816d197c8871c540e64cf7c61fa5
child 592576 480178ad0397c7f196347f6b717421681fa13e04
push id38808
push usercsabou@mozilla.com
push dateTue, 21 Sep 2021 09:46:42 +0000
treeherdermozilla-central@9013de504316 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhunt
bugs1731435
milestone94.0a1
first release with
nightly linux32
9013de504316 / 94.0a1 / 20210921094642 / files
nightly linux64
9013de504316 / 94.0a1 / 20210921094642 / files
nightly mac
9013de504316 / 94.0a1 / 20210921094642 / files
nightly win32
9013de504316 / 94.0a1 / 20210921094642 / files
nightly win64
9013de504316 / 94.0a1 / 20210921094642 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1731435 - Fix. r=rhunt Differential Revision: https://phabricator.services.mozilla.com/D126074
js/src/wasm/WasmOpIter.h
--- a/js/src/wasm/WasmOpIter.h
+++ b/js/src/wasm/WasmOpIter.h
@@ -370,34 +370,37 @@ class MOZ_STACK_CLASS OpIter : private P
   template <typename ValTypeSpanT>
   [[nodiscard]] bool popWithTypes(ValTypeSpanT expected, ValueVector* values);
   [[nodiscard]] bool popWithRefType(Value* value, StackType* type);
   [[nodiscard]] bool popWithRttType(Value* rtt, uint32_t* rttTypeIndex,
                                     uint32_t* rttDepth);
   [[nodiscard]] bool popWithRttType(Value* rtt, uint32_t rttTypeIndex,
                                     uint32_t* rttDepth);
   [[nodiscard]] bool popThenPushType(ResultType expected, ValueVector* values);
-  [[nodiscard]] bool topWithType(ResultType expected, ValueVector* values);
+  [[nodiscard]] bool topWithTypeAndPush(ResultType expected,
+                                        ValueVector* values);
 
   [[nodiscard]] bool pushControl(LabelKind kind, BlockType type);
   [[nodiscard]] bool checkStackAtEndOfBlock(ResultType* type,
                                             ValueVector* values);
   [[nodiscard]] bool getControl(uint32_t relativeDepth, Control** controlEntry);
-  [[nodiscard]] bool checkBranchValue(uint32_t relativeDepth, ResultType* type,
-                                      ValueVector* values);
-  [[nodiscard]] bool checkCastedBranchValue(uint32_t relativeDepth,
-                                            ValType castedFromType,
-                                            ValType castedToType,
-                                            ResultType* branchTargetType,
-                                            ValueVector* values);
-  [[nodiscard]] bool checkBrTableEntry(uint32_t* relativeDepth,
-                                       ResultType prevBranchType,
-                                       ResultType* branchType,
-                                       ValueVector* branchValues);
-
+  [[nodiscard]] bool checkBranchValueAndPush(uint32_t relativeDepth,
+                                             ResultType* type,
+                                             ValueVector* values);
+  [[nodiscard]] bool checkCastedBranchValueAndPush(uint32_t relativeDepth,
+                                                   ValType castedFromType,
+                                                   ValType castedToType,
+                                                   ResultType* branchTargetType,
+                                                   ValueVector* values);
+  [[nodiscard]] bool checkBrTableEntryAndPush(uint32_t* relativeDepth,
+                                              ResultType prevBranchType,
+                                              ResultType* branchType,
+                                              ValueVector* branchValues);
+
+  [[nodiscard]] bool push(StackType t) { return valueStack_.emplaceBack(t); }
   [[nodiscard]] bool push(ValType t) { return valueStack_.emplaceBack(t); }
   [[nodiscard]] bool push(TypeAndValue tv) { return valueStack_.append(tv); }
   [[nodiscard]] bool push(ResultType t) {
     for (size_t i = 0; i < t.length(); i++) {
       if (!push(t[i])) {
         return false;
       }
     }
@@ -985,18 +988,18 @@ inline bool OpIter<Policy>::popThenPushT
         collectValue(observed.value());
       }
     }
   }
   return true;
 }
 
 template <typename Policy>
-inline bool OpIter<Policy>::topWithType(ResultType expected,
-                                        ValueVector* values) {
+inline bool OpIter<Policy>::topWithTypeAndPush(ResultType expected,
+                                               ValueVector* values) {
   if (expected.empty()) {
     return true;
   }
 
   Control& block = controlStack_.back();
 
   size_t expectedLength = expected.length();
   if (values && !values->resize(expectedLength)) {
@@ -1344,38 +1347,36 @@ inline bool OpIter<Policy>::readEnd(Labe
 template <typename Policy>
 inline void OpIter<Policy>::popEnd() {
   MOZ_ASSERT(Classify(op_) == OpKind::End);
 
   controlStack_.popBack();
 }
 
 template <typename Policy>
-inline bool OpIter<Policy>::checkBranchValue(uint32_t relativeDepth,
-                                             ResultType* type,
-                                             ValueVector* values) {
+inline bool OpIter<Policy>::checkBranchValueAndPush(uint32_t relativeDepth,
+                                                    ResultType* type,
+                                                    ValueVector* values) {
   Control* block = nullptr;
   if (!getControl(relativeDepth, &block)) {
     return false;
   }
 
   *type = block->branchTargetType();
-  return topWithType(*type, values);
+  return topWithTypeAndPush(*type, values);
 }
 
 // Check the typing of a branch instruction which casts an input type to
 // an output type, branching on success to a target which takes the output
 // type along with extra values from the stack. On casting failure, the
 // original input type and extra values are left on the stack.
 template <typename Policy>
-inline bool OpIter<Policy>::checkCastedBranchValue(uint32_t relativeDepth,
-                                                   ValType castedFromType,
-                                                   ValType castedToType,
-                                                   ResultType* branchTargetType,
-                                                   ValueVector* values) {
+inline bool OpIter<Policy>::checkCastedBranchValueAndPush(
+    uint32_t relativeDepth, ValType castedFromType, ValType castedToType,
+    ResultType* branchTargetType, ValueVector* values) {
   // Get the branch target type, which will determine the type of extra values
   // that are passed along with the casted type.
   Control* block = nullptr;
   if (!getControl(relativeDepth, &block)) {
     return false;
   }
   *branchTargetType = block->branchTargetType();
 
@@ -1405,36 +1406,36 @@ inline bool OpIter<Policy>::checkCastedB
     return false;
   }
 
   // Create a copy of the branch target type, with the castTypeIndex replaced
   // with the castedFromType. Use this to check that the stack has the proper
   // types to branch to the target type.
   //
   // TODO: We could avoid a potential allocation here by handwriting a custom
-  //       topWithType that handles this case.
+  //       topWithTypeAndPush that handles this case.
   ValTypeVector stackTargetType;
   if (!branchTargetType->cloneToVector(&stackTargetType)) {
     return false;
   }
   stackTargetType[castTypeIndex] = castedFromType;
 
-  return topWithType(ResultType::Vector(stackTargetType), values);
+  return topWithTypeAndPush(ResultType::Vector(stackTargetType), values);
 }
 
 template <typename Policy>
 inline bool OpIter<Policy>::readBr(uint32_t* relativeDepth, ResultType* type,
                                    ValueVector* values) {
   MOZ_ASSERT(Classify(op_) == OpKind::Br);
 
   if (!readVarU32(relativeDepth)) {
     return fail("unable to read br depth");
   }
 
-  if (!checkBranchValue(*relativeDepth, type, values)) {
+  if (!checkBranchValueAndPush(*relativeDepth, type, values)) {
     return false;
   }
 
   afterUnconditionalBranch();
   return true;
 }
 
 template <typename Policy>
@@ -1445,26 +1446,25 @@ inline bool OpIter<Policy>::readBrIf(uin
   if (!readVarU32(relativeDepth)) {
     return fail("unable to read br_if depth");
   }
 
   if (!popWithType(ValType::I32, condition)) {
     return false;
   }
 
-  return checkBranchValue(*relativeDepth, type, values);
+  return checkBranchValueAndPush(*relativeDepth, type, values);
 }
 
 #define UNKNOWN_ARITY UINT32_MAX
 
 template <typename Policy>
-inline bool OpIter<Policy>::checkBrTableEntry(uint32_t* relativeDepth,
-                                              ResultType prevBranchType,
-                                              ResultType* type,
-                                              ValueVector* branchValues) {
+inline bool OpIter<Policy>::checkBrTableEntryAndPush(
+    uint32_t* relativeDepth, ResultType prevBranchType, ResultType* type,
+    ValueVector* branchValues) {
   if (!readVarU32(relativeDepth)) {
     return fail("unable to read br_table depth");
   }
 
   Control* block = nullptr;
   if (!getControl(*relativeDepth, &block)) {
     return false;
   }
@@ -1475,17 +1475,17 @@ inline bool OpIter<Policy>::checkBrTable
     if (prevBranchType.length() != type->length()) {
       return fail("br_table targets must all have the same arity");
     }
 
     // Avoid re-collecting the same values for subsequent branch targets.
     branchValues = nullptr;
   }
 
-  return topWithType(*type, branchValues);
+  return topWithTypeAndPush(*type, branchValues);
 }
 
 template <typename Policy>
 inline bool OpIter<Policy>::readBrTable(Uint32Vector* depths,
                                         uint32_t* defaultDepth,
                                         ResultType* defaultBranchType,
                                         ValueVector* branchValues,
                                         Value* index) {
@@ -1506,25 +1506,25 @@ inline bool OpIter<Policy>::readBrTable(
 
   if (!depths->resize(tableLength)) {
     return false;
   }
 
   ResultType prevBranchType;
   for (uint32_t i = 0; i < tableLength; i++) {
     ResultType branchType;
-    if (!checkBrTableEntry(&(*depths)[i], prevBranchType, &branchType,
-                           branchValues)) {
+    if (!checkBrTableEntryAndPush(&(*depths)[i], prevBranchType, &branchType,
+                                  branchValues)) {
       return false;
     }
     prevBranchType = branchType;
   }
 
-  if (!checkBrTableEntry(defaultDepth, prevBranchType, defaultBranchType,
-                         branchValues)) {
+  if (!checkBrTableEntryAndPush(defaultDepth, prevBranchType, defaultBranchType,
+                                branchValues)) {
     return false;
   }
 
   MOZ_ASSERT(*defaultBranchType != ResultType());
 
   afterUnconditionalBranch();
   return true;
 }
@@ -2258,26 +2258,24 @@ inline bool OpIter<Policy>::readBrOnNull
     return fail("unable to read br_on_null depth");
   }
 
   StackType refType;
   if (!popWithRefType(condition, &refType)) {
     return false;
   }
 
-  if (!checkBranchValue(*relativeDepth, type, values)) {
+  if (!checkBranchValueAndPush(*relativeDepth, type, values)) {
     return false;
   }
 
   if (refType.isBottom()) {
-    infalliblePush(refType);
-  } else {
-    infalliblePush(refType.asNonNullable());
-  }
-  return true;
+    return push(refType);
+  }
+  return push(refType.asNonNullable());
 }
 
 template <typename Policy>
 inline bool OpIter<Policy>::popCallArgs(const ValTypeVector& expectedTypes,
                                         ValueVector* values) {
   // Iterate through the argument types backward so that pops occur in the
   // right order.
 
@@ -3254,18 +3252,18 @@ inline bool OpIter<Policy>::readBrOnCast
 
   // The casted from type is any subtype of eqref
   ValType castedFromType(RefType::eq());
 
   // The casted to type is a non-nullable reference to the type index specified
   // by the input rtt on the stack
   ValType castedToType(RefType::fromTypeIndex(*rttTypeIndex, false));
 
-  return checkCastedBranchValue(*relativeDepth, castedFromType, castedToType,
-                                branchTargetType, values);
+  return checkCastedBranchValueAndPush(*relativeDepth, castedFromType,
+                                       castedToType, branchTargetType, values);
 }
 
 #endif  // ENABLE_WASM_GC
 
 #ifdef ENABLE_WASM_SIMD
 
 template <typename Policy>
 inline bool OpIter<Policy>::readLaneIndex(uint32_t inputLanes,