Bug 1638670 - Combine ScriptStencil with ScriptStencilBase. r=mgaudet
authorTed Campbell <tcampbell@mozilla.com>
Wed, 20 May 2020 14:50:09 +0000
changeset 531255 b6bd6cb99d28fa9cb1bfc379b473af5b337137f1
parent 531254 1ab68e0e1e794a1290c4570c58735333627b96eb
child 531256 60c81cfd3a60b343bbf4fb9d46d7860b63b250e2
push id37436
push userncsoregi@mozilla.com
push dateWed, 20 May 2020 21:30:50 +0000
treeherdermozilla-central@6c10970490f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet
bugs1638670
milestone78.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 1638670 - Combine ScriptStencil with ScriptStencilBase. r=mgaudet These were originally split due to ScriptStencil using virtual methods. Those methods no longer exist so we can simplify this. Differential Revision: https://phabricator.services.mozilla.com/D76024
js/src/frontend/CompilationInfo.h
js/src/frontend/Parser.cpp
js/src/frontend/SharedContext.cpp
js/src/frontend/SharedContext.h
js/src/frontend/Stencil.cpp
js/src/frontend/Stencil.h
--- a/js/src/frontend/CompilationInfo.h
+++ b/js/src/frontend/CompilationInfo.h
@@ -20,17 +20,17 @@
 #include "js/SourceText.h"
 #include "js/Vector.h"
 #include "vm/JSContext.h"
 #include "vm/Realm.h"
 
 namespace js {
 namespace frontend {
 
-using FunctionType = mozilla::Variant<JSFunction*, ScriptStencilBase>;
+using FunctionType = mozilla::Variant<JSFunction*, ScriptStencil>;
 
 // ScopeContext hold information derivied from the scope and environment chains
 // to try to avoid the parser needing to traverse VM structures directly.
 struct ScopeContext {
   // Whether the enclosing scope allows certain syntax. Eval and arrow scripts
   // inherit this from their enclosing scipt so we track it here.
   bool allowNewTarget = false;
   bool allowSuperProperty = false;
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -295,17 +295,17 @@ FunctionBox* PerHandlerParser<ParseHandl
     uint32_t toStringStart, Directives inheritedDirectives,
     GeneratorKind generatorKind, FunctionAsyncKind asyncKind) {
   MOZ_ASSERT(funNode);
 
   CompilationInfo& compilationInfo = this->getCompilationInfo();
 
   size_t index = compilationInfo.funcData.length();
   if (!compilationInfo.funcData.emplaceBack(
-          mozilla::AsVariant(ScriptStencilBase(cx_)))) {
+          mozilla::AsVariant(ScriptStencil(cx_)))) {
     return nullptr;
   }
 
   // This source extent will be further filled in during the remainder of parse.
   SourceExtent extent;
   extent.toStringStart = toStringStart;
 
   /*
@@ -1804,17 +1804,17 @@ bool PerHandlerParser<SyntaxParseHandler
   }
 
   MOZ_ASSERT(gcthings.length() == ngcthings.value());
 
   return true;
 }
 
 static bool CreateLazyScript(JSContext* cx, CompilationInfo& compilationInfo,
-                             Handle<ScriptStencilBase> stencil,
+                             Handle<ScriptStencil> stencil,
                              HandleFunction function, FunctionBox* funbox) {
   MOZ_ASSERT(function);
 
   using ImmutableFlags = ImmutableScriptFlagsEnum;
   ImmutableScriptFlags immutableFlags = funbox->immutableFlags();
 
   // Compute the flags that frontend doesn't directly compute.
   immutableFlags.setFlag(ImmutableFlags::HasMappedArgsObj,
@@ -1860,18 +1860,17 @@ static bool MaybePublishFunction(JSConte
   // functions and incomplete function boxes generated by failed syntax
   // parsing.
   if (!funbox->emitLazy && !funbox->emitBytecode) {
     return true;
   }
 
   // Pull the stencil out of the function box before we clobber the funcData
   // array entry with the JSFunction pointer.
-  Rooted<ScriptStencilBase> stencil(cx,
-                                    std::move(funbox->functionStencil().get()));
+  Rooted<ScriptStencil> stencil(cx, std::move(funbox->functionStencil().get()));
 
   RootedFunction fun(cx, funbox->createFunction(cx));
   if (!fun) {
     return false;
   }
 
   funbox->initializeFunction(fun);
 
--- a/js/src/frontend/SharedContext.cpp
+++ b/js/src/frontend/SharedContext.cpp
@@ -247,19 +247,17 @@ JSFunction* FunctionBox::createFunction(
                                 ? gc::AllocKind::FUNCTION_EXTENDED
                                 : gc::AllocKind::FUNCTION;
 
   return NewFunctionWithProto(cx, nullptr, nargs_, flags_, nullptr, atom, proto,
                               allocKind, TenuredObject);
 }
 
 bool FunctionBox::hasFunctionStencil() const {
-  return compilationInfo_.funcData[funcDataIndex_]
-      .get()
-      .is<ScriptStencilBase>();
+  return compilationInfo_.funcData[funcDataIndex_].get().is<ScriptStencil>();
 }
 
 bool FunctionBox::hasFunction() const {
   return compilationInfo_.funcData[funcDataIndex_].get().is<JSFunction*>();
 }
 
 void FunctionBox::initFromLazyFunction(JSFunction* fun) {
   BaseScript* lazy = fun->baseScript();
@@ -424,14 +422,14 @@ ModuleSharedContext::ModuleSharedContext
       module_(cx, module),
       enclosingScope_(cx, enclosingScope),
       bindings(cx),
       builder(builder) {
   thisBinding_ = ThisBinding::Module;
   setFlag(ImmutableFlags::HasModuleGoal);
 }
 
-MutableHandle<ScriptStencilBase> FunctionBox::functionStencil() const {
-  return compilationInfo_.funcData[funcDataIndex_].as<ScriptStencilBase>();
+MutableHandle<ScriptStencil> FunctionBox::functionStencil() const {
+  return compilationInfo_.funcData[funcDataIndex_].as<ScriptStencil>();
 }
 
 }  // namespace frontend
 }  // namespace js
--- a/js/src/frontend/SharedContext.h
+++ b/js/src/frontend/SharedContext.h
@@ -383,17 +383,17 @@ class FunctionBox : public SharedContext
 
   FunctionBox(JSContext* cx, FunctionBox* traceListHead, SourceExtent extent,
               CompilationInfo& compilationInfo, Directives directives,
               GeneratorKind generatorKind, FunctionAsyncKind asyncKind,
               JSAtom* explicitName, FunctionFlags flags, size_t index);
 
   JSFunction* createFunction(JSContext* cx);
 
-  MutableHandle<ScriptStencilBase> functionStencil() const;
+  MutableHandle<ScriptStencil> functionStencil() const;
 
   bool hasFunctionStencil() const;
   bool hasFunction() const;
 
 #ifdef DEBUG
   bool atomsAreKept();
 #endif
 
--- a/js/src/frontend/Stencil.cpp
+++ b/js/src/frontend/Stencil.cpp
@@ -194,17 +194,17 @@ uint32_t ScopeCreationData::nextFrameSlo
           "nextFrameSlot()");
       return 0;
   }
   MOZ_CRASH("Not an enclosing intra-frame scope");
 }
 
 bool ScopeCreationData::isArrow() const { return funbox_->isArrow(); }
 
-void ScriptStencilBase::trace(JSTracer* trc) {
+void ScriptStencil::trace(JSTracer* trc) {
   for (ScriptThingVariant& thing : gcThings) {
     if (thing.is<ScriptAtom>()) {
       JSAtom* atom = thing.as<ScriptAtom>();
       TraceRoot(trc, &atom, "script-atom");
       MOZ_ASSERT(atom == thing.as<ScriptAtom>(), "Atoms should be unmovable");
     }
   }
 }
--- a/js/src/frontend/Stencil.h
+++ b/js/src/frontend/Stencil.h
@@ -334,43 +334,39 @@ using ScriptAtom = JSAtom*;
 using ScriptThingVariant =
     mozilla::Variant<ScriptAtom, NullScriptThing, BigIntIndex,
                      ObjLiteralCreationData, RegExpIndex, ScopeIndex,
                      FunctionIndex, EmptyGlobalScopeType>;
 
 // A vector of things destined to be converted to GC things.
 using ScriptThingsVector = Vector<ScriptThingVariant>;
 
-// Non-virtual base class for ScriptStencil.
-class ScriptStencilBase {
+// Data generated by frontend that will be used to create a js::BaseScript.
+class ScriptStencil {
  public:
   // See `BaseScript::functionOrGlobal_`.
   mozilla::Maybe<FunctionIndex> functionIndex;
 
   // See `BaseScript::immutableFlags_`.
   ImmutableScriptFlags immutableFlags;
 
   // See `BaseScript::data_`.
   mozilla::Maybe<FieldInitializers> fieldInitializers;
   ScriptThingsVector gcThings;
 
   // See `BaseScript::sharedData_`.
   js::UniquePtr<js::ImmutableScriptData> immutableScriptData = nullptr;
 
-  explicit ScriptStencilBase(JSContext* cx) : gcThings(cx) {}
+  // End of fields.
+
+  explicit ScriptStencil(JSContext* cx) : gcThings(cx) {}
 
   // This traces any JSAtoms in the gcThings array. This will be removed once
   // atoms are deferred from parsing.
   void trace(JSTracer* trc);
-};
-
-// Data used to instantiate the non-lazy script.
-class ScriptStencil : public ScriptStencilBase {
- public:
-  explicit ScriptStencil(JSContext* cx) : ScriptStencilBase(cx) {}
 
   // Allocate a JSScript and initialize it with bytecode. This consumes
   // allocations within this stencil.
   JSScript* intoScript(JSContext* cx, CompilationInfo& compilationInfo,
                        SourceExtent extent);
 };
 
 } /* namespace js::frontend */