Bug 1183400 - Constant-fold yield/yield*/return by kind and not arity. r=shu
authorJeff Walden <jwalden@mit.edu>
Thu, 09 Jul 2015 20:58:14 -0700
changeset 256908 efd0dbc0cf17ed1afc38f130576838623c8fdfcd
parent 256907 6019d456196c067839ab683bc0846438bb0d97b1
child 256909 0ca4340aaf49a8b547011987958756d5b54277fa
push id29194
push userphilringnalda@gmail.com
push dateSat, 08 Aug 2015 22:08:06 +0000
treeherdermozilla-central@d263ff7885e9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshu
bugs1183400
milestone42.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 1183400 - Constant-fold yield/yield*/return by kind and not arity. r=shu
js/src/frontend/FoldConstants.cpp
--- a/js/src/frontend/FoldConstants.cpp
+++ b/js/src/frontend/FoldConstants.cpp
@@ -1291,16 +1291,39 @@ FoldList(ExclusiveContext* cx, ParseNode
     // Repoint the list's tail pointer if the final element was replaced.
     list->pn_tail = elem;
 
     list->checkListConsistency();
 
     return true;
 }
 
+static bool
+FoldReturn(ExclusiveContext* cx, ParseNode* node, Parser<FullParseHandler>& parser,
+           bool inGenexpLambda)
+{
+    MOZ_ASSERT(node->isKind(PNK_RETURN));
+    MOZ_ASSERT(node->isArity(PN_BINARY));
+
+    if (ParseNode*& expr = node->pn_left) {
+        if (!Fold(cx, &expr, parser, inGenexpLambda, SyntacticContext::Other))
+            return false;
+    }
+
+#ifdef DEBUG
+    if (ParseNode* generatorSpecific = node->pn_right) {
+        MOZ_ASSERT(generatorSpecific->isKind(PNK_NAME));
+        MOZ_ASSERT(generatorSpecific->pn_atom->equals(".genrval"));
+        MOZ_ASSERT(generatorSpecific->isAssigned());
+    }
+#endif
+
+    return true;
+}
+
 bool
 Fold(ExclusiveContext* cx, ParseNode** pnp, Parser<FullParseHandler>& parser, bool inGenexpLambda,
      SyntacticContext sc)
 {
     JS_CHECK_RECURSION(cx, return false);
 
     ParseNode* pn = *pnp;
     ParseNode* pn1 = nullptr;
@@ -1440,16 +1463,35 @@ Fold(ExclusiveContext* cx, ParseNode** p
       case PNK_GLOBALCONST:
       case PNK_LET:
       case PNK_ARGSBODY:
       case PNK_CALLSITEOBJ:
       case PNK_EXPORT_SPEC_LIST:
       case PNK_IMPORT_SPEC_LIST:
         return FoldList(cx, pn, parser, inGenexpLambda);
 
+      case PNK_YIELD_STAR:
+        MOZ_ASSERT(pn->isArity(PN_BINARY));
+        MOZ_ASSERT(pn->pn_right->isKind(PNK_NAME));
+        MOZ_ASSERT(!pn->pn_right->isAssigned());
+        return Fold(cx, &pn->pn_left, parser, inGenexpLambda, SyntacticContext::Other);
+
+      case PNK_YIELD:
+        MOZ_ASSERT(pn->isArity(PN_BINARY));
+        MOZ_ASSERT((pn->pn_right->isKind(PNK_NAME) && !pn->pn_right->isAssigned()) ||
+                   (pn->pn_right->isKind(PNK_ASSIGN) &&
+                    pn->pn_right->pn_left->isKind(PNK_NAME) &&
+                    pn->pn_right->pn_right->isKind(PNK_GENERATOR)));
+        if (!pn->pn_left)
+            return true;
+        return Fold(cx, &pn->pn_left, parser, inGenexpLambda, SyntacticContext::Other);
+
+      case PNK_RETURN:
+        return FoldReturn(cx, pn, parser, inGenexpLambda);
+
       case PNK_EXPORT:
       case PNK_ASSIGN:
       case PNK_ADDASSIGN:
       case PNK_SUBASSIGN:
       case PNK_BITORASSIGN:
       case PNK_BITXORASSIGN:
       case PNK_BITANDASSIGN:
       case PNK_LSHASSIGN:
@@ -1467,19 +1509,16 @@ Fold(ExclusiveContext* cx, ParseNode** p
       case PNK_WHILE:
       case PNK_SWITCH:
       case PNK_LETBLOCK:
       case PNK_FOR:
       case PNK_CLASSMETHOD:
       case PNK_WITH:
       case PNK_CLASSNAMES:
       case PNK_DEFAULT:
-      case PNK_YIELD_STAR:
-      case PNK_YIELD:
-      case PNK_RETURN:
       case PNK_IMPORT:
       case PNK_EXPORT_FROM:
       case PNK_EXPORT_DEFAULT:
       case PNK_FORIN:
       case PNK_FOROF:
       case PNK_FORHEAD:
       case PNK_CLASS:
       case PNK_TRY: