Bug 1528844 - Move ParseNode allocation from BinASTParserBase to FullParseHandler. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Sun, 24 Feb 2019 09:42:53 +0000
changeset 518662 58e77ffe2a65
parent 518661 151271d3dfc2
child 518663 b5889271779f
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1528844
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 1528844 - Move ParseNode allocation from BinASTParserBase to FullParseHandler. r=Yoric BinASTParserBase::allocParseNode was used only for creating ParseNodeKind::ParamsBody node, and other nodes are created by FullParseHandler. Added FullParseHandler::newParamsBody and removed ParseNode allocation methods from BinASTParserBase. Differential Revision: https://phabricator.services.mozilla.com/D20774
js/src/frontend/BinASTParser.cpp
js/src/frontend/BinASTParserBase.cpp
js/src/frontend/BinASTParserBase.h
js/src/frontend/BinSource.yaml
js/src/frontend/FullParseHandler.h
--- a/js/src/frontend/BinASTParser.cpp
+++ b/js/src/frontend/BinASTParser.cpp
@@ -3130,19 +3130,17 @@ JS::Result<Ok> BinASTParser<Tok>::parseI
   MOZ_TRY(tokenizer_->checkFields(kind, fields, expected_fields));
 #endif  // defined(DEBUG)
 
   BINJS_MOZ_TRY_DECL(isThisCaptured, tokenizer_->readBool());
   // TODO: Use this in BinASTParser::buildFunction.
   (void)isThisCaptured;
   MOZ_TRY(parseAssertedVarScope());
 
-  BINJS_TRY_DECL(params,
-                 this->template new_<ListNode>(ParseNodeKind::ParamsBody,
-                                               tokenizer_->pos(start)));
+  BINJS_TRY_DECL(params, handler_.newParamsBody(tokenizer_->pos(start)));
   BINJS_MOZ_TRY_DECL(body, parseFunctionBody());
 
   *paramsOut = params;
   *bodyOut = body;
   auto result = Ok();
   return result;
 }
 
@@ -3716,18 +3714,17 @@ JS::Result<Ok> BinASTParser<Tok>::parseI
 
   BINJS_MOZ_TRY_DECL(isThisCaptured, tokenizer_->readBool());
   // TODO: Use this in BinASTParser::buildFunction.
   (void)isThisCaptured;
   Rooted<GCVector<JSAtom*>> positionalParams(cx_, GCVector<JSAtom*>(cx_));
   MOZ_TRY(parseAssertedParameterScope(&positionalParams));
 
   BINJS_MOZ_TRY_DECL(param, parseParameter());
-  BINJS_TRY_DECL(params, this->template new_<ListNode>(
-                             ParseNodeKind::ParamsBody, param->pn_pos));
+  BINJS_TRY_DECL(params, handler_.newParamsBody(param->pn_pos));
   handler_.addList(params, param);
   MOZ_TRY(checkPositionalParameterIndices(positionalParams, params));
   MOZ_TRY(parseAssertedVarScope());
 
   BINJS_MOZ_TRY_DECL(body, parseFunctionBody());
 
   *paramsOut = params;
   *bodyOut = body;
@@ -4746,19 +4743,17 @@ BinASTParser<Tok>::parseListOfOptionalSp
 
 template <typename Tok>
 JS::Result<ListNode*> BinASTParser<Tok>::parseListOfParameter() {
   uint32_t length;
   AutoList guard(*tokenizer_);
 
   const auto start = tokenizer_->offset();
   MOZ_TRY(tokenizer_->enterList(length, guard));
-  BINJS_TRY_DECL(result,
-                 this->template new_<ListNode>(ParseNodeKind::ParamsBody,
-                                               tokenizer_->pos(start)));
+  BINJS_TRY_DECL(result, handler_.newParamsBody(tokenizer_->pos(start)));
 
   for (uint32_t i = 0; i < length; ++i) {
     BINJS_MOZ_TRY_DECL(item, parseParameter());
     handler_.addList(/* list = */ result, /* kid = */ item);
   }
 
   MOZ_TRY(guard.done());
   return result;
--- a/js/src/frontend/BinASTParserBase.cpp
+++ b/js/src/frontend/BinASTParserBase.cpp
@@ -11,16 +11,15 @@
 namespace js {
 namespace frontend {
 
 BinASTParserBase::BinASTParserBase(JSContext* cx, LifoAlloc& alloc,
                                    UsedNameTracker& usedNames,
                                    HandleScriptSourceObject sourceObject,
                                    Handle<LazyScript*> lazyScript)
     : ParserSharedBase(cx, alloc, usedNames, sourceObject),
-      nodeAlloc_(cx, alloc),
       lazyScript_(cx, lazyScript),
       handler_(cx, alloc, nullptr, SourceKind::Binary) {
   MOZ_ASSERT_IF(lazyScript, lazyScript->isBinAST());
 }
 
 }  // namespace frontend
 }  // namespace js
--- a/js/src/frontend/BinASTParserBase.h
+++ b/js/src/frontend/BinASTParserBase.h
@@ -36,26 +36,16 @@ class BinASTParserBase : public ParserSh
 
   virtual void doTrace(JSTracer* trc) {}
 
   void trace(JSTracer* trc) {
     TraceListNode::TraceList(trc, traceListHead_);
     doTrace(trc);
   }
 
- public:
-  ParseNode* allocParseNode(size_t size) {
-    return static_cast<ParseNode*>(nodeAlloc_.allocNode(size));
-  }
-
-  JS_DECLARE_NEW_METHODS(new_, allocParseNode, inline)
-
- private:
-  ParseNodeAllocator nodeAlloc_;
-
   // ---- Parsing-related stuff
  protected:
   Rooted<LazyScript*> lazyScript_;
   FullParseHandler handler_;
 
   friend class BinParseContext;
 };
 
--- a/js/src/frontend/BinSource.yaml
+++ b/js/src/frontend/BinSource.yaml
@@ -877,28 +877,24 @@ FunctionExpressionContents:
 FunctionOrMethodContents:
   inherits: FunctionExpressionContents
 
 GetterContents:
   inherits: FunctionExpressionContents
   fields:
     body:
       before: |
-        BINJS_TRY_DECL(params,
-                       this->template new_<ListNode>(ParseNodeKind::ParamsBody,
-                                                     tokenizer_->pos(start)));
+        BINJS_TRY_DECL(params, handler_.newParamsBody(tokenizer_->pos(start)));
 
 SetterContents:
   inherits: FunctionExpressionContents
   fields:
     param:
       after: |
-        BINJS_TRY_DECL(params,
-                       this->template new_<ListNode>(ParseNodeKind::ParamsBody,
-                                                     param->pn_pos));
+        BINJS_TRY_DECL(params, handler_.newParamsBody(param->pn_pos));
         handler_.addList(params, param);
         MOZ_TRY(checkPositionalParameterIndices(positionalParams, params));
 
 EagerFunctionExpression:
   init: |
     const auto syntax = FunctionSyntaxKind::Expression;
   fields:
     isGenerator:
@@ -1208,38 +1204,34 @@ ListOfOptionalSpreadElementOrExpression:
     } else {
       BINJS_TRY(handler_.addElision(result, tokenizer_->pos(start)));
     }
 
 ListOfParameter:
   type-ok:
     ListNode*
   init: |
-    BINJS_TRY_DECL(result,
-                   this->template new_<ListNode>(ParseNodeKind::ParamsBody,
-                                                 tokenizer_->pos(start)));
+    BINJS_TRY_DECL(result, handler_.newParamsBody(tokenizer_->pos(start)));
   append:
     handler_.addList(/* list = */ result, /* kid = */ item);
 
 ListOfStatement:
   type-ok:
     ListNode*
   init:
     BINJS_TRY_DECL(result, handler_.newStatementList(tokenizer_->pos(start)));
   append:
     handler_.addStatementToList(result, item);
 
 
 #ListOfSpreadElementOrExpression:
 #  type-ok:
 #    ListNode*
 #  init:
-#    BINJS_TRY_DECL(result,
-#                   this->template new_<ListNode>(ParseNodeKind::ParamsBody,
-#                                                 tokenizer_->pos()));
+#    BINJS_TRY_DECL(result, handler_.newParamsBody(tokenizer_->pos()));
 #  append:
 #    result->appendWithoutOrderAssumption(item);
 
 ListOfSwitchCase:
   type-ok:
     ListNode*
   init:
     BINJS_TRY_DECL(result, handler_.newStatementList(tokenizer_->pos(start)));
--- a/js/src/frontend/FullParseHandler.h
+++ b/js/src/frontend/FullParseHandler.h
@@ -785,16 +785,20 @@ class FullParseHandler {
   }
 
   BinaryNodeType newShorthandPropertyDefinition(Node key, Node value) {
     MOZ_ASSERT(isUsableAsObjectPropertyName(key));
 
     return newBinary(ParseNodeKind::Shorthand, key, value, JSOP_INITPROP);
   }
 
+  ListNodeType newParamsBody(const TokenPos& pos) {
+    return new_<ListNode>(ParseNodeKind::ParamsBody, pos);
+  }
+
   void setFunctionFormalParametersAndBody(FunctionNodeType funNode,
                                           ListNodeType paramsBody) {
     MOZ_ASSERT_IF(paramsBody, paramsBody->isKind(ParseNodeKind::ParamsBody));
     funNode->setBody(paramsBody);
   }
   void setFunctionBox(FunctionNodeType funNode, FunctionBox* funbox) {
     funNode->setFunbox(funbox);
     funbox->functionNode = funNode;