Bug 1530034 - Use mozilla::Maybe in BytecodeEmitter when reasonable. r=jorendorff
authorTed Campbell <tcampbell@mozilla.com>
Mon, 25 Feb 2019 14:04:14 +0000
changeset 460898 a69e03c02d34a08c915087ea403e68bbcebe7bdb
parent 460897 a9eee2d6d9b84752ec885fe2f55a4c3c4337b83f
child 460899 942730f2550d0659a8f18f713ef26159714a4e3b
push id35613
push usernerli@mozilla.com
push dateTue, 26 Feb 2019 03:52:35 +0000
treeherdermozilla-central@faec87a80ed1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1530034
milestone67.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 1530034 - Use mozilla::Maybe in BytecodeEmitter when reasonable. r=jorendorff Depends on D20884 Differential Revision: https://phabricator.services.mozilla.com/D20885
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/BytecodeEmitter.h
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -131,19 +131,17 @@ BytecodeEmitter::BytecodeEmitter(Bytecod
       scopeNoteList(cx),
       resumeOffsetList(cx),
       numICEntries(0),
       numYields(0),
       typesetCount(0),
       hasSingletons(false),
       hasTryFinally(false),
       emittingRunOnceLambda(false),
-      emitterMode(emitterMode),
-      scriptStartOffsetSet(false),
-      functionBodyEndPosSet(false) {
+      emitterMode(emitterMode) {
   MOZ_ASSERT_IF(emitterMode == LazyFunction, lazyScript);
 
   if (sc->isFunctionBox()) {
     // Functions have IC entries for type monitoring |this| and arguments.
     numICEntries = sc->asFunctionBox()->function()->nargs() + 1;
   }
 }
 
@@ -1617,61 +1615,57 @@ void BytecodeEmitter::reportNeedMoreArgs
                                               const ListNode* argsList) {
   char actualArgsStr[40];
   SprintfLiteral(actualArgsStr, "%u", argsList->count());
   reportError(pn, JSMSG_MORE_ARGS_NEEDED, errorName, requiredArgs, pluralizer,
               actualArgsStr);
 }
 
 void BytecodeEmitter::reportError(ParseNode* pn, unsigned errorNumber, ...) {
-  MOZ_ASSERT_IF(!pn, this->scriptStartOffsetSet);
-  uint32_t offset = pn ? pn->pn_pos.begin : this->scriptStartOffset;
+  uint32_t offset = pn ? pn->pn_pos.begin : *scriptStartOffset;
 
   va_list args;
   va_start(args, errorNumber);
 
   parser->errorReporter().errorWithNotesAtVA(nullptr, AsVariant(offset),
                                              errorNumber, &args);
 
   va_end(args);
 }
 
 void BytecodeEmitter::reportError(const Maybe<uint32_t>& maybeOffset,
                                   unsigned errorNumber, ...) {
-  MOZ_ASSERT_IF(!maybeOffset, this->scriptStartOffsetSet);
-  uint32_t offset = maybeOffset ? *maybeOffset : this->scriptStartOffset;
+  uint32_t offset = maybeOffset ? *maybeOffset : *scriptStartOffset;
 
   va_list args;
   va_start(args, errorNumber);
 
   parser->errorReporter().errorWithNotesAtVA(nullptr, AsVariant(offset),
                                              errorNumber, &args);
 
   va_end(args);
 }
 
 bool BytecodeEmitter::reportExtraWarning(ParseNode* pn, unsigned errorNumber,
                                          ...) {
-  MOZ_ASSERT_IF(!pn, this->scriptStartOffsetSet);
-  uint32_t offset = pn ? pn->pn_pos.begin : this->scriptStartOffset;
+  uint32_t offset = pn ? pn->pn_pos.begin : *scriptStartOffset;
 
   va_list args;
   va_start(args, errorNumber);
 
   bool result = parser->errorReporter().extraWarningWithNotesAtVA(
       nullptr, AsVariant(offset), errorNumber, &args);
 
   va_end(args);
   return result;
 }
 
 bool BytecodeEmitter::reportExtraWarning(const Maybe<uint32_t>& maybeOffset,
                                          unsigned errorNumber, ...) {
-  MOZ_ASSERT_IF(!maybeOffset, this->scriptStartOffsetSet);
-  uint32_t offset = maybeOffset ? *maybeOffset : this->scriptStartOffset;
+  uint32_t offset = maybeOffset ? *maybeOffset : *scriptStartOffset;
 
   va_list args;
   va_start(args, errorNumber);
 
   bool result = parser->errorReporter().extraWarningWithNotesAtVA(
       nullptr, AsVariant(offset), errorNumber, &args);
 
   va_end(args);
@@ -6242,18 +6236,17 @@ bool BytecodeEmitter::emitReturn(UnaryNo
     if (!emitFinishIteratorResult(true)) {
       return false;
     }
   }
 
   // We know functionBodyEndPos is set because "return" is only
   // valid in a function, and so we've passed through
   // emitFunctionScript.
-  MOZ_ASSERT(functionBodyEndPosSet);
-  if (!updateSourceCoordNotes(functionBodyEndPos)) {
+  if (!updateSourceCoordNotes(*functionBodyEndPos)) {
     return false;
   }
 
   /*
    * EmitNonLocalJumpFixup may add fixup bytecode to close open try
    * blocks having finally clauses and to exit intermingled let blocks.
    * We can't simply transfer control flow to our caller in that case,
    * because we must gosub to those finally clauses from inner to outer,
--- a/js/src/frontend/BytecodeEmitter.h
+++ b/js/src/frontend/BytecodeEmitter.h
@@ -229,23 +229,20 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
      * Check the static scope chain of the root function for resolving free
      * variable accesses in the script.
      */
     LazyFunction
   };
 
   const EmitterMode emitterMode;
 
-  MOZ_INIT_OUTSIDE_CTOR uint32_t scriptStartOffset;
-  bool scriptStartOffsetSet;
+  mozilla::Maybe<uint32_t> scriptStartOffset;
 
   // The end location of a function body that is being emitted.
-  MOZ_INIT_OUTSIDE_CTOR uint32_t functionBodyEndPos;
-  // Whether functionBodyEndPos was set.
-  bool functionBodyEndPosSet;
+  mozilla::Maybe<uint32_t> functionBodyEndPos;
 
   /*
    * Note that BytecodeEmitters are magic: they own the arena "top-of-stack"
    * space above their tempMark points. This means that you cannot alloc from
    * tempLifoAlloc and save the pointer beyond the next BytecodeEmitter
    * destruction.
    */
  private:
@@ -420,24 +417,22 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
   // aliased by multiple statements. If we included the jump target as part of
   // the statement we might have issues where the enclosing statement might
   // not contain all the opcodes of the enclosed statements.
   ptrdiff_t lastNonJumpTargetOffset() const {
     return lastOpcodeIsJumpTarget() ? lastTarget.offset : offset();
   }
 
   void setFunctionBodyEndPos(TokenPos pos) {
-    functionBodyEndPos = pos.end;
-    functionBodyEndPosSet = true;
+    functionBodyEndPos = mozilla::Some(pos.end);
   }
 
   void setScriptStartOffsetIfUnset(TokenPos pos) {
-    if (!scriptStartOffsetSet) {
-      scriptStartOffset = pos.begin;
-      scriptStartOffsetSet = true;
+    if (scriptStartOffset.isNothing()) {
+      scriptStartOffset = mozilla::Some(pos.begin);
     }
   }
 
   void reportError(ParseNode* pn, unsigned errorNumber, ...);
   void reportError(const mozilla::Maybe<uint32_t>& maybeOffset,
                    unsigned errorNumber, ...);
   bool reportExtraWarning(ParseNode* pn, unsigned errorNumber, ...);
   bool reportExtraWarning(const mozilla::Maybe<uint32_t>& maybeOffset,