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 460780 58e77ffe2a6578090f6e986d9820d1c861f3c306
parent 460779 151271d3dfc2a4a509bac6608318b7e09a1cbf9d
child 460781 b5889271779fc3316a4cc5092bbb8ac8b8801519
push id35603
push userdluca@mozilla.com
push dateMon, 25 Feb 2019 01:46:40 +0000
treeherdermozilla-central@3a2ced4fbd98 [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;