Bug 1781008 - Part 2: Add BytecodeEmitter::ec. r=bthrall
authorTooru Fujisawa <arai_a@mac.com>
Sat, 30 Jul 2022 04:45:20 +0000
changeset 625556 dd0966996f42dcd4d548eeb40a7ec7673ff5de57
parent 625555 9c5f59e32d1941269f982ff1c3b09bb63626c376
child 625557 241f5f4edede78ce53d48d0357521787261659fa
push id40060
push usersmolnar@mozilla.com
push dateSat, 30 Jul 2022 21:36:28 +0000
treeherdermozilla-central@ff7fc1a977e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbthrall
bugs1781008
milestone105.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 1781008 - Part 2: Add BytecodeEmitter::ec. r=bthrall Depends on D152779 Differential Revision: https://phabricator.services.mozilla.com/D152780
js/src/frontend/BytecodeCompiler.cpp
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/BytecodeEmitter.h
--- a/js/src/frontend/BytecodeCompiler.cpp
+++ b/js/src/frontend/BytecodeCompiler.cpp
@@ -77,17 +77,17 @@ class MOZ_RAII AutoAssertReportedExcepti
 #else
  public:
   explicit AutoAssertReportedException(JSContext*, ErrorContext* = nullptr) {}
   void reset() {}
 #endif
 };
 
 static bool EmplaceEmitter(CompilationState& compilationState,
-                           Maybe<BytecodeEmitter>& emitter,
+                           Maybe<BytecodeEmitter>& emitter, ErrorContext* ec,
                            uintptr_t stackLimit, const EitherParser& parser,
                            SharedContext* sc);
 
 template <typename Unit>
 class MOZ_STACK_CLASS SourceAwareCompiler {
  protected:
   SourceText<Unit>& sourceBuffer_;
 
@@ -127,17 +127,17 @@ class MOZ_STACK_CLASS SourceAwareCompile
     MOZ_ASSERT(compilationState_.source != nullptr);
     MOZ_ASSERT(parser.isSome());
   }
 
   void assertSourceParserAndScriptCreated() { assertSourceAndParserCreated(); }
 
   [[nodiscard]] bool emplaceEmitter(Maybe<BytecodeEmitter>& emitter,
                                     SharedContext* sharedContext) {
-    return EmplaceEmitter(compilationState_, emitter, stackLimit,
+    return EmplaceEmitter(compilationState_, emitter, errorContext, stackLimit,
                           EitherParser(parser.ptr()), sharedContext);
   }
 
   bool canHandleParseFailure(const Directives& newDirectives);
 
   void handleParseFailure(
       const Directives& newDirectives, TokenStreamPosition& startPosition,
       CompilationState::CompilationStatePosition& startStatePosition);
@@ -619,22 +619,22 @@ bool SourceAwareCompiler<Unit>::createSo
                  sourceBuffer_.length(),
                  /* foldConstants = */ true, compilationState_,
                  syntaxParser.ptrOr(nullptr));
   parser->ss = compilationState_.source.get();
   return parser->checkOptions();
 }
 
 static bool EmplaceEmitter(CompilationState& compilationState,
-                           Maybe<BytecodeEmitter>& emitter,
+                           Maybe<BytecodeEmitter>& emitter, ErrorContext* ec,
                            uintptr_t stackLimit, const EitherParser& parser,
                            SharedContext* sc) {
   BytecodeEmitter::EmitterMode emitterMode =
       sc->selfHosted() ? BytecodeEmitter::SelfHosting : BytecodeEmitter::Normal;
-  emitter.emplace(stackLimit, parser, sc, compilationState, emitterMode);
+  emitter.emplace(ec, stackLimit, parser, sc, compilationState, emitterMode);
   return emitter->init();
 }
 
 template <typename Unit>
 bool SourceAwareCompiler<Unit>::canHandleParseFailure(
     const Directives& newDirectives) {
   // Try to reparse if no parse errors were thrown and the directives changed.
   //
@@ -1130,17 +1130,17 @@ static bool CompileLazyFunctionToStencil
 
   FunctionNode* pn = parser.standaloneLazyFunction(
       input, input.extent().toStringStart, input.strict(),
       input.generatorKind(), input.asyncKind());
   if (!pn) {
     return false;
   }
 
-  BytecodeEmitter bce(stackLimit, &parser, pn->funbox(), compilationState,
+  BytecodeEmitter bce(ec, stackLimit, &parser, pn->funbox(), compilationState,
                       BytecodeEmitter::LazyFunction);
   if (!bce.init(pn->pn_pos)) {
     return false;
   }
 
   if (!bce.emitFunctionScript(pn)) {
     return false;
   }
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -127,47 +127,50 @@ static bool ShouldSuppressBreakpointsAnd
   if (sc->isFunctionBox()) {
     FunctionBox* funbox = sc->asFunctionBox();
     return funbox->isSyntheticFunction() && funbox->isClassConstructor();
   }
 
   return false;
 }
 
-BytecodeEmitter::BytecodeEmitter(BytecodeEmitter* parent, uintptr_t stackLimit,
-                                 SharedContext* sc,
+BytecodeEmitter::BytecodeEmitter(BytecodeEmitter* parent, ErrorContext* ec,
+                                 uintptr_t stackLimit, SharedContext* sc,
                                  CompilationState& compilationState,
                                  EmitterMode emitterMode)
     : sc(sc),
       cx(sc->cx_),
+      ec(ec),
       stackLimit(stackLimit),
       parent(parent),
       bytecodeSection_(cx, sc->extent().lineno, sc->extent().column),
       perScriptData_(cx, compilationState),
       compilationState(compilationState),
       suppressBreakpointsAndSourceNotes(
           ShouldSuppressBreakpointsAndSourceNotes(sc, emitterMode)),
       emitterMode(emitterMode) {
   MOZ_ASSERT_IF(parent, stackLimit == parent->stackLimit);
+  MOZ_ASSERT_IF(parent, ec == parent->ec);
 }
 
 BytecodeEmitter::BytecodeEmitter(BytecodeEmitter* parent,
                                  BCEParserHandle* handle, SharedContext* sc,
                                  CompilationState& compilationState,
                                  EmitterMode emitterMode)
-    : BytecodeEmitter(parent, parent->stackLimit, sc, compilationState,
-                      emitterMode) {
+    : BytecodeEmitter(parent, parent->ec, parent->stackLimit, sc,
+                      compilationState, emitterMode) {
   parser = handle;
 }
 
-BytecodeEmitter::BytecodeEmitter(uintptr_t stackLimit,
+BytecodeEmitter::BytecodeEmitter(ErrorContext* ec, uintptr_t stackLimit,
                                  const EitherParser& parser, SharedContext* sc,
                                  CompilationState& compilationState,
                                  EmitterMode emitterMode)
-    : BytecodeEmitter(nullptr, stackLimit, sc, compilationState, emitterMode) {
+    : BytecodeEmitter(nullptr, ec, stackLimit, sc, compilationState,
+                      emitterMode) {
   ep_.emplace(parser);
   this->parser = ep_.ptr();
 }
 
 void BytecodeEmitter::initFromBodyPosition(TokenPos bodyPosition) {
   setScriptStartOffsetIfUnset(bodyPosition.begin);
   setFunctionBodyEndPos(bodyPosition.end);
 }
--- a/js/src/frontend/BytecodeEmitter.h
+++ b/js/src/frontend/BytecodeEmitter.h
@@ -39,16 +39,19 @@
 #include "vm/FunctionPrefixKind.h"         // FunctionPrefixKind
 #include "vm/GeneratorResumeKind.h"        // GeneratorResumeKind
 #include "vm/Opcodes.h"                    // JSOp
 #include "vm/SharedStencil.h"              // GCThingIndex, MemberInitializers
 #include "vm/StencilEnums.h"               // TryNoteKind
 #include "vm/ThrowMsgKind.h"               // ThrowMsgKind, ThrowCondition
 
 namespace js {
+
+class ErrorContext;
+
 namespace frontend {
 
 class BytecodeOffset;
 class CallOrNewEmitter;
 class ClassEmitter;
 class ElemOpEmitter;
 class EmitterScope;
 class FullParseHandler;
@@ -199,16 +202,17 @@ enum class ValueIsOnStack { Yes, No };
 //
 // See comment block above each helper class for more details and example usage.
 
 struct MOZ_STACK_CLASS BytecodeEmitter {
   // Context shared between parsing and bytecode generation.
   SharedContext* const sc = nullptr;
 
   JSContext* const cx = nullptr;
+  ErrorContext* const ec = nullptr;
 
   uintptr_t stackLimit;
 
   // Enclosing function or global context.
   BytecodeEmitter* const parent = nullptr;
 
   BytecodeSection bytecodeSection_;
 
@@ -308,45 +312,47 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
   /*
    * 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:
   // Internal constructor, for delegation use only.
-  BytecodeEmitter(BytecodeEmitter* parent, uintptr_t stackLimit,
-                  SharedContext* sc, CompilationState& compilationState,
-                  EmitterMode emitterMode);
+  BytecodeEmitter(BytecodeEmitter* parent, ErrorContext* ec,
+                  uintptr_t stackLimit, SharedContext* sc,
+                  CompilationState& compilationState, EmitterMode emitterMode);
 
   BytecodeEmitter(BytecodeEmitter* parent, BCEParserHandle* handle,
                   SharedContext* sc, CompilationState& compilationState,
                   EmitterMode emitterMode);
 
   void initFromBodyPosition(TokenPos bodyPosition);
 
   /*
    * Helpers for reporting when we have insufficient args.
    */
   [[nodiscard]] bool ensureAtLeastArgs(CallNode* callNode,
                                        uint32_t requiredArgs);
   [[nodiscard]] bool ensureArgs(CallNode* callNode, uint32_t requiredArgs);
   void reportNeedMoreArgsError(CallNode* callNode, uint32_t requiredArgs);
 
  public:
-  BytecodeEmitter(uintptr_t stackLimit, const EitherParser& parser,
-                  SharedContext* sc, CompilationState& compilationState,
+  BytecodeEmitter(ErrorContext* ec, uintptr_t stackLimit,
+                  const EitherParser& parser, SharedContext* sc,
+                  CompilationState& compilationState,
                   EmitterMode emitterMode = Normal);
 
   template <typename Unit>
-  BytecodeEmitter(uintptr_t stackLimit, Parser<FullParseHandler, Unit>* parser,
-                  SharedContext* sc, CompilationState& compilationState,
+  BytecodeEmitter(ErrorContext* ec, uintptr_t stackLimit,
+                  Parser<FullParseHandler, Unit>* parser, SharedContext* sc,
+                  CompilationState& compilationState,
                   EmitterMode emitterMode = Normal)
-      : BytecodeEmitter(stackLimit, EitherParser(parser), sc, compilationState,
-                        emitterMode) {}
+      : BytecodeEmitter(ec, stackLimit, EitherParser(parser), sc,
+                        compilationState, emitterMode) {}
 
   [[nodiscard]] bool init();
   [[nodiscard]] bool init(TokenPos bodyPosition);
 
   template <typename T>
   T* findInnermostNestableControl() const;
 
   template <typename T, typename Predicate /* (T*) -> bool */>