We don't have to parse a function's parameters every time if the function is in the source provider cache
https://bugs.webkit.org/show_bug.cgi?id=156943

Reviewed by Filip Pizlo.

This patch makes a few changes to make parsing inner functions
faster.

First, we were always parsing an inner function's parameter
list using the templatized TreeBuiler. This means if our parent scope
was building an AST, we ended up building AST nodes for the inner
function's parameter list even though these nodes would go unused.
This patch fixes that to *always* build an inner function's parameter
list using the SyntaxChecker. (Note that this is consistent now with
always building an inner function's body with a SyntaxChecker.)

Second, we were always parsing an inner function's parameter list
even if we had that function saved in the source provider cache.
I've fixed that bug and made it so that we skip over the parsing
of a function's parameter list when it's in the source provider
cache. We could probably enhance this in the future to skip
over the entirety of a function starting at the "function"
keyword or any other start of the function (depending on
the function type: arrow function, method, etc).

This patch also renames a few fields. First, I fixed a typo
from "tocken" => "token" for a few field names. Secondly,
I renamed a field that was called 'bodyStartColumn' to
'parametersStartColumn' because the field really held the
parameter list's start column.

I'm benchmarking this as a 1.5-2% octane/jquery speedup
on a 15" MBP.

* parser/ASTBuilder.h:
(JSC::ASTBuilder::createFunctionExpr):
(JSC::ASTBuilder::createMethodDefinition):
(JSC::ASTBuilder::createArrowFunctionExpr):
(JSC::ASTBuilder::createGetterOrSetterProperty):
(JSC::ASTBuilder::createFuncDeclStatement):
* parser/Lexer.cpp:
(JSC::Lexer<T>::lex):
* parser/Lexer.h:
(JSC::Lexer::currentPosition):
(JSC::Lexer::positionBeforeLastNewline):
(JSC::Lexer::lastTokenLocation):
(JSC::Lexer::setLastLineNumber):
(JSC::Lexer::lastLineNumber):
(JSC::Lexer::prevTerminator):
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseInner):
(JSC::Parser<LexerType>::parseGeneratorFunctionSourceElements):
(JSC::Parser<LexerType>::parseFunctionBody):
(JSC::stringForFunctionMode):
(JSC::Parser<LexerType>::parseFunctionParameters):
(JSC::Parser<LexerType>::parseFunctionInfo):
* parser/Parser.h:
(JSC::Scope::usedVariablesContains):
(JSC::Scope::forEachUsedVariable):
(JSC::Scope::useVariable):
(JSC::Scope::copyCapturedVariablesToVector):
(JSC::Scope::fillParametersForSourceProviderCache):
(JSC::Scope::restoreFromSourceProviderCache):
* parser/ParserFunctionInfo.h:
* parser/SourceProviderCacheItem.h:
(JSC::SourceProviderCacheItem::endFunctionToken):
(JSC::SourceProviderCacheItem::usedVariables):
(JSC::SourceProviderCacheItem::SourceProviderCacheItem):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@200038 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/parser/SourceProviderCacheItem.h b/Source/JavaScriptCore/parser/SourceProviderCacheItem.h
index 89c82a1..8159434 100644
--- a/Source/JavaScriptCore/parser/SourceProviderCacheItem.h
+++ b/Source/JavaScriptCore/parser/SourceProviderCacheItem.h
@@ -35,10 +35,10 @@
 
 struct SourceProviderCacheItemCreationParameters {
     unsigned functionNameStart;
-    unsigned lastTockenLine;
-    unsigned lastTockenStartOffset;
-    unsigned lastTockenEndOffset;
-    unsigned lastTockenLineStartOffset;
+    unsigned lastTokenLine;
+    unsigned lastTokenStartOffset;
+    unsigned lastTokenEndOffset;
+    unsigned lastTokenLineStartOffset;
     unsigned endFunctionOffset;
     unsigned parameterCount;
     bool needsFullActivation;
@@ -48,6 +48,8 @@
     Vector<UniquedStringImpl*, 8> usedVariables;
     bool isBodyArrowExpression { false };
     JSTokenType tokenType { CLOSEBRACE };
+    ConstructorKind constructorKind;
+    SuperBinding expectedSuperBinding;
 };
 
 #if COMPILER(MSVC)
@@ -65,11 +67,11 @@
     {
         JSToken token;
         token.m_type = isBodyArrowExpression ? tokenType : CLOSEBRACE;
-        token.m_data.offset = lastTockenStartOffset;
-        token.m_location.startOffset = lastTockenStartOffset;
-        token.m_location.endOffset = lastTockenEndOffset;
-        token.m_location.line = lastTockenLine;
-        token.m_location.lineStartOffset = lastTockenLineStartOffset;
+        token.m_data.offset = lastTokenStartOffset;
+        token.m_location.startOffset = lastTokenStartOffset;
+        token.m_location.endOffset = lastTokenEndOffset;
+        token.m_location.line = lastTokenLine;
+        token.m_location.lineStartOffset = lastTokenLineStartOffset;
         // token.m_location.sourceOffset is initialized once by the client. So,
         // we do not need to set it here.
         return token;
@@ -77,26 +79,23 @@
 
     unsigned functionNameStart : 31;
     bool needsFullActivation : 1;
-
     unsigned endFunctionOffset : 31;
-    unsigned lastTockenLine : 31;
-    unsigned lastTockenStartOffset : 31;
-    unsigned lastTockenEndOffset: 31;
-    unsigned parameterCount;
-    
     bool usesEval : 1;
-
+    unsigned lastTokenLine : 31;
     bool strictMode : 1;
-    
-    InnerArrowFunctionCodeFeatures innerArrowFunctionFeatures;
-
-    unsigned lastTockenLineStartOffset;
+    unsigned lastTokenStartOffset : 31;
+    unsigned lastTokenEndOffset: 31;
+    unsigned constructorKind : 2; // ConstructorKind
+    unsigned parameterCount : 31;
+    unsigned expectedSuperBinding : 1; // SuperBinding
+    unsigned lastTokenLineStartOffset;
     unsigned usedVariablesCount;
-
-    UniquedStringImpl** usedVariables() const { return const_cast<UniquedStringImpl**>(m_variables); }
+    InnerArrowFunctionCodeFeatures innerArrowFunctionFeatures;
     bool isBodyArrowExpression;
     JSTokenType tokenType;
 
+    UniquedStringImpl** usedVariables() const { return const_cast<UniquedStringImpl**>(m_variables); }
+
 private:
     SourceProviderCacheItem(const SourceProviderCacheItemCreationParameters&);
 
@@ -121,15 +120,17 @@
     : functionNameStart(parameters.functionNameStart)
     , needsFullActivation(parameters.needsFullActivation)
     , endFunctionOffset(parameters.endFunctionOffset)
-    , lastTockenLine(parameters.lastTockenLine)
-    , lastTockenStartOffset(parameters.lastTockenStartOffset)
-    , lastTockenEndOffset(parameters.lastTockenEndOffset)
-    , parameterCount(parameters.parameterCount)
     , usesEval(parameters.usesEval)
+    , lastTokenLine(parameters.lastTokenLine)
     , strictMode(parameters.strictMode)
-    , innerArrowFunctionFeatures(parameters.innerArrowFunctionFeatures)
-    , lastTockenLineStartOffset(parameters.lastTockenLineStartOffset)
+    , lastTokenStartOffset(parameters.lastTokenStartOffset)
+    , lastTokenEndOffset(parameters.lastTokenEndOffset)
+    , constructorKind(static_cast<unsigned>(parameters.constructorKind))
+    , parameterCount(parameters.parameterCount)
+    , expectedSuperBinding(static_cast<unsigned>(parameters.expectedSuperBinding))
+    , lastTokenLineStartOffset(parameters.lastTokenLineStartOffset)
     , usedVariablesCount(parameters.usedVariables.size())
+    , innerArrowFunctionFeatures(parameters.innerArrowFunctionFeatures)
     , isBodyArrowExpression(parameters.isBodyArrowExpression)
     , tokenType(parameters.tokenType)
 {